36template<
class MetricToPenalty>
45 void reset(
const EdgeMetric & metric );
49 bool addStart( VertId startVert,
float startMetric );
80 bool done()
const {
return nextSteps_.empty(); }
83 float doneDistance()
const {
return nextSteps_.empty() ? FLT_MAX : nextSteps_.top().penalty; }
96 VertId
trackPathBack( VertId backpathStart, EdgePath* res =
nullptr )
const;
113 friend bool operator <(
const CandidateVert & a,
const CandidateVert & b )
118 std::priority_queue<CandidateVert> nextSteps_;
129 float operator()(
float metric, VertId )
const {
return metric; }
134template<
class MetricToPenalty>
136 : topology_( topology )
141template<
class MetricToPenalty>
143 : topology_( topology )
147template<
class MetricToPenalty>
151 vertPathInfoMap_.clear();
152 while ( !nextSteps_.empty() )
156template<
class MetricToPenalty>
159 auto & vi = vertPathInfoMap_[startVert];
160 if ( vi.metric > startMetric )
162 vi = { EdgeId{}, startMetric };
163 nextSteps_.push( CandidateVert{ startVert, metricToPenalty_( startMetric, startVert ) } );
169template<
class MetricToPenalty>
172 auto it = vertPathInfoMap_.find( v );
173 return ( it != vertPathInfoMap_.end() ) ? &it->second :
nullptr;
176template<
class MetricToPenalty>
180 trackPathBack( v, &res );
184template<
class MetricToPenalty>
189 auto it = vertPathInfoMap_.find( v );
190 if ( it == vertPathInfoMap_.end() )
195 auto & vi = it->second;
199 res->push_back( vi.back );
200 v = topology_.dest( vi.back );
205template<
class MetricToPenalty>
208 if ( !( c.
metric < FLT_MAX ) )
210 const auto vert = topology_.org( c.
back );
211 auto & vi = vertPathInfoMap_[vert];
212 if ( vi.metric > c.
metric )
215 nextSteps_.push( CandidateVert{ vert, metricToPenalty_( c.
metric, vert ) } );
221template<
class MetricToPenalty>
224 bool aNextStepAdded =
false;
228 return aNextStepAdded;
230 const float orgMetric = rv.
metric;
232 for ( EdgeId e :
orgRing( topology_, back ) )
236 c.
metric = orgMetric + metric_( e );
237 aNextStepAdded = addNextStep_( c ) || aNextStepAdded;
239 return aNextStepAdded;
242template<
class MetricToPenalty>
245 while ( !nextSteps_.empty() )
247 const auto c = nextSteps_.top();
249 auto & vi = vertPathInfoMap_[c.v];
250 if ( metricToPenalty_( vi.metric, c.v ) < c.penalty )
255 assert( metricToPenalty_( vi.metric, c.v ) == c.penalty );
256 return { .v = c.v, .backward = vi.
back, .penalty = c.penalty, .
metric = vi.metric };
261template<
class MetricToPenalty>
264 auto res = reachNext();
265 addOrgRingSteps( res );
298 const auto startPt = mesh.
triPoint( start );
#define MR_NO_UNIQUE_ADDRESS
Definition MRMacros.h:42
Definition MREdgePathsBuilder.h:284
the class is responsible for finding smallest metric edge paths on a mesh
Definition MREdgePathsBuilder.h:38
Definition MRMeshTopology.h:22
float penalty
Definition MREdgePathsBuilder.h:61
Vector3f target
Definition MREdgePathsBuilder.h:274
ReachedVert growOneEdge()
the same as reachNext() + addOrgRingSteps()
Definition MREdgePathsBuilder.h:262
friend bool operator<(const CandidateVert &a, const CandidateVert &b)
smaller penalty to be the first
Definition MREdgePathsBuilder.h:113
float metric
best summed metric to reach this vertex
Definition MREdgePathsBuilder.h:26
bool done() const
returns true if further edge forest growth is impossible
Definition MREdgePathsBuilder.h:80
VertId v
Definition MREdgePathsBuilder.h:108
bool addStart(VertId startVert, float startMetric)
Definition MREdgePathsBuilder.h:157
ReachedVert reachNext()
Definition MREdgePathsBuilder.h:243
EdgeId backward
edge from this vertex to its predecessor in the forest (if this vertex is not start)
Definition MREdgePathsBuilder.h:57
EdgePathsAStarBuilder(const Mesh &mesh, VertId target, VertId start)
Definition MREdgePathsBuilder.h:286
EdgePathsBuilderT(const MeshTopology &topology)
Definition MREdgePathsBuilder.h:142
float doneDistance() const
returns path length till the next candidate vertex or maximum float value if all vertices have been r...
Definition MREdgePathsBuilder.h:83
bool addOrgRingSteps(const ReachedVert &rv)
Definition MREdgePathsBuilder.h:222
EdgeId back
edge from this vertex to its predecessor in the forest
Definition MREdgePathsBuilder.h:24
float metric
summed metric to reach this vertex
Definition MREdgePathsBuilder.h:64
void reset(const EdgeMetric &metric)
clears everything without freeing memory, and sets new metric
Definition MREdgePathsBuilder.h:148
MR_NO_UNIQUE_ADDRESS MetricToPenalty metricToPenalty_
Definition MREdgePathsBuilder.h:99
HashMap< VertId, VertPathInfo > VertPathInfoMap
Definition MREdgePathsBuilder.h:33
VertId trackPathBack(VertId backpathStart, EdgePath *res=nullptr) const
Definition MREdgePathsBuilder.h:185
EdgePathsBuilderT(const MeshTopology &topology, const EdgeMetric &metric)
Definition MREdgePathsBuilder.h:135
EdgePath getPathBack(VertId backpathStart) const
returns the path in the forest from given vertex to one of start vertices
Definition MREdgePathsBuilder.h:177
bool isStart() const
Definition MREdgePathsBuilder.h:28
void forEachVertex(const MeshTriPoint &p, T &&callback) const
Definition MRMeshTopology.h:602
IteratorRange< OrgRingIterator > orgRing(const MeshTopology &topology, EdgeId edge)
Definition MRRingIterator.h:68
float operator()(float metric, VertId) const
Definition MREdgePathsBuilder.h:129
const VertPathInfoMap & vertPathInfoMap() const
gives read access to the map from vertex to path to it
Definition MREdgePathsBuilder.h:86
VertId v
Definition MREdgePathsBuilder.h:54
float operator()(float metric, VertId v) const
Definition MREdgePathsBuilder.h:275
EdgePathsAStarBuilder(const Mesh &mesh, const MeshTriPoint &target, const MeshTriPoint &start)
Definition MREdgePathsBuilder.h:293
const VertPathInfo * getVertInfo(VertId v) const
returns one element from the map (or nullptr if the element is missing)
Definition MREdgePathsBuilder.h:170
float penalty
best penalty to reach this vertex
Definition MREdgePathsBuilder.h:110
const VertCoords * points
Definition MREdgePathsBuilder.h:273
length
Definition MRObjectDimensionsEnum.h:17
MRMESH_API EdgeMetric edgeLengthMetric(const Mesh &mesh)
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
information about just reached vertex (with final metric value)
Definition MREdgePathsBuilder.h:53
Definition MRMeshTriPoint.h:26
MeshTopology topology
Definition MRMesh.h:24
Vector3f triPoint(const MeshTriPoint &p) const
computes coordinates of point given as face and barycentric representation
Definition MRMesh.h:103
VertCoords points
Definition MRMesh.h:25
Definition MREdgePathsBuilder.h:272
the vertices in the queue are ordered by their metric from a start location
Definition MREdgePathsBuilder.h:128
information associated with each vertex by the paths builder
Definition MREdgePathsBuilder.h:22