Skip to content
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

Major fix for get_s for BlocksOnCylindrical along with with minor changes #2

Closed
wants to merge 15 commits into from
Closed

Conversation

VietAnhDao
Copy link

No description provided.

@VietAnhDao
Copy link
Author

@KrisThielemans
Copy link

There's still some gremlins here. In addition, there's too many white-space changes. I'd prefer that you undo them. This PR should be as small as possible. At the moment, I have to append ?w=1 to the URL in the review as otherwise I'm overwhelmed. Even then there are quite a few changes that have nothing to do with code.

We'll solve the formatting after merging the PRs.

@VietAnhDao
Copy link
Author

VietAnhDao commented Oct 11, 2021

  • Scatter estimation & some of SSRB changes was reverted/deleted. Previously changes was made so BoC projection data was forced to be accepted and it is better to undo these changes. As a consequence scatter estimation will now have break segmentation error if ran with BoC data.
  • Scatter simulation still works fine.

Copy link

@KrisThielemans KrisThielemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still some white-space diffs left unfortunately.

Main thing is that the SSRB code doesn't look correct

error(boost::format("ScatterSimulation: limitation in #planes and voxel-size for the %1% image.\n"
"This would cause a shift of %2%mm w.r.t. the activity image.\n"
"(see https://github.com/UCL/STIR/issues/495.")
% name % (z_to_middle - z_to_middle_standard));
% name % (z_to_middle - z_to_middle_standard));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white space

else if (!is_null_ptr(proj_data_info_cyl_noarc_cor_sptr))
{
const float total_axial_length = proj_data_info_cyl_noarc_cor_sptr->get_scanner_sptr()->get_num_rings() *
proj_data_info_cyl_noarc_cor_sptr->get_scanner_sptr()->get_ring_spacing();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white space

// Find how much is the delta ring
// If the previous projdatainfo had max segment == 1 then should be from SSRB
// in ScatterEstimation. Otherwise use the max possible.
int delta_ring = proj_data_info_cyl_noarc_cor_sptr->get_num_segments() == 1 ? 0 :
new_scanner_sptr->get_num_rings()-1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white space

@VietAnhDao
Copy link
Author

Completely reverted SSRB code. A proper implementation for SSRB will be given in separate PR.

Comment on lines +773 to +778
if (proj_data_info_ptr->get_scanner_ptr()->get_scanner_geometry() == "BlocksOnCylindrical")
{
fovrad_in_mm =
min((min(max_index.x(), -min_index.x()) - 5.f) * voxel_size.x(),
(min(max_index.y(), -min_index.y()) - 5.f) * voxel_size.y());
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document why you need this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reducing the fovrad_in_mm prevent memory leak. Due to radius problem in "BlocksOnCylindrical" it might perform ray tracing where voxels doesn't exist. This might be the source of memory leak. I don't know too much about C++ technicality behind this but I know that if I perform reconstruction without -5.f or use +5.f then memory leak will occur. This I have tested.

@KrisThielemans
Copy link

will need to add some code to test_ScatterSimulation to run the test with a block scanner. Likely needs adding code for the downsampling of such a scanner.

Comment on lines 388 to 390
// BlocksOnCylindrical geometry is already align no shifted needed.
this->shift_detector_coordinates_to_origin =
CartesianCoordinate3D<float>(0,0,0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In @danieldeidda's change, we shifted the "blocks" geometry to coincide with the cylindrical one. (i.e. 0 in first ring), so we will need to replace this code with the same as the lines above

Comment on lines 691 to 693
if (costheta < 0.0001) {
costheta = 0.0001;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is what we think for get_tantheta() independent of R

CartesianCoordinate3D<float> _p1;
CartesianCoordinate3D<float> _p2;
find_cartesian_coordinates_of_detection(_p1, _p2, bin);
CartesianCoordinate3D<float> p2_minus_p1 = _p2 - _p1;
return p2_minus_p1.z() / (sqrt(square(p2_minus_p1.x())+square(p2_minus_p1.y());

VietAnhDao and others added 2 commits November 8, 2021 16:36
Co-authored-by: Kris Thielemans <KrisThielemans@users.noreply.github.com>
Co-authored-by: Kris Thielemans <KrisThielemans@users.noreply.github.com>
@KrisThielemans
Copy link

Thanks! Sadly, we cannot merge as there is a conflict in src/buildblock/GeometryBlocksOnCylindrical.cxx. git cannot resolve them most likely due to white-space changes (which is one reason I don't like them :-)).

In particular, start_z has been changed by @danieldeidda.

Can you merge pkhateri/master on yours and sort out the conflict? sorry.

@@ -668,6 +669,7 @@ calculate_proj_matrix_elems_for_one_bin(

phi = proj_data_info_noarccor.get_phi(bin);
s_in_mm = proj_data_info_noarccor.get_s(bin);
tantheta = proj_data_info_noarccor.get_tantheta(bin);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it repeated here? You've already set it above. (in fact, s_in_mm is also set above)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was set before I downcast the projection data so it would be accessible outside if statement and repeated inside the if statement to get correct value from each geometry of projection data.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_tantheta is virtual, so downcasting or not makes no difference: it will call the same function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't know this. What would happen if there is multiple get_tantheta() for each geometry?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pointer points to one particular object. Calling one of its virtual functions will call the one from its type, even if the pointer is from a base type. "run-time polymorphism" :-)

Copy link

@KrisThielemans KrisThielemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found 2 more things. sorry.

I also noticed you marked several of my requests to reinstate white-space/comment to the original lines as "resolved", but they are still there. Not sure why you did that. However, this is a minor thing, so feel free to ignore.

Comment on lines 689 to 690

float costheta = 1/sqrt(1+square(tantheta));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, these lines can now be reinstated, and all the tantheta lines above removed, which will lead to a smaller change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sorry, I thought I made the changes to fix the white space problem so I marked as resolve. Not too sure if it's me or you who should be marking them as resolved, if it's not resolved just mark them as unresolved again.

As for the git conflict, do I do git merge master? My plan is probably add Daniels changes then delete the "X" orientation code after.

@KrisThielemans
Copy link

KrisThielemans commented Nov 8, 2021

As for the git conflict, do I do git merge master? My plan is probably add Daniels changes then delete the "X" orientation code after.

what you should normally do is (assuming that you called the remote pointing to Parisa's fork pkatheri)

git fetch pkhateri
git checkout BlockSTIR # just to make sure
git merge pkhateri/master
# resolve conflict by editing src/buildblock/GeometryBlocksOnCylindrical.cxx
git add src/buildblock/GeometryBlocksOnCylindrical.cxx
git commit

This will pull in Daniel's new test but also the conflicting edits, which is why you need to resolve them. (i.e. no need to remove the "X" configuration again)

@KrisThielemans
Copy link

I thought I made the changes to fix the white space problem so I marked as resolve. Not too sure if it's me or you who should be marking them as resolved, if it's not resolved just mark them as unresolved again.

Looks like I cannot "unresolve". Have a look at the diff in ScatterEstimation.cxx.

see start_x*/

//calculate start_point to build the map.
<<<<<<< HEAD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well. no. You've now committed the file that contains the conflict, i.e. it has both versions (your code here, and the original pkhateri/master code below). You need to manually edit the file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok figured out what happened. VS code trying to be helpful shows the conflict as an overlay and some options to resolve the conflict. Unfortunately, unless I select an option it will keep both changes which is what it did :) .

@KrisThielemans
Copy link

great. thanks. Can you sort out the tantheta comments in src/recon_buildblock/ProjMatrixByBinUsingRayTracing.cxx. Possibly the white-space/comment stuff in the scatter code. Then ready to go!

@KrisThielemans
Copy link

@danieldeidda @emikhay this is nearly ready. Any objections from anyone to squash-merge (as opposed to merge) when done? The disadvantage is that it gets you into trouble if you've merged this PR somewhere else already. The advantage however is that it removes a lot of the back and forth commits, so I'd prefer that.

If no problem, @VietAnhDao it'd help if you draft a commit message for the squash-merge, i.e. a few bullets with the actual changes that survived.

- s coodrinate is derived from vectors.
- tantheta is derived from vectors.
- scatter simulation accept BlocksOnCylindrical.
@VietAnhDao
Copy link
Author

done :) . I hope I've removed all the white space.

@KrisThielemans
Copy link

I hope I've removed all the white space.

almost, but fine 😄

- s coodrinate is derived from vectors.
- tantheta is derived from vectors.
- scatter simulation accept BlocksOnCylindrical.
- remove X orientation.
@VietAnhDao
Copy link
Author

I have now :)

@KrisThielemans
Copy link

Summary of the changes:

  • get_s() and get_tantheta() is derived from detection coordinates for the BlocksOnCylindrical case
  • scatter simulation accept BlocksOnCylindrical.

@KrisThielemans
Copy link

Now I find that I cannot merge this...

@pkhateri could you squash-merge with the above commit message?

@KrisThielemans
Copy link

@pkhateri or give me write permission to your master branch.

KrisThielemans pushed a commit that referenced this pull request Nov 9, 2021
    - get_s and get_tantheta are derived from end-points.
    - scatter simulation accept BlocksOnCylindrical.
    - remove X orientation.

squashed commit of #2
Co-authored-by: Kris Thielemans <KrisThielemans@users.noreply.github.com>
@KrisThielemans
Copy link

I've squash-merged this on the git command line and pushed to (this) master. So this PR should be closed (but I cannot).

Thanks @VietAnhDao !

@VietAnhDao
Copy link
Author

VietAnhDao commented Nov 9, 2021

Nice ! bit messy but worked out in the end :) do you want me to close this? I do have the "Close with comment" option.

@KrisThielemans
Copy link

yes please

@VietAnhDao
Copy link
Author

Pull request accepted.

@VietAnhDao VietAnhDao closed this Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants