DATAKIT SDK  V2026.4
testlib3mfwrite.cpp File Reference

Functions

DtkErrorStatus _3mfWriteSample (const Dtk_string &inResultDirectory)
 Entry point: writes a cube and a cylinder mesh into a sample.3mf file. More...
 

Function Documentation

◆ _3mfWriteSample()

DtkErrorStatus _3mfWriteSample ( const Dtk_string &  inResultDirectory)

Entry point: writes a cube and a cylinder mesh into a sample.3mf file.

15 {
16  Dtk_ErrorStatus errorStatus = dtkNoError;
17  Dtk_MeshPtr cubeMesh = NULL;
18  Dtk_MeshPtr cylinderMesh = NULL;
19  Dtk_string outputFileName, outputDirectory;
20 
21  std::cout << std::endl << "----------------------------------------------" << std::endl;
22  std::cout << "3mf Write start" << std::endl;
23 
24  // Choosing output directory and file name
25  outputDirectory = inResultDirectory + L"3mf/";
26  outputDirectory.FixPathSeparator();
27  outputDirectory.mkdir();
28  outputFileName = outputDirectory + L"sample.3mf";
29 
30  // Cube Sample
31  cubeMesh = sampleWriter::CreateMeshCube();
33 
34  // Cylinder Sample
35  cylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
36 
37  // First we initialize writing
39  Dtk_3MFWriter *_3mfw = new Dtk_3MFWriter();
40  errorStatus = _3mfw->InitWrite( outputFileName, Dtk_string( "test3mfw.log" ), options );
41 
42  if( errorStatus != dtkNoError )
43  std::cout << "error : " << dtkTypeError( errorStatus ).c_str() << std::endl;
44 
45 
46  // Lets write a small part composed by one cube and one cylinder
47 
48  // Let write the cube
49  cubeMesh->info() = Dtk_Info::Create();
50  cubeMesh->info()->SetName( "Cube" );
51 
52  if( errorStatus == dtkNoError )
53  errorStatus = _3mfw->WriteEntity( Dtk_EntityPtr::DtkDynamicCast( cubeMesh ) );
54 
55  // Let write the cylinder
56  cylinderMesh->info() = Dtk_Info::Create();
57  cylinderMesh->info()->SetName( "Cylinder" );
58 
59  if( errorStatus == dtkNoError )
60  errorStatus = _3mfw->WriteEntity( Dtk_EntityPtr::DtkDynamicCast( cylinderMesh ) );
61 
62  // We finish process and free memory allocated for writing
63  _3mfw->EndWrite();
64  if( errorStatus == dtkNoError )
65  std::cout << "=> " << outputFileName.c_str() << std::endl << "3mf Write end" << std::endl;
66  delete _3mfw;
67  return errorStatus;
68 }
Dtk_Info::Create
static Dtk_SmartPtr< Dtk_Info > Create()
Calls default constructor to allocate a new object.
sampleWriter::CreateMeshCube
Dtk_MeshPtr CreateMeshCube()
Mesh Cube sample.
Definition: testcreatemesh.cpp:207
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
sampleWriter::FillFacesColors
void FillFacesColors(Dtk_MeshPtr &inoutCubeMesh)
Filling mesh faces with colors.
Definition: testcreatemesh.cpp:244
Dtk_3MFWriter::InitWrite
DtkErrorStatus InitWrite(const Dtk_string &inOutputFile, const Dtk_string &inLogFile, const WriteOptions &inOptions)
Initialize the 3mf Writer
Dtk_3MFWriter::WriteOptions
This class provides several options to tune 3mf Writer. It must be provided to _3mfw::InitWrite metho...
Definition: 3mfw.hpp:29
Dtk_SmartPtr< Dtk_Entity >::DtkDynamicCast
static Dtk_SmartPtr< Dtk_Entity > DtkDynamicCast(const Dtk_SmartPtr< T2 > &p)
Definition: util_ptr_dtk.hpp:101
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_3MFWriter::WriteEntity
Dtk_ErrorStatus WriteEntity(const Dtk_EntityPtr &inEntity)
Write the entity provided in parameter in a node.
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_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
Dtk_3MFWriter
3MF Writer main class.
Definition: 3mfw.hpp:16
Dtk_3MFWriter::EndWrite
DtkErrorStatus EndWrite()
Creation of the output file and free the Obj Writer
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:151