Skip to content

Commit 9da3f3a

Browse files
committed
fix(BasicObjects): add is_degenerated
1 parent 984400a commit 9da3f3a

File tree

10 files changed

+92
-40
lines changed

10 files changed

+92
-40
lines changed

include/geode/geometry/basic_objects/infinite_line.hpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ namespace geode
3131
FORWARD_DECLARATION_DIMENSION_CLASS( OwnerInfiniteLine );
3232
FORWARD_DECLARATION_DIMENSION_CLASS( OwnerRay );
3333
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
34-
template < typename PointType, index_t dimension >
35-
class GenericSegment;
3634
FORWARD_DECLARATION_DIMENSION_CLASS( Segment );
37-
FORWARD_DECLARATION_DIMENSION_CLASS( OwnerSegment );
3835

3936
template < index_t dimension >
4037
using RefPoint = std::reference_wrapper< const Point< dimension > >;
@@ -47,9 +44,7 @@ namespace geode
4744
{
4845
public:
4946
GenericLine( const Vector< dimension >& direction, PointType origin );
50-
51-
explicit GenericLine(
52-
const GenericSegment< PointType, dimension >& segment );
47+
explicit GenericLine( const Segment< dimension >& segment );
5348
GenericLine( const GenericLine< PointType, dimension >& other );
5449
GenericLine< PointType, dimension >& operator=(
5550
const GenericLine< PointType, dimension >& other );
@@ -75,7 +70,7 @@ namespace geode
7570
explicit OwnerInfiniteLine(
7671
const Vector< dimension >& direction, Point< dimension > origin );
7772

78-
OwnerInfiniteLine( const Segment< dimension >& segment );
73+
explicit OwnerInfiniteLine( const Segment< dimension >& segment );
7974
OwnerInfiniteLine( const OwnerInfiniteLine< dimension >& other );
8075
OwnerInfiniteLine< dimension >& operator=(
8176
const OwnerInfiniteLine< dimension >& other );
@@ -94,7 +89,7 @@ namespace geode
9489
explicit OwnerRay(
9590
const Vector< dimension >& direction, Point< dimension > origin );
9691

97-
OwnerRay( const Segment< dimension >& segment );
92+
explicit OwnerRay( const Segment< dimension >& segment );
9893
OwnerRay( const OwnerRay< dimension >& other );
9994
OwnerRay< dimension >& operator=( const OwnerRay< dimension >& other );
10095
OwnerRay( OwnerRay< dimension >&& other ) noexcept;
@@ -111,7 +106,7 @@ namespace geode
111106
public:
112107
InfiniteLine( const Vector< dimension >& direction,
113108
const Point< dimension >& origin );
114-
InfiniteLine( const Segment< dimension >& segment );
109+
explicit InfiniteLine( const Segment< dimension >& segment );
115110

116111
InfiniteLine( const InfiniteLine< dimension >& other );
117112
InfiniteLine( const OwnerInfiniteLine< dimension >& other );

include/geode/geometry/basic_objects/plane.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
namespace geode
3030
{
3131
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
32+
FORWARD_DECLARATION_DIMENSION_CLASS( Triangle );
33+
ALIAS_3D( Triangle );
3234
class OwnerPlane;
3335

3436
template < index_t dimension >
@@ -43,7 +45,7 @@ namespace geode
4345
{
4446
public:
4547
GenericPlane( const Vector3D& normal, PointType origin );
46-
48+
explicit GenericPlane( const Triangle3D& triangle );
4749
GenericPlane( const GenericPlane& other );
4850
GenericPlane& operator=( const GenericPlane& other );
4951
GenericPlane( GenericPlane&& other ) noexcept;
@@ -64,6 +66,7 @@ namespace geode
6466

6567
public:
6668
explicit OwnerPlane( const Vector3D& normal, Point3D origin );
69+
explicit OwnerPlane( const Triangle3D& triangle );
6770
OwnerPlane( const OwnerPlane& other );
6871
OwnerPlane& operator=( const OwnerPlane& other );
6972
OwnerPlane( OwnerPlane&& other ) noexcept;
@@ -76,7 +79,7 @@ namespace geode
7679

7780
public:
7881
Plane( const Vector3D& normal, const Point3D& origin );
79-
82+
explicit Plane( const Triangle3D& triangle );
8083
Plane( const Plane& other );
8184
Plane( const OwnerPlane& other );
8285
Plane& operator=( const Plane& other );

include/geode/geometry/basic_objects/tetrahedron.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace geode
6464
void set_point( local_index_t vertex, PointType point );
6565
[[nodiscard]] const std::array< PointType, 4 >& vertices() const;
6666
[[nodiscard]] BoundingBox3D bounding_box() const;
67+
[[nodiscard]] bool is_degenerated() const;
6768

6869
private:
6970
std::array< PointType, 4 > vertices_;

include/geode/geometry/basic_objects/triangle.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace geode
8585
[[nodiscard]] BoundingBox< dimension > bounding_box() const;
8686
[[nodiscard]] local_index_t longest_edge_index() const;
8787
[[nodiscard]] double minimum_height() const;
88+
[[nodiscard]] bool is_degenerated() const;
8889

8990
private:
9091
std::array< PointType, 3 > vertices_;

src/geode/geometry/basic_objects/infinite_line.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace geode
3535
}
3636
template < typename PointType, index_t dimension >
3737
GenericLine< PointType, dimension >::GenericLine(
38-
const GenericSegment< PointType, dimension >& segment )
38+
const Segment< dimension >& segment )
3939
: GenericLine( segment.normalized_direction(), segment.vertices()[0] )
4040
{
4141
}
@@ -77,8 +77,7 @@ namespace geode
7777
template < index_t dimension >
7878
OwnerInfiniteLine< dimension >::OwnerInfiniteLine(
7979
const Segment< dimension >& segment )
80-
: OwnerInfiniteLine(
81-
segment.normalized_direction(), segment.vertices()[0] )
80+
: Base( segment )
8281
{
8382
}
8483
template < index_t dimension >
@@ -104,7 +103,7 @@ namespace geode
104103
template < index_t dimension >
105104
InfiniteLine< dimension >::InfiniteLine(
106105
const Segment< dimension >& segment )
107-
: InfiniteLine( segment.normalized_direction(), segment.vertices()[0] )
106+
: Base( segment )
108107
{
109108
}
110109
template < index_t dimension >
@@ -135,7 +134,7 @@ namespace geode
135134
}
136135
template < index_t dimension >
137136
OwnerRay< dimension >::OwnerRay( const Segment< dimension >& segment )
138-
: OwnerRay( segment.normalized_direction(), segment.vertices()[0] )
137+
: Base( segment )
139138
{
140139
}
141140
template < index_t dimension >
@@ -159,7 +158,7 @@ namespace geode
159158
}
160159
template < index_t dimension >
161160
Ray< dimension >::Ray( const Segment< dimension >& segment )
162-
: Ray( segment.normalized_direction(), segment.vertices()[0] )
161+
: Base( segment )
163162
{
164163
}
165164
template < index_t dimension >

src/geode/geometry/basic_objects/plane.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <geode/geometry/basic_objects/plane.hpp>
2525

26+
#include <geode/geometry/basic_objects/triangle.hpp>
27+
2628
namespace geode
2729
{
2830
template < typename PointType >
@@ -31,6 +33,13 @@ namespace geode
3133
: normal_( normal.normalize() ), origin_( std::move( origin ) )
3234
{
3335
}
36+
template < typename PointType >
37+
GenericPlane< PointType >::GenericPlane( const Triangle3D& triangle )
38+
: normal_( triangle.normal().value() ),
39+
origin_( triangle.vertices()[0] )
40+
{
41+
}
42+
3443
template < typename PointType >
3544
GenericPlane< PointType >::GenericPlane( const GenericPlane& ) = default;
3645
template < typename PointType >
@@ -69,6 +78,8 @@ namespace geode
6978
: Base( normal, std::move( origin ) )
7079
{
7180
}
81+
OwnerPlane::OwnerPlane( const Triangle3D& triangle ) : Base( triangle ) {}
82+
7283
OwnerPlane::OwnerPlane( const OwnerPlane& ) = default;
7384
OwnerPlane& OwnerPlane::operator=( const OwnerPlane& ) = default;
7485
OwnerPlane::OwnerPlane( OwnerPlane&& ) noexcept = default;
@@ -78,6 +89,8 @@ namespace geode
7889
: Base( normal, origin )
7990
{
8091
}
92+
Plane::Plane( const Triangle3D& triangle ) : Base( triangle ) {}
93+
8194
Plane::Plane( const Plane& ) = default;
8295
Plane::Plane( const OwnerPlane& other )
8396
: Base( other.normal(), other.origin() )

src/geode/geometry/basic_objects/tetrahedron.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
#include <geode/geometry/basic_objects/tetrahedron.hpp>
2525

26+
#include <geode/geometry/basic_objects/plane.hpp>
27+
#include <geode/geometry/basic_objects/triangle.hpp>
2628
#include <geode/geometry/bounding_box.hpp>
29+
#include <geode/geometry/distance.hpp>
2730

2831
namespace geode
2932
{
@@ -79,6 +82,35 @@ namespace geode
7982
return bbox;
8083
}
8184

85+
template < typename PointType >
86+
bool GenericTetrahedron< PointType >::is_degenerated() const
87+
{
88+
for( const auto [vertex0, vertex1, vertex2] : tetrahedron_facet_vertex )
89+
{
90+
const Point3D& point0 = vertices_.at( vertex0 );
91+
const Point3D& point1 = vertices_.at( vertex1 );
92+
const Point3D& point2 = vertices_.at( vertex2 );
93+
const Triangle3D triangle{ point0, point1, point2 };
94+
if( triangle.is_degenerated() )
95+
{
96+
continue;
97+
}
98+
for( const auto vertex3 : LRange{ 4 } )
99+
{
100+
if( vertex3 == vertex0 || vertex3 == vertex1
101+
|| vertex3 == vertex2 )
102+
{
103+
continue;
104+
}
105+
const Point3D& point3 = vertices_.at( vertex3 );
106+
return std::get< 0 >(
107+
point_plane_distance( point3, Plane{ triangle } ) )
108+
<= GLOBAL_EPSILON;
109+
}
110+
}
111+
return true;
112+
}
113+
82114
OwnerTetrahedron::OwnerTetrahedron( Point3D point0,
83115
Point3D point1,
84116
Point3D point2,

src/geode/geometry/basic_objects/triangle.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,26 @@ namespace geode
269269
return point_segment_distance( opposite_vertex, longest_edge );
270270
}
271271

272+
template < typename PointType, index_t dimension >
273+
bool GenericTriangle< PointType, dimension >::is_degenerated() const
274+
{
275+
for( const auto edge_id : LRange{ 3 } )
276+
{
277+
const auto next_vertex = edge_id == 2 ? 0 : edge_id + 1;
278+
const Point< dimension >& point0 = vertices_.at( edge_id );
279+
const Point< dimension >& point1 = vertices_.at( next_vertex );
280+
const auto edge_length = point_point_distance( point0, point1 );
281+
if( edge_length > GLOBAL_EPSILON )
282+
{
283+
const auto last_vertex = next_vertex == 2 ? 0 : next_vertex + 1;
284+
const Point< dimension >& point2 = vertices_.at( last_vertex );
285+
return point_segment_distance( point2, { point0, point1 } )
286+
<= GLOBAL_EPSILON;
287+
}
288+
}
289+
return true;
290+
}
291+
272292
template < index_t dimension >
273293
OwnerTriangle< dimension >::OwnerTriangle( Point< dimension > point0,
274294
Point< dimension > point1,

src/geode/mesh/helpers/rasterize.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ namespace
537537
const geode::Segment2D segment_in_grid{ pt0_in_grid, pt1_in_grid };
538538
const auto normal_in_grid =
539539
geode::perpendicular( segment_in_grid.direction() );
540+
const geode::InfiniteLine2D line_in_grid{ segment_in_grid };
540541
const auto critical_point = compute_critical_point( normal_in_grid );
541542

542543
for( const auto j : geode::Range( min[1], max[1] + 1 ) )
@@ -549,13 +550,13 @@ namespace
549550

550551
// Test segment line through box
551552
const auto p_minus = point + critical_point;
552-
const auto p_minus_dist = geode::point_line_signed_distance(
553-
p_minus, { segment_in_grid } );
553+
const auto p_minus_dist =
554+
geode::point_line_signed_distance( p_minus, line_in_grid );
554555
const geode::Point2D p_plus{ { 1. + i
555556
- critical_point.value( 0 ),
556557
1. + j - critical_point.value( 1 ) } };
557-
const auto p_plus_dist = geode::point_line_signed_distance(
558-
p_plus, { segment_in_grid } );
558+
const auto p_plus_dist =
559+
geode::point_line_signed_distance( p_plus, line_in_grid );
559560
if( std::fabs( p_minus_dist ) > 2. * geode::GLOBAL_EPSILON
560561
&& std::fabs( p_plus_dist ) > 2. * geode::GLOBAL_EPSILON
561562
&& p_minus_dist * p_plus_dist > 0. )

src/geode/model/helpers/surface_radial_sort.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ namespace
8989
geode::Point3D opposite_point;
9090
};
9191

92-
bool is_polygon_degenerate( const geode::SurfaceMesh3D& mesh,
93-
const geode::PolygonEdge& edge,
94-
const geode::Point3D& opposite_point )
95-
{
96-
const auto edge_vertices = mesh.polygon_edge_vertices( edge );
97-
return geode::point_line_distance( opposite_point,
98-
{ geode::Segment3D{ mesh.point( edge_vertices[0] ),
99-
mesh.point( edge_vertices[1] ) } } )
100-
<= geode::GLOBAL_EPSILON;
101-
}
102-
10392
std::pair< bool, std::vector< BorderPolygon > > border_polygons(
10493
const geode::BRep& brep,
10594
const geode::Line3D& line,
@@ -126,20 +115,18 @@ namespace
126115
{
127116
polygons.emplace_back(
128117
surface, true, std::move( edge0.value() ) );
129-
degenerate_polygon =
130-
degenerate_polygon
131-
|| is_polygon_degenerate( surface_mesh, edge0.value(),
132-
polygons.back().opposite_point );
118+
degenerate_polygon = degenerate_polygon
119+
|| surface_mesh.is_polygon_degenerated(
120+
edge0->polygon_id );
133121
}
134122
if( auto edge1 = surface_mesh.polygon_edge_from_vertices(
135123
pair[1], pair[0] ) )
136124
{
137125
polygons.emplace_back(
138126
surface, false, std::move( edge1.value() ) );
139-
degenerate_polygon =
140-
degenerate_polygon
141-
|| is_polygon_degenerate( surface_mesh, edge1.value(),
142-
polygons.back().opposite_point );
127+
degenerate_polygon = degenerate_polygon
128+
|| surface_mesh.is_polygon_degenerated(
129+
edge1->polygon_id );
143130
}
144131
}
145132
}

0 commit comments

Comments
 (0)