Commit 446b8725 authored by Jan's avatar Jan
Browse files

Support PolyMesh as well

parent 34bf0964
include (plugin)
openflipper_plugin (DIRS Snappy
TYPES SPLATCLOUD TRIANGLEMESH )
TYPES SPLATCLOUD TRIANGLEMESH POLYMESH )
......@@ -73,6 +73,7 @@ static const int COLORRANGE_0_1 = 0;
//== IMPLEMENTATION ==============================================
FilePTSPlugin::FilePTSPlugin() :
loadOptions_( 0 ),
saveOptions_( 0 ),
......@@ -597,9 +598,9 @@ bool FilePTSPlugin::readTextFile( const char *_filename, SplatCloud &_splatCloud
return true;
}
bool FilePTSPlugin::readTextFile ( const char *_filename, TriMesh &_mesh ) {
bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor ) {
// clear Mesh
_mesh.clear();
_adaptor.clear();
// set default options
bool pointCount = OpenFlipperSettings().value( "FilePTS/Load/PointCount", true ).toBool();
......@@ -621,8 +622,8 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, TriMesh &_mesh ) {
}
// request properties
if( loadNormals ) { _mesh.request_vertex_normals(); }
if( loadColors ) { _mesh.request_vertex_colors(); }
if( loadNormals ) { _adaptor.request_vertex_normals(); }
if( loadColors ) { _adaptor.request_vertex_colors(); }
QFile f(_filename);
......@@ -641,7 +642,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, TriMesh &_mesh ) {
const int size = line.toInt(&ok);
if ( ok ) {
emit log( LOGINFO, tr("Point count in header: \"%1\"").arg( size ) );
_mesh.reserve(size,0,0);
_adaptor.reserve(size);
} else {
emit log( LOGERR, tr("Failed to read point count header. Got \"%1\"").arg( line ) );
return false;
......@@ -660,7 +661,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, TriMesh &_mesh ) {
double pos[3];
in >> pos[0] >> pos[1] >> pos[2];
if ( in.status() == QTextStream::Ok ) {
_mesh.add_vertex( TriMesh::Point(pos) );
_adaptor.add_point( TriMesh::Point(pos) );
} else {
emit log( LOGERR, tr("Failed to read postion for point %1\n").arg( currentPoint ) );
break;
......@@ -691,7 +692,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, TriMesh &_mesh ) {
color[2] = (unsigned char) col[2];
}
_mesh.set_color( _mesh.vertex_handle(_mesh.n_vertices()-1),color );
_adaptor.setColor(color);
} else {
emit log( LOGERR, tr("Failed to read color for point %1\n").arg( currentPoint ) );
......@@ -711,7 +712,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, TriMesh &_mesh ) {
normal[1] = nrm[1];
normal[2] = nrm[2];
_mesh.set_normal( _mesh.vertex_handle(_mesh.n_vertices()-1),normal);
_adaptor.setNormal(normal);
} else {
emit log( LOGERR, tr("Failed to read normal for point %1\n").arg( currentPoint ) );
break;
......@@ -1069,12 +1070,15 @@ int FilePTSPlugin::loadObject( QString _filename )
// set default options
bool loadBinaryFile = OpenFlipperSettings().value( "FilePTS/Load/BinaryFile", false ).toBool();
enum dataType{ splatcloud,
trianglemesh } loadType = splatcloud;
trianglemesh,
polymesh } loadType = splatcloud;
// get options
if( OpenFlipper::Options::gui() && loadOptions_ )
{
if (loadType_->currentText() == "TriangleMesh") {
loadType = trianglemesh;
} else if (loadType_->currentText() == "PolyMesh") {
loadType = polymesh;
} else {
loadType = splatcloud;
}
......@@ -1157,7 +1161,7 @@ int FilePTSPlugin::loadObject( QString _filename )
for( i=0; i<num; ++i )
emit deleteObject( objectIDs[ i ] );
}
} else {
} else if ( loadType == trianglemesh ) {
// add a new, empty splatcloud-object
int triangleMeshID = -1;
......@@ -1179,7 +1183,9 @@ int FilePTSPlugin::loadObject( QString _filename )
if ( loadBinaryFile ) {
emit log(LOGERR,"Binary not supported for mesh target!");
} else {
readTextFile( _filename.toLatin1(), *mesh ) ;
AdaptorMesh<TriMesh> adaptor(*mesh);
readTextFile( _filename.toLatin1(), adaptor ) ;
// emit signals that the object has to be updated and that a file was opened
emit updatedObject( triangleMeshID, UPDATE_ALL );
......@@ -1193,6 +1199,44 @@ int FilePTSPlugin::loadObject( QString _filename )
}
}
}
} else { // PolyMesh
// add a new, empty splatcloud-object
int polyMeshID = -1;
emit addEmptyObject( DATA_POLY_MESH, polyMeshID );
if( polyMeshID != -1 ) {
// get splatcloud-object by id
PolyMeshObject *triObject = 0;
if( PluginFunctions::getObject( polyMeshID, triObject ) )
{
// set name of splatcloud-object to filename
triObject->setFromFileName( _filename );
triObject->setName( triObject->filename() );
// get splatcloud and scenegraph splatcloud-node
PolyMesh *mesh = triObject->mesh();
if( mesh != 0 ) {
if ( loadBinaryFile ) {
emit log(LOGERR,"Binary not supported for mesh target!");
} else {
AdaptorMesh<PolyMesh> adaptor(*mesh);
readTextFile( _filename.toLatin1(), adaptor ) ;
// emit signals that the object has to be updated and that a file was opened
emit updatedObject( polyMeshID, UPDATE_ALL );
emit openedFile( polyMeshID );
ACG::SceneGraph::DrawModes::DrawMode pointsDrawMode = ACG::SceneGraph::DrawModes::getDrawMode( "Points" );
triObject->meshNode()->drawMode(pointsDrawMode);
return polyMeshID;
}
}
}
}
}
// return failure
......@@ -1252,6 +1296,7 @@ QWidget *FilePTSPlugin::loadOptionsWidget( QString /*_currentFilter*/ )
loadType_ = new QComboBox();
loadType_->addItem(tr("SplatCloud"));
loadType_->addItem(tr("TriangleMesh"));
loadType_->addItem(tr("PolyMesh"));
loadBinaryFile_ = new QCheckBox( tr("Load as Binary File") );
......
......@@ -72,6 +72,7 @@
#include <ObjectTypes/SplatCloud/SplatCloud.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <QComboBox>
#include <QCheckBox>
......@@ -83,6 +84,71 @@
//== CLASS DEFINITION ============================================
class AdaptorBase {
public:
virtual void clear() = 0;
virtual void add_point(ACG::Vec3d _point) = 0;
virtual void setNormal(ACG::Vec3d _normal) = 0;
virtual void setColor(ACG::Vec4f _color) = 0;
virtual void setPointSize(double _size ) = 0;
virtual void setIndex(int _size ) = 0;
virtual void request_vertex_normals() = 0;
virtual void request_vertex_colors() = 0;
virtual void reserve(int _size) = 0;
};
template <typename MeshT>
class AdaptorMesh : public AdaptorBase {
public:
AdaptorMesh(MeshT& _mesh) : mesh_(_mesh),currentPoint_(0) {}
void clear() override {
mesh_.clear();
};
void add_point(ACG::Vec3d _point) override {
currentPoint_ = mesh_.add_vertex(_point);
};
void setNormal(ACG::Vec3d _normal) override{
mesh_.set_normal( currentPoint_,_normal );
};
void setColor(ACG::Vec4f _color) override{
mesh_.set_color( currentPoint_,_color );
};
void setPointSize(double /*_size*/ ) override {
};
void setIndex(int /*_size*/ ) override {
};
void request_vertex_normals(){
mesh_.request_vertex_normals();
}
void request_vertex_colors() {
mesh_.request_vertex_colors();
}
void reserve(int _size) {
mesh_.reserve(_size,0,0);
};
private :
MeshT& mesh_;
typename MeshT::VertexHandle currentPoint_;
};
class FilePTSPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface, LoggingInterface, ScriptInterface, RPCInterface, AboutInfoInterface
{
......@@ -154,7 +220,7 @@ private:
bool readBinaryFile( const char *_filename, SplatCloud &_splatCloud ) /*const*/;
bool readTextFile ( const char *_filename, SplatCloud &_splatCloud ) /*const*/;
bool readTextFile ( const char *_filename, TriMesh &_mesh );
bool readTextFile ( const char *_filename, AdaptorBase& _adaptor );
// write binary/text file from scenegraph node to disc
bool writeBinaryFile( const char *_filename, const SplatCloudNode *_splatCloudNode ) /*const*/;
......
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