A question about the function Region.RayIntersectBoundary(...) #155
-
Take class VTS/src/Vts/MonteCarlo/Tissues/InfiniteCylinderTissueRegion.cs Lines 128 to 136 in cdc7b3b The _onBoundary here is actually obtained when calculating whether p2 is included in the region, so when p2 is on the region boundary, the above branch will inevitably return false.While p1 is outside the region and p2 is on the boundary (i.e. oneIn = false, _onBoundary= true, twoIn = true ), the line between p1 and p2 may have 0 or 1 intersection (excluding p2 ). Why to ignore the case where there is 1 intersection and to return false?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Thank you for your very good question. First, a possible scenario is that _onBoundary is set by the check of p1 on line 128, and not updated by the check of p2 on line 129. So _onBoundary is not set only by check on p2. Second, in the scenario you describe where p1 is outside, p2 set _onBoundary to be true and also set twoIn to be true, then the ray is going from outside the cylinder to just the surface and so no intersection. As an aside, the outer Monte Carlo engine is calling this code to determine if a pseudo-collision is to be placed at the intersection of a photon ray and the cylinder. This pseudo-collision is needed to 1) pro-rate the length of the remainder of the track due to optical property change going from outside in or inside out, and 2) change direction if refraction/reflection occurs. Say you have the following scenario, an infinite cylinder with center (0,0,2) and radius=1.99 is specified in the example infile infile_infinite_cylinder_AOfXAndYAndZ.txt. If "Seed"=0, each time you run infile, same simulation is executed. Setting a break point at line 132 you'll see how the outside code plays a part in this logic.
Let me know if this helps or you'd like further clarification. I'm sorry for my lengthy description. For me it is easier to see code in action. |
Beta Was this translation helpful? Give feedback.
-
I made your edits (R=0.0397598, Z=0.08 for the infinite cylinder) to my infile. There is an intersection point at (0,0,0.0402402). I should have mentioned on my last post that RayIntersectBoundary gets called twice, and the second call adjusts pseudo-collision point sometimes. Try this:
One thing I do when debugging is that I set a break point in Photon.Move line 170 and just see how the photon collision points are getting updated. Then periodically I check on the variable History,HistoryData and look at each PhotonDataPoint Position values to make sure the code is putting a pseudo-collision at the tissue region boundary intersections. I hope this helps. The code is complex in certain circumstances. I feel you are in the trenches with it (which is inspiring!) and so would like to help you understand as best I can. |
Beta Was this translation helpful? Give feedback.
I made your edits (R=0.0397598, Z=0.08 for the infinite cylinder) to my infile. There is an intersection point at (0,0,0.0402402). I should have mentioned on my last post that RayIntersectBoundary gets called twice, and the second call adjusts pseudo-collision point sometimes. Try this: