DATAKIT API  V2025.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)
80 {
81  cout << endl << "----------------------------------------------" << endl;
82  cout << "Obj Write start" << endl;
83  //Standard Obj Sample File Processing
84  int err = StandardObjSample( inResultDirectory );
85  cout << "Obj Write end" << endl;
86  return err;
87 }

◆ StandardObjSample()

int StandardObjSample ( const Dtk_string inResultDirectory)
18 {
20  int status;
21  Dtk_MeshPtr cubeMesh = NULL;
22  Dtk_MeshPtr texturedMesh = NULL;
23  Dtk_string outputFileName, outputDirectory;
24  Dtk_transfo transfo;
25  Dtk_dir dir( 5, 0, 0 );
26  transfo.addTranslate( dir );
27 
28  // Choosing output directory and file name
29  outputDirectory = inResultDirectory + L"dtk/Obj/";
30  outputDirectory.FixPathSeparator();
31  outputDirectory.mkdir();
32  outputFileName = outputDirectory + L"sample.obj";
33 
34  // Cube Sample
35  cubeMesh = sampleWriter::CreateMeshCube();
37 
38  // Cylinder Sample
39  texturedMesh = sampleWriter::CreateTexturedMeshCube( inResultDirectory + L"../InputImages/" );
40 
41  // First we initialize writing
42  Objw::WriteOptions options;
43  options.m_UseRender = DTK_TRUE;
44  status = Objw::InitWrite( outputFileName, Dtk_string( "testobjw.log" ), options );
45 
46  if( status != 0 )
47  {
49  cout << "error : " << dtkTypeError( status ).c_str() << endl;
50  return status;
51  }
52 
53  // Lets write a small part composed by one textured cube and one cube with colors
54 
55  // Let's name the textured cube
56  texturedMesh->info()->SetName( "TexturedCube" );
57 
58  // Let's write the textured cube
59  if( err == dtkNoError )
60  err = Objw::WriteEntity( Dtk_EntityPtr::DtkDynamicCast( texturedMesh ) );
61 
62  // Let's name the colored cube
63  cubeMesh->info()->SetName( "Cube" );
64  // We translate it before writing
65  cubeMesh->Transform( transfo );
66  // And finally write it
67  if( err == dtkNoError )
69 
70  // We finish process and free memory allocated for writing
71  if( err == dtkNoError )
72  err = Objw::EndWrite();
73 
74  cout << "=> " << outputFileName.c_str() << endl;
75 
76  return err;
77 }
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
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:727
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
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:244
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:272
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:17
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15