33template<
class MetricToPenalty>
41 bool addStart( VertId startVert,
float startMetric );
72 bool done()
const {
return nextSteps_.empty(); }
75 float doneDistance()
const {
return nextSteps_.empty() ? FLT_MAX : nextSteps_.top().penalty; }
98 float penalty = FLT_MAX;
101 friend bool operator <(
const CandidateVert & a,
const CandidateVert & b )
103 return a.penalty > b.penalty;
106 std::priority_queue<CandidateVert> nextSteps_;
117 float operator()(
float metric, VertId )
const {
return metric; }
122template<
class MetricToPenalty>
124 : topology_( topology )
129template<
class MetricToPenalty>
132 auto & vi = vertPathInfoMap_[startVert];
133 if ( vi.metric > startMetric )
135 vi = { EdgeId{}, startMetric };
136 nextSteps_.push( CandidateVert{ startVert, metricToPenalty_( startMetric, startVert ) } );
142template<
class MetricToPenalty>
145 auto it = vertPathInfoMap_.find( v );
146 return ( it != vertPathInfoMap_.end() ) ? &it->second :
nullptr;
149template<
class MetricToPenalty>
155 auto it = vertPathInfoMap_.find( v );
156 if ( it == vertPathInfoMap_.end() )
161 auto & vi = it->second;
164 res.push_back( vi.back );
165 v = topology_.dest( vi.back );
170template<
class MetricToPenalty>
173 if ( !( c.
metric < FLT_MAX ) )
175 const auto vert = topology_.org( c.
back );
176 auto & vi = vertPathInfoMap_[vert];
177 if ( vi.metric > c.
metric )
180 nextSteps_.push( CandidateVert{ vert, metricToPenalty_( c.
metric, vert ) } );
186template<
class MetricToPenalty>
189 bool aNextStepAdded =
false;
193 return aNextStepAdded;
195 const float orgMetric = rv.
metric;
197 for ( EdgeId e :
orgRing( topology_, back ) )
201 c.
metric = orgMetric + metric_( e );
202 aNextStepAdded = addNextStep_( c ) || aNextStepAdded;
204 return aNextStepAdded;
207template<
class MetricToPenalty>
210 while ( !nextSteps_.empty() )
212 const auto c = nextSteps_.top();
214 auto & vi = vertPathInfoMap_[c.v];
215 if ( metricToPenalty_( vi.metric, c.v ) < c.penalty )
220 assert( metricToPenalty_( vi.metric, c.v ) == c.penalty );
221 return { .v = c.v, .backward = vi.
back, .penalty = c.penalty, .
metric = vi.metric };
226template<
class MetricToPenalty>
229 auto res = reachNext();
230 addOrgRingSteps( res );
263 const auto startPt = mesh.
triPoint( start );
#define MR_NO_UNIQUE_ADDRESS
Definition MRMacros.h:37
length
Definition MRObjectDimensionsEnum.h:14
Definition MREdgePathsBuilder.h:249
EdgePathsAStarBuilder(const Mesh &mesh, VertId target, VertId start)
Definition MREdgePathsBuilder.h:251
EdgePathsAStarBuilder(const Mesh &mesh, const MeshTriPoint &target, const MeshTriPoint &start)
Definition MREdgePathsBuilder.h:258
the class is responsible for finding smallest metric edge paths on a mesh
Definition MREdgePathsBuilder.h:35
ReachedVert growOneEdge()
the same as reachNext() + addOrgRingSteps()
Definition MREdgePathsBuilder.h:227
bool done() const
returns true if further edge forest growth is impossible
Definition MREdgePathsBuilder.h:72
bool addStart(VertId startVert, float startMetric)
Definition MREdgePathsBuilder.h:130
ReachedVert reachNext()
Definition MREdgePathsBuilder.h:208
float doneDistance() const
returns path length till the next candidate vertex or maximum float value if all vertices have been r...
Definition MREdgePathsBuilder.h:75
bool addOrgRingSteps(const ReachedVert &rv)
Definition MREdgePathsBuilder.h:187
MR_NO_UNIQUE_ADDRESS MetricToPenalty metricToPenalty_
Definition MREdgePathsBuilder.h:87
EdgePathsBuilderT(const MeshTopology &topology, const EdgeMetric &metric)
Definition MREdgePathsBuilder.h:123
EdgePath getPathBack(VertId backpathStart) const
returns the path in the forest from given vertex to one of start vertices
Definition MREdgePathsBuilder.h:150
const VertPathInfoMap & vertPathInfoMap() const
gives read access to the map from vertex to path to it
Definition MREdgePathsBuilder.h:78
const VertPathInfo * getVertInfo(VertId v) const
returns one element from the map (or nullptr if the element is missing)
Definition MREdgePathsBuilder.h:143
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)
std::function< float(EdgeId)> EdgeMetric
Definition MRMesh/MRMeshFwd.h:460
HashMap< VertId, VertPathInfo > VertPathInfoMap
Definition MREdgePathsBuilder.h:30
std::vector< EdgeId > EdgePath
Definition MRMesh/MRMeshFwd.h:120
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:482
information about just reached vertex (with final metric value)
Definition MREdgePathsBuilder.h:45
float penalty
Definition MREdgePathsBuilder.h:53
EdgeId backward
edge from this vertex to its predecessor in the forest (if this vertex is not start)
Definition MREdgePathsBuilder.h:49
float metric
summed metric to reach this vertex
Definition MREdgePathsBuilder.h:56
VertId v
Definition MREdgePathsBuilder.h:46
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:237
Vector3f target
Definition MREdgePathsBuilder.h:239
float operator()(float metric, VertId v) const
Definition MREdgePathsBuilder.h:240
const VertCoords * points
Definition MREdgePathsBuilder.h:238
the vertices in the queue are ordered by their metric from a start location
Definition MREdgePathsBuilder.h:116
float operator()(float metric, VertId) const
Definition MREdgePathsBuilder.h:117
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