-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add cuboid_phantom #1446
base: master
Are you sure you want to change the base?
ENH: Add cuboid_phantom #1446
Conversation
Could this get a review please? |
I'll have a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of things, please check.
Code reuse is quite low in the module. For instance, the cuboid_phantom
function seems to have about 95 % overlap with ellipsoid_phantom
(not counting the docstring). And major parts of _cuboid_phantom_2d
are copy-pasted from the ellipse case as well.
If you see a possibility, try to factor out the parts that allow it. Otherwise, please add a TODO comment.
else: | ||
# Calculate the points that could possibly be inside the volume | ||
max_radius = np.sqrt([a_squared, b_squared]) | ||
idx, shapes = _getshapes_2d(center, max_radius, space.shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have to do this for non-rotated rectangles? Can't you just get the min and max per axis and use those directly as bounding boxes? In other words, can't you directly construct slice
objects from the min and max and use those for indexing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OTOH, I can see why you want to use the same kind of logic. Maybe it's okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just leave this as is since the other optimization is relatively minor for most cases. This would only give a notable improvement in the case of slightly rotated and very elongated rectangles, which I'll just leave for now.
odl/phantom/geometric.py
Outdated
# Parentheses to get best order for broadcasting | ||
max_distance = np.maximum(squared_dist[0], squared_dist[1]) | ||
|
||
# Find the points within the ellipse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rectangle?
odl/phantom/geometric.py
Outdated
# Find the points within the ellipse | ||
inside = max_distance <= 1 | ||
|
||
# Add the ellipse intensity to those points |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
||
The provided cuboids need to be specified relative to the | ||
reference rectangle ``[-1, -1] x [1, 1]``. | ||
The angles are to be given in radians. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about 3D?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3D is not currently supported, I'll update the rest to reflect this
odl/phantom/geometric.py
Outdated
The phantom is created by adding the values of each cuboid. The | ||
cuboid are defined by a center point | ||
``(center_x, center_y, [center_z])``, the lengths of its principial | ||
axes ``(axis_1, axis_2, [axis_2])``, and a rotation angle ``rotation`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
axis_3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But since 3D isn't supported, remove 3rd axis stuff.
odl/phantom/geometric.py
Outdated
[ 0., 1., 2., 1., 0.], | ||
[ 1., 2., 2., 2., 1.], | ||
[ 0., 1., 2., 1., 0.], | ||
[ 0., 0., 1., 0., 0.]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is not right with this example. It doesn't look like a cuboid to me.
odl/phantom/geometric.py
Outdated
Space in which the phantom should be created, must be 2- or | ||
3-dimensional. If ``space.shape`` is 1 in an axis, a corresponding | ||
slice of the phantom is created (instead of squashing the whole | ||
phantom into the slice). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3D is not supported, so this needs an update
odl/phantom/geometric.py
Outdated
space, min_pt=snapped_min_pt, max_pt=snapped_max_pt, | ||
cell_sides=space.cell_sides) | ||
|
||
tmp_phantom = _phantom(tmp_space, ellipsoids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch has obviously never been run, since it cannot work.
Checking updated PR...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing to fix, after that I guess we can merge.
space = odl.uniform_discr([-1, -1], [1, 1], [300, 300]) | ||
ellipses = [[1.0, 0.6, 0.6, 0.0, 0.0, 1.5], | ||
[1.0, 0.1, 0.3, 0.0, 0.0, 0.3]] | ||
cuboid_phantom(space, ellipses).show('cuboid phantom 2d') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use cuboids
or cubes
instead of ellipses
.
No description provided.