DATAKIT SDK  V2026.2
tess.h
Go to the documentation of this file.
1 #ifndef _TESS_H
2 #define _TESS_H
3 
5 #include "util/util_mesh_dtk.hpp"
6 #include "util/error_dtk.hpp"
8 #include "def/define.h"
9 #include "util/dtk_maindoc.hpp"
10 #include "util/util_stl_dtk.hpp"
11 
12 //! \defgroup tess_main_func Tesselation main functions
13 //! \brief All the basics functions you need to tesselate any Dtk brep data structures.
14 //! To better control the tesselation process, see section \ref tess_option.
15 //! @{
16 
17 //! \brief Init the tesselation library
18 //! \param[in] inWorkingDirectory : Directory for temporary file used for tesselation
19 //! \param[in] inTolerance(mm) : Maximum accepted chordal error between the CAD surface and the tesselated mesh
20 //! \return 0 if OK \n -4 if no licence found
21 int tess_InitTesselation(Dtk_string inWorkingDirectory,double inTolerance);
22 
23 //! \brief Return current status of tesselation started
25 
26 //! \brief Init the tesselation library with parameters suited for most visualisation purposes
27 //! Linear tolerance is deactivated, and angular tolerance set to 10 degrees
28 //! \warning This function disable the linear tolerance, see tess_set_linearTolerance(). It is suited for visualisation purpose only. If you need a more precise tesselation control using linear tolerance, call tess_disableTolLinear(DTK_FALSE) to re-enable it.
29 //! \return 0 if OK \n -4 if no licence found
31 
32 //! \brief Free the data used by tesselation library
34 
35 //! \brief Tesselate a body. Generates one mesh per shell in the body.
36 //! \param[in] inBodyToWrite : Body to be tessellate
37 //! \param[out] outMeshes : Result meshes, one `Dtk_MeshPtr` per shell
38 //! \param[out] outIsSolid : Info on each mesh topology. 0 if open, 1 if closed
39 //! \param[in] inTessWireframe : Enable the tesselation of wireframes contained in the body's shell. See Dtk_Shell::GetNumWireSet()
40 //! \param[in] inApplyRenderInfos : Enable the application of render infos from body to mesh
42  Dtk_tab<Dtk_MeshPtr>& outMeshes,
44  Dtk_bool inTessWireframe = DTK_FALSE,
45  Dtk_bool inApplyRenderInfos = DTK_FALSE );
46 
47 //! \brief Tesselate a shell
48 //! \param[in] inShell : Shell to be tesselate
49 //! \param[out] outMesh : Result mesh
50 //! \param[out] outIsSolid : Info on mesh topology. 0 if open, 1 if closed
52 
53 //! \brief Tesselate an array of Faces
54 //! \param[in] inTabFace : Faces to be tesselate
55 //! \param[out] outMesh : Result mesh
56 //! \param[out] outIsSolid : Info on mesh topology. 0 if open, 1 if closed
58 
59 //! \brief Tesselate a single face
60 //! \param[in] inFace : Face to be tesselate
61 //! \param[out] outMesh : Result mesh
62 //DTK_TOREMOVE_START
63 #ifdef AF51BDA7E49648f8AB95949F4CA52EF8
65 #else
66 //DTK_TOREMOVE_END
68 //DTK_TOREMOVE_START
69 #endif
70 //DTK_TOREMOVE_END
71 
72 //! \brief Get the boundaries (outer and inner) of a mesh face as polylines.
73 //! Each shell yields a Dtk_mesh, each face of the shell yields a Dtk_mesh_face in the Dtk_mesh, and each edge of the face yields a Dtk_Polyline that you can get with this function.
74 //! To get the body indice of the corresponding edge, use polyline->get_info()->FindAttribute("TOPO_ID_EDGE",dtk_val) where dtk_val is an integer value containing the TopoId of the edge.
75 //! The first polyline is the outer boundary, the others are inner boundaries (holes).
76 //!
77 //! \note This function requires that the option tess_ComputeBoundariesFromMesh() is enabled (default behaviour).
78 //!
79 //! \note Function Dtk_mesh_face::get_polyline_indices() provide point indices of the mesh face boundaries, but there are not ordered as continuous polylines.
80 //! tess_getBoundariesFromMeshFace extracts the boundaries as ordered polylines.
81 //!
82 //! \param[in] : mesh
83 //! \param[in] : inFace = face to be processed
84 //! \param[out] : outBoundaries = result function
85 //! \b Sample:
86 //! \code
87 //! Dtk_MeshPtr mesh;
88 //! Dtk_Size_t nbFace =mesh->get_nb_mesh_face();
89 //! for ( int iFace = 0; iFace < nbFace; iFace++ )
90 //! {
91 //! Dtk_mesh_face * meshFace = mesh->get_mesh_face(iFace);
92 //! Dtk_tab<Dtk_tab<Dtk_PolylinePtr>> boundaries;
93 //! tess_getBoundariesFromMeshFace(mesh, meshFace, boundaries);
94 //! const Dtk_Size_t nbloop = boundaries.size();
95 //! for ( Dtk_Size_t iLoop = 0; iLoop < nbloop; iLoop++)
96 //! {
97 //! Dtk_tab<Dtk_PolylinePtr> loop = boundaries[iLoop];
98 //! for ( Dtk_Size_t iEdge = 0; iEdge < loop.size(); iEdge++ )
99 //! {
100 //! Dtk_PolylinePtr polyline = loop[iEdge];
101 //! Dtk_Val edgeIdInOriginalBody;
102 //! polyline->get_info()->FindAttribute("TOPO_ID_EDGE",edgeIdInOriginalBody);
103 //! }
104 //! }
105 //! }
106 //! \endcode
108  const Dtk_mesh_face* inFace,
110 
111 //! @}
112 
113 //! \defgroup tess_option Tesselation options
114 //! \brief Options to better control the tesselation process.
115 //! Main functions are in section \ref tess_main_func.
116 //! @{
117 
118 //! \brief Set linear tolerance (mm). Maximum chordal error accepted between the CAD surface and the tesselated mesh. Smaller value produces finer mesh, greater value produces coarser mesh.
119 //! For visualization the constraint is purely visual, so an exact distance per model is unnecessary. In this case, using only an angular tolerance is sufficient.
120 //! For engineering workflows (CFD, FEM, etc.), stricter geometric control is required, and a linear tolerance must be specified. A common guideline is to set it to a proportion of the model bbox diagonal.
121 //! Note that angular tolerance is still relevant when linear tolerance is set, to avoids loosing details in areas with small details, like high curvature zones.
122 //! \warning This tolerance is a distance in mm, not a ratio, therefore it is relative to the model size. If you need a single value that works for any model (common for visualisation), use the angular tolerance.
123 //! \warning If set to 0.0, the linear tolerance is disabled. To re-enable it, set a valid linear tolerance and call tess_disableTolLinear(DTK_FALSE).
124 //! \image html discretisation.png
125 void tess_set_linear(double tol);
126 //! \brief Get the current linear tolerance. See tess_set_linear().
128 //! \brief Set activation of linear tolerance
130 //! \brief Return linear tolerance activation. DTK_TRUE if linear tolerance is disabled.
132 
133 //! \brief Set angular tolerance (radian). Default value: 10°. Maximum angle between a triangle and the CAD surface.
134 //! This tolerance is independent of the model size, therefore a single value can be used for any model. It is well suited for visualisation purposes.
135 //! \image html tess_angulartol.png
136 void tess_set_angular(double angle);
137 //! \brief Get the current angular tolerance. See tess_set_angular().
139 //! \brief Set activation of angular tolerance
141 //! \brief Return angular tolerance activation. DTK_TRUE if angular tolerance is disabled.
143 
144 //! \brief Set a maximum ratio between longest and shortest edge of each triangle. With 1.0 only equilateral triangles are generated. With 2.0, the longest edge can be at most twice the shortest edge, etc.
145 //! Example with ratio= 1.0
146 //! \image html tess_ratio1.png
147 //! Example with ratio= 1000.0 (no constraint)
148 //! \image html tess_ratio10000.png
149 void tess_set_Ratio(double tol);
150 //! \brief Get the current maximum ratio between longest and shortest edge of each triangle. See tess_set_Ratio().
151 double tess_get_Ratio();
152 
153 //! \brief Set the maximum size of a triangle edge. Default value: inf (mm)
154 //! \param[in] tol(mm) : maximum size of a triangle edge
155 void tess_set_MaxSize(double tol);
156 //! \brief Get the current maximum size of a triangle edge. See tess_set_MaxSize().
158 
159 //! \brief Set linear tolerance for Wireframe tessellation. Default value is 0.001 (mm). Smaller value produces finer wireframes, greater value produces coarser wireframes.
161 //! \brief Get the current linear tolerance for Wireframe tessellation. See tess_set_Wireframe_Discretisation().
163 
164 //! \brief Set a vertex map optimisation that reduces the mesh memory footprint (the geometry stay the same). Enabled by default.
165 //! If enabled, two vertices of the same face that have the same coordinates will be stored only once, and shared by index.
166 //! For example if you tesselate a cube ( 6 faces ):
167 //! - If enabled: vertex array size = 36\n
168 //! - If disabled: vertex array size = 24\n
169 //! \warning Not compatible with Dtk_mesh::compute_round_normals(). You must disable this optimization to use it.
170 void tess_set_optimize_mesh(int ival);
171 //! \brief Get the current state of the vertex map optimisation. See tess_set_optimize_mesh().
173 
174 //! \brief Set boundaries computation from mesh option. Default value is enabled (1). See tess_getBoundariesFromMeshFace().
176 //! \brief Get boundaries computation from mesh option. Returns 1 if enabled, 0 if disabled.
178 
179 //! \brief Set normales computation from surface option. Enabled by default. If enabled, the normals of each vertex are computed from the CAD surface (smooth, more precise), otherwise they are computed from the triangles.
181 //! \brief Get normales computation option. Returns 1 if enabled, 0 if disabled.
183 
184 //! \brief Set boundaries computation option. Default value is enabled (1). See tess_getBoundariesFromMeshFace().
186 //! \brief Get boundaries computation option. Returns 1 if enabled, 0 if disabled.
188 
189 //! \brief Set face duplication option. Default value is enabled (1).
191 //! \brief Get face duplication option. Returns 1 if enabled, 0 if disabled.
193 
194 //DTK_TOREMOVE_START
195 #ifdef AF51BDA7E49648f8AB95949F4CA52EF8
196 void tess_set_ErCorde(double tol);
197 void tess_set_Discretisation(double tol);
198 #endif
199 //DTK_TOREMOVE_END
200 
201 //! \brief Set automatic surface spring check option. If enabled, all periodic surface will be tesselated more accurately using set_TesselateSurfaceMethod(1).
202 //! Manual activation of set_TesselateSurfaceMethod(1) is not necessary anymore because of this option.
204 //! \brief Get automatic surface spring check option. Returns 1 if enabled, 0 if disabled.
206 
207 //! \brief Set usage of edge tolerance to guide the tesselation. Default value is disabled (0).
209 //! \brief Get usage of edge tolerance to guide the tesselation. Returns 1 if enabled, 0 if disabled.
211 
212 //! \brief Set additional verification of face/boundaries before tesselation. Default false (0).
213 void Dtk_SetMailleFacesVerif(int bval);
214 //! \brief Get status of additional verification of face/boundaries before tesselation. Returns 1 if enabled, 0 if disabled.
216 
217 //! @}
218 
220 {
221 private :
222  Dtk_tab<Dtk_PolylinePtr> outerpln;
224  Dtk_ErrorStatus status;
225 
226 public :
229  Dtk_ErrorStatus Create( Dtk_FacePtr &inFace,const double inTolBound);
230  void Delete();
232  Dtk_Size_t Get_Nbinner() { return(innerpln.size()) ;};
234  Dtk_ErrorStatus CheckStatus() { return (status); };
235 };
236 
238 {
241 };
242 
243 
244 
245 //////////////////////////////////////////////////////////////////////////////
246 // Deprecated
247 
250 
251 void get_tesselation_activateSplitMode(int &outmode, double &outratio);
252 void set_tesselation_activateSplitMode(const int inmode, const double inratio);
258 int end_stl_fic(int *ient);
259 
260 SetAsDeprecated("2026.1", "Use tess_InitTesselation() instead.")
261 //! \deprecated Use tess_InitTesselation() instead
262 extern int tess_InitLocalTess();
263 
264 
266 //! \deprecated Use tess_FaceToMesh or tess_FacesArrayToMesh instead
267 extern Dtk_ErrorStatus tess_AddFace(Dtk_FacePtr &inFace);
268 
269 
270 SetAsDeprecated("2026.1", "Use tess_FaceToMesh or tess_FacesArrayToMesh instead.")
271 //! \deprecated Use tess_AddFace instead
272 extern Dtk_ErrorStatus tess_AddFace(Dtk_OrientedFaceStr &inFace);
273 
274 SetAsDeprecated("2026.1", "Use tess_FacesArrayToMesh instead.")
275 //! \deprecated Use tess_FacesArrayToMesh instead
276 extern int tess_TesselateMemo(Dtk_MeshPtr &outMesh, int *outIsSolid);
277 
278 SetAsDeprecated("2026.1", "Manual activation not needed/supported anymore, see CheckAutoSurfaceIsSpring(). If set_TesselateSurfaceMethod(0), remove this call. If set_TesselateSurfaceMethod(1), replace it by CheckAutoSurfaceIsSpring(DTK_TRUE), or lower the linear and/or angular tol to keep exactly the same results.")
279 //! \deprecated Manual activation not needed/supported anymore see CheckAutoSurfaceIsSpring()
280 void set_TesselateSurfaceMethod(int ival);
281 
282 SetAsDeprecated("2026.1", "Manual activation not supported anymore.")
283 //! \deprecated Manual activation not supported anymore
284 int get_TesselateSurfaceMethod();
285 
287 //! \deprecated Use tess_getBoundariesFromMeshFace instead
289 
290 #endif
tess_ShellToMesh
Dtk_ErrorStatus tess_ShellToMesh(const Dtk_ShellPtr &inShell, Dtk_MeshPtr &outMesh, Dtk_Int32 *outIsSolid)
Tesselate a shell.
Dtk_mesh_face
This is a high level face class.
Definition: util_mesh_dtk.hpp:865
init_stl_write
int init_stl_write(Dtk_string sfic)
tess_set_MaxSize
void tess_set_MaxSize(double tol)
Set the maximum size of a triangle edge. Default value: inf (mm)
Dtk_OrientedFaceStr::_orientation
Dtk_bool _orientation
Definition: tess.h:240
FaceBoundariesToPolylines::FaceBoundariesToPolylines
FaceBoundariesToPolylines()
tess_disableTolAngular
void tess_disableTolAngular(Dtk_bool bval)
Set activation of angular tolerance.
set_activationSplitModeFromConfig
void set_activationSplitModeFromConfig()
tess_InitTesselation
int tess_InitTesselation(Dtk_string inWorkingDirectory, double inTolerance)
Init the tesselation library.
DTK_TRUE
#define DTK_TRUE
Definition: define.h:719
tess_set_Wireframe_Discretisation
void tess_set_Wireframe_Discretisation(double tol)
Set linear tolerance for Wireframe tessellation. Default value is 0.001 (mm). Smaller value produces ...
tess_FaceToMesh
Dtk_ErrorStatus tess_FaceToMesh(Dtk_FacePtr &inFace, Dtk_MeshPtr &outMesh)
Tesselate a single face.
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
SetAsDeprecated
SetAsDeprecated("2026.1", "Use tess_InitTesselation() instead.") extern int tess_InitLocalTess()
tess_get_Ratio
double tess_get_Ratio()
Get the current maximum ratio between longest and shortest edge of each triangle. See tess_set_Ratio(...
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:704
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:720
Dtk_bool
char Dtk_bool
Definition: define.h:717
tess_ComputeBoundariesFromMesh
void tess_ComputeBoundariesFromMesh(int value)
Set boundaries computation from mesh option. Default value is enabled (1). See tess_getBoundariesFrom...
outIsSolid
int * outIsSolid
Definition: tess.h:276
get_tesselation_activateSplitMode
void get_tesselation_activateSplitMode(int &outmode, double &outratio)
Dtk_OrientedFaceStr::_face
Dtk_FacePtr _face
Definition: tess.h:239
FaceBoundariesToPolylines::Get_outer
Dtk_ErrorStatus Get_outer(Dtk_tab< Dtk_PolylinePtr > &outpln)
CheckUseEdgeTolerance
void CheckUseEdgeTolerance(Dtk_bool inBval)
Set usage of edge tolerance to guide the tesselation. Default value is disabled (0).
util_mesh_dtk.hpp
TesselationIsStarted
Dtk_ErrorStatus TesselationIsStarted()
Return current status of tesselation started.
get_tesselationSuppressDuplicateFace
Dtk_bool get_tesselationSuppressDuplicateFace()
Get face duplication option. Returns 1 if enabled, 0 if disabled.
util_topology_ptr_dtk.hpp
CheckAutoSurfaceIsSpring
void CheckAutoSurfaceIsSpring(Dtk_bool inBval)
Set automatic surface spring check option. If enabled, all periodic surface will be tesselated more a...
outBoundaries
const Dtk_mesh_face Dtk_tab< Dtk_tab< Dtk_MeshPolylinePtr > > & outBoundaries
Definition: tess.h:288
tess_AddNaturalBoundariesForUnBounded
void tess_AddNaturalBoundariesForUnBounded(int value)
Set boundaries computation option. Default value is enabled (1). See tess_getBoundariesFromMeshFace()...
tess_set_linear
void tess_set_linear(double tol)
Set linear tolerance (mm). Maximum chordal error accepted between the CAD surface and the tesselated ...
tess_BodyToMeshes
Dtk_ErrorStatus tess_BodyToMeshes(const Dtk_BodyPtr &inBodyToWrite, Dtk_tab< Dtk_MeshPtr > &outMeshes, Dtk_tab< Dtk_Int32 > &outIsSolid, Dtk_bool inTessWireframe=DTK_FALSE, Dtk_bool inApplyRenderInfos=DTK_FALSE)
Tesselate a body. Generates one mesh per shell in the body.
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:679
FaceBoundariesToPolylines::~FaceBoundariesToPolylines
~FaceBoundariesToPolylines()
tess_get_MaxSize
double tess_get_MaxSize()
Get the current maximum size of a triangle edge. See tess_set_MaxSize().
tess_get_optimize_mesh
int tess_get_optimize_mesh()
Get the current state of the vertex map optimisation. See tess_set_optimize_mesh().
error_dtk.hpp
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
tess_get_angular
double tess_get_angular()
Get the current angular tolerance. See tess_set_angular().
Dtk_GetMailleFacesVerif
int Dtk_GetMailleFacesVerif()
Get status of additional verification of face/boundaries before tesselation. Returns 1 if enabled,...
tess_FacesArrayToMesh
Dtk_ErrorStatus tess_FacesArrayToMesh(Dtk_tab< Dtk_FacePtr > &inTabFace, Dtk_MeshPtr &outMesh, Dtk_Int32 *outIsSolid)
Tesselate an array of Faces.
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
dtk_maindoc.hpp
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...
end_stl_fic
int end_stl_fic(int *ient)
tess_get_Wireframe_Discretisation
double tess_get_Wireframe_Discretisation()
Get the current linear tolerance for Wireframe tessellation. See tess_set_Wireframe_Discretisation().
util_stl_dtk.hpp
FaceBoundariesToPolylines::Get_inner
Dtk_ErrorStatus Get_inner(Dtk_tab< Dtk_PolylinePtr > &outpln, Dtk_Size_t number)
tess_TesselateFeature_to_dtk_mesh
Dtk_ErrorStatus tess_TesselateFeature_to_dtk_mesh(Dtk_FeaturePtr &feat, Dtk_MeshPtr &outMesh)
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,...
FaceBoundariesToPolylines::Delete
void Delete()
define.h
tess_set_optimize_mesh
void tess_set_optimize_mesh(int ival)
Set a vertex map optimisation that reduces the mesh memory footprint (the geometry stay the same)....
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
write_mesh_solid
int write_mesh_solid(const Dtk_MeshPtr &tm)
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).
util_geom_ptr_dtk.hpp
tess_disableTolLinear
void tess_disableTolLinear(Dtk_bool bval)
Set activation of linear tolerance.
Dtk_OrientedFaceStr
Definition: tess.h:238
Dtk_SetMailleFacesVerif
void Dtk_SetMailleFacesVerif(int bval)
Set additional verification of face/boundaries before tesselation. Default false (0).
tess_EndTesselation
void tess_EndTesselation()
Free the data used by tesselation library.
tess_get_linear
double tess_get_linear()
Get the current linear tolerance. See tess_set_linear().
FaceBoundariesToPolylines::Create
Dtk_ErrorStatus Create(Dtk_FacePtr &inFace, const double inTolBound)
set_tesselation_activateSplitMode
void set_tesselation_activateSplitMode(const int inmode, const double inratio)
FaceBoundariesToPolylines::CheckStatus
Dtk_ErrorStatus CheckStatus()
Definition: tess.h:234
FaceBoundariesToPolylines
Definition: tess.h:220
FaceBoundariesToPolylines::Get_Nbinner
Dtk_Size_t Get_Nbinner()
Definition: tess.h:232