Adding AC3D write support for OpenMesh base exporter (does not include materials)

parent e501a029
......@@ -20,7 +20,7 @@
*
*/
#include <ITAGeoHalfedgeMeshModel.h>
#include <ITAGeo/Halfedge/MeshModel.h>
#include <ITAException.h>
......@@ -33,12 +33,12 @@ using namespace ITAGeo;
int main( int argc, char** argv )
{
// Convert string from supported file formats
string s = CHalfedgeMeshModel::GetSupportedInputFormats();
string s = Halfedge::CMeshModel::GetSupportedInputFormats();
size_t idx = s.find_first_of( ";;" );
if( idx < 13 + 2 )
cerr << "Could not retrieve supported input formats from OpenMesh" << endl;
string sSupportedImportFiles = s.substr( 13, idx - 2 - 13 );
s = CHalfedgeMeshModel::GetSupportedOutputFormats();
s = Halfedge::CMeshModel::GetSupportedOutputFormats();
idx = s.find_first_of( ";;" );
if( idx < 13 + 2 )
cerr << "Could not retrieve supported input formats from OpenMesh" << endl;
......@@ -60,7 +60,7 @@ int main( int argc, char** argv )
cout << "Converting from input file '" << sModelFilePathIn << "' to '" << sModelFilePathOut << "'" << endl;
CHalfedgeMeshModel oHEModel;
Halfedge::CMeshModel oHEModel;
try
{
......
......@@ -49,7 +49,7 @@ typedef OpenMesh::PolyMesh_ArrayKernelT<> CITAMesh;
*
*/
inline bool ReadAC3DMaterialLine( std::istream& ssInStream, CITAGeoHalfedgeAC3DReader::CAC3DObject::CMaterial& oMat )
inline bool ReadAC3DMaterialLine( std::istream& ssInStream, ITAGeo::Halfedge::AC3D::CReader::CAC3DObject::CMaterial& oMat )
{
std::string sMaterialID;
ssInStream >> sMaterialID;
......@@ -101,7 +101,7 @@ inline bool ReadAC3DMaterialLine( std::istream& ssInStream, CITAGeoHalfedgeAC3DR
return true;
};
inline bool ReadAC3DObject( std::istream& ssInStream, CITAGeoHalfedgeAC3DReader::CAC3DObject& oObject )
inline bool ReadAC3DObject( std::istream& ssInStream, ITAGeo::Halfedge::AC3D::CReader::CAC3DObject& oObject )
{
std::string sNext;
......@@ -122,7 +122,7 @@ inline bool ReadAC3DObject( std::istream& ssInStream, CITAGeoHalfedgeAC3DReader:
oObject.voKids.resize( iNumKids );
for( size_t i = 0; i < oObject.voKids.size(); i++ )
{
CITAGeoHalfedgeAC3DReader::CAC3DObject& oAC3DObject( oObject.voKids[ i ] );
ITAGeo::Halfedge::AC3D::CReader::CAC3DObject& oAC3DObject( oObject.voKids[ i ] );
std::string sSecondToken;
ssInStream >> sSecondToken;
if( sSecondToken == "OBJECT" )
......@@ -160,7 +160,7 @@ inline bool ReadAC3DObject( std::istream& ssInStream, CITAGeoHalfedgeAC3DReader:
oObject.voSurfaces.resize( iTotalNumSurfaces );
for( size_t i = 0; i < oObject.voSurfaces.size(); i++ )
{
CITAGeoHalfedgeAC3DReader::CAC3DObject::CSurface& oSurf( oObject.voSurfaces[ i ] );
ITAGeo::Halfedge::AC3D::CReader::CAC3DObject::CSurface& oSurf( oObject.voSurfaces[ i ] );
std::string sSurfToken;
......@@ -199,7 +199,7 @@ inline bool ReadAC3DObject( std::istream& ssInStream, CITAGeoHalfedgeAC3DReader:
return true;
};
void ImportAC3DWorldObject( const CITAGeoHalfedgeAC3DReader::CAC3DObject& oObject, OpenMesh::IO::BaseImporter& oBaseImporter, const std::vector<CITAGeoHalfedgeAC3DReader::CAC3DObject::CMaterial>& voMaterials )
void ImportAC3DWorldObject( const ITAGeo::Halfedge::AC3D::CReader::CAC3DObject& oObject, OpenMesh::IO::BaseImporter& oBaseImporter, const std::vector<ITAGeo::Halfedge::AC3D::CReader::CAC3DObject::CMaterial>& voMaterials )
{
std::vector< OpenMesh::VertexHandle > vhVertices( oObject.v3DVertices.size() );
for( size_t i = 0; i < oObject.v3DVertices.size(); i++ )
......@@ -220,7 +220,7 @@ void ImportAC3DWorldObject( const CITAGeoHalfedgeAC3DReader::CAC3DObject& oObjec
}
OpenMesh::FaceHandle hFace = oBaseImporter.add_face( vhFaceVertices );
oBaseImporter.set_face_texindex( hFace, oObject.voSurfaces[ i ].iMaterialID );
const CITAGeoHalfedgeAC3DReader::CAC3DObject::CMaterial& oMat( voMaterials[ oObject.voSurfaces[ i ].iMaterialID ] );
const ITAGeo::Halfedge::AC3D::CReader::CAC3DObject::CMaterial& oMat( voMaterials[ oObject.voSurfaces[ i ].iMaterialID ] );
oBaseImporter.set_color( hFace, OpenMesh::Vec4f( float( oMat.dRed ), float( oMat.dGreen ), float( oMat.dBlue ), float( oMat.dTransmissive ) ) );
}
......
......@@ -28,80 +28,93 @@
// Vista includes
#include <VistaBase/VistaVector3D.h>
//! Invis AC3D generic reader class (file or stream output)
/**
* This class is globally registered as the base reader
* for OpenMesh objects from AC3D files. It can
* only handle standard mesh functionality including
* textures.
*/
class CITAGeoHalfedgeAC3DReader : public OpenMesh::IO::BaseReader
{
public:
CITAGeoHalfedgeAC3DReader();
~CITAGeoHalfedgeAC3DReader();
// STL includes
#include <string>
std::string sModelName; //!< Name from file
struct CAC3DObject
namespace ITAGeo
{
namespace Halfedge
{
struct CSurface
{
unsigned int uiType;
std::vector< int > viIndices;
int iMaterialID;
int iReferences;
inline CSurface()
{
iMaterialID = -1;
iReferences = -1;
};
};
struct CMaterial
namespace AC3D
{
double dRed, dGreen, dBlue;
double dAmbientRed, dAmbientGreen, dAmbientBlue;
double dEmissiveRed, dEmissiveGreen, dEmissiveBlue;
double dSpecularRed, dSpecularGreen, dSpecularBlue;
double dShining;
double dTransmissive;
std::string sMaterialID;
inline CMaterial()
//! Invis AC3D generic reader class (file or stream output)
/**
* This class is globally registered as the base reader
* for OpenMesh objects from AC3D files. It can
* only handle standard mesh functionality including
* textures.
*/
class CReader : public OpenMesh::IO::BaseReader
{
Reset();
public:
CReader();
~CReader();
std::string sModelName; //!< Name from file
struct CAC3DObject
{
struct CSurface
{
unsigned int uiType;
std::vector< int > viIndices;
int iMaterialID;
int iReferences;
inline CSurface()
{
iMaterialID = -1;
iReferences = -1;
};
};
struct CMaterial
{
double dRed, dGreen, dBlue;
double dAmbientRed, dAmbientGreen, dAmbientBlue;
double dEmissiveRed, dEmissiveGreen, dEmissiveBlue;
double dSpecularRed, dSpecularGreen, dSpecularBlue;
double dShining;
double dTransmissive;
std::string sMaterialID;
inline CMaterial()
{
Reset();
};
inline void Reset()
{
sMaterialID = "default";
dRed = dGreen = dBlue = 0.0f;
dAmbientRed = dAmbientGreen = dAmbientBlue = 0.0f;
dEmissiveRed = dEmissiveGreen = dEmissiveBlue = 0.0f;
dSpecularRed = dSpecularGreen = dSpecularBlue = 0.0f;
dShining = 0.0f;
dTransmissive = 0.0f;
};
};
std::string sObjectType;
std::string sName;
std::vector< CAC3DObject > voKids;
std::vector< VistaVector3D > v3DVertices;
std::vector< CSurface > voSurfaces;
};
private:
std::vector< ITAGeo::Halfedge::AC3D::CReader::CAC3DObject::CMaterial > m_voMaterial;
inline std::string get_description() const { return std::string( "AC3D reader" ); };
inline std::string get_extensions() const { return "ac"; };
bool read( const std::string& sFilePath, OpenMesh::IO::BaseImporter& oBaseImporter, OpenMesh::IO::Options& oOptions );
bool read( std::istream& ssInStream, OpenMesh::IO::BaseImporter& oBaseImporter, OpenMesh::IO::Options& oOptions );
};
inline void Reset()
{
sMaterialID = "default";
dRed = dGreen = dBlue = 0.0f;
dAmbientRed = dAmbientGreen = dAmbientBlue = 0.0f;
dEmissiveRed = dEmissiveGreen = dEmissiveBlue = 0.0f;
dSpecularRed = dSpecularGreen = dSpecularBlue = 0.0f;
dShining = 0.0f;
dTransmissive = 0.0f;
};
};
std::string sObjectType;
std::string sName;
std::vector< CAC3DObject > voKids;
std::vector< VistaVector3D > v3DVertices;
std::vector< CSurface > voSurfaces;
};
private:
std::vector< CAC3DObject::CMaterial > m_voMaterial;
inline std::string get_description() const { return std::string( "AC3D reader" ); };
inline std::string get_extensions() const { return "ac"; };
bool read( const std::string& sFilePath, OpenMesh::IO::BaseImporter& oBaseImporter, OpenMesh::IO::Options& oOptions );
bool read( std::istream& ssInStream, OpenMesh::IO::BaseImporter& oBaseImporter, OpenMesh::IO::Options& oOptions );
};
}
}
}
#endif // INCLUDE_WATCHER_ITA_GEO_HALFEDGE_AC3D_READER
/*
* ----------------------------------------------------------------
*
* ITA geometrical acoustics
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_GEO_HALFEDGE_AC3D_WRITER
#define INCLUDE_WATCHER_ITA_GEO_HALFEDGE_AC3D_WRITER
// ITABase includes
#include <ITAException.h>
// OpenMesh includes
#pragma warning( disable : 4512 4127 )
#include <OpenMesh/Core/IO/writer/BaseWriter.hh>
#pragma warning( default : 4512 4127 )
namespace ITAGeo
{
namespace Halfedge
{
namespace AC3D
{
//! AC3D generic writer class (file or stream output)
/**
* This class is globally registered as the base writer
* for AC3D files from an OpenMesh object.
*/
class CWriter : public OpenMesh::IO::BaseWriter
{
public:
CWriter();
~CWriter();
std::string sModelName; //!< Default: ITAGeoHalfedgeSketchUpGenericWriter
private:
inline std::string get_description() const { return std::string("AC3D writer"); };
inline std::string get_extensions() const { return "ac"; };
//! AC3D plain file writer
/**
* Exports to AC3D file format by iterating over
* OpenMesh faces (only).
*/
bool write(const std::string& _filename, OpenMesh::IO::BaseExporter& _be, OpenMesh::IO::Options _opt, std::streamsize _precision = 6) const;
bool write(std::ostream& _os, OpenMesh::IO::BaseExporter& _be, OpenMesh::IO::Options _opt, std::streamsize _precision = 6) const;
};
}
}
}
#endif // INCLUDE_WATCHER_ITA_GEO_HALFEDGE_AC3D_WRITER
......@@ -7,6 +7,7 @@ if( ITA_GEO_WITH_AC3D_SUPPORT )
set( DirFiles
Reader.h
Helper.h
Writer.h
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
......
......@@ -64,10 +64,8 @@ namespace ITAGeo
bool write(const std::string& _filename, OpenMesh::IO::BaseExporter& _be, OpenMesh::IO::Options _opt, std::streamsize _precision = 6) const;
bool write(std::ostream& _os, OpenMesh::IO::BaseExporter& _be, OpenMesh::IO::Options _opt, std::streamsize _precision = 6) const;
};
}
}
}
#endif // INCLUDE_WATCHER_ITA_GEO_HALFEDGE_SKETCH_UP_WRITER
......@@ -19,19 +19,21 @@
#include <fstream>
#include <vector>
using namespace ITAGeo::Halfedge::AC3D;
typedef OpenMesh::PolyMesh_ArrayKernelT<> CITAMesh;
CITAGeoHalfedgeAC3DReader::CITAGeoHalfedgeAC3DReader()
CReader::CReader()
{
OpenMesh::IO::IOManager().register_module( this );
}
CITAGeoHalfedgeAC3DReader::~CITAGeoHalfedgeAC3DReader()
CReader::~CReader()
{
}
bool CITAGeoHalfedgeAC3DReader::read( const std::string& sFilePath, OpenMesh::IO::BaseImporter& oBaseImporter, OpenMesh::IO::Options& oOptions )
bool CReader::read( const std::string& sFilePath, OpenMesh::IO::BaseImporter& oBaseImporter, OpenMesh::IO::Options& oOptions )
{
VistaFileSystemFile oFile( sFilePath );
if( oFile.Exists() == false )
......@@ -49,7 +51,7 @@ bool CITAGeoHalfedgeAC3DReader::read( const std::string& sFilePath, OpenMesh::IO
return bStreamImplRet;
}
bool CITAGeoHalfedgeAC3DReader::read( std::istream& ssInStream, OpenMesh::IO::BaseImporter& oBaseImporter, OpenMesh::IO::Options& )
bool CReader::read( std::istream& ssInStream, OpenMesh::IO::BaseImporter& oBaseImporter, OpenMesh::IO::Options& )
{
std::string sToken, sSecondToken;
......@@ -98,4 +100,4 @@ bool CITAGeoHalfedgeAC3DReader::read( std::istream& ssInStream, OpenMesh::IO::Ba
return true;
}
CITAGeoHalfedgeAC3DReader g_oAC3DReaderInstance; //!< Global reader instance
CReader g_oAC3DReaderInstance; //!< Global reader instance
#include <ITAGeo/Halfedge/AC3D/Writer.h>
// OpenMesh includes
#pragma warning( disable : 4512 4127 )
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
#include <OpenMesh/Core/IO/IOManager.hh>
#include <OpenMesh/Core/Mesh/Handles.hh>
#pragma warning( default : 4512 4127 )
// ITA includes
#include <ITAException.h>
// Vista includes
#include <VistaTools/VistaFileSystemFile.h>
// STL includes
#include <fstream>
#include <vector>
//Using namespace
using namespace ITAGeo::Halfedge::AC3D;
typedef OpenMesh::PolyMesh_ArrayKernelT<> CITAMesh;
CWriter::CWriter()
{
OpenMesh::IO::IOManager().register_module( this );
sModelName = "ITAGeoHalfedgeAC3DGenericWriter";
}
CWriter::~CWriter()
{
}
bool CWriter::write( const std::string& sFilePath, OpenMesh::IO::BaseExporter& oBaseExporter, OpenMesh::IO::Options iOptions, std::streamsize iPresition ) const
{
VistaFileSystemFile oFile( sFilePath );
if( oFile.IsDirectory() )
ITA_EXCEPT1( INVALID_PARAMETER, "File target is a directory" );
if( oFile.IsReadOnly() && oFile.Exists() )
ITA_EXCEPT1( INVALID_PARAMETER, "File target is read-only" );
auto os = std::ofstream( sFilePath.c_str() );
return CWriter::write( os, oBaseExporter, iOptions, iPresition );
}
bool CWriter::write( std::ostream& os, OpenMesh::IO::BaseExporter& oBaseExporter, OpenMesh::IO::Options, std::streamsize ) const
{
std::ostream& out( os );
out << "AC3Db" << std::endl;
out << "MATERIAL \"default\" rgb 0 0.328 0.621 amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10 trans 0.5" << std::endl;
out << "OBJECT world" << std::endl;
out << "kids " << 1 << std::endl;
out << "OBJECT poly" << std::endl;
out << "name \"polygon_object\"" << std::endl;
out << "numvert " << oBaseExporter.n_vertices() << std::endl;
for( unsigned j = 0; j < oBaseExporter.n_vertices(); j++ )
{
CITAMesh::Point pPoint = oBaseExporter.point( OpenMesh::VertexHandle( int( j ) ) );
out << pPoint[ 0 ] << " " << pPoint[ 1 ] << " " << pPoint[ 2 ] << std::endl;
}
out << "numsurf " << oBaseExporter.n_faces() << std::endl;
for( int n = 0; n < oBaseExporter.n_faces(); n++ )
{
std::vector< OpenMesh::VertexHandle > vhVertices;
OpenMesh::FaceHandle hFace = OpenMesh::FaceHandle( int( n ) );
unsigned int nFaceVertices = oBaseExporter.get_vhandles( hFace, vhVertices ); // Warning: assumes, that OpenMesh face handles are ascending (0..n-1)
assert( nFaceVertices == unsigned int( vhVertices.size() ) );
out << "SURF 0x10" << std::endl;
out << "mat 0" << std::endl; // Materials are not well supported by OpenMesh base exporter
out << "refs " << nFaceVertices << std::endl;
for( size_t j = 0; j < vhVertices.size(); j++ )
{
OpenMesh::VertexHandle hVertex( vhVertices[ j ] );
out << hVertex.idx() << " 0 0" << std::endl;
}
}
out << "kids 0" << std::endl;
return true;
}
CWriter g_oAC3DWriterInstance; //!< Global writer instance, registers skp file extension
......@@ -4,6 +4,7 @@ if( ITA_GEO_WITH_AC3D_SUPPORT )
set( DirFiles
Reader.cpp
Writer.cpp
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
......@@ -16,7 +17,3 @@ if( ITA_GEO_WITH_AC3D_SUPPORT )
source_group( ${DirFiles_SourceGroup} FILES ${LocalSourceGroupFiles} )
endif( )
#include <ITAGeo/Halfedge/SketchUp/Writer.h>
#include <ITAGeo/Halfedge/SketchUp/Writer.h>
#include <ITAGeo/SketchUp/Helper.h>
#include <ITAGeo/SketchUp/Conversions.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment