MeshLib Documentation
Loading...
Searching...
No Matches
MRPointCloudTriangulationHelpers.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRPch/MRBindingMacros.h"
4#include "MRVector.h"
5#include "MRId.h"
6#include "MRConstants.h"
7#include "MRBuffer.h"
8#include "MRPointsProject.h"
9#include "MRFewSmallest.h"
10#include <climits>
11#include <optional>
12#include <queue>
13
14namespace MR
15{
21namespace TriangulationHelpers
22{
23
29MRMESH_API float updateNeighborsRadius( const VertCoords& points, VertId v, VertId boundaryV,
30 const std::vector<VertId>& fan, float baseRadius );
31
36MRMESH_API void findNeighborsInBall( const PointCloud& pointCloud, VertId v, float radius, std::vector<VertId>& neighbors );
37
45MRMESH_API float findNumNeighbors( const PointCloud& pointCloud, VertId v, int numNeis, std::vector<VertId>& neighbors,
46 FewSmallest<PointsProjectionResult> & tmp, float upDistLimitSq = FLT_MAX );
47
52MRMESH_API void filterNeighbors( const VertNormals& normals, VertId v, std::vector<VertId>& neighbors );
53
55{
56 float weight{ 0.0f }; // profit of flipping this edge
57 int id{ -1 }; // index
58
59 // needed to remove outdated queue elements
60 int prevId{ -1 }; // id of prev neighbor
61 int nextId{ -1 }; // id of next neighbor
62
63 bool stable{ false }; // if this flag is true, edge cannot be flipped
65 {
66 if ( stable == other.stable )
67 return weight < other.weight;
68 return stable;
69 }
70 bool operator==( const FanOptimizerQueueElement& other ) const = default;
71
72 bool isOutdated( const std::vector<VertId>& neighbors ) const
73 {
74 return !neighbors[nextId].valid() || !neighbors[prevId].valid();
75 }
76};
77
83{
86 std::vector<VertId> neighbors;
87
89 std::vector<std::pair<double, int>> cacheAngleOrder;
90
93 VertId border;
94
97
100 MR_BIND_IGNORE std::priority_queue<FanOptimizerQueueElement> queue;
101};
102
104{
107 float radius = 0;
108
111 int numNeis = 0;
112
114 float critAngle = PI2_F;
115
117 float boundaryAngle = 0.9f * PI_F;
118
120 const VertCoords* trustedNormals = nullptr;
121
124
126 int maxRemoves = INT_MAX;
127
129 std::vector<VertId> * allNeighbors = nullptr;
130
132 float * actualRadius = nullptr;
133
135 const PointCloud * searchNeighbors = nullptr;
136};
137
139MRMESH_API void buildLocalTriangulation( const PointCloud& cloud, VertId v, const Settings & settings,
140 TriangulatedFanData & fanData );
141
144[[nodiscard]] MRMESH_API std::optional<std::vector<SomeLocalTriangulations>> buildLocalTriangulations(
145 const PointCloud& cloud, const Settings & settings, const ProgressCallback & progress = {} );
146
148[[nodiscard]] MRMESH_API std::optional<AllLocalTriangulations> buildUnitedLocalTriangulations(
149 const PointCloud& cloud, const Settings & settings, const ProgressCallback & progress = {} );
150
160[[nodiscard]] MRMESH_API bool isBoundaryPoint( const PointCloud& cloud, VertId v, const Settings & settings,
161 TriangulatedFanData & fanData );
162
164[[nodiscard]] MRMESH_API std::optional<VertBitSet> findBoundaryPoints( const PointCloud& pointCloud, const Settings & settings,
165 ProgressCallback cb = {} );
166
167
168} //namespace TriangulationHelpers
169
170} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
the class stores some number of smallest elements from a larger number of candidates
Definition MRFewSmallest.h:14
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:576
MRMESH_API void findNeighborsInBall(const PointCloud &pointCloud, VertId v, float radius, std::vector< VertId > &neighbors)
Finds all neighbors of v in given radius (v excluded)
MRMESH_API float updateNeighborsRadius(const VertCoords &points, VertId v, VertId boundaryV, const std::vector< VertId > &fan, float baseRadius)
Finds max radius of neighbors search, for possible better local triangulation.
MRMESH_API bool isBoundaryPoint(const PointCloud &cloud, VertId v, const Settings &settings, TriangulatedFanData &fanData)
Checks if given vertex is on boundary of the point cloud, by constructing local triangulation around ...
MRMESH_API void filterNeighbors(const VertNormals &normals, VertId v, std::vector< VertId > &neighbors)
Filter neighbors with crossing normals.
MRMESH_API float findNumNeighbors(const PointCloud &pointCloud, VertId v, int numNeis, std::vector< VertId > &neighbors, FewSmallest< PointsProjectionResult > &tmp, float upDistLimitSq=FLT_MAX)
Finds at most given number of neighbors of v (v excluded)
MRMESH_API std::optional< std::vector< SomeLocalTriangulations > > buildLocalTriangulations(const PointCloud &cloud, const Settings &settings, const ProgressCallback &progress={})
MRMESH_API std::optional< VertBitSet > findBoundaryPoints(const PointCloud &pointCloud, const Settings &settings, ProgressCallback cb={})
Returns bit set of points that are considered as boundary by calling isBoundaryPoint in each.
MRMESH_API void buildLocalTriangulation(const PointCloud &cloud, VertId v, const Settings &settings, TriangulatedFanData &fanData)
constructs local triangulation around given point
MRMESH_API std::optional< AllLocalTriangulations > buildUnitedLocalTriangulations(const PointCloud &cloud, const Settings &settings, const ProgressCallback &progress={})
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh/MRPointCloud.h:16
Definition MRPointCloudTriangulationHelpers.h:55
bool stable
Definition MRPointCloudTriangulationHelpers.h:63
bool operator==(const FanOptimizerQueueElement &other) const =default
float weight
Definition MRPointCloudTriangulationHelpers.h:56
int prevId
Definition MRPointCloudTriangulationHelpers.h:60
int nextId
Definition MRPointCloudTriangulationHelpers.h:61
bool operator<(const FanOptimizerQueueElement &other) const
Definition MRPointCloudTriangulationHelpers.h:64
bool isOutdated(const std::vector< VertId > &neighbors) const
Definition MRPointCloudTriangulationHelpers.h:72
Definition MRPointCloudTriangulationHelpers.h:104
int maxRemoves
the maximum number of optimization steps (removals) in local triangulation
Definition MRPointCloudTriangulationHelpers.h:126
float boundaryAngle
the vertex is considered as boundary if its neighbor ring has angle more than this value
Definition MRPointCloudTriangulationHelpers.h:117
int numNeis
Definition MRPointCloudTriangulationHelpers.h:111
bool automaticRadiusIncrease
automatic increase of the radius if points outside can make triangles from original radius not-Delone
Definition MRPointCloudTriangulationHelpers.h:123
std::vector< VertId > * allNeighbors
optional output of considered neighbor points after filtering but before triangulation/optimization
Definition MRPointCloudTriangulationHelpers.h:129
const PointCloud * searchNeighbors
optional: if provided this cloud will be used for searching of neighbors (so it must have same validP...
Definition MRPointCloudTriangulationHelpers.h:135
const VertCoords * trustedNormals
if oriented normals are known, they will be used for neighbor points selection
Definition MRPointCloudTriangulationHelpers.h:120
float * actualRadius
optional output: actual radius of neighbor search (after increase if any)
Definition MRPointCloudTriangulationHelpers.h:132
float critAngle
max allowed angle for triangles in fan
Definition MRPointCloudTriangulationHelpers.h:114
float radius
Definition MRPointCloudTriangulationHelpers.h:107
Data with caches for optimizing fan triangulation.
Definition MRPointCloudTriangulationHelpers.h:83
FewSmallest< PointsProjectionResult > nearesetPoints
the storage to collect n-nearest neighbours, here to avoid allocations for each point
Definition MRPointCloudTriangulationHelpers.h:96
VertId border
Definition MRPointCloudTriangulationHelpers.h:93
std::vector< std::pair< double, int > > cacheAngleOrder
temporary reusable storage to avoid allocations for each point
Definition MRPointCloudTriangulationHelpers.h:89
MR_BIND_IGNORE std::priority_queue< FanOptimizerQueueElement > queue
Definition MRPointCloudTriangulationHelpers.h:100
std::vector< VertId > neighbors
Definition MRPointCloudTriangulationHelpers.h:86