Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions include/geode/mesh/helpers/ray_tracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@
{
class opengeode_mesh_api RayTracing2D
{
OPENGEODE_DISABLE_COPY( RayTracing2D );

public:
struct EdgeDistance
{
EdgeDistance() = default;

EdgeDistance( index_t edge_in,

Check warning on line 58 in include/geode/mesh/helpers/ray_tracing.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/mesh/helpers/ray_tracing.hpp:58:27 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'EdgeDistance' of convertible types are easily swapped by mistake
double distance_in,
POSITION position_in,
Point2D point_in )
: edge{ edge_in },
distance{ distance_in },
position{ position_in },
point{ std::move( point_in ) }
point{ point_in }
{
}

Expand All @@ -84,8 +86,9 @@
const InfiniteLine2D& infinite_line );
RayTracing2D( const EdgedCurve2D& mesh,
const Point2D& origin,
const OwnerSegment2D& segment );
OwnerSegment2D segment );
RayTracing2D( RayTracing2D&& other ) noexcept;
RayTracing2D& operator=( RayTracing2D&& other ) noexcept;
~RayTracing2D();

[[nodiscard]] std::optional< EdgeDistance > closest_edge() const;
Expand All @@ -103,19 +106,21 @@

class opengeode_mesh_api RayTracing3D
{
OPENGEODE_DISABLE_COPY( RayTracing3D );

public:
struct PolygonDistance
{
PolygonDistance() = default;

PolygonDistance( index_t polygon_in,

Check warning on line 116 in include/geode/mesh/helpers/ray_tracing.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/mesh/helpers/ray_tracing.hpp:116:30 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'PolygonDistance' of convertible types are easily swapped by mistake
double distance_in,
POSITION position_in,
Point3D point_in )
: polygon{ polygon_in },
distance{ distance_in },
position{ position_in },
point{ std::move( point_in ) }
point{ point_in }
{
}

Expand All @@ -139,8 +144,9 @@
const InfiniteLine3D& infinite_line );
RayTracing3D( const SurfaceMesh3D& mesh,
const Point3D& origin,
const OwnerSegment3D& segment );
OwnerSegment3D segment );
RayTracing3D( RayTracing3D&& other ) noexcept;
RayTracing3D& operator=( RayTracing3D&& other ) noexcept;
~RayTracing3D();

[[nodiscard]] std::optional< PolygonDistance > closest_polygon() const;
Expand Down
80 changes: 43 additions & 37 deletions src/geode/mesh/helpers/ray_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
auto bbox_with_line = bbox;
bbox_with_line.add_point( line.origin() );
const auto diagonal = bbox_with_line.diagonal();
return line.origin() - line.direction() * diagonal.length();
return line.origin() - ( line.direction() * diagonal.length() );
}

template < geode::index_t dimension, typename Line >
Expand All @@ -56,7 +56,7 @@
auto bbox_with_line = bbox;
bbox_with_line.add_point( line.origin() );
const auto diagonal = bbox_with_line.diagonal();
return line.origin() + line.direction() * diagonal.length();
return line.origin() + ( line.direction() * diagonal.length() );
}

bool test_vertex_mode( const geode::EdgedCurve2D& mesh,
Expand Down Expand Up @@ -258,8 +258,8 @@

Impl( const EdgedCurve2D& mesh,
const Point2D& origin,
const OwnerSegment2D& segment )
: mesh_( mesh ), origin_( origin ), segment_{ segment }
OwnerSegment2D segment )
: mesh_( mesh ), origin_( origin ), segment_{ std::move( segment ) }
{
}

Expand Down Expand Up @@ -330,9 +330,8 @@
{
distance *= -1.;
}
std::lock_guard< std::mutex > lock{ mutex_ };
results_.emplace_back( edge_id, distance, result.second,
std::move( intersection_result ) );
results_.emplace_back(
edge_id, distance, result.second, intersection_result );
}
return false;
}
Expand All @@ -359,7 +358,6 @@
OwnerSegment2D segment_;
mutable std::vector< EdgeDistance > results_;
mutable bool are_results_sorted_{ false };
std::mutex mutex_;
};

RayTracing2D::RayTracing2D(
Expand All @@ -377,13 +375,15 @@

RayTracing2D::RayTracing2D( const EdgedCurve2D& mesh,
const Point2D& origin,
const OwnerSegment2D& segment )
: impl_{ mesh, origin, segment }
OwnerSegment2D segment )
: impl_{ mesh, origin, std::move( segment ) }
{
}

RayTracing2D::RayTracing2D( RayTracing2D&& ) noexcept = default;

RayTracing2D& RayTracing2D::operator=( RayTracing2D&& ) noexcept = default;

RayTracing2D::~RayTracing2D() = default;

std::optional< RayTracing2D::EdgeDistance >
Expand Down Expand Up @@ -448,8 +448,8 @@

Impl( const SurfaceMesh3D& mesh,
const Point3D& origin,
const OwnerSegment3D& segment )
: mesh_( mesh ), origin_( origin ), segment_{ segment }
OwnerSegment3D segment )
: mesh_( mesh ), origin_( origin ), segment_{ std::move( segment ) }
{
}

Expand Down Expand Up @@ -491,16 +491,16 @@
return results_;
}

bool compute( index_t polygon_id )

Check warning on line 494 in src/geode/mesh/helpers/ray_tracing.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/helpers/ray_tracing.cpp:494:14 [readability-function-cognitive-complexity]

function 'compute' has cognitive complexity of 20 (threshold 10)
{
const auto& p0 =
const auto& point0 =
mesh_.point( mesh_.polygon_vertex( { polygon_id, 0 } ) );
for( const auto e :
for( const auto edge :
LRange{ 1, mesh_.nb_polygon_edges( polygon_id ) - 1 } )
{
const auto edge_vertices =
mesh_.polygon_edge_vertices( { polygon_id, e } );
const Triangle3D triangle{ p0,
mesh_.polygon_edge_vertices( { polygon_id, edge } );
const Triangle3D triangle{ point0,
mesh_.point( edge_vertices.front() ),
mesh_.point( edge_vertices.back() ) };
const auto result = segment_triangle_intersection_detection(
Expand All @@ -521,38 +521,43 @@
{
distance *= -1.;
}
std::lock_guard< std::mutex > lock{ mutex_ };
results_.emplace_back( polygon_id, distance, result.second,
std::move( intersection_result ) );
intersection_result );
break;
}
for( const auto e2 : LRange{ 3 } )
for( const auto edge2 : LRange{ 3 } )
{
auto [ray_edge_distance, point, _] =
segment_segment_distance( Segment3D{ segment_ },
{ triangle.vertices()[e2].get(),
triangle.vertices()[( e2 + 1 ) % 3].get() } );
auto [ray_edge_distance, ray_point,
_] = segment_segment_distance( Segment3D{ segment_ },
{ triangle.vertices()[edge2].get(),
triangle.vertices()[( edge2 + 1 ) % 3].get() } );
if( ray_edge_distance > GLOBAL_EPSILON )
{
continue;
}
if( Vector3D{ origin_, point }.dot( segment_.direction() )
< 0 )
const Vector3D origin_target{ origin_, ray_point };
auto distance = origin_target.length();
if( origin_target.dot( segment_.direction() ) < 0 )
{
ray_edge_distance *= -1.;
distance *= -1.;
}
std::lock_guard< std::mutex > lock{ mutex_ };
results_.emplace_back( polygon_id, ray_edge_distance,
result.second, std::move( point ) );
results_.emplace_back(
polygon_id, distance, result.second, ray_point );
}
const auto [distance, __, triangle_point] =
const auto [triangle_distance, ray_point, _] =
segment_triangle_distance( segment_, triangle );
if( distance < GLOBAL_EPSILON )
if( triangle_distance > GLOBAL_EPSILON )
{
std::lock_guard< std::mutex > lock{ mutex_ };
results_.emplace_back(
polygon_id, distance, result.second, triangle_point );
continue;
}
const Vector3D origin_target{ origin_, ray_point };
auto distance = origin_target.length();
if( origin_target.dot( segment_.direction() ) < 0 )
{
distance *= -1.;
}
results_.emplace_back(
polygon_id, distance, result.second, ray_point );
break;
}
return false;
Expand Down Expand Up @@ -581,7 +586,6 @@
OwnerSegment3D segment_;
mutable std::vector< PolygonDistance > results_;
mutable bool are_results_sorted_{ false };
std::mutex mutex_;
};

RayTracing3D::RayTracing3D(
Expand All @@ -599,13 +603,15 @@

RayTracing3D::RayTracing3D( const SurfaceMesh3D& mesh,
const Point3D& origin,
const OwnerSegment3D& segment )
: impl_{ mesh, origin, segment }
OwnerSegment3D segment )
: impl_{ mesh, origin, std::move( segment ) }
{
}

RayTracing3D::RayTracing3D( RayTracing3D&& ) noexcept = default;

RayTracing3D& RayTracing3D::operator=( RayTracing3D&& ) noexcept = default;

RayTracing3D::~RayTracing3D() = default;

std::optional< RayTracing3D::PolygonDistance >
Expand Down
Loading
Loading