DATAKIT API  V2025.1
How to use Tessellation

The Tessellation Library allows you to to convert a CAD model to a mesh (a set of triangles). A mesh can be usefull for graphic display or mesh based files generation (like obj, vrml, pdf3d, cgr...).
Tesselation module should be used in datakit API context, i.e the function Dtk_API::StartAPI() should be called before any tesselation routine calls.

Tessellation Process

Our tesselation algorithm works roughly in 5 steps.

  • Step 1 - Discretization of each surface and boundary in a point cloud, with respect to the user provided precision (the linear tolerance), see Tesselation precision settings .
  • Step 2 - Computation of a set of triangles from this cloud, with respect to the user provided options (maximum triangle size, maximum size ratio between two neighbor triangles), see Other settings .
  • Step 3 - Storage of the resulting triangles in a Dtk_mesh.
  • Step 4 - Computation of the normals for each mesh vertices.

Using the tessellation library

How to tesselate each entity

To tesselate a Dtk_Body use tess_BodyToMeshes(). This method returns an array with one mesh per shell contained in the body.
To tesselate a Dtk_Shell use tess_ShellToMesh(). This is usefull to tesselate a body shell per shell. This method is used if you check if the shell is closed or not and you can ajust the result.
To tesselate a Dtk_Face use tess_FaceToMesh(). This is usefull to tesselate a shell face per face. In this case you cannot obtain any connexion beetwen faces.
To tesselate a set of Dtk_Face use tess_FacesArrayToMesh(). This is usefull to store each faces of a body in an array, and tessellate in one pass. This method can be used with surface format where each open shell contain only one face.
You can save an array with Dtk_Face entity , or use the structure Dtk_OrientedFaceStr , that store orientation in addition of face from shell.


Tesselation settings

Tesselation precision settings

A mesh is by definition less precise than its corresponding brep: a surface composed of a triangle set cannot be as "smooth" as its NURBS mathematical definition. Our tesselation module allows you to control this precision with a linear or angular tolerance.

Linear Tolerance
The linear tolerance represents the chordal error, i.e the maximum distance between the reference curve (the brep curve stored in the body) and the approximated mesh. A smaller value produces a denser mesh on curved geometry that is more accurate, but also heavier. Note that this value is dependant to the model size, a smaller model needs a smaller linear tolerance to keep the same precision as a bigger model.

Discretization result for linear tolerance = 0.5mm (green : the exact surface (reference curve), red : resulting mesh). We can see that the maximum distance between the reference curve and the approximated mesh never exceeds 0.5.
To change the linear tolerance use

tess_set_linear(double tol)

To disable linear tolerance use


Angular Tolerance
Angular tolerance is another way to control the resulting mesh precision.
It is the maximum angle between the reference curve (the brep curve stored in the body) and the approximated mesh. This tolerance has the advantage to be independant to the model size.

Angular tolerance represents deviation angle between points (green : exact surface definition, resulting triangle basis)

Discretization result for angular tolerance = 0.104rad (6deg) (green : the exact surface (reference curve), red : resulting mesh). We can see that the maximum angle between the reference curve and the approximated mesh never exceeds 6deg = 0.104rad.
To enable angular tolerance use

tess_set_angular(double angle); // The angle value is in radian !

To disable angular tolerance use



By default, the linear tolerance is enabled alone.
The tolerance value is the second parameter of tess_InitTesselation(Dtk_string inWorkingDirectory,double inTolerance).
Both linear and angular modes can be combined. In such a case, final meshing results will depend on both criterias.

Other settings

You can set the size ratio between two neighbor triangles with tess_set_Ratio(double tol) . A value at 1.0 generates only isosceles triangles

You can set the maximun lenght of a triangle with the function tess_set_MaxSize(double tol);


Miscallenous functions


  • By default, the tessellation computes the exact normal value from the original surface, not a normal from the triangle.
    However, you can disable this calculation if the approximation is sufficient for you, by calling :
  • In Dtk_mesh, we save the boundaries computed from the vertices for each face, then you can retrieve them with:
    In the array of polylines, the first one is the outer boundary and others represent the inners if they exist. You can desactivate this storage by calling beforehand the following function : To get current status for this option use : this function return DTK_TRUE if enable (Default value) or DTK_FALSE if disable.

  • Special periodical surfaces / springs These surfaces require a more precise method to be tessellated.
    If we detect a surface like a spring, we activate this specific method.
    You can activate this method at any time with Note that this method is time consuming.

  • Duplicated faces are removed by default, but you can disable this option with : To get current status for this option use :
  • Some formats contain a tolerance for the edge , but this value is neither mandatory nor necessarily relevant. If you want to use this value you need to use If the tolerance value read in the part is lower than tolerance value defined previously, this value is used
    To get current status for this option use :
  • Sometime surfaces with various curvatures can be correctly tessellate only with much lower linear tolerance values, in this case it is better to use angular value, but if you want or need linear value, the best way is to temporarily divide the surface at the curvature.
    In this case use the function :
    void set_tesselation_activateSplitMode(const int inmode, const double inratio);
    • inmode can be :
      • no split ( default value )
      • split based on surface curvature
      • split based on great nodal sequence variation
    • inratio is value limit to split face
      depends of mode selected ( curvature or nodal sequence ) equal to the value for curvature or variation between 2 values for nodal sequence, triggering the split.

To get current status for this option use :

void get_tesselation_activateSplitMode(int &outmode, double &outratio);

To disable the split method after use :

WARNING : this method is time-consuming and will be used for special part like turbine blades

For other information, do not hesitate to contact us.



Relationship between Dtk_mesh and Dtk_BodyPtr after tessellation

After using one of the following tessellation methods :

After using one of the following tessellation methods :

Sample to tessellate a Dtk_Body

Dtk_Info::FindAttribute
Dtk_ErrorStatus FindAttribute(const Dtk_string &name, Dtk_Val &val) const
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:689
write_mesh_solid
int write_mesh_solid(Dtk_mesh *tm)
Dtk_mesh_face
This is a high level face class.
Definition: util_mesh_dtk.hpp:870
Dtk_Info::GetName
Dtk_string GetName() const
Retrieves the entity name.
get_tesselationSuppressDuplicateFace
Dtk_bool get_tesselationSuppressDuplicateFace()
: return current status of suppress duplicate face option default value is enable to deactivate this ...
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
tess_set_Ratio
void tess_set_Ratio(double tol)
: define a ratio
DTK_TRUE
#define DTK_TRUE
Definition: define.h:727
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
DTK_FALSE
#define DTK_FALSE
Definition: define.h:728
Dtk_bool
char Dtk_bool
Definition: define.h:725
tess_InitTesselation
int tess_InitTesselation(Dtk_string inWorkingDirectory, double inTolerance)
Init the tesselation library.
get_tesselation_activateSplitMode
void get_tesselation_activateSplitMode(int &outmode, double &outratio)
: read value of splitting of surface
Dtk_Val
Definition: dtk_val.hpp:67
Dtk_Val::GetInt
int GetInt(Dtk_status &st=Dtk_status::GetDefaultStatus()) const
tess_getBoundariesFromMeshFace
void tess_getBoundariesFromMeshFace(const Dtk_MeshPtr &mesh, const Dtk_mesh_face *inFace, Dtk_tab< Dtk_tab< Dtk_PolylinePtr > > &outBoundaries)
: reorder the polylines of a Dtk_mesh_face into correct loop
tess_ComputeNormalesFromSurface
int tess_ComputeNormalesFromSurface()
: Check value of option compute normales of vertex from real surface
TesselationIsStarted
Dtk_ErrorStatus TesselationIsStarted()
: Check if tesselation is initialized
DTK_TYPE_FACE
@ DTK_TYPE_FACE
Definition: define.h:141
Dtk_mesh_face::get_id
int get_id()
Return the face Id.
Dtk_SmartPtr::DtkDynamicCast
static Dtk_SmartPtr< T > DtkDynamicCast(const Dtk_SmartPtr< T2 > &p)
Definition: util_ptr_dtk.hpp:101
end_stl_fic
int end_stl_fic(int *ient)
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
set_tesselationSuppressDuplicateFace
void set_tesselationSuppressDuplicateFace(Dtk_bool inBval)
: Enable or disable the suppression of duplicate face before tessellation
reinit_SplitMode
void reinit_SplitMode()
: disable splitting of surface
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
tess_disableTolAngular
Dtk_bool tess_disableTolAngular()
: return state of Angular tolerance method
set_TesselateSurfaceMethod
void set_TesselateSurfaceMethod(int ival)
: select computation method for surface tesselation
CheckUseEdgeTolerance
Dtk_bool CheckUseEdgeTolerance()
: return current status of if we use the tolerance of edge and face read from the part available valu...
DTK_TYPE_EDGE
@ DTK_TYPE_EDGE
Definition: define.h:128
tess_ComputeBoundariesFromMesh
int tess_ComputeBoundariesFromMesh()
: Check value of option memorize noundaries of mesh
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:85
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:502
tess_set_angular
void tess_set_angular(double angle)
: Set angle for cord heigh ratio method
tess_EndTesselation
void tess_EndTesselation()
Free the data used by tesselation library.
init_stl_write
int init_stl_write(Dtk_string sfic)
tess_set_MaxSize
void tess_set_MaxSize(double tol)
: sets maximum size of triangles
tess_disableTolLinear
Dtk_bool tess_disableTolLinear()
: return state of linear tolerance method
Dtk_tab::at
T & at(Dtk_Size_t k)
Definition: util_stl_dtk.hpp:396
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_Info::GetId
int GetId() const
set_tesselation_activateSplitMode
void set_tesselation_activateSplitMode(const int inmode, const double inratio)
: memorize option for splitting of surfaces before tessellation
tess_set_linear
void tess_set_linear(double tol)
: Set tolerance for linear tolerance method