DATAKIT API  V2025.1
CGR Write Sample
//start_of_maincgrmeshwrite
int
CgrWriteSample( const Dtk_string &inResultDirectory )
{
int status;
Dtk_MeshPtr CubeMesh;
Dtk_MeshPtr CylinderMesh;
Dtk_MeshPtr WireMesh;
Dtk_mesh_asm_node * mesh_asm = NULL;
Dtk_mesh_asm_node * mesh_asm_1 = NULL;
Dtk_mesh_asm_node * mesh_asm_2 = NULL;
Dtk_mesh_asm_node * mesh_asm_3 = NULL;
Dtk_mesh_asm_node * mesh_asm_4 = NULL;
Dtk_string outputFileName, outputDirectory;
cout << endl << "----------------------------------------------" << endl;
cout << "Cgr Write start" << endl;
// Choosing output directory and file name
outputDirectory = inResultDirectory + L"dtk/Cgr/";
outputDirectory.FixPathSeparator();
outputDirectory.mkdir();
outputFileName = outputDirectory + L"sample.cgr";
// Axis System
// Cube Sample
// Cylinder Sample
CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
// Wire Sample
// PART5 : CREATING HIERARCHY
// CREATE ROOT ASM NODE
mesh_asm = new Dtk_mesh_asm_node();
mesh_asm->set_id( 0 ); // id of node
Dtk_transfo * transfo1 = new Dtk_transfo(); // transformation matrix
//apply scale
transfo1->setXdir( Dtk_dir( 0.8, 0.0, 0.0 ) );
transfo1->setYdir( Dtk_dir( 0.0, 0.8, 0.0 ) );
transfo1->setZdir( Dtk_dir( 0.0, 0.0, 0.8 ) );
transfo1->setOrigin( Dtk_pnt( 0.0, 0.0, 0.8 ) );
transfo1->setScale( 1.0 );
// CREATE ASM 1
mesh_asm_1 = new Dtk_mesh_asm_node(); //create new node
mesh_asm_1->set_id( 1 ); // id of node
mesh_asm->add_asm_instance( mesh_asm_1, transfo1 ); // add mesh_asm_1 node in mesh_asm
//WRITE AXIS SYSTEM
mesh_asm->add_axis_system(TmpAxis); // add axis system in mesh_asm
//WRITE CUBE MESH
mesh_asm->add_mesh( CubeMesh );
//WRITE CUBE MESH
mesh_asm_2 = new Dtk_mesh_asm_node(); //create new node
mesh_asm_2->set_id( 2 ); // id of node
Dtk_transfo * transfo2 = new Dtk_transfo();
transfo2->setOrigin( Dtk_pnt( -4, -4, -4 ) );
mesh_asm->add_asm_instance( mesh_asm_2, transfo2 ); // add mesh_asm_2 node in mesh_asm
mesh_asm_2->add_mesh( CubeMesh ); // add mesh in instance mesh_asm_2
//WRITE WIRE MESH
mesh_asm_3 = new Dtk_mesh_asm_node(); //create new node
mesh_asm_3->set_id( 3 ); // id of node
mesh_asm_2->add_asm_instance( mesh_asm_3, transfo2 ); // add mesh_asm_3 node in mesh_asm_2
mesh_asm_3->add_mesh( WireMesh ); // add wireframe in instance mesh_asm_3
//WRITE CYLINDER MESH
mesh_asm_4 = new Dtk_mesh_asm_node(); //create new node
mesh_asm_4->set_id( 4 ); // id of node
Dtk_transfo * transfo3 = new Dtk_transfo();
transfo3->setOrigin( Dtk_pnt( -6., -7., -6. ) );
mesh_asm_1->add_asm_instance( mesh_asm_4, transfo3 ); // add mesh_asm_4 node in mesh_asm_1
Dtk_RGB rgb = Dtk_RGB( 0, 0, 255 );
mesh_asm_4->set_color( rgb ); // set color in instance mesh_asm_2
mesh_asm_4->add_mesh( CylinderMesh ); // add mesh in instance mesh_asm_4
WriteOptions options;
//initialize writing
options.SetFileRelease( 14 );
//CGR write start here
// First we initialize writing with name of files and protection fonction if needed (3rd parameter)
status = cgrw_InitWrite( outputFileName, outputDirectory + L"testcgrw.log", NULL, L"", options );
if( status != 0 )
{
delete mesh_asm;
cout << "error : " << dtkTypeError( status ).c_str() << endl;
return status;
}
// Then we write for the mesh assembly constructed
cgrw_WriteMeshAsm( mesh_asm );
// And free memory allocated for writing
cout << "=> " << outputFileName.c_str() << endl << "Cgr Write end" << endl;
delete mesh_asm;
return 0;
}
//end_of_maincgrmeshwrite
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
CgrWriteSample
int CgrWriteSample(const Dtk_string &inResultDirectory)
Definition: testlibcgrwrite.cpp:17
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.