Skip to content

Commit cee71d8

Browse files
authored
findDirMax( const MeshVertPart& ) (#4488)
1 parent 93a1fdc commit cee71d8

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

source/MRMesh/MRDirMax.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ VertId findDirMaxT( const V & dir, const Polyline<V> & polyline, UseAABBTree u )
107107

108108
} // anonymous namespace
109109

110+
VertId findDirMax( const Vector3f & dir, const Mesh & m, UseAABBTree u )
111+
{
112+
return findDirMax( dir, MeshPart{ m }, u );
113+
}
114+
110115
VertId findDirMax( const Vector3f & dir, const MeshPart & mp, UseAABBTree u )
111116
{
112117
if ( u == UseAABBTree::No || ( u == UseAABBTree::YesIfAlreadyConstructed && !mp.mesh.getAABBTreeNotCreate() ) )
@@ -131,6 +136,14 @@ VertId findDirMax( const Vector3f & dir, const MeshPart & mp, UseAABBTree u )
131136
} );
132137
}
133138

139+
VertId findDirMax( const Vector3f & dir, const MeshVertPart & mp, UseAABBTree u )
140+
{
141+
if ( u == UseAABBTree::No || ( u == UseAABBTree::YesIfAlreadyConstructed && !mp.mesh.getAABBTreePointsNotCreate() ) )
142+
return findDirMaxBruteForce( dir, mp );
143+
144+
return findDirMax( dir, mp.mesh.getAABBTreePoints(), mp.region );
145+
}
146+
134147
VertId findDirMax( const Vector3f & dir, const Polyline3 & polyline, UseAABBTree u )
135148
{
136149
return findDirMaxT( dir, polyline, u );
@@ -141,19 +154,26 @@ VertId findDirMax( const Vector2f & dir, const Polyline2 & polyline, UseAABBTree
141154
return findDirMaxT( dir, polyline, u );
142155
}
143156

144-
VertId findDirMax( const Vector3f & dir, const PointCloud & cloud, UseAABBTree u )
157+
VertId findDirMax( const Vector3f & dir, const PointCloud & cloud, const VertBitSet * region, UseAABBTree u )
145158
{
146159
if ( u == UseAABBTree::No || ( u == UseAABBTree::YesIfAlreadyConstructed && !cloud.getAABBTreeNotCreate() ) )
147-
return findDirMaxBruteForce( dir, cloud );
160+
return findDirMaxBruteForce( dir, cloud, region );
148161

149-
const auto& tree = cloud.getAABBTree();
162+
return findDirMax( dir, cloud.getAABBTree(), region );
163+
}
164+
165+
VertId findDirMax( const Vector3f & dir, const AABBTreePoints & tree, const VertBitSet * region )
166+
{
150167
const auto& orderedPoints = tree.orderedPoints();
151168

152169
return findDirMaxT( dir, tree, [&]( const AABBTreePoints::Node & node, float & furthestProj, VertId & res )
153170
{
154171
auto [first, last] = node.getLeafPointRange();
155172
for ( int i = first; i < last; ++i )
156173
{
174+
if ( region )
175+
if ( !region->test( orderedPoints[i].id ) )
176+
continue;
157177
auto proj = dot( orderedPoints[i].coord, dir );
158178
if ( proj > furthestProj )
159179
{

source/MRMesh/MRDirMax.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@
66
namespace MR
77
{
88

9+
/// finds the vertex in the mesh part having the largest projection on given direction,
10+
/// optionally uses aabb-tree inside for faster computation
11+
/// \ingroup AABBTreeGroup
12+
[[nodiscard]] MRMESH_API VertId findDirMax( const Vector3f & dir, const Mesh & m, UseAABBTree u = UseAABBTree::Yes );
13+
914
/// finds the vertex in the mesh part having the largest projection on given direction,
1015
/// optionally uses aabb-tree inside for faster computation
1116
/// \ingroup AABBTreeGroup
1217
[[nodiscard]] MRMESH_API VertId findDirMax( const Vector3f & dir, const MeshPart & mp, UseAABBTree u = UseAABBTree::Yes );
1318

19+
/// finds the vertex in the mesh part having the largest projection on given direction,
20+
/// optionally uses aabb-points-tree inside for faster computation
21+
/// \ingroup AABBTreeGroup
22+
[[nodiscard]] MRMESH_API VertId findDirMax( const Vector3f & dir, const MeshVertPart & mp, UseAABBTree u = UseAABBTree::Yes );
23+
1424
/// finds the vertex in the polyline having the largest projection on given direction,
1525
/// optionally uses aabb-tree inside for faster computation
1626
/// \ingroup AABBTreeGroup
@@ -24,7 +34,11 @@ namespace MR
2434
/// finds the point in the cloud having the largest projection on given direction,
2535
/// optionally uses aabb-tree inside for faster computation
2636
/// \ingroup AABBTreeGroup
27-
[[nodiscard]] MRMESH_API VertId findDirMax( const Vector3f & dir, const PointCloud & cloud, UseAABBTree u = UseAABBTree::Yes );
37+
[[nodiscard]] MRMESH_API VertId findDirMax( const Vector3f & dir, const PointCloud & cloud, const VertBitSet * region = nullptr, UseAABBTree u = UseAABBTree::Yes );
38+
39+
/// finds the point in the tree having the largest projection on given direction
40+
/// \ingroup AABBTreeGroup
41+
[[nodiscard]] MRMESH_API VertId findDirMax( const Vector3f & dir, const AABBTreePoints & tree, const VertBitSet * region = nullptr );
2842

2943
} //namespace MR
3044

source/MRMesh/MRDirMaxBruteForce.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ VertId findDirMaxBruteForce( const Vector2f & dir, const VertCoords2 & points, c
7373
return findDirMaxBruteForceT( dir, points, region );
7474
}
7575

76-
VertId findDirMaxBruteForce( const Vector3f & dir, const PointCloud & cloud )
76+
VertId findDirMaxBruteForce( const Vector3f & dir, const PointCloud & cloud, const VertBitSet * region )
7777
{
78-
return findDirMaxBruteForce( dir, cloud.points, &cloud.validPoints );
78+
return findDirMaxBruteForce( dir, cloud.points, region ? region : &cloud.validPoints );
7979
}
8080

8181
VertId findDirMaxBruteForce( const Vector3f & dir, const Polyline3 & polyline )
@@ -113,6 +113,11 @@ VertId findDirMaxBruteForce( const Vector3f & dir, const MeshPart & mp )
113113
return pv.v;
114114
}
115115

116+
VertId findDirMaxBruteForce( const Vector3f & dir, const MeshVertPart & mp )
117+
{
118+
return findDirMaxBruteForce( dir, mp.mesh.points, &mp.mesh.topology.getVertIds( mp.region ) );
119+
}
120+
116121
MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const VertCoords & points, const VertBitSet * region )
117122
{
118123
return findDirMinMaxBruteForceT( dir, points, region );
@@ -123,9 +128,9 @@ MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector2f & dir, const Ve
123128
return findDirMinMaxBruteForceT( dir, points, region );
124129
}
125130

126-
MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const PointCloud & cloud )
131+
MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const PointCloud & cloud, const VertBitSet * region )
127132
{
128-
return findDirMinMaxBruteForce( dir, cloud.points, &cloud.validPoints );
133+
return findDirMinMaxBruteForce( dir, cloud.points, region ? region : &cloud.validPoints );
129134
}
130135

131136
MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const Polyline3 & polyline )
@@ -162,4 +167,9 @@ MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const Me
162167
);
163168
}
164169

170+
MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const MeshVertPart & mp )
171+
{
172+
return findDirMinMaxBruteForce( dir, mp.mesh.points, &mp.mesh.topology.getVertIds( mp.region ) );
173+
}
174+
165175
} //namespace MR

source/MRMesh/MRDirMaxBruteForce.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace MR
1313
[[nodiscard]] MRMESH_API VertId findDirMaxBruteForce( const Vector2f & dir, const VertCoords2 & points, const VertBitSet * region = nullptr );
1414

1515
/// finds the point in the cloud having the largest projection on given direction by traversing all valid points
16-
[[nodiscard]] MRMESH_API VertId findDirMaxBruteForce( const Vector3f & dir, const PointCloud & cloud );
16+
[[nodiscard]] MRMESH_API VertId findDirMaxBruteForce( const Vector3f & dir, const PointCloud & cloud, const VertBitSet * region = nullptr );
1717

1818
/// finds the vertex in the polyline having the largest projection on given direction by traversing all valid vertices
1919
[[nodiscard]] MRMESH_API VertId findDirMaxBruteForce( const Vector3f & dir, const Polyline3 & polyline );
@@ -24,14 +24,17 @@ namespace MR
2424
/// finds the vertex in the mesh part having the largest projection on given direction by traversing all (region) faces
2525
[[nodiscard]] MRMESH_API VertId findDirMaxBruteForce( const Vector3f & dir, const MeshPart & mp );
2626

27+
/// finds the vertex in the mesh part having the largest projection on given direction by traversing all (region) vertices
28+
[[nodiscard]] MRMESH_API VertId findDirMaxBruteForce( const Vector3f & dir, const MeshVertPart & mp );
29+
2730
/// finds the points having the smallest and the largest projections on given direction by traversing all region points
2831
[[nodiscard]] MRMESH_API MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const VertCoords & points, const VertBitSet * region = nullptr );
2932

3033
/// finds the points having the smallest and the largest projections on given direction by traversing all region points
3134
[[nodiscard]] MRMESH_API MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector2f & dir, const VertCoords2 & points, const VertBitSet * region = nullptr );
3235

3336
/// finds the points in the cloud having the smallest and the largest projections on given direction by traversing all valid points
34-
[[nodiscard]] MRMESH_API MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const PointCloud & cloud );
37+
[[nodiscard]] MRMESH_API MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const PointCloud & cloud, const VertBitSet * region = nullptr );
3538

3639
/// finds the vertex in the polyline having the smallest and the largest projections on given direction by traversing all valid vertices
3740
[[nodiscard]] MRMESH_API MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const Polyline3 & polyline );
@@ -42,4 +45,7 @@ namespace MR
4245
/// finds the vertices in the mesh part having the smallest and the largest projections on given direction by traversing all (region) faces
4346
[[nodiscard]] MRMESH_API MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const MeshPart & mp );
4447

48+
/// finds the vertices in the mesh part having the smallest and the largest projections on given direction by traversing all (region) vertices
49+
[[nodiscard]] MRMESH_API MinMaxArg<float, VertId> findDirMinMaxBruteForce( const Vector3f & dir, const MeshVertPart & mp );
50+
4551
} //namespace MR

0 commit comments

Comments
 (0)