DATAKIT SDK  V2026.1
testlibcgrwrite.cpp File Reference

Functions

int CgrWriteSample (const Dtk_string &inResultDirectory)
 

Function Documentation

◆ CgrWriteSample()

int CgrWriteSample ( const Dtk_string inResultDirectory)
13 {
14  int status;
15  Dtk_MeshPtr CubeMesh;
16  Dtk_MeshPtr CylinderMesh;
17  Dtk_MeshPtr WireMesh;
18  Dtk_AxisSystemPtr TmpAxis;
19  Dtk_mesh_asm_node * mesh_asm = NULL;
20  Dtk_mesh_asm_node * mesh_asm_1 = NULL;
21  Dtk_mesh_asm_node * mesh_asm_2 = NULL;
22  Dtk_mesh_asm_node * mesh_asm_3 = NULL;
23  Dtk_mesh_asm_node * mesh_asm_4 = NULL;
24  Dtk_string outputFileName, outputDirectory;
25 
26  cout << endl << "----------------------------------------------" << endl;
27  cout << "Cgr Write start" << endl;
28 
29  // Choosing output directory and file name
30  outputDirectory = inResultDirectory + L"Cgr/";
31  outputDirectory.FixPathSeparator();
32  outputDirectory.mkdir();
33  outputFileName = outputDirectory + L"sample.cgr";
34 
35  // Axis System
37 
38  // Cube Sample
39  CubeMesh = sampleWriter::CreateMeshCube();
40 
41  // Cylinder Sample
42  CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
43 
44  // Wire Sample
45  WireMesh = sampleWriter::CreateMeshWire();
46 
47  // PART5 : CREATING HIERARCHY
48 
49  // CREATE ROOT ASM NODE
50  mesh_asm = new Dtk_mesh_asm_node();
51 
52  mesh_asm->set_id( 0 ); // id of node
53  Dtk_transfo * transfo1 = new Dtk_transfo(); // transformation matrix
54  //apply scale
55  transfo1->setXdir( Dtk_dir( 0.8, 0.0, 0.0 ) );
56  transfo1->setYdir( Dtk_dir( 0.0, 0.8, 0.0 ) );
57  transfo1->setZdir( Dtk_dir( 0.0, 0.0, 0.8 ) );
58  transfo1->setOrigin( Dtk_pnt( 0.0, 0.0, 0.8 ) );
59  transfo1->setScale( 1.0 );
60 
61  // CREATE ASM 1
62  mesh_asm_1 = new Dtk_mesh_asm_node(); //create new node
63  mesh_asm_1->set_id( 1 ); // id of node
64  mesh_asm->add_asm_instance( mesh_asm_1, transfo1 ); // add mesh_asm_1 node in mesh_asm
65 
66  //WRITE AXIS SYSTEM
67  mesh_asm->add_axis_system(TmpAxis); // add axis system in mesh_asm
68 
69  //WRITE CUBE MESH
70  mesh_asm->add_mesh( CubeMesh );
71 
72  //WRITE CUBE MESH
73  mesh_asm_2 = new Dtk_mesh_asm_node(); //create new node
74  mesh_asm_2->set_id( 2 ); // id of node
75  Dtk_transfo * transfo2 = new Dtk_transfo();
76  transfo2->setOrigin( Dtk_pnt( -4, -4, -4 ) );
77  mesh_asm->add_asm_instance( mesh_asm_2, transfo2 ); // add mesh_asm_2 node in mesh_asm
78  mesh_asm_2->add_mesh( CubeMesh ); // add mesh in instance mesh_asm_2
79 
80  //WRITE WIRE MESH
81  mesh_asm_3 = new Dtk_mesh_asm_node(); //create new node
82  mesh_asm_3->set_id( 3 ); // id of node
83  mesh_asm_2->add_asm_instance( mesh_asm_3, transfo2 ); // add mesh_asm_3 node in mesh_asm_2
84  mesh_asm_3->add_mesh( WireMesh ); // add wireframe in instance mesh_asm_3
85 
86  //WRITE CYLINDER MESH
87  mesh_asm_4 = new Dtk_mesh_asm_node(); //create new node
88  mesh_asm_4->set_id( 4 ); // id of node
89  Dtk_transfo * transfo3 = new Dtk_transfo();
90  transfo3->setOrigin( Dtk_pnt( -6., -7., -6. ) );
91  mesh_asm_1->add_asm_instance( mesh_asm_4, transfo3 ); // add mesh_asm_4 node in mesh_asm_1
92  Dtk_RGB rgb = Dtk_RGB( 0, 0, 255 );
93  mesh_asm_4->set_color( rgb ); // set color in instance mesh_asm_2
94  mesh_asm_4->add_mesh( CylinderMesh ); // add mesh in instance mesh_asm_4
95 
96 
97  WriteOptions options;
98 
99  //initialize writing
100  options.SetFileRelease( 14 );
101 
102  //CGR write start here
103  // First we initialize writing with name of files and protection fonction if needed (3rd parameter)
104  status = cgrw_InitWrite( outputFileName, outputDirectory + L"testcgrw.log", NULL, L"", options );
105  if( status != 0 )
106  {
107  cgrw_EndWrite();
108  delete mesh_asm;
109  cout << "error : " << dtkTypeError( status ).c_str() << endl;
110  return status;
111  }
112  // Then we write for the mesh assembly constructed
113  cgrw_WriteMeshAsm( mesh_asm );
114 
115  // And free memory allocated for writing
116  cgrw_EndWrite();
117 
118  cout << "=> " << outputFileName.c_str() << endl << "Cgr Write end" << endl;
119 
120  delete mesh_asm;
121 
122  return 0;
123 }
Dtk_mesh_asm_node
This class gathers asm node related datas.
Definition: cgrw.hpp:21
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
sampleWriter::CreateMeshCube
Dtk_MeshPtr CreateMeshCube()
Mesh Cube sample.
Definition: testcreatemesh.cpp:204
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:53
sampleWriter::CreateAxisSystem
Dtk_AxisSystemPtr CreateAxisSystem()
Definition: testcreatecube.cpp:1525
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:385
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:334
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:20
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:82
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:95
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14
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.