DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Static Public Member Functions
DGtal::MeshWriter< TPoint > Struct Template Reference

#include <MeshWriter.h>

Static Public Member Functions

static bool export2OFF (std::ostream &out, const MeshFromPoints< TPoint > &aMesh, bool exportColor=false) throw (DGtal::IOException)
static bool export2OBJ (std::ostream &out, const MeshFromPoints< TPoint > &aMesh) throw (DGtal::IOException)

Detailed Description

template<typename TPoint>
struct DGtal::MeshWriter< TPoint >

Aim: Export a Mesh (MeshFromPoints object) in different format as OFF and OBJ).

Description of template struct 'MeshWriter'

The exportation can be done automatically according the input file extension with the ">>" operator

Example of typical use: First you have to add the following include files:

Then you create a simple MeshFromPoints object:

Finally you can export directly the MeshFromPoints object:

See also:
MeshFromPoints MeshWriter

Definition at line 77 of file MeshWriter.h.


Member Function Documentation

template<typename TPoint >
bool MeshWriter::export2OBJ ( std::ostream &  out,
const MeshFromPoints< TPoint > &  aMesh 
) throw (DGtal::IOException)
inlinestatic

Export a MeshFromPoints towards a OBJ format.

Parameters:
out,:the output stream of the exported OBJ object.
aMesh,:the MeshFromPoints object to be exported.
Returns:
true if no errors occur.

Definition at line 93 of file MeshWriter.ih.

References DGtal::Trace::error(), and DGtal::trace.

Referenced by DGtal::operator>>().

{
try
{
out << "# OBJ format"<< endl;
out << "# generated from MeshWriter from the DGTal library"<< endl;
out << endl;
out << "o anObj" << endl;
out << endl;
// processing vertex
for(unsigned int i=0; i< aMesh.nbVertex(); i++){
out << "v " << aMesh.getVertex(i)[0] << " " << aMesh.getVertex(i)[1] << " "<< aMesh.getVertex(i)[2] << endl;
}
out << endl;
// processing faces:
for (unsigned int i=0; i< aMesh.nbFaces(); i++){
vector<unsigned int> aFace = aMesh.getFace(i);
out << "f " ;
for(unsigned int j=0; j<aFace.size(); j++){
unsigned int indexVertex = aFace.at(j);
out << (indexVertex+1) << " " ;
}
out << endl;
}
out << endl;
}catch( ... )
{
trace.error() << "OBJ writer IO error on export " << endl;
throw dgtalio;
}
return true;
}
template<typename TPoint >
bool MeshWriter::export2OFF ( std::ostream &  out,
const MeshFromPoints< TPoint > &  aMesh,
bool  exportColor = false 
) throw (DGtal::IOException)
inlinestatic

Export MeshFromPoints towards a OFF format.

Parameters:
out,:the output stream of the exported OFF object.
aMeshthe MeshFromPoints object to be exported.
exportColortrue to export colors (default false).
Returns:
true if no errors occur.

Definition at line 47 of file MeshWriter.ih.

References DGtal::Color::alpha(), DGtal::Color::blue(), DGtal::Trace::error(), DGtal::Color::green(), DGtal::Color::red(), and DGtal::trace.

Referenced by DGtal::operator>>().

{
try
{
out << "OFF"<< endl;
out << "# generated from MeshWriter from the DGTal library"<< endl;
out << aMesh.nbVertex() << " " << aMesh.nbFaces() << " " << 0 << " " << endl;
for(unsigned int i=0; i< aMesh.nbVertex(); i++){
out << aMesh.getVertex(i)[0] << " " << aMesh.getVertex(i)[1] << " "<< aMesh.getVertex(i)[2] << endl;
}
for (unsigned int i=0; i< aMesh.nbFaces(); i++){
vector<unsigned int> aFace = aMesh.getFace(i);
out << aFace.size() << " " ;
for(unsigned int j=0; j<aFace.size(); j++){
unsigned int indexVertex = aFace.at(j);
out << indexVertex << " " ;
}
DGtal::Color col = aMesh.getFaceColor(i);
if(exportColor){
out << " ";
out << ((double) col.red())/255.0 << " "
<< ((double) col.green())/255.0 << " "<< ((double) col.blue())/255.0
<< " " << ((double) col.alpha())/255.0 ;
}
out << endl;
}
}catch( ... )
{
trace.error() << "OFF writer IO error on export " << endl;
throw dgtalio;
}
return true;
}

The documentation for this struct was generated from the following files: