Skip to content

Commit d645830

Browse files
committed
Merge branch 'next' into fix/segmentation
2 parents 49f67eb + be410e1 commit d645830

File tree

9 files changed

+445
-44
lines changed

9 files changed

+445
-44
lines changed

include/geode/geometry/sign.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
namespace geode
2929
{
3030
FORWARD_DECLARATION_DIMENSION_CLASS( Triangle );
31+
FORWARD_DECLARATION_DIMENSION_CLASS( Polygon );
3132
ALIAS_2D_AND_3D( Triangle );
33+
ALIAS_2D( Polygon );
3234
class Tetrahedron;
3335
enum struct SIDE;
3436
using Sign = SIDE;
@@ -48,6 +50,9 @@ namespace geode
4850
[[nodiscard]] Sign opengeode_geometry_api triangle_area_sign(
4951
const Triangle2D& triangle );
5052

53+
[[nodiscard]] Sign opengeode_geometry_api polygon_area_sign(
54+
const Polygon2D& polygon );
55+
5156
/*!
5257
* Return the sign of a 3D triangle area aligned on X- Y- or Z-axis.
5358
*/

include/geode/mesh/helpers/ray_tracing.hpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,63 @@
3535

3636
namespace geode
3737
{
38+
FORWARD_DECLARATION_DIMENSION_CLASS( EdgedCurve );
3839
FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMesh );
40+
ALIAS_2D( EdgedCurve );
3941
ALIAS_3D( SurfaceMesh );
4042
} // namespace geode
4143

4244
namespace geode
4345
{
46+
class opengeode_mesh_api RayTracing2D
47+
{
48+
public:
49+
struct EdgeDistance
50+
{
51+
EdgeDistance() = default;
52+
53+
EdgeDistance( index_t edge_in,
54+
double distance_in,
55+
POSITION position_in,
56+
Point2D point_in )
57+
: edge{ edge_in },
58+
distance{ distance_in },
59+
position{ position_in },
60+
point{ std::move( point_in ) }
61+
{
62+
}
63+
64+
[[nodiscard]] bool operator<( const EdgeDistance& other ) const
65+
{
66+
return std::fabs( distance ) < std::fabs( other.distance );
67+
}
68+
69+
index_t edge{ NO_ID };
70+
double distance{ 0 };
71+
POSITION position{ POSITION::outside };
72+
Point2D point;
73+
};
74+
75+
public:
76+
RayTracing2D( const EdgedCurve2D& mesh, const Ray2D& ray );
77+
RayTracing2D(
78+
const EdgedCurve2D& mesh, const InfiniteLine2D& infinite_line );
79+
RayTracing2D( RayTracing2D&& other ) noexcept;
80+
~RayTracing2D();
81+
82+
[[nodiscard]] std::optional< EdgeDistance > closest_edge() const;
83+
84+
[[nodiscard]] std::optional< absl::FixedArray< EdgeDistance > >
85+
closest_edges( index_t nb_closest_wanted ) const;
86+
87+
[[nodiscard]] std::vector< EdgeDistance > all_intersections() const;
88+
89+
[[nodiscard]] bool operator()( index_t edge_id );
90+
91+
private:
92+
IMPLEMENTATION_MEMBER( impl_ );
93+
};
94+
4495
class opengeode_mesh_api RayTracing3D
4596
{
4697
public:
@@ -80,7 +131,7 @@ namespace geode
80131
[[nodiscard]] std::optional< PolygonDistance > closest_polygon() const;
81132

82133
[[nodiscard]] std::optional< absl::FixedArray< PolygonDistance > >
83-
closest_polygons( index_t size ) const;
134+
closest_polygons( index_t nb_closest_wanted ) const;
84135

85136
[[nodiscard]] std::vector< PolygonDistance > all_intersections() const;
86137

include/geode/model/helpers/ray_tracing.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
namespace geode
3333
{
3434
FORWARD_DECLARATION_DIMENSION_CLASS( Block );
35-
ALIAS_3D( Block );
3635
FORWARD_DECLARATION_DIMENSION_CLASS( Surface );
37-
ALIAS_3D( Surface );
36+
ALIAS_3D( Block );
37+
ALIAS_2D( Surface );
3838
class BRep;
39+
class Section;
3940
struct uuid;
4041
} // namespace geode
4142

@@ -57,4 +58,12 @@ namespace geode
5758

5859
[[nodiscard]] std::optional< uuid > opengeode_model_api
5960
block_containing_point( const BRep& brep, const Point3D& point );
61+
62+
bool opengeode_model_api is_point_inside_surface( const Section& section,
63+
const Surface2D& surface,
64+
const Point2D& point );
65+
66+
[[nodiscard]] std::optional< uuid >
67+
opengeode_model_api surface_containing_point(
68+
const Section& section, const Point2D& point );
6069
} // namespace geode

src/geode/geometry/sign.cpp

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

2424
#include <geode/geometry/sign.hpp>
2525

26+
#include <geode/geometry/basic_objects/polygon.hpp>
2627
#include <geode/geometry/basic_objects/tetrahedron.hpp>
2728
#include <geode/geometry/basic_objects/triangle.hpp>
2829
#include <geode/geometry/internal/position_from_sides.hpp>
@@ -53,6 +54,24 @@ namespace geode
5354
GEO::PCK::orient_2d( vertices[0], vertices[1], vertices[2] ) );
5455
}
5556

57+
Sign polygon_area_sign( const Polygon2D& polygon )
58+
{
59+
const auto& polygon_vertices = polygon.vertices();
60+
const auto& p1 = polygon_vertices[0];
61+
for( const auto other_index : LRange{ 1, polygon_vertices.size() - 1 } )
62+
{
63+
const auto& p2 = polygon_vertices[other_index];
64+
const auto& p3 = polygon_vertices[static_cast< local_index_t >(
65+
other_index + 1 )];
66+
const auto sign = triangle_area_sign( { p1, p2, p3 } );
67+
if( sign != Sign::zero )
68+
{
69+
return sign;
70+
}
71+
}
72+
return geode::Sign::zero;
73+
}
74+
5675
Sign triangle_area_sign( const Triangle3D& triangle, local_index_t axis )
5776
{
5877
const auto axis1 = new_axis[axis][0];

0 commit comments

Comments
 (0)