DATAKIT SDK  V2026.1
testlibobjwrite.cpp File Reference

Functions

int ObjWriteSample (const Dtk_string &inResultDirectory)
 
int StandardObjSample (const Dtk_string &inResultDirectory)
 

Function Documentation

◆ ObjWriteSample()

int ObjWriteSample ( const Dtk_string inResultDirectory)
75 {
76  cout << endl << "----------------------------------------------" << endl;
77  cout << "Obj Write start" << endl;
78  //Standard Obj Sample File Processing
79  int err = StandardObjSample( inResultDirectory );
80  cout << "Obj Write end" << endl;
81  return err;
82 }

◆ StandardObjSample()

int StandardObjSample ( const Dtk_string inResultDirectory)
13 {
15  int status;
16  Dtk_MeshPtr cubeMesh = NULL;
17  Dtk_MeshPtr texturedMesh = NULL;
18  Dtk_string outputFileName, outputDirectory;
19  Dtk_transfo transfo;
20  Dtk_dir dir( 5, 0, 0 );
21  transfo.addTranslate( dir );
22 
23  // Choosing output directory and file name
24  outputDirectory = inResultDirectory + L"Obj/";
25  outputDirectory.FixPathSeparator();
26  outputDirectory.mkdir();
27  outputFileName = outputDirectory + L"sample.obj";
28 
29  // Cube Sample
30  cubeMesh = sampleWriter::CreateMeshCube();
32 
33  // Cylinder Sample
34  texturedMesh = sampleWriter::CreateTexturedMeshCube( inResultDirectory + L"../InputImages/" );
35 
36  // First we initialize writing
37  Objw::WriteOptions options;
38  options.m_UseRender = DTK_TRUE;
39  status = Objw::InitWrite( outputFileName, Dtk_string( "testobjw.log" ), options );
40 
41  if( status != 0 )
42  {
44  cout << "error : " << dtkTypeError( status ).c_str() << endl;
45  return status;
46  }
47 
48  // Lets write a small part composed by one textured cube and one cube with colors
49 
50  // Let's name the textured cube
51  texturedMesh->info()->SetName( "TexturedCube" );
52 
53  // Let's write the textured cube
54  if( err == dtkNoError )
55  err = Objw::WriteEntity( Dtk_EntityPtr::DtkDynamicCast( texturedMesh ) );
56 
57  // Let's name the colored cube
58  cubeMesh->info()->SetName( "Cube" );
59  // We translate it before writing
60  cubeMesh->Transform( transfo );
61  // And finally write it
62  if( err == dtkNoError )
64 
65  // We finish process and free memory allocated for writing
66  if( err == dtkNoError )
67  err = Objw::EndWrite();
68 
69  cout << "=> " << outputFileName.c_str() << endl;
70 
71  return err;
72 }
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
Objw::WriteEntity
Dtk_ErrorStatus WriteEntity(const Dtk_EntityPtr &inEntity, Dtk_transfo inMat=Dtk_transfo())
Write the entity provided in parameter in a node.
DTK_TRUE
#define DTK_TRUE
Definition: define.h:730
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Objw::WriteOptions::m_UseRender
bool m_UseRender
Use of Dtk_RGB or Dtk_RenderInfos.
Definition: objw.hpp:29
sampleWriter::FillFacesColors
void FillFacesColors(Dtk_MeshPtr &inoutCubeMesh)
Filling mesh faces with colors.
Definition: testcreatemesh.cpp:241
Objw::WriteOptions
This class provides several options to tune Obj Writer. It must be provided to Objw::InitWrite method...
Definition: objw.hpp:18
sampleWriter::CreateTexturedMeshCube
Dtk_MeshPtr CreateTexturedMeshCube(const Dtk_string &inImageDirectory)
Textured Mesh Cube sample.
Definition: testcreatemesh.cpp:269
Objw::InitWrite
DtkErrorStatus InitWrite(const Dtk_string &inOutputFile, const Dtk_string &inLogFile, WriteOptions &inOptions)
Initialize the Obj Writer
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_SmartPtr
Definition: util_ptr_dtk.hpp:37
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Objw::EndWrite
DtkErrorStatus EndWrite()
Creation of the output file and free the Obj Writer
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
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_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
StandardObjSample
int StandardObjSample(const Dtk_string &inResultDirectory)
Definition: testlibobjwrite.cpp:12
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:147
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14