33template<
class MetricToPenalty>
40 bool addStart( VertId startVert,
float startMetric );
65 bool done()
const {
return nextSteps_.empty(); }
67 float doneDistance()
const {
return nextSteps_.empty() ? FLT_MAX : nextSteps_.top().penalty; }
88 float penalty = FLT_MAX;
91 friend bool operator <(
const CandidateVert & a,
const CandidateVert & b )
93 return a.penalty > b.penalty;
96 std::priority_queue<CandidateVert> nextSteps_;
107 float operator()(
float metric, VertId )
const {
return metric; }
112template<
class MetricToPenalty>
114 : topology_( topology )
119template<
class MetricToPenalty>
122 auto & vi = vertPathInfoMap_[startVert];
123 if ( vi.metric > startMetric )
125 vi = { EdgeId{}, startMetric };
126 nextSteps_.push( CandidateVert{ startVert, metricToPenalty_( startMetric, startVert ) } );
132template<
class MetricToPenalty>
135 auto it = vertPathInfoMap_.find( v );
136 return ( it != vertPathInfoMap_.end() ) ? &it->second :
nullptr;
139template<
class MetricToPenalty>
145 auto it = vertPathInfoMap_.find( v );
146 if ( it == vertPathInfoMap_.end() )
151 auto & vi = it->second;
154 res.push_back( vi.back );
155 v = topology_.dest( vi.back );
160template<
class MetricToPenalty>
163 if ( !( c.
metric < FLT_MAX ) )
165 const auto vert = topology_.org( c.
back );
166 auto & vi = vertPathInfoMap_[vert];
167 if ( vi.metric > c.
metric )
170 nextSteps_.push( CandidateVert{ vert, metricToPenalty_( c.
metric, vert ) } );
176template<
class MetricToPenalty>
179 bool aNextStepAdded =
false;
183 return aNextStepAdded;
185 const float orgMetric = rv.
metric;
187 for ( EdgeId e :
orgRing( topology_, back ) )
191 c.
metric = orgMetric + metric_( e );
192 aNextStepAdded = addNextStep_( c ) || aNextStepAdded;
194 return aNextStepAdded;
197template<
class MetricToPenalty>
200 while ( !nextSteps_.empty() )
202 const auto c = nextSteps_.top();
204 auto & vi = vertPathInfoMap_[c.v];
205 if ( metricToPenalty_( vi.metric, c.v ) < c.penalty )
210 assert( metricToPenalty_( vi.metric, c.v ) == c.penalty );
211 return { .v = c.v, .backward = vi.
back, .penalty = c.penalty, .
metric = vi.metric };
216template<
class MetricToPenalty>
219 auto res = reachNext();
220 addOrgRingSteps( res );
253 const auto startPt = mesh.
triPoint( start );
#define MR_NO_UNIQUE_ADDRESS
Definition MRMacros.h:37
length
Definition MRObjectDimensionsEnum.h:14
Definition MREdgePathsBuilder.h:239
EdgePathsAStarBuilder(const Mesh &mesh, VertId target, VertId start)
Definition MREdgePathsBuilder.h:241
EdgePathsAStarBuilder(const Mesh &mesh, const MeshTriPoint &target, const MeshTriPoint &start)
Definition MREdgePathsBuilder.h:248
the class is responsible for finding smallest metric edge paths on a mesh
Definition MREdgePathsBuilder.h:35
ReachedVert growOneEdge()
Definition MREdgePathsBuilder.h:217
bool done() const
Definition MREdgePathsBuilder.h:65
bool addStart(VertId startVert, float startMetric)
Definition MREdgePathsBuilder.h:120
ReachedVert reachNext()
Definition MREdgePathsBuilder.h:198
float doneDistance() const
Definition MREdgePathsBuilder.h:67
bool addOrgRingSteps(const ReachedVert &rv)
Definition MREdgePathsBuilder.h:177
MR_NO_UNIQUE_ADDRESS MetricToPenalty metricToPenalty_
Definition MREdgePathsBuilder.h:77
EdgePathsBuilderT(const MeshTopology &topology, const EdgeMetric &metric)
Definition MREdgePathsBuilder.h:113
EdgePath getPathBack(VertId backpathStart) const
Definition MREdgePathsBuilder.h:140
const VertPathInfoMap & vertPathInfoMap() const
Definition MREdgePathsBuilder.h:69
const VertPathInfo * getVertInfo(VertId v) const
Definition MREdgePathsBuilder.h:133
Definition MRMesh/MRMeshTopology.h:18
void forEachVertex(const MeshTriPoint &p, T &&callback) const
Definition MRMesh/MRMeshTopology.h:571
MRMESH_API EdgeMetric edgeLengthMetric(const Mesh &mesh)
Definition MRCameraOrientationPlugin.h:8
std::function< float(EdgeId)> EdgeMetric
Definition MRMesh/MRMeshFwd.h:438
HashMap< VertId, VertPathInfo > VertPathInfoMap
Definition MREdgePathsBuilder.h:30
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:460
Definition MREdgePathsBuilder.h:44
float penalty
Definition MREdgePathsBuilder.h:49
EdgeId backward
Definition MREdgePathsBuilder.h:47
float metric
Definition MREdgePathsBuilder.h:51
VertId v
Definition MREdgePathsBuilder.h:45
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:227
Vector3f target
Definition MREdgePathsBuilder.h:229
float operator()(float metric, VertId v) const
Definition MREdgePathsBuilder.h:230
const VertCoords * points
Definition MREdgePathsBuilder.h:228
the vertices in the queue are ordered by their metric from a start location
Definition MREdgePathsBuilder.h:106
float operator()(float metric, VertId) const
Definition MREdgePathsBuilder.h:107
information associated with each vertex by the paths builder
Definition MREdgePathsBuilder.h:19
float metric
Definition MREdgePathsBuilder.h:23
EdgeId back
Definition MREdgePathsBuilder.h:21
bool isStart() const
Definition MREdgePathsBuilder.h:25