DATAKIT API  V2025.1
DtkDumpStl Class Reference

Public Member Functions

void addMesh (Dtk_MeshPtr mesh)
 
 DtkDumpStl (const Dtk_string outputname, const Dtk_bool AsciiMode=DTK_FALSE)
 
Dtk_Size_t endDump ()
 
Dtk_bool isAvailable ()
 
 ~DtkDumpStl ()
 

Constructor & Destructor Documentation

◆ DtkDumpStl()

DtkDumpStl::DtkDumpStl ( const Dtk_string  outputname,
const Dtk_bool  AsciiMode = DTK_FALSE 
)
10 {
11  if ( AsciiMode == DTK_TRUE )
12  fstl_ = outputname.OpenFile(DTK_W);
13  else
14  fstl_ = outputname.OpenFile(DTK_WB);
15 
16  isAscii_ = AsciiMode;
17  pos_ = 0;
18  nbtriangle_ = 0;
19 
20  if ( fstl_ )
21  {
22  if ( isAscii_ == DTK_FALSE)
23  {
24  char s[255];
25  for(int i = 0 ; i < 80 ; ++i)
26  {
27  s[i]=' ';
28  }
29  fwrite(s,80,sizeof(char),fstl_);
30  pos_ = ftell(fstl_);
31  fwrite(&nbtriangle_,1,sizeof(int),fstl_);
32  }
33  else
34  fprintf(fstl_,"SOLID SOL%d\n",1);
35  }
36 }

◆ ~DtkDumpStl()

DtkDumpStl::~DtkDumpStl ( )
117 {
118  if ( fstl_ )
119  endDump();
120 }

Member Function Documentation

◆ addMesh()

void DtkDumpStl::addMesh ( Dtk_MeshPtr  mesh)
40 {
41  if ( fstl_ )
42  {
43  mesh->explode(); // convert all in triangles
44  Dtk_Size_t i,ilen,j,jlen;
45  Dtk_dir dir; Dtk_pnt pnt;
46  float data;
47  short truc = 0; // use to complete triangle in binary mode
48 
49  ilen = mesh->get_nb_mesh_face();
50  for ( i=0;i<ilen;++i)
51  {
52  jlen = mesh->get_mesh_face(i)->get_nbtriangles();
53  for ( j=0;j<jlen;++j)
54  {
55  // for each traingles
56  nbtriangle_++; // increase global counter
57  dir = mesh->get_mesh_face(i)->get_triangle_normal(j);
58  if ( isAscii_ == DTK_FALSE )
59  {
60  data = (float)dir[0]; fwrite(&data,1,sizeof(float),fstl_);
61  data = (float)dir[1]; fwrite(&data,1,sizeof(float),fstl_);
62  data = (float)dir[2]; fwrite(&data,1,sizeof(float),fstl_);
63 
64  }
65  else
66  {
67  fprintf(fstl_,"FACET NORMAL %lf %lf %lf\n",dir[0],dir[1],dir[2]);
68  fprintf(fstl_," OUTER LOOP\n");
69 
70  }
71 
72  for(int k = 0 ; k < 3 ; k++)
73  {
74  pnt = mesh->get_mesh_face(i)->get_triangle_vertex(j,k);
75  if ( isAscii_ == DTK_FALSE)
76  {
77  data = (float)pnt[0]; fwrite(&data,1,sizeof(float),fstl_);
78  data = (float)pnt[1]; fwrite(&data,1,sizeof(float),fstl_);
79  data = (float)pnt[2]; fwrite(&data,1,sizeof(float),fstl_);
80  }
81  else
82  {
83  fprintf(fstl_," VERTEX %lf %lf %lf\n",pnt[0],pnt[1],pnt[2]);
84  }
85  }
86  if ( isAscii_ == DTK_FALSE)
87  fwrite(&truc,1,sizeof(short),fstl_);
88  else
89  {
90  fprintf(fstl_," ENDLOOP\n");
91  fprintf(fstl_,"ENDFACET\n");
92  }
93 
94  }
95  }
96  }
97 
98 }

◆ endDump()

Dtk_Size_t DtkDumpStl::endDump ( )
101 {
102  if (fstl_ )
103  {
104  if ( isAscii_ == DTK_FALSE )
105  {
106  fseek(fstl_,pos_,SEEK_SET);
107  fwrite(&nbtriangle_,1,sizeof(int),fstl_);
108  }
109  fclose(fstl_);
110  }
111  fstl_ = NULL;
112  return(nbtriangle_);
113 }

◆ isAvailable()

Dtk_bool DtkDumpStl::isAvailable ( )
15 { return ((fstl_ == NULL) ? DTK_FALSE : DTK_TRUE ); }
DTK_TRUE
#define DTK_TRUE
Definition: define.h:727
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
DTK_FALSE
#define DTK_FALSE
Definition: define.h:728
Dtk_string::OpenFile
FILE * OpenFile(const Dtk_string &inRights) const
File Utility : Open a file with the given rights.
DTK_W
#define DTK_W
Definition: dtk_string.hpp:43
DTK_WB
#define DTK_WB
Definition: dtk_string.hpp:45
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:22
DtkDumpStl::endDump
Dtk_Size_t endDump()
Definition: util_writemesh_dtk.cpp:100
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15