FreeCAD C++
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
MeshCore::MeshKernel Class Reference

#include <Mod/Mesh/App/Core/MeshKernel.h>

Detailed Description

The MeshKernel class is the basic class that holds the data points, the edges and the facets describing a mesh object.

The bounding box is calculated during the buildup of the data structure and gets only re-caclulated after insertion of new facets but not after removal of facets.

This class provides only some rudimental querying methods.

Public Member Functions

 MeshKernel (void)
 Construction.
 
 MeshKernel (const MeshKernel &rclMesh)
 Construction.
 
 ~MeshKernel (void)
 Destruction.
 
I/O methods
void Write (std::ostream &rclOut) const
 Binary streaming of data.
 
void Read (std::istream &rclIn)
 
Querying
unsigned long CountFacets (void) const
 Returns the number of facets.
 
unsigned long CountEdges (void) const
 Returns the number of edge.
 
unsigned long CountPoints (void) const
 
unsigned int GetMemSize (void) const
 Returns the number of required memory in bytes.
 
const Base::BoundBox3fGetBoundBox (void) const
 Determines the bounding box.
 
void RecalcBoundBox (void)
 
MeshPoint GetPoint (unsigned long ulIndex) const
 
std::vector< Base::Vector3fCalcVertexNormals () const
 
MeshGeomFacet GetFacet (unsigned long ulIndex) const
 
MeshGeomFacet GetFacet (const MeshFacet &rclFacet) const
 
void GetFacetPoints (unsigned long ulFaIndex, unsigned long &rclP0, unsigned long &rclP1, unsigned long &rclP2) const
 
std::vector< unsigned long > GetFacetPoints (const std::vector< unsigned long > &) const
 
void GetFacetNeighbours (unsigned long ulIndex, unsigned long &rulNIdx0, unsigned long &rulNIdx1, unsigned long &rulNIdx2) const
 
std::vector< unsigned long > HasFacets (const MeshPointIterator &rclIter) const
 
bool IsValid (void) const
 
const MeshPointArrayGetPoints (void) const
 
MeshPointArray GetPoints (const std::vector< unsigned long > &) const
 
MeshPointModifier ModifyPoints ()
 
const MeshFacetArrayGetFacets (void) const
 
MeshFacetArray GetFacets (const std::vector< unsigned long > &) const
 
MeshFacetModifier ModifyFacets ()
 
void GetEdges (std::vector< MeshGeomEdge > &) const
 
Evaluation
float GetSurface () const
 
float GetSurface (const std::vector< unsigned long > &aSegment) const
 
float GetVolume () const
 
bool HasOpenEdges () const
 
bool HasNonManifolds () const
 
bool HasSelfIntersections () const
 
Facet visitors

The MeshKernel class provides different methods to visit "topologic connected" facets to a given start facet. Two facets are regarded as "topologic connected" if they share a common edge or a common point. All methods expect a MeshFacetVisitor as argument that can decide to continue or to stop. If there is no topologic neighbour facet any more being not marked as "VISIT" the algorithm stops anyway.

See also
MeshFacetVisitor, MeshOrientationVisitor, MeshSearchNeighbourFacetsVisitor and MeshTopFacetVisitor.
unsigned long VisitNeighbourFacets (MeshFacetVisitor &rclFVisitor, unsigned long ulStartFacet) const
 
unsigned long VisitNeighbourFacetsOverCorners (MeshFacetVisitor &rclFVisitor, unsigned long ulStartFacet) const
 
Point visitors

The MeshKernel class provides a method to visit neighbour points to a given start point. Two points are regarded as neighbours if they share an edge. The method expects a MeshPointVisitor as argument that can decide to continue or to stop. If there is no topologic neighbour point any more being not marked as "VISIT" the algorithm stops anyway.

unsigned long VisitNeighbourPoints (MeshPointVisitor &rclPVisitor, unsigned long ulStartPoint) const
 
Iterators

The iterator methods are provided for convenience. They return an iterator object that points to the first element in the appropriate list.

MeshKernel mesh = ...
// iterate over all facets
for ( MeshFacetIterator it = mesh.FacetIterator(); it.More(); it.Next() )
...

An iterator can also be used in the following way

MeshKernel mesh = ...
// iterate over all facets
MeshFacetIterator it(mesh);
for ( it.Init(); it.More(); it.Next() )
...
MeshFacetIterator FacetIterator () const
 
MeshPointIterator PointIterator () const
 
Modification
MeshKerneloperator+= (const MeshGeomFacet &rclSFacet)
 
void AddFacet (const MeshGeomFacet &rclSFacet)
 
MeshKerneloperator+= (const std::vector< MeshGeomFacet > &rclFAry)
 
void AddFacets (const std::vector< MeshGeomFacet > &rclFAry)
 
unsigned long AddFacets (const std::vector< MeshFacet > &rclFAry, bool checkManifolds)
 
unsigned long AddFacets (const std::vector< MeshFacet > &rclFAry, const std::vector< Base::Vector3f > &rclPAry, bool checkManifolds)
 
void Merge (const MeshKernel &rKernel)
 
void Merge (const MeshPointArray &rPoints, const MeshFacetArray &rFaces)
 
bool DeleteFacet (const MeshFacetIterator &rclIter)
 
bool DeleteFacet (unsigned long ulInd)
 
void DeleteFacets (const std::vector< unsigned long > &raulFacets)
 
bool DeletePoint (const MeshPointIterator &rclIter)
 
bool DeletePoint (unsigned long ulInd)
 
void DeletePoints (const std::vector< unsigned long > &raulPoints)
 
void RemoveInvalids ()
 
void RebuildNeighbours (void)
 
void Cleanup ()
 
void Clear (void)
 
MeshKerneloperator= (const std::vector< MeshGeomFacet > &rclFAry)
 
MeshKerneloperator= (const MeshKernel &rclMesh)
 
void Assign (const MeshPointArray &rPoints, const MeshFacetArray &rFaces, bool checkNeighbourHood=false)
 
void Adopt (MeshPointArray &rPoints, MeshFacetArray &rFaces, bool checkNeighbourHood=false)
 
void Swap (MeshKernel &mesh)
 Swaps the content of this kernel and mesh.
 
void operator *= (const Base::Matrix4D &rclMat)
 Transform the data structure with the given transformation matrix.
 
void Transform (const Base::Matrix4D &rclMat)
 
void MovePoint (unsigned long ulPtIndex, const Base::Vector3f &rclTrans)
 
void SetPoint (unsigned long ulPtIndex, const Base::Vector3f &rPoint)
 
void SetPoint (unsigned long ulPtIndex, float x, float y, float z)
 
void Smooth (int iterations, float d_max)
 
void CutFacets (const MeshFacetGrid &rclGrid, const Base::ViewProjMethod *pclP, const Base::Polygon2d &rclPoly, bool bCutInner, std::vector< MeshGeomFacet > &raclFacets)
 
void CutFacets (const MeshFacetGrid &rclGrid, const Base::ViewProjMethod *pclP, const Base::Polygon2d &rclPoly, bool bCutInner, std::vector< unsigned long > &raclCutted)
 

Protected Member Functions

void RebuildNeighbours (unsigned long)
 
void ErasePoint (unsigned long ulIndex, unsigned long ulFacetIndex, bool bOnlySetInvalid=false)
 
void AdjustNormal (MeshFacet &rclFacet, const Base::Vector3f &rclNormal)
 
Base::Vector3f GetNormal (const MeshFacet &rclFacet) const
 
Base::Vector3f GetGravityPoint (const MeshFacet &rclFacet) const
 

Protected Attributes

MeshPointArray _aclPointArray
 
MeshFacetArray _aclFacetArray
 
Base::BoundBox3f _clBoundBox
 
bool _bValid
 

Member Function Documentation

◆ AddFacet()

void MeshCore::MeshKernel::AddFacet ( const MeshGeomFacet rclSFacet)

Adds a single facet to the data structure. This method is very slow and should be called occasionally only. This does the same as the += operator above.

◆ AddFacets() [1/3]

void MeshCore::MeshKernel::AddFacets ( const std::vector< MeshGeomFacet > &  rclFAry)

Adds an array of facets to the data structure. This method keeps temporarily set properties and flags. This does the same as the += operator above.

◆ AddFacets() [2/3]

unsigned long MeshCore::MeshKernel::AddFacets ( const std::vector< MeshFacet > &  rclFAry,
bool  checkManifolds 
)

Adds an array of topologic facets to the data structure without inserting new points. Facets which would create non-manifolds are not inserted. The client programmer must make sure that the referenced point indices are correct and that no geometric overlaps can be created. The method returns the total number of facets. This method might be useful to close gaps or fill up holes in a mesh.

Note
This method is quite expensive and should be rarely used.

◆ AddFacets() [3/3]

unsigned long MeshCore::MeshKernel::AddFacets ( const std::vector< MeshFacet > &  rclFAry,
const std::vector< Base::Vector3f > &  rclPAry,
bool  checkManifolds 
)

Adds new points and facets to the data structure. The client programmer must make sure that all new points are referenced by the new facets. All points in rclPAry get copied at the end of the internal point array to keep their order. The point indices of the facets must be related to the internal point array, not the passed array rclPAry.

Example: We have a mesh with p points and f facets where we want append new points and facets to. Let's assume that the first facet of rclFAry references the 1st, 2nd and 3rd points of rclPAry then its indices must be p, p+1, p+2 – not 0,1,2. This is due to the fact that facets of rclFAry can also reference point indices of the internal point array.

Note
This method is quite expensive and should be rarely used.

◆ AdjustNormal()

void MeshCore::MeshKernel::AdjustNormal ( MeshFacet rclFacet,
const Base::Vector3f rclNormal 
)
protected

Adjusts the facet's orierntation to the given normal direction.

◆ Adopt()

void MeshCore::MeshKernel::Adopt ( MeshPointArray rPoints,
MeshFacetArray rFaces,
bool  checkNeighbourHood = false 
)

This method does basically the same as Assign() unless that it swaps the content of both arrays. These arrays may be empty after assigning to the kernel. This method is a convenient way to build up the mesh structure from outside and assign to a mesh kernel without copying the data. Especially for huge meshes this saves memory and increases speed.

◆ Assign()

void MeshCore::MeshKernel::Assign ( const MeshPointArray rPoints,
const MeshFacetArray rFaces,
bool  checkNeighbourHood = false 
)

This allows to assign the mesh structure directly. The caller must make sure that the point indices are correctly set but the neighbourhood gets checked and corrected if checkNeighbourHood is true.

◆ CalcVertexNormals()

std::vector<Base::Vector3f> MeshCore::MeshKernel::CalcVertexNormals ( ) const

Returns an array of the vertex normals of the mesh. A vertex normal gets calculated by summarizing the normals of the associated facets.

◆ Cleanup()

void MeshCore::MeshKernel::Cleanup ( )

Removes unreferenced points or facets with invalid indices from the mesh.

◆ Clear()

void MeshCore::MeshKernel::Clear ( void  )

Clears the whole data structure.

◆ CutFacets() [1/2]

void MeshCore::MeshKernel::CutFacets ( const MeshFacetGrid rclGrid,
const Base::ViewProjMethod pclP,
const Base::Polygon2d rclPoly,
bool  bCutInner,
std::vector< MeshGeomFacet > &  raclFacets 
)

CheckFacets() is invoked within this method and all found facets get deleted from the mesh structure. The facets to be deleted are returned with their geometric representation.

See also
CheckFacets().

◆ CutFacets() [2/2]

void MeshCore::MeshKernel::CutFacets ( const MeshFacetGrid rclGrid,
const Base::ViewProjMethod pclP,
const Base::Polygon2d rclPoly,
bool  bCutInner,
std::vector< unsigned long > &  raclCutted 
)

Does basically the same as method above unless that the facets to be deleted are returned with their index number in the facet array of the mesh structure.

◆ DeleteFacet() [1/2]

bool MeshCore::MeshKernel::DeleteFacet ( const MeshFacetIterator rclIter)

Deletes the facet the iterator points to. The deletion of a facet requires the following steps:

  • Mark the neighbour index of all neighbour facets to the deleted facet as invalid
  • Adjust the indices of the neighbour facets of all facets.
  • If there is no neighbour facet check if the points can be deleted. True is returned if the facet could be deleted.
    Note
    This method is very slow and should only be called occasionally.
    After deletion of the facet rclIter becomes invalid and must not be used before setting to a new position.

◆ DeleteFacet() [2/2]

bool MeshCore::MeshKernel::DeleteFacet ( unsigned long  ulInd)

Does basically the same as the method above unless that the index of the facet is given.

◆ DeleteFacets()

void MeshCore::MeshKernel::DeleteFacets ( const std::vector< unsigned long > &  raulFacets)

Removes several facets from the data structure.

Note
This method overwrites the free usable property of each mesh point.
This method also removes points from the structure that are no longer referenced by the facets.
This method is very slow and should only be called occasionally.

◆ DeletePoint() [1/2]

bool MeshCore::MeshKernel::DeletePoint ( const MeshPointIterator rclIter)

Deletes the point the iterator points to. The deletion of a point requires the following step:

  • Find all associated facets to this point.
  • Delete these facets. True is returned if the point could be deleted.
    Note
    This method is very slow and should only be called occasionally.
    After deletion of the point rclIter becomes invalid and must not be used before setting to a new position.

◆ DeletePoint() [2/2]

bool MeshCore::MeshKernel::DeletePoint ( unsigned long  ulInd)

Does basically the same as the method above unless that the index of the facet is given.

◆ DeletePoints()

void MeshCore::MeshKernel::DeletePoints ( const std::vector< unsigned long > &  raulPoints)

Removes several points from the data structure.

Note
This method overwrites the free usable property of each mesh point.

◆ ErasePoint()

void MeshCore::MeshKernel::ErasePoint ( unsigned long  ulIndex,
unsigned long  ulFacetIndex,
bool  bOnlySetInvalid = false 
)
protected

Checks if this point is associated to no other facet and deletes if so. The point indices of the facets get adjusted. ulIndex is the index of the point to be deleted. ulFacetIndex is the index of the quasi deleted facet and is ignored. If bOnlySetInvalid is true the point doesn't get deleted but marked as invalid.

◆ FacetIterator()

MeshFacetIterator MeshCore::MeshKernel::FacetIterator ( ) const

Returns an iterator object to go over all facets.

◆ GetEdges()

void MeshCore::MeshKernel::GetEdges ( std::vector< MeshGeomEdge > &  ) const

Returns the array of all edges. Notice: The Edgelist will be temporary generated. Changes on the mesh structure does not affect the Edgelist

◆ GetFacet()

MeshGeomFacet MeshCore::MeshKernel::GetFacet ( unsigned long  ulIndex) const

Returns the facet at the given index. This method is rather slow and should be called occasionally only. For fast access the MeshFacetIterator interface should be used.

◆ GetFacetNeighbours()

void MeshCore::MeshKernel::GetFacetNeighbours ( unsigned long  ulIndex,
unsigned long &  rulNIdx0,
unsigned long &  rulNIdx1,
unsigned long &  rulNIdx2 
) const

Returns the indices of the neighbour facets of the given facet index.

◆ GetFacetPoints() [1/2]

void MeshCore::MeshKernel::GetFacetPoints ( unsigned long  ulFaIndex,
unsigned long &  rclP0,
unsigned long &  rclP1,
unsigned long &  rclP2 
) const

Returns the point indices of the given facet index.

◆ GetFacetPoints() [2/2]

std::vector<unsigned long> MeshCore::MeshKernel::GetFacetPoints ( const std::vector< unsigned long > &  ) const

Returns the point indices of the given facet indices.

◆ GetFacets() [1/2]

const MeshFacetArray& MeshCore::MeshKernel::GetFacets ( void  ) const

Returns the array of all facets

◆ GetFacets() [2/2]

MeshFacetArray MeshCore::MeshKernel::GetFacets ( const std::vector< unsigned long > &  ) const

Returns an array of facets to the given indices. The indices must not be out of range.

◆ GetGravityPoint()

Base::Vector3f MeshCore::MeshKernel::GetGravityPoint ( const MeshFacet rclFacet) const
protected

Calculates the gravity point to the given facet.

◆ GetNormal()

Base::Vector3f MeshCore::MeshKernel::GetNormal ( const MeshFacet rclFacet) const
protected

Calculates the normal to the given facet.

◆ GetPoint()

MeshPoint MeshCore::MeshKernel::GetPoint ( unsigned long  ulIndex) const

Returns the point at the given index. This method is rather slow and should be called occasionally only. For fast access the MeshPointIterator interfsce should be used.

◆ GetPoints() [1/2]

const MeshPointArray& MeshCore::MeshKernel::GetPoints ( void  ) const

Returns the array of all data points.

◆ GetPoints() [2/2]

MeshPointArray MeshCore::MeshKernel::GetPoints ( const std::vector< unsigned long > &  ) const

Returns an array of points to the given indices. The indices must not be out of range.

◆ GetSurface() [1/2]

float MeshCore::MeshKernel::GetSurface ( ) const

Calculates the surface area of the mesh object.

◆ GetSurface() [2/2]

float MeshCore::MeshKernel::GetSurface ( const std::vector< unsigned long > &  aSegment) const

Calculates the surface area of the segment defined by aSegment.

◆ GetVolume()

float MeshCore::MeshKernel::GetVolume ( ) const

Calculates the volume of the mesh object. Therefore the mesh must be a solid, if not 0 is returned.

◆ HasFacets()

std::vector<unsigned long> MeshCore::MeshKernel::HasFacets ( const MeshPointIterator rclIter) const

Determines all facets that are associated to this point. This method is very slow and should be called occasionally only.

◆ HasNonManifolds()

bool MeshCore::MeshKernel::HasNonManifolds ( ) const

Checks whether the mesh has non.manifold edges. An edge is regarded as non-manifolds if it shares more than two facets.

◆ HasOpenEdges()

bool MeshCore::MeshKernel::HasOpenEdges ( ) const

Checks whether the mesh has open edges.

◆ HasSelfIntersections()

bool MeshCore::MeshKernel::HasSelfIntersections ( ) const

Checks whether the mesh intersects itself.

◆ IsValid()

bool MeshCore::MeshKernel::IsValid ( void  ) const

Returns true if the data structure is valid.

◆ Merge() [1/2]

void MeshCore::MeshKernel::Merge ( const MeshKernel rKernel)

Adds all facets and referenced points to the underlying mesh structure. The client programmer must be sure that both meshes don't have geometric overlaps, otherwise the resulting mesh might be invalid, i.e. has self-intersections.

Note
The method guarantees that the order of the arrays of the underlying mesh and of the given array is kept.
Not all points of rKernel are necessarily appended to the underlying mesh but only these points which are referenced by facets of rKernel.

◆ Merge() [2/2]

void MeshCore::MeshKernel::Merge ( const MeshPointArray rPoints,
const MeshFacetArray rFaces 
)

This method is provided for convenience that directly accepts the point and facet arrays.

Note
Not all points of rPoints are necessarily appended to the underlying mesh but only these points which are referenced by facets of rFaces.

◆ ModifyFacets()

MeshFacetModifier MeshCore::MeshKernel::ModifyFacets ( )

Returns a modifier for the facet array

◆ ModifyPoints()

MeshPointModifier MeshCore::MeshKernel::ModifyPoints ( )

Returns a modifier for the point array

◆ MovePoint()

void MeshCore::MeshKernel::MovePoint ( unsigned long  ulPtIndex,
const Base::Vector3f rclTrans 
)

Moves the point at the given index along the vector rclTrans.

◆ operator+=() [1/2]

MeshKernel& MeshCore::MeshKernel::operator+= ( const MeshGeomFacet rclSFacet)

Adds a single facet to the data structure. This method is very slow and should be called occasionally only.

◆ operator+=() [2/2]

MeshKernel& MeshCore::MeshKernel::operator+= ( const std::vector< MeshGeomFacet > &  rclFAry)

Adds an array of facets to the data structure. This method keeps temporarily set properties and flags.

◆ operator=() [1/2]

MeshKernel& MeshCore::MeshKernel::operator= ( const std::vector< MeshGeomFacet > &  rclFAry)

Replaces the current data structure with the structure built up of the array of triangles given in rclFAry.

◆ operator=() [2/2]

MeshKernel& MeshCore::MeshKernel::operator= ( const MeshKernel rclMesh)

Assignment operator.

◆ PointIterator()

MeshPointIterator MeshCore::MeshKernel::PointIterator ( ) const

Returns an iterator object to go over all points.

◆ RebuildNeighbours() [1/2]

void MeshCore::MeshKernel::RebuildNeighbours ( void  )

Rebuilds the neighbour indices for all facets.

◆ RebuildNeighbours() [2/2]

void MeshCore::MeshKernel::RebuildNeighbours ( unsigned long  )
protected

Rebuilds the neighbour indices for subset of all facets from index index on.

◆ RecalcBoundBox()

void MeshCore::MeshKernel::RecalcBoundBox ( void  )

Forces a recalculation of the bounding box. This method should be called after the removal of points.or after a transformation of the data structure.

◆ RemoveInvalids()

void MeshCore::MeshKernel::RemoveInvalids ( )

Removes all as INVALID marked points and facets from the structure.

◆ SetPoint() [1/2]

void MeshCore::MeshKernel::SetPoint ( unsigned long  ulPtIndex,
const Base::Vector3f rPoint 
)

Sets the point at the given index to the new rPoint.

◆ SetPoint() [2/2]

void MeshCore::MeshKernel::SetPoint ( unsigned long  ulPtIndex,
float  x,
float  y,
float  z 
)

Sets the point at the given index to the new rPoint.

◆ Smooth()

void MeshCore::MeshKernel::Smooth ( int  iterations,
float  d_max 
)

Smoothes the mesh kernel.

◆ Transform()

void MeshCore::MeshKernel::Transform ( const Base::Matrix4D rclMat)

Transform the data structure with the given transformation matrix. It does exactly the same as the '*=' operator.

◆ VisitNeighbourFacets()

unsigned long MeshCore::MeshKernel::VisitNeighbourFacets ( MeshFacetVisitor rclFVisitor,
unsigned long  ulStartFacet 
) const

This method visits all neighbour facets, i.e facets that share a common edge starting from the facet associated to index ulStartFacet. All facets having set the VISIT flag are ignored. Therefore the user have to set or unset this flag if needed. All facets that get visited during this algorithm are marked as VISIT and the Visit() method of the given MeshFacetVisitor gets invoked. If there are no unvisited neighbours any more the algorithms returns immediately and returns the number of visited facets.

Note
For the start facet ulStartFacet MeshFacetVisitor::Visit() does not get invoked though the facet gets marked as VISIT.

◆ VisitNeighbourFacetsOverCorners()

unsigned long MeshCore::MeshKernel::VisitNeighbourFacetsOverCorners ( MeshFacetVisitor rclFVisitor,
unsigned long  ulStartFacet 
) const

Does basically the same as the method above unless the facets that share just a common point are regared as neighbours.

◆ VisitNeighbourPoints()

unsigned long MeshCore::MeshKernel::VisitNeighbourPoints ( MeshPointVisitor rclPVisitor,
unsigned long  ulStartPoint 
) const

This method visits all neighbour points starting from the point associated to index ulStartPoint. All points having set the VISIT flag are ignored. Therefore the user have to set or unset this flag if needed before the algorithm starts. All points that get visited during this algorithm are marked as VISIT and the Visit() method of the given MeshPointVisitor gets invoked. If there are no unvisited neighbours any more the algorithms returns immediately and returns the number of visited points.

Note
For the start facet ulStartPoint MeshPointVisitor::Visit() does not get invoked though the point gets marked as VISIT.

Member Data Documentation

◆ _aclFacetArray

MeshFacetArray MeshCore::MeshKernel::_aclFacetArray
protected

Holds the array of facets.

◆ _aclPointArray

MeshPointArray MeshCore::MeshKernel::_aclPointArray
protected

Holds the array of geometric points.

◆ _bValid

bool MeshCore::MeshKernel::_bValid
protected

Current state of validality.

◆ _clBoundBox

Base::BoundBox3f MeshCore::MeshKernel::_clBoundBox
protected

The current calculated bounding box.