DATAKIT SDK  V2026.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
    void set_TesselateSurfaceMethod(int ival);
    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_Entity::get_info
Dtk_InfoPtr get_info() const
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:692
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:865
Dtk_Info::GetName
Dtk_string GetName() const
Retrieves the entity name.
tess_set_MaxSize
void tess_set_MaxSize(double tol)
Set the maximum size of a triangle edge. Default value: inf (mm)
tess_disableTolAngular
void tess_disableTolAngular(Dtk_bool bval)
Set activation of angular tolerance.
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
tess_InitTesselation
int tess_InitTesselation(Dtk_string inWorkingDirectory, double inTolerance)
Init the tesselation library.
DTK_TRUE
#define DTK_TRUE
Definition: define.h:730
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:715
tess_ComputeNormalesFromSurface
void tess_ComputeNormalesFromSurface(int value)
Set normales computation from surface option. Enabled by default. If enabled, the normals of each ver...
DTK_FALSE
#define DTK_FALSE
Definition: define.h:731
Dtk_bool
char Dtk_bool
Definition: define.h:728
tess_ComputeBoundariesFromMesh
void tess_ComputeBoundariesFromMesh(int value)
Set boundaries computation from mesh option. Default value is enabled (1). See tess_getBoundariesFrom...
get_tesselation_activateSplitMode
void get_tesselation_activateSplitMode(int &outmode, double &outratio)
CheckUseEdgeTolerance
void CheckUseEdgeTolerance(Dtk_bool inBval)
Set usage of edge tolerance to guide the tesselation. Default value is disabled (0).
Dtk_Val
Definition: dtk_val.hpp:67
TesselationIsStarted
Dtk_ErrorStatus TesselationIsStarted()
Return current status of tesselation started.
Dtk_Val::GetInt
int GetInt(Dtk_status &st=Dtk_status::GetDefaultStatus()) const
get_tesselationSuppressDuplicateFace
Dtk_bool get_tesselationSuppressDuplicateFace()
Get face duplication option. Returns 1 if enabled, 0 if disabled.
outBoundaries
const Dtk_mesh_face Dtk_tab< Dtk_tab< Dtk_MeshPolylinePtr > > & outBoundaries
Definition: tess.h:288
tess_set_linear
void tess_set_linear(double tol)
Set linear tolerance (mm). Maximum chordal error accepted between the CAD surface and the tesselated ...
DTK_TYPE_FACE
@ DTK_TYPE_FACE
Definition: define.h:143
Dtk_mesh_face::get_id
int get_id()
Return the face Id.
Dtk_SmartPtr< Dtk_Face >::DtkDynamicCast
static Dtk_SmartPtr< Dtk_Face > 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
reinit_SplitMode
void reinit_SplitMode()
tess_set_Ratio
void tess_set_Ratio(double tol)
Set a maximum ratio between longest and shortest edge of each triangle. With 1.0 only equilateral tri...
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
tess_getBoundariesFromMeshFace
void tess_getBoundariesFromMeshFace(const Dtk_MeshPtr &mesh, const Dtk_mesh_face *inFace, Dtk_tab< Dtk_tab< Dtk_PolylinePtr >> &outBoundaries)
Get the boundaries (outer and inner) of a mesh face as polylines. Each shell yields a Dtk_mesh,...
DTK_TYPE_EDGE
@ DTK_TYPE_EDGE
Definition: define.h:130
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:84
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:503
inFace
const Dtk_mesh_face * inFace
Definition: tess.h:288
tess_set_angular
void tess_set_angular(double angle)
Set angular tolerance (radian). Default value: 10°. Maximum angle between a triangle and the CAD surf...
set_tesselationSuppressDuplicateFace
void set_tesselationSuppressDuplicateFace(Dtk_bool inBval)
Set face duplication option. Default value is enabled (1).
tess_disableTolLinear
void tess_disableTolLinear(Dtk_bool bval)
Set activation of linear tolerance.
init_stl_write
int init_stl_write(Dtk_string sfic)
tess_EndTesselation
void tess_EndTesselation()
Free the data used by tesselation library.
Dtk_tab::at
T & at(Dtk_Size_t k)
Definition: util_stl_dtk.hpp:397
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:147
Dtk_Info::GetId
int GetId() const
set_tesselation_activateSplitMode
void set_tesselation_activateSplitMode(const int inmode, const double inratio)