DATAKIT API  V2025.1
WriteBody.cpp File Reference

Functions

int GetTesselationStatus ()
 
void WriteBody (Dtk_NodePtr inNode)
 
void WriteDtk_Mesh (const Dtk_MeshPtr &inMeshToWrite)
 

Variables

Dtk_transfo CurrentMatrix
 

Function Documentation

◆ GetTesselationStatus()

int GetTesselationStatus ( )
9 {
10  return TessStatus;
11 }

◆ WriteBody()

void WriteBody ( Dtk_NodePtr  inNode)
14 {
15  // Get if the node represent infinite geometry
16  // 1 = Infinite, 0 = Finite
17  int NodeInfiniteGeometry = inNode->GetInfos()->GetInfiniteGeometryFlag();
18  if (NodeInfiniteGeometry == 0)
19  {
20  //Calling both methods GetDtk_MeshPtr() and GetDtk_BodyPtr() on BodyNode will give you the same result
21  //Choose the one you need in order to avoid duplicated data
22  const Dtk_BodyPtr TmpBody = inNode->GetDtk_BodyPtr();
23  if (TmpBody.IsNotNULL())
24  {
25  // Used to write an XML File
26  if (IsXmlDumpActivated())
27  {
28  XmlWriteBody(TmpBody);
29  }
30  }
31 
32  // Some CAD formats store also faceted data besides B-Rep.
33  // So you can get faceted data corresponding to the body using the following method
34  const Dtk_MeshPtr TmpFacetedBody = inNode->GetDtk_MeshPtr();
35  if (TmpFacetedBody.IsNotNULL())
36  {
37  TmpFacetedBody->Transform(CurrentMatrix);
38  WriteDtk_Mesh(TmpFacetedBody);
39  }
40 
41 
42  // If there is no mesh data associated to the current body, you can tessellate (and if init of tessellation engine is successful)
43  if (TmpFacetedBody.IsNULL() && TmpBody.IsNotNULL() && GetTesselationStatus() == dtkNoError)
44  {
45  Dtk_tab<Dtk_MeshPtr> meshes;
46  Dtk_tab<Dtk_Int32> isclosed;
47  int err_tess = tess_BodyToMeshes(TmpBody, meshes, isclosed);
48  if( inNode->Name().len() > 0 )
49  cout << "NodeName = " << inNode->Name().c_str() << ";";
50  cout << "err_tess = " << dtkTypeError( err_tess ).c_str() << endl ;
51  if (err_tess == 0)
52  {
53  Dtk_Size_t i, nbmeshes = meshes.size();
54  for (i = 0; i < nbmeshes; i++)
55  {
56  meshes[i]->Transform(CurrentMatrix);
57  WriteDtk_Mesh(meshes[i]);
58  }
59  }
60 
61  if (IsPdfDumpActivated() && TmpBody->HasWire())
62  {// handling wire / points
64  }
65  }
66  }
67 }

◆ WriteDtk_Mesh()

void WriteDtk_Mesh ( const Dtk_MeshPtr inMeshToWrite)
9 {
10  // convert triangles-strip, fans, polygons into simple triangles
11  inMeshToWrite->explode();
12 
13  // Used to write a PDF File
14  if (IsPdfDumpActivated())
15  {
17  }
18 
19  // Used to write an XML File
20  if (IsXmlDumpActivated())
21  {
22  XmlWriteMesh(inMeshToWrite);
23  }
24 
25  Dtk_RGB rgb = inMeshToWrite->get_mesh_color(); // mesh global color.
26 
27  // vertices :
28  Dtk_Size_t nbvertices = inMeshToWrite->get_nb_vertices();
29  Dtk_Size_t i, j;
30  for (i = 0; i < nbvertices; i++)
31  {
32  Dtk_pnt pnt;
33  Dtk_dir dir;
34  Dtk_RGB color;
35  float u, v;
36  u = v = 0.0;
37  inMeshToWrite->get_vertex(i, &pnt); // coordinates of the vertices
38  if (inMeshToWrite->has_normals())
39  inMeshToWrite->get_normal(i, &dir); // vertex normal (if enabled)
40  if (inMeshToWrite->has_colors())
41  inMeshToWrite->get_color(i, &color); // vertex color (if enabled)
42  if (inMeshToWrite->has_texcoords())
43  {
44  u = inMeshToWrite->GetUTexture(i); // vertex u,v texture coordinate (if enabled)
45  v = inMeshToWrite->GetVTexture(i);
46  }
47  }
48  // mesh_faces
49  Dtk_Size_t k, m, nbmeshfaces = inMeshToWrite->get_nb_mesh_face();
50  for (i = 0; i < nbmeshfaces; i++)
51  {
52  Dtk_mesh_face* mf = inMeshToWrite->get_mesh_face(i);
53  Dtk_Size_t nbtriangles = mf->get_nbtriangles();
54  Dtk_Int32 trianglesindices[3];
55  for (j = 0; j < nbtriangles; j++)
56  {
57  const Dtk_UInt32* tri = mf->get_triangle_indices(j);
58  trianglesindices[0] = tri[0];
59  trianglesindices[1] = tri[1];
60  trianglesindices[2] = tri[2];
61  // id of vertex in vertices table you read in the first step of this function
62  }
63 
64  //face boundaries
65  Dtk_Size_t nbpolyline = mf->get_nbpolylines();
66  for (j = 0; j < nbpolyline; j++)
67  {
68  const Dtk_tab<Dtk_UInt32> *pnt;
69  pnt = mf->get_polyline_indices(j);
70  Dtk_Size_t nbvertex = pnt->size();
71  for (k = 0; k < nbvertex; k++)
72  {
73  m = (*pnt)[k]; // id of vertex in vertices table
74  Dtk_pnt pt = inMeshToWrite->get_vertex(m);
75  }
76  }
77  }
78 }

Variable Documentation

◆ CurrentMatrix

Dtk_transfo CurrentMatrix
extern
PdfWriteEntity
void PdfWriteEntity(Dtk_EntityPtr inEntity)
Definition: PdfWrite.cpp:173
Dtk_mesh_face
This is a high level face class.
Definition: util_mesh_dtk.hpp:870
Dtk_Info::GetInfiniteGeometryFlag
int GetInfiniteGeometryFlag() const
XmlWriteMesh
void XmlWriteMesh(const Dtk_MeshPtr &inMeshToWrite)
Definition: XmlWrite.cpp:63
CurrentMatrix
Dtk_transfo CurrentMatrix
Definition: WritePrototype.cpp:11
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
WriteDtk_Mesh
void WriteDtk_Mesh(const Dtk_MeshPtr &inMeshToWrite)
Definition: WriteMesh.cpp:8
Dtk_UInt32
uint32_t Dtk_UInt32
Definition: define.h:688
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
Dtk_mesh_face::get_polyline_indices
const Dtk_tab< Dtk_UInt32 > * get_polyline_indices(Dtk_Size_t inI) const
Get inI-th polygon.
Dtk_mesh_face::get_nbpolylines
Dtk_Size_t get_nbpolylines() const
Get the number of polylines kept in the class instance.
Dtk_DocElement::Name
const Dtk_string & Name() const
Retrieves the Dtk_DocElement Name - read only -.
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:687
Dtk_mesh_face::get_triangle_indices
const Dtk_UInt32 * get_triangle_indices(Dtk_Size_t inI) const
Get pointer of triangle indices of i-th triangle.
Dtk_DocElement::GetInfos
Dtk_InfoPtr GetInfos() const
Retrieves the Dtk_DocElement Dtk_InfoPtr - read only -.
Dtk_SmartPtr< Dtk_Entity >::DtkDynamicCast
static Dtk_SmartPtr< Dtk_Entity > DtkDynamicCast(const Dtk_SmartPtr< T2 > &p)
Definition: util_ptr_dtk.hpp:101
Dtk_SmartPtr::IsNULL
Dtk_bool IsNULL() const
Definition: util_ptr_dtk.hpp:118
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
XmlWriteBody
void XmlWriteBody(const Dtk_BodyPtr &inBody)
Definition: XmlWrite.cpp:118
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:22
GetTesselationStatus
int GetTesselationStatus()
Definition: TesselationEngine.cpp:8
Dtk_mesh_face::get_nbtriangles
Dtk_Size_t get_nbtriangles() const
Get the number of simple triangles kept in the class instance.
Dtk_Node::GetDtk_MeshPtr
Dtk_MeshPtr GetDtk_MeshPtr()
Retrieves the Dtk_Node as a Dtk_meshPtr - if exists -.
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)
: Make Tesselation from a Dtk_body and create a Set of Dtk_mesh if available
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
TessStatus
int TessStatus
Definition: TesselationEngine.cpp:6
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
Dtk_string::len
int len() const
Retrieve the length of the Dtk_string.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_RGB
Definition: dtk_rgb.hpp:7
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:26
Dtk_Node::GetDtk_BodyPtr
Dtk_BodyPtr GetDtk_BodyPtr()
Retrieves the Dtk_Node as a Dtk_BodyPtr - if exists -.