The MeshTopoAlgorithm class provides several algorithms to manipulate a mesh. More...
#include <TopoAlgorithm.h>
Public Member Functions | |
MeshTopoAlgorithm (MeshKernel &rclM) | |
virtual | ~MeshTopoAlgorithm () |
Topological Operations | |
bool | InsertVertex (FacetIndex ulFacetPos, const Base::Vector3f &rclPoint) |
Inserts a new vertex in the given triangle so that is split into three triangles. More... | |
bool | InsertVertexAndSwapEdge (FacetIndex ulFacetPos, const Base::Vector3f &rclPoint, float fMaxAngle) |
This method is provided for convenience. More... | |
void | SwapEdge (FacetIndex ulFacetPos, FacetIndex ulNeighbour) |
Swaps the common edge of two adjacent facets even if the operation might be illegal. More... | |
bool | SplitEdge (FacetIndex ulFacetPos, FacetIndex ulNeighbour, const Base::Vector3f &rP) |
Splits the common edge of the two adjacent facets with index ulFacetPos and ulNeighbour. More... | |
bool | SplitOpenEdge (FacetIndex ulFacetPos, unsigned short uSide, const Base::Vector3f &rP) |
Splits the facet with index ulFacetPos on the edge side uSide into two facets. More... | |
void | SplitFacet (FacetIndex ulFacetPos, const Base::Vector3f &rP1, const Base::Vector3f &rP2) |
Splits the facet with index ulFacetPos into up to three facets. More... | |
bool | CollapseVertex (const VertexCollapse &vc) |
Collapse a vertex. More... | |
bool | IsCollapseEdgeLegal (const EdgeCollapse &ec) const |
Checks whether a collapse edge operation is legal, that is fulfilled if none of the adjacent facets flips its normal. More... | |
bool | CollapseEdge (FacetIndex ulFacetPos, FacetIndex ulNeighbour) |
Collapses the common edge of two adjacent facets. More... | |
bool | CollapseEdge (const EdgeCollapse &ec) |
Convenience function that passes already all needed information. More... | |
bool | CollapseFacet (FacetIndex ulFacetPos) |
Removes the facet with index ulFacetPos and all its neighbour facets. More... | |
Topological Optimization | |
void | OptimizeTopology (float fMaxAngle) |
Tries to make a more beautiful mesh by swapping the common edge of two adjacent facets where needed. More... | |
void | OptimizeTopology () |
void | DelaunayFlip (float fMaxAngle) |
Tries to make a more beautiful mesh by swapping the common edge of two adjacent facets where needed. More... | |
int | DelaunayFlip () |
Overloaded method DelaunayFlip that doesn't use ShouldSwapEdge to check for legal swap edge. More... | |
void | AdjustEdgesToCurvatureDirection () |
Tries to adjust the edges to the curvature direction with the minimum absolute value of maximum and minimum curvature. More... | |
bool | SnapVertex (FacetIndex ulFacetPos, const Base::Vector3f &rP) |
Creates a new triangle with neighbour facet ulFacetPos and the vertex rclPoint whereat it must lie outside the given facet. More... | |
bool | IsSwapEdgeLegal (FacetIndex ulFacetPos, FacetIndex ulNeighbour) const |
Checks whether a swap edge operation is legal, that is fulfilled if the two adjacent facets builds a convex polygon. More... | |
bool | ShouldSwapEdge (FacetIndex ulFacetPos, FacetIndex ulNeighbour, float fMaxAngle) const |
Checks whether the swap edge operation is legal and whether it makes sense. More... | |
float | SwapEdgeBenefit (FacetIndex f, int e) const |
Computes a value for the benefit of swapping the edge. More... | |
void | Cleanup () |
Removes all invalid marked elements from the mesh structure. More... | |
bool | RemoveDegeneratedFacet (FacetIndex index) |
Removes the degenerated facet at position index from the mesh structure. More... | |
bool | RemoveCorruptedFacet (FacetIndex index) |
Removes the corrupted facet at position index from the mesh structure. More... | |
void | FillupHoles (unsigned long length, int level, AbstractPolygonTriangulator &, std::list< std::vector< PointIndex > > &aFailed) |
Closes holes in the mesh that consists of up to length edges. More... | |
void | FillupHoles (int level, AbstractPolygonTriangulator &, const std::list< std::vector< PointIndex > > &aBorders, std::list< std::vector< PointIndex > > &aFailed) |
This is an overloaded method provided for convenience. More... | |
void | FindHoles (unsigned long length, std::list< std::vector< PointIndex > > &aBorders) const |
Find holes which consists of up to length edges. More... | |
void | FindComponents (unsigned long count, std::vector< FacetIndex > &aInds) |
Find topologic independent components with maximum count facets and returns an array of the indices. More... | |
void | RemoveComponents (unsigned long count) |
Removes topologic independent components with maximum count facets. More... | |
void | HarmonizeNormals () |
Harmonizes the normals. More... | |
void | FlipNormals () |
Flips the normals. More... | |
void | BeginCache () |
Caching facility. More... | |
void | EndCache () |
The MeshTopoAlgorithm class provides several algorithms to manipulate a mesh.
It supports various mesh operations like inserting a new vertex, swapping the common edge of two adjacent facets, split a facet, ...
MeshTopoAlgorithm::MeshTopoAlgorithm | ( | MeshKernel & | rclM | ) |
|
virtual |
References Cleanup(), and EndCache().
void MeshTopoAlgorithm::AdjustEdgesToCurvatureDirection | ( | ) |
Tries to adjust the edges to the curvature direction with the minimum absolute value of maximum and minimum curvature.
References Base::Distance(), MeshCore::MeshGeomFacet::GetNormal(), MeshCore::MeshPointIterator::Init(), MeshCore::MeshFacet::IsFlag(), IsSwapEdgeLegal(), MeshCore::MeshPointIterator::More(), MeshCore::MeshPointIterator::Next(), Base::Vector3< _Precision >::Normalize(), MeshCore::MeshFacetArray::ResetFlag(), MeshCore::MeshFacet::SetFlag(), MeshCore::MeshFacet::Side(), SwapEdge(), MeshCore::MeshFacet::VISIT, Base::Vector3< _Precision >::x, Base::Vector3< _Precision >::y, and Base::Vector3< _Precision >::z.
Referenced by Mesh::MeshObject::optimizeEdges().
void MeshTopoAlgorithm::BeginCache | ( | ) |
Caching facility.
void MeshTopoAlgorithm::Cleanup | ( | ) |
Removes all invalid marked elements from the mesh structure.
Referenced by MeshCore::MeshRemoveNeedles::Fixup(), MeshCore::MeshFixMergeFacets::Fixup(), Mesh::MeshObject::offsetSpecial2(), MeshPart::MeshAlgos::offsetSpecial2(), and ~MeshTopoAlgorithm().
bool MeshTopoAlgorithm::CollapseEdge | ( | const EdgeCollapse & | ec | ) |
Convenience function that passes already all needed information.
References MeshCore::FACET_INDEX_MAX, DraftVecUtils::find(), MeshCore::MeshFacet::ReplaceNeighbour(), MeshCore::MeshFacet::SetInvalid(), and MeshCore::MeshFacet::Transpose().
bool MeshTopoAlgorithm::CollapseEdge | ( | FacetIndex | ulFacetPos, |
FacetIndex | ulNeighbour | ||
) |
Collapses the common edge of two adjacent facets.
This operation removes one common point of the collapsed edge and the facets ulFacetPos and ulNeighbour from the data structure.
References MeshCore::FACET_INDEX_MAX, MeshCore::MeshFacet::IsValid(), MeshCore::MeshFacet::SetInvalid(), MeshCore::MeshFacet::Side(), and MeshCore::MeshFacet::Transpose().
Referenced by Mesh::MeshObject::collapseEdge(), and MeshCore::MeshRemoveNeedles::Fixup().
bool MeshTopoAlgorithm::CollapseFacet | ( | FacetIndex | ulFacetPos | ) |
Removes the facet with index ulFacetPos and all its neighbour facets.
The three vertices that are referenced by this facet are replaced by its gravity point.
References MeshCore::FACET_INDEX_MAX, MeshCore::MeshFacet::IsValid(), MeshCore::MeshFacet::SetInvalid(), MeshCore::MeshFacet::Side(), and MeshCore::MeshFacet::Transpose().
Referenced by Mesh::MeshObject::collapseFacet(), Mesh::MeshObject::collapseFacets(), Mesh::MeshObject::offsetSpecial2(), and MeshPart::MeshAlgos::offsetSpecial2().
bool MeshTopoAlgorithm::CollapseVertex | ( | const VertexCollapse & | vc | ) |
Collapse a vertex.
At the moment only removing inner vertexes referenced by three facets is supposrted.
References MeshCore::FACET_INDEX_MAX, DraftVecUtils::find(), MeshCore::MeshFacet::HasPoint(), MeshCore::POINT_INDEX_MAX, MeshCore::MeshFacet::ReplaceNeighbour(), MeshCore::MeshFacet::SetInvalid(), and MeshCore::MeshFacet::Transpose().
Referenced by MeshCore::MeshFixMergeFacets::Fixup().
int MeshTopoAlgorithm::DelaunayFlip | ( | ) |
Overloaded method DelaunayFlip that doesn't use ShouldSwapEdge to check for legal swap edge.
References MeshCore::MeshGeomFacet::CenterOfCircumCircle(), Base::DistanceP2(), MeshCore::FACET_INDEX_MAX, MeshCore::MeshFacet::IsFlag(), MeshCore::MeshFacet::SetFlag(), MeshCore::MeshFacet::Side(), SwapEdge(), and MeshCore::MeshFacet::TMP0.
void MeshTopoAlgorithm::DelaunayFlip | ( | float | fMaxAngle | ) |
Tries to make a more beautiful mesh by swapping the common edge of two adjacent facets where needed.
A swap is needed where two adjacent facets don't fulfill the Delaunay condition.
References Base::DistanceP2(), MeshCore::FACET_INDEX_MAX, ShouldSwapEdge(), MeshCore::MeshFacet::Side(), and SwapEdge().
void MeshTopoAlgorithm::EndCache | ( | ) |
Referenced by ~MeshTopoAlgorithm().
void MeshTopoAlgorithm::FillupHoles | ( | int | level, |
AbstractPolygonTriangulator & | cTria, | ||
const std::list< std::vector< PointIndex > > & | aBorders, | ||
std::list< std::vector< PointIndex > > & | aFailed | ||
) |
This is an overloaded method provided for convenience.
It takes as first argument the boundaries which must be filled up.
References Base::Console(), MeshCore::MeshAlgorithm::FillupHole(), Base::ConsoleSingleton::Log(), and MeshCore::AbstractPolygonTriangulator::NeedsReindexing().
void MeshTopoAlgorithm::FillupHoles | ( | unsigned long | length, |
int | level, | ||
AbstractPolygonTriangulator & | cTria, | ||
std::list< std::vector< PointIndex > > & | aFailed | ||
) |
Closes holes in the mesh that consists of up to length edges.
In case a fit needs to be done then the points of the neighbours of level rings will be used. Holes for which the triangulation failed are returned in aFailed.
References FillupHoles(), MeshCore::MeshAlgorithm::GetMeshBorders(), and MeshCore::MeshAlgorithm::SplitBoundaryLoops().
Referenced by FillupHoles(), and Mesh::MeshObject::fillupHoles().
void MeshTopoAlgorithm::FindComponents | ( | unsigned long | count, |
std::vector< FacetIndex > & | aInds | ||
) |
Find topologic independent components with maximum count facets and returns an array of the indices.
References MeshCore::MeshComponents::OverEdge, and MeshCore::MeshComponents::SearchForComponents().
Referenced by RemoveComponents(), and Mesh::MeshObject::removeComponents().
void MeshTopoAlgorithm::FindHoles | ( | unsigned long | length, |
std::list< std::vector< PointIndex > > & | aBorders | ||
) | const |
Find holes which consists of up to length edges.
References MeshCore::MeshAlgorithm::GetMeshBorders().
void MeshTopoAlgorithm::FlipNormals | ( | ) |
Flips the normals.
Referenced by Mesh::MeshObject::flipNormals().
void MeshTopoAlgorithm::HarmonizeNormals | ( | ) |
Harmonizes the normals.
References MeshCore::MeshEvalOrientation::GetIndices().
Referenced by MeshCore::MeshFixOrientation::Fixup(), and Mesh::MeshObject::harmonizeNormals().
bool MeshTopoAlgorithm::InsertVertex | ( | FacetIndex | ulFacetPos, |
const Base::Vector3f & | rclPoint | ||
) |
Inserts a new vertex in the given triangle so that is split into three triangles.
The given point must lie inside the triangle not outside or on an edge.
References MeshCore::FACET_INDEX_MAX, and MeshCore::MeshFacet::ReplaceNeighbour().
Referenced by Mesh::MeshObject::insertVertex(), and InsertVertexAndSwapEdge().
bool MeshTopoAlgorithm::InsertVertexAndSwapEdge | ( | FacetIndex | ulFacetPos, |
const Base::Vector3f & | rclPoint, | ||
float | fMaxAngle | ||
) |
This method is provided for convenience.
It inserts a new vertex to the mesh and tries to swap the common edges of the newly created facets with their neighbours. Just inserting a new vertex leads to very acute-angled triangles which might be problematic for some algorithms. This method tries to swap the edges to build more well-formed triangles.
References MeshCore::FACET_INDEX_MAX, InsertVertex(), ShouldSwapEdge(), and SwapEdge().
Referenced by Mesh::MeshObject::refine().
bool MeshTopoAlgorithm::IsCollapseEdgeLegal | ( | const EdgeCollapse & | ec | ) | const |
Checks whether a collapse edge operation is legal, that is fulfilled if none of the adjacent facets flips its normal.
If this operation is legal true is returned, false is returned if this operation is illegal.
References MeshCore::MeshGeomFacet::GetNormal().
Referenced by MeshCore::MeshRemoveNeedles::Fixup().
bool MeshTopoAlgorithm::IsSwapEdgeLegal | ( | FacetIndex | ulFacetPos, |
FacetIndex | ulNeighbour | ||
) | const |
Checks whether a swap edge operation is legal, that is fulfilled if the two adjacent facets builds a convex polygon.
If this operation is legal true is returned, false is returned if this operation is illegal or if ulFacetPos and ulNeighbour are not adjacent facets.
References MeshCore::MeshGeomFacet::IsDegenerated(), and MeshCore::MeshFacet::Side().
Referenced by AdjustEdgesToCurvatureDirection(), and ShouldSwapEdge().
void MeshTopoAlgorithm::OptimizeTopology | ( | ) |
References SwapEdge(), SwapEdgeBenefit(), and draftutils.todo::todo.
void MeshTopoAlgorithm::OptimizeTopology | ( | float | fMaxAngle | ) |
Tries to make a more beautiful mesh by swapping the common edge of two adjacent facets where needed.
fMaxAngle is the maximum allowed angle between the normals of two adjacent facets to allow swapping the common edge. A too high value might result into folds on the surface.
References MeshCore::FACET_INDEX_MAX, ShouldSwapEdge(), MeshCore::MeshFacet::Side(), and SwapEdge().
Referenced by Mesh::MeshObject::optimizeTopology().
void MeshTopoAlgorithm::RemoveComponents | ( | unsigned long | count | ) |
Removes topologic independent components with maximum count facets.
References FindComponents().
bool MeshTopoAlgorithm::RemoveCorruptedFacet | ( | FacetIndex | index | ) |
Removes the corrupted facet at position index from the mesh structure.
A facet is corrupted if the indices of its corner points are not all different.
References MeshCore::FACET_INDEX_MAX, and MeshCore::MeshFacet::ReplaceNeighbour().
Referenced by MeshCore::MeshFixCorruptedFacets::Fixup().
bool MeshTopoAlgorithm::RemoveDegeneratedFacet | ( | FacetIndex | index | ) |
Removes the degenerated facet at position index from the mesh structure.
A facet is degenerated if its corner points are collinear.
References MeshCore::FACET_INDEX_MAX, MeshCore::MeshFacet::ReplaceNeighbour(), and MeshCore::MeshFacet::Side().
Referenced by MeshCore::MeshFixDegeneratedFacets::Fixup().
bool MeshTopoAlgorithm::ShouldSwapEdge | ( | FacetIndex | ulFacetPos, |
FacetIndex | ulNeighbour, | ||
float | fMaxAngle | ||
) | const |
Checks whether the swap edge operation is legal and whether it makes sense.
This operation only makes sense if the maximum angle of both facets is decreased and if the angle between the facet normals does not exceed fMaxAngle.
References Base::Vector3< _Precision >::GetAngle(), MeshCore::MeshGeomFacet::GetNormal(), IsSwapEdgeLegal(), MeshCore::MeshGeomFacet::MaximumAngle(), and MeshCore::MeshFacet::Side().
Referenced by DelaunayFlip(), MeshCore::MeshFixDeformedFacets::Fixup(), InsertVertexAndSwapEdge(), and OptimizeTopology().
bool MeshTopoAlgorithm::SnapVertex | ( | FacetIndex | ulFacetPos, |
const Base::Vector3f & | rP | ||
) |
Creates a new triangle with neighbour facet ulFacetPos and the vertex rclPoint whereat it must lie outside the given facet.
References Base::DistanceP2(), MeshCore::FACET_INDEX_MAX, MeshCore::MeshFacet::HasOpenEdge(), Base::Vector3< _Precision >::Length(), and SplitOpenEdge().
Referenced by Mesh::MeshObject::snapVertex().
bool MeshTopoAlgorithm::SplitEdge | ( | FacetIndex | ulFacetPos, |
FacetIndex | ulNeighbour, | ||
const Base::Vector3f & | rP | ||
) |
Splits the common edge of the two adjacent facets with index ulFacetPos and ulNeighbour.
The point rP must lie inside of one the given facets are on the common edge. The two facets get broken into four facets, i.e. that two new facets get created. If rP is coincident with a corner point nothing happens.
References MeshCore::FACET_INDEX_MAX, and MeshCore::MeshFacet::Side().
Referenced by Mesh::MeshObject::splitEdge(), and Mesh::MeshObject::splitEdges().
void MeshTopoAlgorithm::SplitFacet | ( | FacetIndex | ulFacetPos, |
const Base::Vector3f & | rP1, | ||
const Base::Vector3f & | rP2 | ||
) |
Splits the facet with index ulFacetPos into up to three facets.
The points rP1 and rP2 should lie on two different edges of the facet. This method splits up the both neighbour facets as well. If either rP1 or rP2 (probably due to a previous call of SplitFacet()) is coincident with a corner point then the facet is split into two facets. If both points are coincident with corner points of this facet nothing is done.
References Base::Distance().
Referenced by MeshPart::MeshAlgos::cutByCurve(), and Mesh::MeshObject::splitFacet().
bool MeshTopoAlgorithm::SplitOpenEdge | ( | FacetIndex | ulFacetPos, |
unsigned short | uSide, | ||
const Base::Vector3f & | rP | ||
) |
Splits the facet with index ulFacetPos on the edge side uSide into two facets.
This side must be an open edge otherwise nothing is done. The point rP must be near to this edge and must not be coincident with any corner vertices of the facet.
References MeshCore::FACET_INDEX_MAX.
Referenced by SnapVertex().
void MeshTopoAlgorithm::SwapEdge | ( | FacetIndex | ulFacetPos, |
FacetIndex | ulNeighbour | ||
) |
Swaps the common edge of two adjacent facets even if the operation might be illegal.
To be sure that this operation is legal, check either with IsSwapEdgeLegal() or ShouldSwapEdge() before. An illegal swap edge operation can produce non-manifolds, degenerated facets or it might create a fold on the surface, i.e. geometric overlaps of several triangles.
References MeshCore::FACET_INDEX_MAX, and MeshCore::MeshFacet::Side().
Referenced by AdjustEdgesToCurvatureDirection(), DelaunayFlip(), MeshCore::MeshFixCaps::Fixup(), MeshCore::MeshFixDeformedFacets::Fixup(), InsertVertexAndSwapEdge(), OptimizeTopology(), and Mesh::MeshObject::swapEdge().
float MeshTopoAlgorithm::SwapEdgeBenefit | ( | FacetIndex | f, |
int | e | ||
) | const |
Computes a value for the benefit of swapping the edge.
References MeshCore::FACET_INDEX_MAX.
Referenced by OptimizeTopology().