Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions source/MRMesh/MREdgeMetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ EdgeMetric edgeAbsCurvMetric( const Mesh & mesh, float angleSinFactor, float ang
return edgeAbsCurvMetric( mesh.topology, mesh.points, angleSinFactor, angleSinForBoundary );
}

EdgeMetric edgeDihedralAngleMetric( const MeshTopology& topology, const VertCoords& points, const DihedralAngleProcessParams& params )
{
return [&topology, &points, params]( EdgeId e ) -> float
{
if ( topology.isBdEdge( e, nullptr ) )
return params.boundaryValue;

auto a = dihedralAngle( topology, points, e );
return a >= 0 ? params.convexFactor * a : params.concaveFactor * a;
};
}

EdgeMetric edgeDihedralAngleMetric( const Mesh& mesh, const DihedralAngleProcessParams& params )
{
return edgeDihedralAngleMetric( mesh.topology, mesh.points, params );
}

EdgeMetric edgeTableSymMetric( const MeshTopology & topology, const EdgeMetric & metric )
{
MR_TIMER;
Expand Down
13 changes: 13 additions & 0 deletions source/MRMesh/MREdgeMetric.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ namespace MR
[[nodiscard]] MRMESH_API EdgeMetric edgeAbsCurvMetric( const Mesh & mesh, float angleSinFactor = 2, float angleSinForBoundary = 0 );
[[nodiscard]] MRMESH_API EdgeMetric edgeAbsCurvMetric( const MeshTopology& topology, const VertCoords& points, float angleSinFactor = 2, float angleSinForBoundary = 0 );

struct DihedralAngleProcessParams
{
float convexFactor = 1; ///< positive convex dihedral angles are returned multiplied on this factor
float concaveFactor = 1; ///< positive convex dihedral angles are returned multiplied on this factor
float boundaryValue = 0; ///< this value will be returned as dihedral angle for boundary edges
};

/// this metric returns edge's dihedral angle computed by MR::dihedralAngle and post-processed based on the given parameters;
/// returned value is NOT multiplied on edge's length as in other metrics;
/// this metric is symmetric: m(e) == m(e.sym())
[[nodiscard]] MRMESH_API EdgeMetric edgeDihedralAngleMetric( const Mesh& mesh, const DihedralAngleProcessParams& params = {} );
[[nodiscard]] MRMESH_API EdgeMetric edgeDihedralAngleMetric( const MeshTopology& topology, const VertCoords& points, const DihedralAngleProcessParams& params = {} );

/// pre-computes the metric for all mesh edges to quickly return it later for any edge;
/// input metric must be symmetric: metric(e) == metric(e.sym())
[[nodiscard]] MRMESH_API EdgeMetric edgeTableSymMetric( const MeshTopology & topology, const EdgeMetric & metric );
Expand Down
17 changes: 13 additions & 4 deletions source/MRMesh/MRGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ namespace MR
{

void Graph::construct( NeighboursPerVertex neighboursPerVertex, EndsPerEdge endsPerEdge )
{
construct(
std::move( neighboursPerVertex ),
VertBitSet( neighboursPerVertex.size(), true ),
std::move( endsPerEdge ),
EdgeBitSet( endsPerEdge.size(), true )
);
}

void Graph::construct( NeighboursPerVertex neighboursPerVertex, VertBitSet validVerts,
EndsPerEdge endsPerEdge, EdgeBitSet validEdges )
{
MR_TIMER;

validVerts_.clear();
validVerts_.resize( neighboursPerVertex.size(), true );
validVerts_ = std::move( validVerts );
neighboursPerVertex_ = std::move( neighboursPerVertex );

validEdges_.clear();
validEdges_.resize( endsPerEdge.size(), true );
validEdges_ = std::move( validEdges );
endsPerEdge_ = std::move( endsPerEdge );

assert( checkValidity() );
Expand Down
4 changes: 4 additions & 0 deletions source/MRMesh/MRGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class Graph
/// constructs the graph from all valid vertices and edges
MRMESH_API void construct( NeighboursPerVertex neighboursPerVertex, EndsPerEdge endsPerEdge );

/// constructs the graph from given data that can contain invalid vertices and edges
MRMESH_API void construct( NeighboursPerVertex neighboursPerVertex, VertBitSet validVerts,
EndsPerEdge endsPerEdge, EdgeBitSet validEdges );

/// returns the number of vertex records, including invalid ones
[[nodiscard]] size_t vertSize() const { return neighboursPerVertex_.size(); }

Expand Down
12 changes: 12 additions & 0 deletions source/MRMesh/MRHeap.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,43 @@ class Heap
T val;
};

/// constructs an empty heap
Heap( P pred = {} ) : pred_( pred ) {}

/// constructs heap for given number of elements, assigning given default value to each element
explicit Heap( size_t size, T def MR_LIFETIMEBOUND_NESTED = {}, P pred = {} );

/// constructs heap from given elements (id's shall not repeat and have spaces, but can be arbitrary shuffled)
explicit Heap( std::vector<Element> elms MR_LIFETIMEBOUND_NESTED, P pred = {} );

/// returns the size of the heap
size_t size() const { return heap_.size(); }

/// increases the size of the heap by adding elements at the end
void resize( size_t size, T def MR_LIFETIME_CAPTURE_BY_NESTED(this) = {} );

/// returns the value associated with given element
const T & value( I elemId ) const MR_LIFETIMEBOUND { return heap_[ id2PosInHeap_[ elemId ] ].val; }

/// returns the element with the largest value
const Element & top() const MR_LIFETIMEBOUND { return heap_[0]; }

/// sets new value to given element
void setValue( I elemId, const T & newVal MR_LIFETIME_CAPTURE_BY_NESTED(this) );

/// sets new value to given element, which shall be larger/smaller than the current value
void setLargerValue( I elemId, const T & newVal MR_LIFETIME_CAPTURE_BY_NESTED(this) );
void setSmallerValue( I elemId, const T & newVal MR_LIFETIME_CAPTURE_BY_NESTED(this) );
template<typename U>
void increaseValue( I elemId, const U & inc ) { setLargerValue( elemId, value( elemId ) + inc ); }

/// sets new value to the current top element, returning its previous value
Element setTopValue( const T & newVal MR_LIFETIME_CAPTURE_BY_NESTED(this) ) { Element res = top(); setValue( res.id, newVal ); return res; }

private:
/// tests whether heap element at posA is less than posB
bool less_( size_t posA, size_t posB ) const;

/// lifts the element in the queue according to its value
void lift_( size_t pos, I elemId );

Expand Down
2 changes: 2 additions & 0 deletions source/MRMesh/MRMesh.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<ClInclude Include="MRMeshPatch.h" />
<ClInclude Include="MRMeshRelax.hpp" />
<ClInclude Include="MRMeshReplicate.h" />
<ClInclude Include="MRSegmentMesh.h" />
<ClInclude Include="MRMeshSubdivideCallbacks.h" />
<ClInclude Include="MRMeshThickness.h" />
<ClInclude Include="MRMeshTopologyDiff.h" />
Expand Down Expand Up @@ -465,6 +466,7 @@
<ClCompile Include="MRMeshDoubleLayer.cpp" />
<ClCompile Include="MRMeshPatch.cpp" />
<ClCompile Include="MRMeshSave3mf.cpp" />
<ClCompile Include="MRSegmentMesh.cpp" />
<ClCompile Include="MRMeshTotalAngle.cpp" />
<ClCompile Include="MRObjectMeshData.cpp" />
<ClCompile Include="MROneMeshContours.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions source/MRMesh/MRMesh.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,9 @@
<ClInclude Include="MRMeshTotalAngle.h">
<Filter>Source Files\MeshAlgorithm</Filter>
</ClInclude>
<ClInclude Include="MRSegmentMesh.h">
<Filter>Source Files\Algorithms</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MRParallelProgressReporter.cpp">
Expand Down Expand Up @@ -2321,6 +2324,9 @@
<ClCompile Include="MRMeshTotalAngle.cpp">
<Filter>Source Files\MeshAlgorithm</Filter>
</ClCompile>
<ClCompile Include="MRSegmentMesh.cpp">
<Filter>Source Files\Algorithms</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\.editorconfig" />
Expand Down
Loading
Loading