MeshLib Documentation
Loading...
Searching...
No Matches
MRAggregateFlow.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshTriPoint.h"
4#include "MRVector.h"
5#include "MRPolyline.h"
6#include <functional>
7
8namespace MR
9{
10
12{
16 float amount = 1;
17};
18
20{
22 Polyline3* pPolyline = nullptr;
24 UndirectedEdgeScalars* pFlowPerEdge = nullptr;
27};
28
31{
32public:
34 MRMESH_API FlowAggregator( const Mesh & mesh, const VertScalars & heights );
35
39 MRMESH_API VertScalars computeFlow( const std::vector<FlowOrigin> & starts, const OutputFlows & out = {} ) const;
40 // same with all amounts equal to 1
41 MRMESH_API VertScalars computeFlow( const std::vector<MeshTriPoint> & starts, const OutputFlows & out = {} ) const;
42 // general version that supplies starts in a functional way
43 MRMESH_API VertScalars computeFlow( size_t numStarts,
44 const std::function<MeshTriPoint(size_t)> & startById,
45 const std::function<float(size_t)> & amountById,
46 const std::function<const FaceBitSet*(size_t)> & regionById,
47 const OutputFlows & out = {} ) const;
48
49 struct Flows
50 {
51 Polyline3 polyline;
52 UndirectedEdgeScalars flowPerEdge;
53 };
54
58 MRMESH_API HashMap<VertId, Flows> computeFlowsPerBasin( const std::vector<FlowOrigin> & starts ) const;
59 // same with all amounts equal to 1
60 MRMESH_API HashMap<VertId, Flows> computeFlowsPerBasin( const std::vector<MeshTriPoint> & starts ) const;
61 // general version that supplies starts in a functional way
63 const std::function<MeshTriPoint(size_t)> & startById,
64 const std::function<float(size_t)> & amountById ) const;
65
68 [[nodiscard]] MRMESH_API UndirectedEdgeBitSet computeCatchmentDelineation() const;
69
70private:
71 const Mesh & mesh_;
72 const VertScalars & heights_;
73 VertMap downFlowVert_; // for each vertex stores what next vertex is on flow path (invalid vertex for local minima)
74 VertMap rootVert_; // for each vertex stores the final vertex is on flow path (self-vertex for local minima)
75 Vector<SurfacePath, VertId> downPath_; // till next vertex
76 std::vector<VertId> vertsSortedDesc_; // all vertices sorted in descending heights order
77};
78
79} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
this class can track multiple flows and find in each mesh vertex the amount of water reached it
Definition MRAggregateFlow.h:31
MRMESH_API UndirectedEdgeBitSet computeCatchmentDelineation() const
MRMESH_API VertScalars computeFlow(size_t numStarts, const std::function< MeshTriPoint(size_t)> &startById, const std::function< float(size_t)> &amountById, const std::function< const FaceBitSet *(size_t)> &regionById, const OutputFlows &out={}) const
MRMESH_API HashMap< VertId, Flows > computeFlowsPerBasin(const std::vector< FlowOrigin > &starts) const
MRMESH_API HashMap< VertId, Flows > computeFlowsPerBasin(size_t numStarts, const std::function< MeshTriPoint(size_t)> &startById, const std::function< float(size_t)> &amountById) const
MRMESH_API VertScalars computeFlow(const std::vector< MeshTriPoint > &starts, const OutputFlows &out={}) const
MRMESH_API HashMap< VertId, Flows > computeFlowsPerBasin(const std::vector< MeshTriPoint > &starts) const
MRMESH_API FlowAggregator(const Mesh &mesh, const VertScalars &heights)
prepares the processing of given mesh with given height in each vertex
MRMESH_API VertScalars computeFlow(const std::vector< FlowOrigin > &starts, const OutputFlows &out={}) const
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
Definition MRCameraOrientationPlugin.h:8
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMesh/MRMeshFwd.h:460
Definition MRAggregateFlow.h:50
UndirectedEdgeScalars flowPerEdge
Definition MRAggregateFlow.h:52
Polyline3 polyline
Definition MRAggregateFlow.h:51
Definition MRAggregateFlow.h:12
MeshTriPoint point
point on the mesh, where this flow starts
Definition MRAggregateFlow.h:14
float amount
amount of flow, e.g. can be proportional to the horizontal area associated with the start point
Definition MRAggregateFlow.h:16
Definition MRMesh/MRMeshTriPoint.h:23
Definition MRMesh/MRMesh.h:23
Definition MRAggregateFlow.h:20
float amountGreaterThan
output in outPolyline only the flows with the amount greater than
Definition MRAggregateFlow.h:26
UndirectedEdgeScalars * pFlowPerEdge
optional output: flow in each line of outPolyline
Definition MRAggregateFlow.h:24
Polyline3 * pPolyline
optional output: lines of all flows
Definition MRAggregateFlow.h:22