32template<
class MetricToPenalty>
64 bool done()
const {
return nextSteps_.empty(); }
66 float doneDistance()
const {
return nextSteps_.empty() ? FLT_MAX : nextSteps_.top().penalty; }
87 float penalty = FLT_MAX;
90 friend bool operator <(
const CandidateVert & a,
const CandidateVert & b )
92 return a.penalty > b.penalty;
95 std::priority_queue<CandidateVert> nextSteps_;
111template<
class MetricToPenalty>
113 : topology_( topology )
118template<
class MetricToPenalty>
121 auto & vi = vertPathInfoMap_[startVert];
122 if ( vi.metric > startMetric )
124 vi = {
EdgeId{}, startMetric };
125 nextSteps_.push( CandidateVert{ startVert, metricToPenalty_( startMetric, startVert ) } );
131template<
class MetricToPenalty>
134 auto it = vertPathInfoMap_.find( v );
135 return ( it != vertPathInfoMap_.end() ) ? &it->second :
nullptr;
138template<
class MetricToPenalty>
144 auto it = vertPathInfoMap_.find( v );
145 if ( it == vertPathInfoMap_.end() )
150 auto & vi = it->second;
153 res.push_back( vi.back );
154 v = topology_.dest( vi.back );
159template<
class MetricToPenalty>
162 if ( !( c.
metric < FLT_MAX ) )
164 const auto vert = topology_.org( c.
back );
165 auto & vi = vertPathInfoMap_[vert];
166 if ( vi.metric > c.
metric )
169 nextSteps_.push( CandidateVert{ vert, metricToPenalty_( c.
metric, vert ) } );
175template<
class MetricToPenalty>
178 bool aNextStepAdded =
false;
182 return aNextStepAdded;
184 const float orgMetric = rv.
metric;
190 c.
metric = orgMetric + metric_( e );
191 aNextStepAdded = addNextStep_( c ) || aNextStepAdded;
193 return aNextStepAdded;
196template<
class MetricToPenalty>
199 while ( !nextSteps_.empty() )
201 const auto c = nextSteps_.top();
203 auto & vi = vertPathInfoMap_[c.v];
204 if ( metricToPenalty_( vi.metric, c.v ) < c.penalty )
209 assert( metricToPenalty_( vi.metric, c.v ) == c.penalty );
210 return { .v = c.v, .backward = vi.
back, .penalty = c.penalty, .
metric = vi.metric };
215template<
class MetricToPenalty>
218 auto res = reachNext();
219 addOrgRingSteps( res );
252 const auto startPt = mesh.
triPoint( start );
List< Vector3f^> VertCoords
Definition MRDotNet/MRMeshFwd.h:95
int VertId
Definition MRDotNet/MRMeshFwd.h:51
int EdgeId
Definition MRDotNet/MRMeshFwd.h:52
length
Definition MRObjectDimensionsEnum.h:14
Definition MREdgePathsBuilder.h:238
EdgePathsAStarBuilder(const Mesh &mesh, VertId target, VertId start)
Definition MREdgePathsBuilder.h:240
EdgePathsAStarBuilder(const Mesh &mesh, const MeshTriPoint &target, const MeshTriPoint &start)
Definition MREdgePathsBuilder.h:247
the class is responsible for finding smallest metric edge paths on a mesh
Definition MREdgePathsBuilder.h:34
ReachedVert growOneEdge()
Definition MREdgePathsBuilder.h:216
bool done() const
Definition MREdgePathsBuilder.h:64
bool addStart(VertId startVert, float startMetric)
Definition MREdgePathsBuilder.h:119
ReachedVert reachNext()
Definition MREdgePathsBuilder.h:197
float doneDistance() const
Definition MREdgePathsBuilder.h:66
bool addOrgRingSteps(const ReachedVert &rv)
Definition MREdgePathsBuilder.h:176
MetricToPenalty metricToPenalty_
Definition MREdgePathsBuilder.h:76
EdgePathsBuilderT(const MeshTopology &topology, const EdgeMetric &metric)
Definition MREdgePathsBuilder.h:112
EdgePath getPathBack(VertId backpathStart) const
Definition MREdgePathsBuilder.h:139
const VertPathInfoMap & vertPathInfoMap() const
Definition MREdgePathsBuilder.h:68
const VertPathInfo * getVertInfo(VertId v) const
Definition MREdgePathsBuilder.h:132
Definition MRMesh/MRMeshTopology.h:18
void forEachVertex(const MeshTriPoint &p, T &&callback) const
Definition MRMesh/MRMeshTopology.h:560
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
MRMESH_API EdgeMetric edgeLengthMetric(const Mesh &mesh)
Definition MRCameraOrientationPlugin.h:7
std::function< float(EdgeId)> EdgeMetric
Definition MRMesh/MRMeshFwd.h:428
HashMap< VertId, VertPathInfo > VertPathInfoMap
Definition MREdgePathsBuilder.h:29
std::vector< EdgeId > EdgePath
Definition MRMesh/MRMeshFwd.h:98
IteratorRange< OrgRingIterator > orgRing(const MeshTopology &topology, EdgeId edge)
Definition MRRingIterator.h:70
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMesh/MRMeshFwd.h:450
Definition MREdgePathsBuilder.h:43
float penalty
Definition MREdgePathsBuilder.h:48
EdgeId backward
Definition MREdgePathsBuilder.h:46
float metric
Definition MREdgePathsBuilder.h:50
VertId v
Definition MREdgePathsBuilder.h:44
Definition MRMesh/MRMeshTriPoint.h:23
Definition MRMesh/MRMesh.h:23
MRMESH_API Vector3f triPoint(const MeshTriPoint &p) const
computes coordinates of point given as face and barycentric representation
MeshTopology topology
Definition MRMesh/MRMesh.h:24
VertCoords points
Definition MRMesh/MRMesh.h:25
Definition MREdgePathsBuilder.h:226
Vector3f target
Definition MREdgePathsBuilder.h:228
float operator()(float metric, VertId v) const
Definition MREdgePathsBuilder.h:229
const VertCoords * points
Definition MREdgePathsBuilder.h:227
the vertices in the queue are ordered by their metric from a start location
Definition MREdgePathsBuilder.h:105
float operator()(float metric, VertId) const
Definition MREdgePathsBuilder.h:106
information associated with each vertex by the paths builder
Definition MREdgePathsBuilder.h:18
float metric
Definition MREdgePathsBuilder.h:22
EdgeId back
Definition MREdgePathsBuilder.h:20
bool isStart() const
Definition MREdgePathsBuilder.h:24