DATAKIT SDK  V2026.4
testlibcgrwrite.cpp File Reference

Functions

DtkErrorStatus CgrWriteSample (const Dtk_string &inResultDirectory)
 Entry point: builds an assembly tree with cube, cylinder, and wire meshes and writes it to sample.cgr. More...
 

Function Documentation

◆ CgrWriteSample()

DtkErrorStatus CgrWriteSample ( const Dtk_string &  inResultDirectory)

Entry point: builds an assembly tree with cube, cylinder, and wire meshes and writes it to sample.cgr.

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