# FoundationClasses
TKMath
Poly

# Poly_CoherentTriangulation Class Reference

`#include <Poly_CoherentTriangulation.hxx>`

Inheritance diagram for Poly_CoherentTriangulation:

[legend]

## Public Member Functions

Standard_EXPORT | Poly_CoherentTriangulation (const Handle_NCollection_BaseAllocator &theAlloc=0L)
Standard_EXPORT | Poly_CoherentTriangulation (const Handle_Poly_Triangulation &theTriangulation, const Handle_NCollection_BaseAllocator &theAlloc=0L)
virtual Standard_EXPORT | ~Poly_CoherentTriangulation ()
Standard_EXPORT Handle_Poly_Triangulation | GetTriangulation () const
Standard_EXPORT Standard_Boolean | RemoveDegenerated (const Standard_Real theTol, NCollection_List< TwoIntegers > *pLstRemovedNode=0L)
Standard_EXPORT Standard_Boolean | GetFreeNodes (NCollection_List< Standard_Integer > &lstNodes) const
Standard_Integer | MaxNode () const
Standard_Integer | MaxTriangle () const
void | SetDeflection (const Standard_Real theDefl)
Standard_Real | Deflection () const
Standard_EXPORT Standard_Integer | SetNode (const gp_XYZ &thePnt, const Standard_Integer iN=-1)
const Poly_CoherentNode & | Node (const Standard_Integer i) const
Poly_CoherentNode & | ChangeNode (const Standard_Integer i)
Standard_EXPORT Standard_Integer | NNodes () const
const Poly_CoherentTriangle & | Triangle (const Standard_Integer i) const
Standard_EXPORT Standard_Integer | NTriangles () const
Standard_EXPORT Standard_Integer | NLinks () const
Standard_EXPORT Standard_Boolean | RemoveTriangle (Poly_CoherentTriangle &theTr)
Standard_EXPORT void | RemoveLink (Poly_CoherentLink &theLink)
Standard_EXPORT Poly_CoherentTriangle * | AddTriangle (const Standard_Integer iNode0, const Standard_Integer iNode1, const Standard_Integer iNode2)
Standard_EXPORT Poly_CoherentLink * | AddLink (const Poly_CoherentTriangle &theTri, const Standard_Integer theConn)
Standard_EXPORT Standard_Boolean | FindTriangle (const Poly_CoherentLink &theLink, const Poly_CoherentTriangle *pTri[2]) const
Standard_EXPORT Standard_Integer | ComputeLinks ()
Standard_EXPORT void | ClearLinks ()
Standard_EXPORT void | Dump (Standard_OStream &) const

## Protected Attributes

NCollection_Vector< Poly_CoherentTriangle > | myTriangles
NCollection_Vector< Poly_CoherentNode > | myNodes
NCollection_Vector< Poly_CoherentLink > | myLinks
Handle_NCollection_BaseAllocator | myAlloc
Standard_Real | myDeflection

## Data Structures

class | IteratorOfLink
class | IteratorOfNode
class | IteratorOfTriangle
struct | TwoIntegers
| Couple of integer indices (used in RemoveDegenerated()). More...

## Detailed Description

Triangulation structure that allows to:

- Store the connectivity of each triangle with up to 3 neighbouring ones and with the corresponding 3rd nodes on them,
- Store the connectivity of each node with all triangles that share this node
- Add nodes and triangles to the structure,
- Find all triangles sharing a single or a couple of nodes
- Remove triangles from structure
- Optionally create Links between pairs of nodes according to the current triangulation.
- Convert from/to Poly_Triangulation structure.

This class is useful for algorithms that need to analyse and/or edit a triangulated mesh -- for example for mesh refining. The connectivity model follows the idea that all Triangles in a mesh should have coherent orientation like on a surface of a solid body. Connections between more than 2 triangles are not suppoorted.

## Architecture

The data types used in this structure are:

- Poly_CoherentNode: Inherits go_XYZ therefore provides the full public API of gp_XYZ. Contains references to all incident triangles. You can add new nodes but you cannot remove existing ones. However each node that has no referenced triangle is considered as "free" (use the method IsFreeNode() to check this). Free nodes are not available to further processing, particularly they are not exported in Poly_Triangulation.
- Poly_CoherentTriangle: Main data type. Refers three Nodes, three connected Triangles, three opposite (connected) Nodes and three Links. If there is boundary then 1, 2 or 3 references to Triangles/connected Nodes/Links are assigned to NULL (for pointers) or -1 (for integer node index).
  You can find a triangle by one node using its triangle iterator or by two nodes - creating a temporary Poly_CoherentLink and calling the method FindTriangle().
  Triangles can be removed but they are never deleted from the containing array. Removed triangles have all nodes equal to -1. You can use the method IsEmpty() to check that.
- Poly_CoherentLink: Auxiliary data type. Normally the array of Links is empty, because for many algorithms it is sufficient to define only Triangles. You can explicitly create the Links at least once, calling the method ComputeLinks(). Each Link is oriented couple of Poly_CoherentNode (directed to the ascending Node index). It refers two connected triangulated Nodes - on the left and on the right, therefore a Poly_CoherentLink instance refers the full set of nodes that constitute a couple of connected Triangles. A boundary Link has either the first (left) or the second (right) connected node index equal to -1.
  When the array of Links is created, all subsequent calls to AddTriangle and RemoveTriangle try to preserve the connectivity Triangle-Link in addition to the connectivity Triangle-Triangle. Particularly, new Links are created by method AddTriangle() and existing ones are removed by method RemoveTriangle(), in each case whenever necessary.
  Similarly to Poly_CoherentTriangle, a Link can be removed but not destroyed separately from others. Removed Link can be recogniosed using the method IsEmpty(). To destroy all Links, call the method ClearLinks(), this method also nullifies Link references in all Triangles. All objects (except for free Nodes and empty Triangles and Links) can be visited by the corresponding Iterator. Direct access is provided for Nodes, any we discourage you to access Triangles directly (because you may encounter an empty triangle this way, what is excluded if you use Iterator).
  All CoherentTriangles must have the same topological orientation. Therefore you should care about the sequence of nodes when you add a new CoherentTriangle.
  Memory management: All data objects are stored in NCollection_Vector containers that prove to be efficient for the performance. In addition references to triangles are stored in ring lists, with an instance of such list per Poly_CoherentNode. These lists are allocated in a memory allocator that is provided in the constructor of Poly_CoherentTriangulation. By default the standard OCCT allocator (aka NCollection_BaseAllocator) is used. But if you need to increase the performance you can use NCollection_IncAllocator instead.

## Constructor & Destructor Documentation

Standard_EXPORT Poly_CoherentTriangulation::Poly_CoherentTriangulation | ( | const Handle_NCollection_BaseAllocator & | theAlloc = `0L` | ) |

| Empty constructor.

Standard_EXPORT Poly_CoherentTriangulation::Poly_CoherentTriangulation | ( | const Handle_Poly_Triangulation & | theTriangulation,
|  | const Handle_NCollection_BaseAllocator & | theAlloc = `0L`
| ) |

| Constructor. It does not create Links, you should call ComputeLinks following this constructor if you need these links.

virtual Standard_EXPORT Poly_CoherentTriangulation::~Poly_CoherentTriangulation | ( |  | ) | `[virtual]`

| Destructor.

## Member Function Documentation

Standard_EXPORT Poly_CoherentLink* Poly_CoherentTriangulation::AddLink | ( | const Poly_CoherentTriangle & | theTri,
|  | const Standard_Integer | theConn
| ) |

Add a single link to triangulation, based on a triangle and its side index. This method does not check for coincidence with already present links.

Parameters:

  | theTri | Triangle that contains the link to be added.
  | theConn | Index of the side (i.e., 0, 1 0r 2) defining the added link.

Standard_EXPORT Poly_CoherentTriangle* Poly_CoherentTriangulation::AddTriangle | ( | const Standard_Integer | iNode0,
|  | const Standard_Integer | iNode1,
|  | const Standard_Integer | iNode2
| ) |

Add a triangle to the triangulation.

Returns:
  Pointer to the added triangle instance or NULL if an error occurred.

Poly_CoherentNode& Poly_CoherentTriangulation::ChangeNode | ( | const Standard_Integer | i | ) | `[inline]`

| Get the node at the given index 'i'.

Standard_EXPORT void Poly_CoherentTriangulation::ClearLinks | ( |  | ) |

| Clear all Links data from the Triangulation data.

Standard_EXPORT Standard_Integer Poly_CoherentTriangulation::ComputeLinks | ( |  | ) |

| (Re)Calculate all links in this Triangulation.

Standard_Real Poly_CoherentTriangulation::Deflection | ( |  | ) | const`[inline]`

| Query the Deflection parameter (default value 0. -- if never initialized)

Standard_EXPORT void Poly_CoherentTriangulation::Dump | ( | Standard_OStream & |  | ) | const

| Debugging output.

Standard_EXPORT Standard_Boolean Poly_CoherentTriangulation::FindTriangle | ( | const Poly_CoherentLink & | theLink,
|  | const Poly_CoherentTriangle * | pTri[2]
| ) | const

Find one or two triangles that share the given couple of nodes.

Parameters:

  | theLink | Link (in fact, just a couple of nodes) on which the triangle is searched.
  | pTri | `[out]` Array of two pointers to triangle. pTri[0] stores the triangle to the left of the link, while pTri[1] stores the one to the right of the link.

Returns:
  True if at least one triangle is found and output as pTri.

Standard_EXPORT Standard_Boolean Poly_CoherentTriangulation::GetFreeNodes | ( | NCollection_List< Standard_Integer > & | lstNodes | ) | const

Create a list of free nodes. These nodes may appear as a result of any custom mesh decimation or RemoveDegenerated() call. This analysis is necessary if you support additional data structures based on the triangulation (e.g., edges on the surface boundary).

Parameters:

  | lstNodes | `[out]` List that receives the indices of free nodes.

Standard_EXPORT Handle_Poly_Triangulation Poly_CoherentTriangulation::GetTriangulation | ( |  | ) | const

| Create an instance of Poly_Triangulation from this object.

Standard_Integer Poly_CoherentTriangulation::MaxNode | ( |  | ) | const`[inline]`

| Query the index of the last node in the triangulation

Standard_Integer Poly_CoherentTriangulation::MaxTriangle | ( |  | ) | const`[inline]`

| Query the index of the last triangle in the triangulation

Standard_EXPORT Standard_Integer Poly_CoherentTriangulation::NLinks | ( |  | ) | const

| Query the total number of active Links.

Standard_EXPORT Standard_Integer Poly_CoherentTriangulation::NNodes | ( |  | ) | const

| Query the total number of active nodes (i.e. nodes used by 1 or more triangles)

const Poly_CoherentNode& Poly_CoherentTriangulation::Node | ( | const Standard_Integer | i | ) | const`[inline]`

| Get the node at the given index 'i'.

Standard_EXPORT Standard_Integer Poly_CoherentTriangulation::NTriangles | ( |  | ) | const

| Query the total number of active triangles (i.e. triangles that refer nodes, non-empty ones)

Standard_EXPORT Standard_Boolean Poly_CoherentTriangulation::RemoveDegenerated | ( | const Standard_Real | theTol,
|  | NCollection_List< TwoIntegers > * | pLstRemovedNode = `0L`
| ) |

Find and remove degenerated triangles in Triangulation.

Parameters:

  | theTol | Tolerance for the degeneration case. If any two nodes of a triangle have the distance less than this tolerance, this triangle is considered degenerated and therefore removed by this method.
  | pLstRemovedNode | Optional parameter. If defined, then it will receive the list of arrays where the first number is the index of removed node and the seond - the index of remaining node to which the mesh was reconnected.

Standard_EXPORT void Poly_CoherentTriangulation::RemoveLink | ( | Poly_CoherentLink & | theLink | ) |

| Removal of a single link from the triangulation.

Standard_EXPORT Standard_Boolean Poly_CoherentTriangulation::RemoveTriangle | ( | Poly_CoherentTriangle & | theTr | ) |

| Removal of a single triangle from the triangulation.

void Poly_CoherentTriangulation::SetDeflection | ( | const Standard_Real | theDefl | ) | `[inline]`

| Set the Deflection value as the parameter of the given triangulation.

Standard_EXPORT Standard_Integer Poly_CoherentTriangulation::SetNode | ( | const gp_XYZ & | thePnt,
|  | const Standard_Integer | iN = `-1`
| ) |

Initialize a node

Parameters:

  | thePoint | 3D Coordinates of the node.
  | iN | Index of the node. If negative (default), the node is added to the end of the current array of nodes.

Returns:
  Index of the added node.

const Poly_CoherentTriangle& Poly_CoherentTriangulation::Triangle | ( | const Standard_Integer | i | ) | const`[inline]`

| Get the triangle at the given index 'i'.

## Field Documentation

Handle_NCollection_BaseAllocator Poly_CoherentTriangulation::myAlloc `[protected]`

Standard_Real Poly_CoherentTriangulation::myDeflection `[protected]`

NCollection_Vector<Poly_CoherentLink> Poly_CoherentTriangulation::myLinks `[protected]`

NCollection_Vector<Poly_CoherentNode> Poly_CoherentTriangulation::myNodes `[protected]`

NCollection_Vector<Poly_CoherentTriangle> Poly_CoherentTriangulation::myTriangles `[protected]`

The documentation for this class was generated from the following file:

- Poly_CoherentTriangulation.hxx