Skip to content

Commit

Permalink
Final cleanup of PR. Ready for review.
Browse files Browse the repository at this point in the history
  • Loading branch information
hayakawa16 committed Aug 29, 2023
1 parent f766756 commit 348ff31
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 246 deletions.
48 changes: 24 additions & 24 deletions src/Vts.Test/MonteCarlo/Tissues/BoundingCylinderTissueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace Vts.Test.MonteCarlo.Tissues
[TestFixture]
public class BoundingCylinderTissueTests
{
private BoundedTissue _oneLayerTissue, _twoLayerTissue;
private BoundedTissue _oneLayerTissueBoundedByCylinder, _twoLayerTissueBoundedByCylinder;
/// <summary>
/// Validate general constructor of Tissue for a one layer and two layer tissue cylinder
/// </summary>
[OneTimeSetUp]
public void Create_instance_of_class()
{
_oneLayerTissue = new BoundedTissue(new CaplessCylinderTissueRegion(
_oneLayerTissueBoundedByCylinder = new BoundedTissue(new CaplessCylinderTissueRegion(
new Position(0, 0, 50), 1.0, 100.0, new OpticalProperties()),
new ITissueRegion[]
{
Expand All @@ -33,7 +33,7 @@ public void Create_instance_of_class()
new DoubleRange(100.0, double.PositiveInfinity),
new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
});
_twoLayerTissue = new BoundedTissue(new CaplessCylinderTissueRegion(
_twoLayerTissueBoundedByCylinder = new BoundedTissue(new CaplessCylinderTissueRegion(
new Position(0, 0, 50), 1.0, 100.0, new OpticalProperties()),
new ITissueRegion[]
{
Expand All @@ -58,18 +58,18 @@ public void Create_instance_of_class()
[Test]
public void Verify_GetRegionIndex_method_returns_correct_result()
{
var index = _oneLayerTissue.GetRegionIndex(new Position(10, 0, 0)); // outside cylinder
var index = _oneLayerTissueBoundedByCylinder.GetRegionIndex(new Position(10, 0, 0)); // outside cylinder
Assert.AreEqual(3, index);
index = _oneLayerTissue.GetRegionIndex(new Position(0, 0, 2.5)); // inside cylinder
index = _oneLayerTissueBoundedByCylinder.GetRegionIndex(new Position(0, 0, 2.5)); // inside cylinder
Assert.AreEqual(1, index);
index = _oneLayerTissue.GetRegionIndex(new Position(0, 0, 0)); // on cylinder is considered in
index = _oneLayerTissueBoundedByCylinder.GetRegionIndex(new Position(0, 0, 0)); // on cylinder is considered in
Assert.AreEqual(1, index);
// two layer results
index = _twoLayerTissue.GetRegionIndex(new Position(10, 0, 0)); // outside cylinder
index = _twoLayerTissueBoundedByCylinder.GetRegionIndex(new Position(10, 0, 0)); // outside cylinder
Assert.AreEqual(4, index);
index = _twoLayerTissue.GetRegionIndex(new Position(0, 0, 2.5)); // inside cylinder
index = _twoLayerTissueBoundedByCylinder.GetRegionIndex(new Position(0, 0, 2.5)); // inside cylinder
Assert.AreEqual(2, index);
index = _twoLayerTissue.GetRegionIndex(new Position(0, 0, 0)); // on cylinder is considered in
index = _twoLayerTissueBoundedByCylinder.GetRegionIndex(new Position(0, 0, 0)); // on cylinder is considered in
Assert.AreEqual(1, index);
}

Expand All @@ -83,56 +83,56 @@ public void Verify_GetNeighborRegionIndex_method_returns_correct_result()
new Position(-1, 0, 1),
new Direction(1.0, 0, 0),
1.0,
_oneLayerTissue,
_oneLayerTissueBoundedByCylinder,
3,
new Random());
var index = _oneLayerTissue.GetNeighborRegionIndex(photon);
var index = _oneLayerTissueBoundedByCylinder.GetNeighborRegionIndex(photon);
Assert.AreEqual(1, index);
photon = new Photon( // on side of cylinder pointed out of it
new Position(-1, 0, 1),
new Direction(-1.0, 0, 0),
1.0,
_oneLayerTissue,
_oneLayerTissueBoundedByCylinder,
1,
new Random());
index = _oneLayerTissue.GetNeighborRegionIndex(photon);
index = _oneLayerTissueBoundedByCylinder.GetNeighborRegionIndex(photon);
Assert.AreEqual(3, index);
// two layer results
photon = new Photon( // on side of cylinder pointed into LAYER 1
new Position(-1, 0, 0.5),
new Direction(1.0, 0, 0),
1.0,
_twoLayerTissue,
_twoLayerTissueBoundedByCylinder,
4,
new Random());
index = _twoLayerTissue.GetNeighborRegionIndex(photon);
index = _twoLayerTissueBoundedByCylinder.GetNeighborRegionIndex(photon);
Assert.AreEqual(1, index);
photon = new Photon( // on side of cylinder in LAYER 1 pointed out of it
new Position(-1, 0, 0.5),
new Direction(-1.0, 0, 0),
1.0,
_twoLayerTissue,
_twoLayerTissueBoundedByCylinder,
1,
new Random());
index = _twoLayerTissue.GetNeighborRegionIndex(photon);
index = _twoLayerTissueBoundedByCylinder.GetNeighborRegionIndex(photon);
Assert.AreEqual(4, index);
photon = new Photon( // on side of cylinder pointed into LAYER 2
new Position(-1, 0, 1.5),
new Direction(1.0, 0, 0),
1.0,
_twoLayerTissue,
_twoLayerTissueBoundedByCylinder,
4,
new Random());
index = _twoLayerTissue.GetNeighborRegionIndex(photon);
index = _twoLayerTissueBoundedByCylinder.GetNeighborRegionIndex(photon);
Assert.AreEqual(2, index);
photon = new Photon( // on side of cylinder in LAYER 2 pointed out of it
new Position(-1, 0, 1.5),
new Direction(-1.0, 0, 0),
1.0,
_twoLayerTissue,
_twoLayerTissueBoundedByCylinder,
1,
new Random());
index = _twoLayerTissue.GetNeighborRegionIndex(photon);
index = _twoLayerTissueBoundedByCylinder.GetNeighborRegionIndex(photon);
Assert.AreEqual(4, index);
}

Expand All @@ -146,15 +146,15 @@ public void Verify_GetAngleRelativeToBoundaryNormal_method_returns_correct_resul
new Position(0.0, 0.0, 0.0),
new Direction(0.0, 0.0, 1.0),
1,
_twoLayerTissue,
_twoLayerTissueBoundedByCylinder,
1,
new Random());
var cosTheta = _twoLayerTissue.GetAngleRelativeToBoundaryNormal(photon);
var cosTheta = _twoLayerTissueBoundedByCylinder.GetAngleRelativeToBoundaryNormal(photon);
Assert.AreEqual(1, cosTheta);
// put on side of cylinder pointing in
photon.DP.Position = new Position(1.0, 1.0, 5.0);
photon.DP.Direction = new Direction(1.0, 0.0, 0.0);
cosTheta = _twoLayerTissue.GetAngleRelativeToBoundaryNormal(photon);
cosTheta = _twoLayerTissueBoundedByCylinder.GetAngleRelativeToBoundaryNormal(photon);
Assert.IsTrue(Math.Abs(cosTheta - 1/Math.Sqrt(2)) < 1e-6);
}

Expand Down
48 changes: 24 additions & 24 deletions src/Vts.Test/MonteCarlo/Tissues/BoundingVoxelTissueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace Vts.Test.MonteCarlo.Tissues
[TestFixture]
public class BoundingVoxelTissueTests
{
private BoundedTissue _oneLayerTissue, _twoLayerTissue;
private BoundedTissue _oneLayerTissueBoundedByVoxel, _twoLayerTissueBoundedByVoxel;
/// <summary>
/// Validate general constructor of Tissue for a one layer and two layer tissue voxel
/// </summary>
[OneTimeSetUp]
public void Create_instance_of_class()
{
_oneLayerTissue = new BoundedTissue(new CaplessVoxelTissueRegion(
_oneLayerTissueBoundedByVoxel = new BoundedTissue(new CaplessVoxelTissueRegion(
new DoubleRange(-1, 1, 2), // x range
new DoubleRange(-1, 1, 2), // y range
new DoubleRange(0, 100.0, 2), // z range spans tissue
Expand All @@ -36,7 +36,7 @@ public void Create_instance_of_class()
new DoubleRange(100.0, double.PositiveInfinity),
new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
});
_twoLayerTissue = new BoundedTissue(new CaplessVoxelTissueRegion(
_twoLayerTissueBoundedByVoxel = new BoundedTissue(new CaplessVoxelTissueRegion(
new DoubleRange(-1, 1, 2), // x range
new DoubleRange(-1, 1, 2), // y range
new DoubleRange(0, 100.0, 2), // z range spans tissue
Expand Down Expand Up @@ -64,18 +64,18 @@ public void Create_instance_of_class()
[Test]
public void Verify_GetRegionIndex_method_returns_correct_result()
{
var index = _oneLayerTissue.GetRegionIndex(new Position(10, 0, 0)); // outside voxel
var index = _oneLayerTissueBoundedByVoxel.GetRegionIndex(new Position(10, 0, 0)); // outside voxel
Assert.AreEqual(3, index);
index = _oneLayerTissue.GetRegionIndex(new Position(0, 0, 2.5)); // inside voxel
index = _oneLayerTissueBoundedByVoxel.GetRegionIndex(new Position(0, 0, 2.5)); // inside voxel
Assert.AreEqual(1, index);
index = _oneLayerTissue.GetRegionIndex(new Position(0, 0, 0)); // on voxel is considered in
index = _oneLayerTissueBoundedByVoxel.GetRegionIndex(new Position(0, 0, 0)); // on voxel is considered in
Assert.AreEqual(1, index);
// two layer results
index = _twoLayerTissue.GetRegionIndex(new Position(10, 0, 0)); // outside voxel
index = _twoLayerTissueBoundedByVoxel.GetRegionIndex(new Position(10, 0, 0)); // outside voxel
Assert.AreEqual(4, index);
index = _twoLayerTissue.GetRegionIndex(new Position(0, 0, 2.5)); // inside voxel
index = _twoLayerTissueBoundedByVoxel.GetRegionIndex(new Position(0, 0, 2.5)); // inside voxel
Assert.AreEqual(2, index);
index = _twoLayerTissue.GetRegionIndex(new Position(0, 0, 0)); // on voxel is considered in
index = _twoLayerTissueBoundedByVoxel.GetRegionIndex(new Position(0, 0, 0)); // on voxel is considered in
Assert.AreEqual(1, index);
}

Expand All @@ -89,56 +89,56 @@ public void Verify_GetNeighborRegionIndex_method_returns_correct_result()
new Position(-1, 0, 1),
new Direction(1.0, 0, 0),
1.0,
_oneLayerTissue,
_oneLayerTissueBoundedByVoxel,
3,
new Random());
var index = _oneLayerTissue.GetNeighborRegionIndex(photon);
var index = _oneLayerTissueBoundedByVoxel.GetNeighborRegionIndex(photon);
Assert.AreEqual(1, index);
photon = new Photon( // on side of voxel pointed out of it
new Position(-1, 0, 1),
new Direction(-1.0, 0, 0),
1.0,
_oneLayerTissue,
_oneLayerTissueBoundedByVoxel,
1,
new Random());
index = _oneLayerTissue.GetNeighborRegionIndex(photon);
index = _oneLayerTissueBoundedByVoxel.GetNeighborRegionIndex(photon);
Assert.AreEqual(3, index);
// two layer results
photon = new Photon( // on side of voxel pointed into LAYER 1
new Position(-1, 0, 0.5),
new Direction(1.0, 0, 0),
1.0,
_twoLayerTissue,
_twoLayerTissueBoundedByVoxel,
4,
new Random());
index = _twoLayerTissue.GetNeighborRegionIndex(photon);
index = _twoLayerTissueBoundedByVoxel.GetNeighborRegionIndex(photon);
Assert.AreEqual(1, index);
photon = new Photon( // on side of voxel in LAYER 1 pointed out of it
new Position(-1, 0, 0.5),
new Direction(-1.0, 0, 0),
1.0,
_twoLayerTissue,
_twoLayerTissueBoundedByVoxel,
1,
new Random());
index = _twoLayerTissue.GetNeighborRegionIndex(photon);
index = _twoLayerTissueBoundedByVoxel.GetNeighborRegionIndex(photon);
Assert.AreEqual(4, index);
photon = new Photon( // on side of voxel pointed into LAYER 2
new Position(-1, 0, 1.5),
new Direction(1.0, 0, 0),
1.0,
_twoLayerTissue,
_twoLayerTissueBoundedByVoxel,
4,
new Random());
index = _twoLayerTissue.GetNeighborRegionIndex(photon);
index = _twoLayerTissueBoundedByVoxel.GetNeighborRegionIndex(photon);
Assert.AreEqual(2, index);
photon = new Photon( // on side of voxel in LAYER 2 pointed out of it
new Position(-1, 0, 1.5),
new Direction(-1.0, 0, 0),
1.0,
_twoLayerTissue,
_twoLayerTissueBoundedByVoxel,
1,
new Random());
index = _twoLayerTissue.GetNeighborRegionIndex(photon);
index = _twoLayerTissueBoundedByVoxel.GetNeighborRegionIndex(photon);
Assert.AreEqual(4, index);
}

Expand All @@ -152,15 +152,15 @@ public void Verify_GetAngleRelativeToBoundaryNormal_method_returns_correct_resul
new Position(0, 0, 0.0),
new Direction(0.0, 0, 1.0),
1,
_twoLayerTissue,
_twoLayerTissueBoundedByVoxel,
1,
new Random());
var cosTheta = _twoLayerTissue.GetAngleRelativeToBoundaryNormal(photon);
var cosTheta = _twoLayerTissueBoundedByVoxel.GetAngleRelativeToBoundaryNormal(photon);
Assert.AreEqual(1,cosTheta);
// put on side of cylinder pointing in
photon.DP.Position = new Position(-1.0, 0.0, 5.0);
photon.DP.Direction = new Direction(1.0, 0.0, 0.0);
cosTheta = _twoLayerTissue.GetAngleRelativeToBoundaryNormal(photon);
cosTheta = _twoLayerTissueBoundedByVoxel.GetAngleRelativeToBoundaryNormal(photon);
Assert.AreEqual(1, cosTheta);
}

Expand Down
35 changes: 20 additions & 15 deletions src/Vts.Test/MonteCarlo/Tissues/CaplessCylinderTissueRegionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public void Validate_caplessCylinder_properties()
/// Currently OnBoundary of an inclusion region isn't called by any code ckh 3/5/19.
/// </summary>
[Test]
public void verify_OnBoundary_method_returns_correct_result()
public void Verify_OnBoundary_method_returns_correct_result()
{
// OnBoundary returns true if *exactly* on boundary
bool result = _caplessCylinderTissueRegion.OnBoundary(new Position(0, 0, 1.0)); // on top cap boundary
var result = _caplessCylinderTissueRegion.OnBoundary(new Position(0, 0, 1.0)); // on top cap boundary
Assert.IsFalse(result);
result = _caplessCylinderTissueRegion.OnBoundary(new Position(0, 0, 3.0)); // on bottom cap boundary -> so false
Assert.IsFalse(result);
Expand All @@ -65,9 +65,9 @@ public void verify_OnBoundary_method_returns_correct_result()
/// or *on* boundary.
/// </summary>
[Test]
public void verify_ContainsPosition_method_returns_correct_result()
public void Verify_ContainsPosition_method_returns_correct_result()
{
bool result = _caplessCylinderTissueRegion.ContainsPosition(new Position(0, 0, 2.0)); // inside
var result = _caplessCylinderTissueRegion.ContainsPosition(new Position(0, 0, 2.0)); // inside
Assert.IsTrue(result);
result = _caplessCylinderTissueRegion.ContainsPosition(new Position(0, 0, 3.0)); // on boundary
Assert.IsTrue(result);
Expand All @@ -77,44 +77,49 @@ public void verify_ContainsPosition_method_returns_correct_result()
/// Validate method RayIntersectBoundary return correct result
/// </summary>
[Test]
public void verify_RayIntersectBoundary_method_returns_correct_result()
public void Verify_RayIntersectBoundary_method_returns_correct_result()
{
// test intersection with sides
Photon photon = new Photon();
photon.DP.Position = new Position(0, 0, 2);
photon.DP.Direction = new Direction(1, 0, 0);
photon.S = 2.0; // definitely intersect sides
var photon = new Photon
{
DP =
{
Position = new Position(0, 0, 2),
Direction = new Direction(1, 0, 0)
},
S = 2.0 // definitely intersect sides
};
double distanceToBoundary;
bool result = _caplessCylinderTissueRegion.RayIntersectBoundary(photon, out distanceToBoundary);
var result = _caplessCylinderTissueRegion.RayIntersectBoundary(photon, out distanceToBoundary);
Assert.AreEqual(true, result);
Assert.AreEqual(1.0, distanceToBoundary);
photon.S = 0.5; // definitely don't intersect sides
result = _caplessCylinderTissueRegion.RayIntersectBoundary(photon, out distanceToBoundary);
Assert.AreEqual(false, result);
Assert.AreEqual(Double.PositiveInfinity, distanceToBoundary);
Assert.AreEqual(double.PositiveInfinity, distanceToBoundary);
photon.S = 1.0; // ends right at boundary => both out and no intersection
result = _caplessCylinderTissueRegion.RayIntersectBoundary(photon, out distanceToBoundary);
Assert.AreEqual(false, result);
Assert.AreEqual(Double.PositiveInfinity, distanceToBoundary);
Assert.AreEqual(double.PositiveInfinity, distanceToBoundary);
// intersect cap of caplessCylinder tests
photon.DP.Position = new Position(0, 0, 0); // intersect top cap
photon.DP.Direction = new Direction(0, 0, 1);
photon.S = 2.0; // make sure intersects top cap
result = _caplessCylinderTissueRegion.RayIntersectBoundary(photon, out distanceToBoundary);
Assert.AreEqual(false, result);
Assert.AreEqual(Double.PositiveInfinity, distanceToBoundary);
Assert.AreEqual(double.PositiveInfinity, distanceToBoundary);
photon.DP.Position = new Position(0, 0, 4); // intersect bottom cap
photon.DP.Direction = new Direction(0, 0, -1);
photon.S = 2.0; // make sure intersects top cap
result = _caplessCylinderTissueRegion.RayIntersectBoundary(photon, out distanceToBoundary);
Assert.AreEqual(false, result);
Assert.AreEqual(Double.PositiveInfinity, distanceToBoundary);
Assert.AreEqual(double.PositiveInfinity, distanceToBoundary);
photon.DP.Position = new Position(0, 0, 0); // intersect both
photon.DP.Direction = new Direction(0, 0, 1);
photon.S = 10.0; // make sure intersects both
result = _caplessCylinderTissueRegion.RayIntersectBoundary(photon, out distanceToBoundary);
Assert.AreEqual(false, result);
Assert.AreEqual(Double.PositiveInfinity, distanceToBoundary);
Assert.AreEqual(double.PositiveInfinity, distanceToBoundary);
}
}
}
Loading

0 comments on commit 348ff31

Please sign in to comment.