Skip to content

Commit

Permalink
clean up remaining ifs and reduce ray misses by appropriately sizing ray
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Jul 19, 2024
1 parent 4cac1ee commit e0af8f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/simplnx/Utilities/Math/GeometryMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ inline bool IsPointInBox(const nx::core::Point3D<T>& point, const nx::core::Boun
{
const auto& min = box.getMinPoint();
const auto& max = box.getMaxPoint();
return (min[0] <= point[0]) && (point[0] <= max[0]) && (min[1] <= point[1]) && (point[1] <= max[1]) && (min[2] <= point[2]) && (point[2] <= max[2]);
return !(min[0] > point[0]) && !(point[0] > max[0]) && !(min[1] > point[1]) && !(point[1] > max[1]) && !(min[2] > point[2]) && !(point[2] > max[2]);
}

/**
Expand All @@ -260,10 +260,12 @@ bool DoesRayIntersectBox(const nx::core::Ray<T>& ray, const nx::core::BoundingBo
const auto& min = bounds.getMinPoint();
const auto& max = bounds.getMaxPoint();

auto end = ray.getEndPointRef();
auto end = ray.getEndPoint();

return !((min[0] > origin[0]) && (min[0] > end[0]) && (min[1] > origin[1]) && (min[1] > end[1]) && (min[2] > origin[2]) && (min[2] > end[2]) &&
(max[0] < origin[0]) && (max[0] < end[0]) && (max[1] < origin[1]) && (max[1] < end[1]) && (max[2] < origin[2]) && (max[2] < end[2]));
// The line should have one point fall in the box since the length
// is half the bounding box diameter
return !((min[0] > origin[0]) && (min[0] > end[0])) && !((min[1] > origin[1]) && (min[1] > end[1])) && !((min[2] > origin[2]) && (min[2] > end[2])) && !((max[0] < origin[0]) && (max[0] < end[0])) &&
!((max[1] < origin[1]) && (max[1] < end[1])) && !((max[2] < origin[2]) && (max[2] < end[2]));
}

/**
Expand All @@ -282,8 +284,10 @@ bool DoesRayIntersectBox(const nx::core::Ray<T, true>& ray, const nx::core::Boun

const auto& end = ray.getEndPointRef();

return !((min[0] > origin[0]) && (min[0] > end[0]) && (min[1] > origin[1]) && (min[1] > end[1]) && (min[2] > origin[2]) && (min[2] > end[2]) &&
(max[0] < origin[0]) && (max[0] < end[0]) && (max[1] < origin[1]) && (max[1] < end[1]) && (max[2] < origin[2]) && (max[2] < end[2]));
// The line should have one point fall in the box since the length
// is half the bounding box diameter
return !((min[0] > origin[0]) && (min[0] > end[0])) && !((min[1] > origin[1]) && (min[1] > end[1])) && !((min[2] > origin[2]) && (min[2] > end[2])) && !((max[0] < origin[0]) && (max[0] < end[0])) &&
!((max[1] < origin[1]) && (max[1] < end[1])) && !((max[2] < origin[2]) && (max[2] < end[2]));
}

/**
Expand Down Expand Up @@ -734,13 +738,11 @@ char IsPointInPolyhedron(const nx::core::TriangleGeom& triangleGeomRef, const st
doNextCheck = true;
break;
}

/* If ray hits face at interior point, increment crossings. */
else if(code == 'f')
{
crossings++;
}

/* If query endpoint q sits on a V/E/F, return that code. */
else if(code == 'V' || code == 'E' || code == 'F')
{
Expand Down
5 changes: 2 additions & 3 deletions src/simplnx/Utilities/SampleSurfaceMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ class SampleSurfaceMeshImpl
{
for(usize iter = start; iter < end; iter++)
{
float32 radius = 0.0f;
usize numPoints = m_Points.size();

// find bounding box for current feature
BoundingBox3Df boundingBox(GeometryMath::FindBoundingBoxOfFaces(m_Faces, m_FaceIds[iter]));
radius = GeometryMath::FindDistanceBetweenPoints(boundingBox.getMinPoint(), boundingBox.getMaxPoint());
float32 radius = GeometryMath::FindDistanceBetweenPoints(boundingBox.getMinPoint(), boundingBox.getMaxPoint()) / 2;

// check points in vertex array to see if they are in the bounding box of the feature
for(usize i = 0; i < numPoints; i++)
Expand Down Expand Up @@ -108,7 +107,7 @@ class SampleSurfaceMeshImplByPoints

// find bounding box for current feature
BoundingBox3Df boundingBox(GeometryMath::FindBoundingBoxOfFaces(m_Faces, m_FaceIds));
float32 radius = GeometryMath::FindDistanceBetweenPoints(boundingBox.getMinPoint(), boundingBox.getMaxPoint());
float32 radius = GeometryMath::FindDistanceBetweenPoints(boundingBox.getMinPoint(), boundingBox.getMaxPoint()) / 2;

usize pointsVisited = 0;
// check points in vertex array to see if they are in the bounding box of the feature
Expand Down

0 comments on commit e0af8f7

Please sign in to comment.