DATAKIT API  V2025.1
testlibcgrwrite.cpp File Reference

Functions

int CgrWriteSample (const Dtk_string &inResultDirectory)
 

Function Documentation

◆ CgrWriteSample()

int CgrWriteSample ( const Dtk_string inResultDirectory)
18 {
19  int status;
20  Dtk_MeshPtr CubeMesh;
21  Dtk_MeshPtr CylinderMesh;
22  Dtk_MeshPtr WireMesh;
23  Dtk_AxisSystemPtr TmpAxis;
24  Dtk_mesh_asm_node * mesh_asm = NULL;
25  Dtk_mesh_asm_node * mesh_asm_1 = NULL;
26  Dtk_mesh_asm_node * mesh_asm_2 = NULL;
27  Dtk_mesh_asm_node * mesh_asm_3 = NULL;
28  Dtk_mesh_asm_node * mesh_asm_4 = NULL;
29  Dtk_string outputFileName, outputDirectory;
30 
31  cout << endl << "----------------------------------------------" << endl;
32  cout << "Cgr Write start" << endl;
33 
34  // Choosing output directory and file name
35  outputDirectory = inResultDirectory + L"dtk/Cgr/";
36  outputDirectory.FixPathSeparator();
37  outputDirectory.mkdir();
38  outputFileName = outputDirectory + L"sample.cgr";
39 
40  // Axis System
42 
43  // Cube Sample
44  CubeMesh = sampleWriter::CreateMeshCube();
45 
46  // Cylinder Sample
47  CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
48 
49  // Wire Sample
50  WireMesh = sampleWriter::CreateMeshWire();
51 
52  // PART5 : CREATING HIERARCHY
53 
54  // CREATE ROOT ASM NODE
55  mesh_asm = new Dtk_mesh_asm_node();
56 
57  mesh_asm->set_id( 0 ); // id of node
58  Dtk_transfo * transfo1 = new Dtk_transfo(); // transformation matrix
59  //apply scale
60  transfo1->setXdir( Dtk_dir( 0.8, 0.0, 0.0 ) );
61  transfo1->setYdir( Dtk_dir( 0.0, 0.8, 0.0 ) );
62  transfo1->setZdir( Dtk_dir( 0.0, 0.0, 0.8 ) );
63  transfo1->setOrigin( Dtk_pnt( 0.0, 0.0, 0.8 ) );
64  transfo1->setScale( 1.0 );
65 
66  // CREATE ASM 1
67  mesh_asm_1 = new Dtk_mesh_asm_node(); //create new node
68  mesh_asm_1->set_id( 1 ); // id of node
69  mesh_asm->add_asm_instance( mesh_asm_1, transfo1 ); // add mesh_asm_1 node in mesh_asm
70 
71  //WRITE AXIS SYSTEM
72  mesh_asm->add_axis_system(TmpAxis); // add axis system in mesh_asm
73 
74  //WRITE CUBE MESH
75  mesh_asm->add_mesh( CubeMesh );
76 
77  //WRITE CUBE MESH
78  mesh_asm_2 = new Dtk_mesh_asm_node(); //create new node
79  mesh_asm_2->set_id( 2 ); // id of node
80  Dtk_transfo * transfo2 = new Dtk_transfo();
81  transfo2->setOrigin( Dtk_pnt( -4, -4, -4 ) );
82  mesh_asm->add_asm_instance( mesh_asm_2, transfo2 ); // add mesh_asm_2 node in mesh_asm
83  mesh_asm_2->add_mesh( CubeMesh ); // add mesh in instance mesh_asm_2
84 
85  //WRITE WIRE MESH
86  mesh_asm_3 = new Dtk_mesh_asm_node(); //create new node
87  mesh_asm_3->set_id( 3 ); // id of node
88  mesh_asm_2->add_asm_instance( mesh_asm_3, transfo2 ); // add mesh_asm_3 node in mesh_asm_2
89  mesh_asm_3->add_mesh( WireMesh ); // add wireframe in instance mesh_asm_3
90 
91  //WRITE CYLINDER MESH
92  mesh_asm_4 = new Dtk_mesh_asm_node(); //create new node
93  mesh_asm_4->set_id( 4 ); // id of node
94  Dtk_transfo * transfo3 = new Dtk_transfo();
95  transfo3->setOrigin( Dtk_pnt( -6., -7., -6. ) );
96  mesh_asm_1->add_asm_instance( mesh_asm_4, transfo3 ); // add mesh_asm_4 node in mesh_asm_1
97  Dtk_RGB rgb = Dtk_RGB( 0, 0, 255 );
98  mesh_asm_4->set_color( rgb ); // set color in instance mesh_asm_2
99  mesh_asm_4->add_mesh( CylinderMesh ); // add mesh in instance mesh_asm_4
100 
101 
102  WriteOptions options;
103 
104  //initialize writing
105  options.SetFileRelease( 14 );
106 
107  //CGR write start here
108  // First we initialize writing with name of files and protection fonction if needed (3rd parameter)
109  status = cgrw_InitWrite( outputFileName, outputDirectory + L"testcgrw.log", NULL, L"", options );
110  if( status != 0 )
111  {
112  cgrw_EndWrite();
113  delete mesh_asm;
114  cout << "error : " << dtkTypeError( status ).c_str() << endl;
115  return status;
116  }
117  // Then we write for the mesh assembly constructed
118  cgrw_WriteMeshAsm( mesh_asm );
119 
120  // And free memory allocated for writing
121  cgrw_EndWrite();
122 
123  cout << "=> " << outputFileName.c_str() << endl << "Cgr Write end" << endl;
124 
125  delete mesh_asm;
126 
127  return 0;
128 }
Dtk_mesh_asm_node
This class gathers asm node related datas.
Definition: util_cgr_dtk.hpp:178
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
sampleWriter::CreateMeshCube
Dtk_MeshPtr CreateMeshCube()
Mesh Cube sample.
Definition: testcreatemesh.cpp:207
Dtk_transfo::setOrigin
void setOrigin(const Dtk_pnt &O)
Set a new O center point.
Dtk_mesh_asm_node::set_id
void set_id(int inId)
Set an Id.
Dtk_transfo::setZdir
void setZdir(const Dtk_dir &Z)
Set a new Z vector.
Dtk_mesh_asm_node::add_axis_system
int add_axis_system(Dtk_AxisSystemPtr inAxisSystem)
Add an Dtk_AxisSystemPtr in Dtk_mesh_asm_node in the current asm node.
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
sampleWriter::CreateAxisSystem
Dtk_AxisSystemPtr CreateAxisSystem()
Definition: testcreatecube.cpp:1465
Dtk_mesh_asm_node::set_color
void set_color(Dtk_RGB &inColor)
set color on Dtk_mesh_asm_node
Dtk_transfo::setXdir
void setXdir(const Dtk_dir &X)
Set a new X vector.
cgrw_EndWrite
int cgrw_EndWrite()
Free the Cgr Writer
sampleWriter::CreateMeshWire
Dtk_MeshPtr CreateMeshWire()
Wire mesh sample.
Definition: testcreatemesh.cpp:388
cgrw_WriteMeshAsm
Dtk_status cgrw_WriteMeshAsm(Dtk_mesh_asm_node *inRoot)
Write a mesh assembly.
cgrw_InitWrite
int cgrw_InitWrite(Dtk_string inFileWritten, Dtk_string inLogFile, Licence_dtk inLicFct, Dtk_string inLicenceFile, const WriteOptions &inOptions=WriteOptions())
Initialize the Cgr Writer
Dtk_transfo::setScale
void setScale(Dtk_Double64 scale)
Set a new scale.
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.
sampleWriter::CreateMeshCylinder
Dtk_MeshPtr CreateMeshCylinder(int nbpoints)
Mesh Cylinder sample.
Definition: testcreatemesh.cpp:337
Dtk_mesh_asm_node::add_mesh
int add_mesh(Dtk_MeshPtr mesh)
Add an Dtk_mesh in Dtk_mesh_asm_node in the current asm node.
Dtk_transfo::setYdir
void setYdir(const Dtk_dir &Y)
Set a new Y vector.
Dtk_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:22
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
WriteOptions
This class provides several options to tunes cgr Writter. It must be provided to cgr::cgrw_InitWrite ...
Definition: cgrw.hpp:18
Dtk_RGB
Definition: dtk_rgb.hpp:7
WriteOptions::SetFileRelease
void SetFileRelease(const Dtk_UInt32 inRelease)
Sets the release for the written files.
Definition: cgrw.hpp:31
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15
Dtk_mesh_asm_node::add_asm_instance
int add_asm_instance(Dtk_mesh_asm_node *inMeshAsm, Dtk_transfo *inTransfo)
Add an asm instance to the current asm node.