...
 
Commits (1)
include (plugin)
openflipper_plugin (DIRS Snappy
TYPES SPLATCLOUD)
TYPES SPLATCLOUD TRIANGLEMESH )
......@@ -57,7 +57,7 @@
#include "Snappy/snappy.h"
#include <QtWidgets>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
......@@ -77,6 +77,7 @@ static const int COLORRANGE_0_1 = 0;
FilePTSPlugin::FilePTSPlugin() :
loadOptions_( 0 ),
saveOptions_( 0 ),
loadType_(0),
loadBinaryFile_( 0 ),
loadNormals_ ( 0 ),
loadPointsizes_( 0 ),
......@@ -482,6 +483,7 @@ bool FilePTSPlugin::readTextFile( const char *_filename, SplatCloud &_splatCloud
const int read = fscanf( file, "%32f %32f %32f", &pos[0], &pos[1], &pos[2] );
if( read != 3 ) {
std::cerr << pos[0] << " " << pos[1] << " " << pos[2] << std::endl;
emit log( LOGERR, tr("Scanned for 3 coordinates but got %1 at Index %2.\n").arg( read ).arg(splatIdx) );
break;
}
......@@ -595,6 +597,156 @@ bool FilePTSPlugin::readTextFile( const char *_filename, SplatCloud &_splatCloud
return true;
}
bool FilePTSPlugin::readTextFile ( const char *_filename, TriMesh &_mesh ) {
// clear Mesh
_mesh.clear();
// set default options
bool loadNormals = OpenFlipperSettings().value( "FilePTS/Load/Normals", true ).toBool();
bool loadPointsizes = OpenFlipperSettings().value( "FilePTS/Load/Pointsizes", false ).toBool();
bool loadColors = OpenFlipperSettings().value( "FilePTS/Load/Colors", false ).toBool();
int loadColorRange = OpenFlipperSettings().value( "FilePTS/Load/ColorRange",0 ).toInt();
bool loadIndices = OpenFlipperSettings().value( "FilePTS/Load/Indices", false ).toBool();
// get options
if( OpenFlipper::Options::gui() && loadOptions_ )
{
loadNormals = loadNormals_ ->isChecked();
loadPointsizes = loadPointsizes_->isChecked();
loadColors = loadColors_ ->isChecked();
loadColorRange = loadColorRange_->currentIndex();
loadIndices = loadIndices_ ->isChecked();
}
// request properties
if( loadNormals ) { _mesh.request_vertex_normals(); }
if( loadColors ) { _mesh.request_vertex_colors(); }
// open file
FILE *file = fopen( _filename, "rb" );
if( !file )
{
emit log( LOGERR, tr("Could not open input file \"%1\".\n").arg( _filename ) );
return false;
}
int splatIdx;
for( splatIdx = 0; ; ++splatIdx )
{
// read position
{
float pos[3];
const int read = fscanf( file, "%32f %32f %32f", &pos[0], &pos[1], &pos[2] );
if( read != 3 ) {
std::cerr << pos[0] << " " << pos[1] << " " << pos[2] << std::endl;
emit log( LOGERR, tr("Scanned for 3 coordinates but got %1 at Index %2.\n").arg( read ).arg(splatIdx) );
break;
}
_mesh.add_vertex( TriMesh::Point(pos) );
}
// read color
if( loadColors )
{
float col[3];
const int read = fscanf( file, "%32f %32f %32f", &col[0], &col[1], &col[2] );
if( read != 3 ) {
emit log( LOGERR, tr("Scanned for 3 colors but got %1 at Index %2.\n").arg( read ).arg(splatIdx) );
break;
}
TriMesh::Color color(0.0,0.0,0.0,1.0);
if( loadColorRange == COLORRANGE_0_1 )
{
color[0] = (unsigned char) (255.999f * col[0]);
color[1] = (unsigned char) (255.999f * col[1]);
color[2] = (unsigned char) (255.999f * col[2]);
}
else // loadColorRange == COLORRANGE_0_255
{
color[0] = (unsigned char) col[0];
color[1] = (unsigned char) col[1];
color[2] = (unsigned char) col[2];
}
_mesh.set_color( _mesh.vertex_handle(_mesh.n_vertices()-1),color );
}
// read normal
if( loadNormals )
{
float nrm[3];
fscanf( file, "%32f %32f %32f", &nrm[0], &nrm[1], &nrm[2] );
TriMesh::Normal normal;
normal[0] = nrm[0];
normal[1] = nrm[1];
normal[2] = nrm[2];
_mesh.set_normal( _mesh.vertex_handle(_mesh.n_vertices()-1),normal);
}
// // read pointsize
// if( loadPointsizes )
// {
// float ps = 0.0f;
// fscanf( file, "%32f", &ps );
// SplatCloud::Pointsize pointsize;
// pointsize = ps;
// _splatCloud.pointsizes( splatIdx ) = pointsize;
// }
// // read index
// if( loadIndices )
// {
// int idx = -1;
// fscanf( file, "%16i", &idx );
// SplatCloud::Index index;
// index = idx;
// _splatCloud.indices( splatIdx ) = index;
// }
// check for errors
if( ferror( file ) )
{
emit log( LOGERR, tr("Could not read input file \"%1\".\n").arg( _filename ) );
fclose( file );
return false; // return failure
}
if( feof( file ) )
{
emit log( LOGERR, tr("Unexpected end in input file \"%1\".\n").arg( _filename ) );
fclose( file );
return false; // return failure
}
}
// check for errors
if( !feof( file ) ) // if end-of-file is *not* reached, something went wrong
{
emit log( LOGERR, tr("Bad file format of input file \"%1\".\n").arg( _filename ) );
fclose( file );
return false; // return failure
}
// close file
fclose( file );
// return success
return true;
}
//----------------------------------------------------------------
......@@ -898,84 +1050,127 @@ int FilePTSPlugin::loadObject( QString _filename )
{
// set default options
bool loadBinaryFile = OpenFlipperSettings().value( "FilePTS/Load/BinaryFile", false ).toBool();
enum dataType{ splatcloud,
trianglemesh } loadType = splatcloud;
// get options
if( OpenFlipper::Options::gui() && loadOptions_ )
{
if (loadType_->currentText() == "TriangleMesh") {
loadType = trianglemesh;
} else {
loadType = splatcloud;
}
loadBinaryFile = loadBinaryFile_->isChecked();
}
// add a new, empty splatcloud-object
int splatCloudObjectId = -1;
emit addEmptyObject( DATA_SPLATCLOUD, splatCloudObjectId );
if( splatCloudObjectId != -1 )
{
// create list of ids and add id of splatcloud-object
IdList objectIDs;
objectIDs.push_back( splatCloudObjectId );
// get splatcloud-object by id
SplatCloudObject *splatCloudObject = 0;
if( PluginFunctions::getObject( splatCloudObjectId, splatCloudObject ) )
{
// set name of splatcloud-object to filename
splatCloudObject->setFromFileName( _filename );
splatCloudObject->setName( splatCloudObject->filename() );
// get splatcloud and scenegraph splatcloud-node
SplatCloud *splatCloud = splatCloudObject->splatCloud();
SplatCloudNode *splatCloudNode = splatCloudObject->splatCloudNode();
if( (splatCloud != 0) && (splatCloudNode != 0) )
if ( loadType == splatcloud ) {
// add a new, empty splatcloud-object
int splatCloudObjectId = -1;
emit addEmptyObject( DATA_SPLATCLOUD, splatCloudObjectId );
if( splatCloudObjectId != -1 )
{
// read splatcloud from disk
if( loadBinaryFile ? readBinaryFile( _filename.toLatin1(), *splatCloud ) : readTextFile( _filename.toLatin1(), *splatCloud ) )
{
// emit signals that the object has to be updated and that a file was opened
emit updatedObject( splatCloudObjectId, UPDATE_ALL );
emit openedFile( splatCloudObjectId );
// get drawmodes
ACG::SceneGraph::DrawModes::DrawMode splatsDrawMode = ACG::SceneGraph::DrawModes::getDrawMode( "Splats" );
ACG::SceneGraph::DrawModes::DrawMode dotsDrawMode = ACG::SceneGraph::DrawModes::getDrawMode( "Dots" );
ACG::SceneGraph::DrawModes::DrawMode pointsDrawMode = ACG::SceneGraph::DrawModes::getDrawMode( "Points" );
// if drawmodes don't exist something went wrong
if( splatsDrawMode == ACG::SceneGraph::DrawModes::NONE ||
dotsDrawMode == ACG::SceneGraph::DrawModes::NONE ||
pointsDrawMode == ACG::SceneGraph::DrawModes::NONE )
// create list of ids and add id of splatcloud-object
IdList objectIDs;
objectIDs.push_back( splatCloudObjectId );
// get splatcloud-object by id
SplatCloudObject *splatCloudObject = 0;
if( PluginFunctions::getObject( splatCloudObjectId, splatCloudObject ) )
{
emit log( LOGERR, tr("Shader DrawModes for SplatCloud not existent!") );
// set name of splatcloud-object to filename
splatCloudObject->setFromFileName( _filename );
splatCloudObject->setName( splatCloudObject->filename() );
// get splatcloud and scenegraph splatcloud-node
SplatCloud *splatCloud = splatCloudObject->splatCloud();
SplatCloudNode *splatCloudNode = splatCloudObject->splatCloudNode();
if( (splatCloud != 0) && (splatCloudNode != 0) )
{
// read splatcloud from disk
if( loadBinaryFile ? readBinaryFile( _filename.toLatin1(), *splatCloud ) : readTextFile( _filename.toLatin1(), *splatCloud ) )
{
// emit signals that the object has to be updated and that a file was opened
emit updatedObject( splatCloudObjectId, UPDATE_ALL );
emit openedFile( splatCloudObjectId );
// get drawmodes
ACG::SceneGraph::DrawModes::DrawMode splatsDrawMode = ACG::SceneGraph::DrawModes::getDrawMode( "Splats" );
ACG::SceneGraph::DrawModes::DrawMode dotsDrawMode = ACG::SceneGraph::DrawModes::getDrawMode( "Dots" );
ACG::SceneGraph::DrawModes::DrawMode pointsDrawMode = ACG::SceneGraph::DrawModes::getDrawMode( "Points" );
// if drawmodes don't exist something went wrong
if( splatsDrawMode == ACG::SceneGraph::DrawModes::NONE ||
dotsDrawMode == ACG::SceneGraph::DrawModes::NONE ||
pointsDrawMode == ACG::SceneGraph::DrawModes::NONE )
{
emit log( LOGERR, tr("Shader DrawModes for SplatCloud not existent!") );
}
else
{
// get global drawmode
ACG::SceneGraph::DrawModes::DrawMode drawmode = PluginFunctions::drawMode();
// if global drawmode does *not* contain any of 'Splats', 'Dots' or 'Points' drawmode, add 'Points'
if( !drawmode.containsAtomicDrawMode( splatsDrawMode ) &&
!drawmode.containsAtomicDrawMode( dotsDrawMode ) &&
!drawmode.containsAtomicDrawMode( pointsDrawMode ) )
{
drawmode |= pointsDrawMode;
PluginFunctions::setDrawMode( drawmode );
}
}
// group objects
int groupObjectId = RPC::callFunctionValue<int>( "datacontrol", "groupObjects", objectIDs );
if( groupObjectId != -1 )
{
// everything is okay, so return id of group-object
return groupObjectId;
}
}
}
}
else
{
// get global drawmode
ACG::SceneGraph::DrawModes::DrawMode drawmode = PluginFunctions::drawMode();
// if global drawmode does *not* contain any of 'Splats', 'Dots' or 'Points' drawmode, add 'Points'
if( !drawmode.containsAtomicDrawMode( splatsDrawMode ) &&
!drawmode.containsAtomicDrawMode( dotsDrawMode ) &&
!drawmode.containsAtomicDrawMode( pointsDrawMode ) )
{
drawmode |= pointsDrawMode;
PluginFunctions::setDrawMode( drawmode );
}
}
// something went wrong, so delete objects
size_t i, num = objectIDs.size();
for( i=0; i<num; ++i )
emit deleteObject( objectIDs[ i ] );
}
} else {
// add a new, empty splatcloud-object
int triangleMeshID = -1;
emit addEmptyObject( DATA_TRIANGLE_MESH, triangleMeshID );
if( triangleMeshID != -1 ) {
// group objects
int groupObjectId = RPC::callFunctionValue<int>( "datacontrol", "groupObjects", objectIDs );
if( groupObjectId != -1 )
// get splatcloud-object by id
TriMeshObject *triObject = 0;
if( PluginFunctions::getObject( triangleMeshID, triObject ) )
{
// everything is okay, so return id of group-object
return groupObjectId;
// set name of splatcloud-object to filename
triObject->setFromFileName( _filename );
triObject->setName( triObject->filename() );
// get splatcloud and scenegraph splatcloud-node
TriMesh *mesh = triObject->mesh();
if( mesh != 0 ) {
if ( loadBinaryFile ) {
emit log(LOGERR,"Binary not supported for mesh target!");
} else {
readTextFile( _filename.toLatin1(), *mesh ) ;
// emit signals that the object has to be updated and that a file was opened
emit updatedObject( triangleMeshID, UPDATE_ALL );
emit openedFile( triangleMeshID );
}
}
}
}
}
}
// something went wrong, so delete objects
size_t i, num = objectIDs.size();
for( i=0; i<num; ++i )
emit deleteObject( objectIDs[ i ] );
}
// return failure
......@@ -1032,6 +1227,10 @@ QWidget *FilePTSPlugin::loadOptionsWidget( QString /*_currentFilter*/ )
{
// create new widget (including Load Options and buttons)
loadType_ = new QComboBox();
loadType_->addItem(tr("SplatCloud"));
loadType_->addItem(tr("TriangleMesh"));
loadBinaryFile_ = new QCheckBox( tr("Load as Binary File") );
loadNormals_ = new QCheckBox( tr("Contains Normals") );
......@@ -1065,6 +1264,7 @@ QWidget *FilePTSPlugin::loadOptionsWidget( QString /*_currentFilter*/ )
QVBoxLayout *loadLayout = new QVBoxLayout();
loadLayout->setAlignment( Qt::AlignTop );
loadLayout->setSpacing( 6 );
loadLayout->addWidget( loadType_ );
loadLayout->addWidget( loadBinaryFile_ );
loadLayout->addWidget( loadStructureGroupBox );
loadLayout->addWidget( loadMakeDefaultButton_ );
......@@ -1078,6 +1278,7 @@ QWidget *FilePTSPlugin::loadOptionsWidget( QString /*_currentFilter*/ )
connect( loadMakeDefaultButton_, SIGNAL( clicked() ), this, SLOT( slotLoadMakeDefaultButtonClicked() ) );
// get Load Options from OpenFlipper (from disc)
loadType_->setCurrentIndex( OpenFlipperSettings().value( "FilePTS/Load/LoadType", 0 ).toInt() );
loadBinaryFile_-> setChecked ( OpenFlipperSettings().value( "FilePTS/Load/BinaryFile", true ).toBool() );
loadNormals_-> setChecked ( OpenFlipperSettings().value( "FilePTS/Load/Normals", true ).toBool() );
loadPointsizes_-> setChecked ( OpenFlipperSettings().value( "FilePTS/Load/Pointsizes", true ).toBool() );
......@@ -1180,7 +1381,8 @@ void FilePTSPlugin::slotUpdateSaveColorRange()
void FilePTSPlugin::slotLoadMakeDefaultButtonClicked()
{
// pass our Load Options to OpenFlipper (to disc)
// pass our Load Options to OpenFlipper (to disc)
OpenFlipperSettings().setValue( "FilePTS/Load/LoadType", loadType_->currentIndex() );
OpenFlipperSettings().setValue( "FilePTS/Load/BinaryFile", loadBinaryFile_->isChecked() );
OpenFlipperSettings().setValue( "FilePTS/Load/Normals", loadNormals_-> isChecked() );
OpenFlipperSettings().setValue( "FilePTS/Load/Pointsizes", loadPointsizes_->isChecked() );
......
......@@ -52,18 +52,13 @@
//
//================================================================
#ifndef FILEPTSPLUGIN_HH
#define FILEPTSPLUGIN_HH
#pragma once
//== INCLUDES ====================================================
#include <QObject>
class QCheckBox;
class QComboBox;
class QPushButton;
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/FileInterface.hh>
......@@ -76,6 +71,14 @@ class QPushButton;
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/SplatCloud/SplatCloud.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <QComboBox>
#include <QCheckBox>
#include <QLayout>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QPushButton>
//== CLASS DEFINITION ============================================
......@@ -91,7 +94,9 @@ class FilePTSPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
Q_INTERFACES( ScriptInterface )
Q_INTERFACES( RPCInterface )
Q_INTERFACES( AboutInfoInterface )
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-FilePTS")
signals:
// -- File Interface --
......@@ -149,6 +154,8 @@ private:
bool readBinaryFile( const char *_filename, SplatCloud &_splatCloud ) /*const*/;
bool readTextFile ( const char *_filename, SplatCloud &_splatCloud ) /*const*/;
bool readTextFile ( const char *_filename, TriMesh &_mesh );
// write binary/text file from scenegraph node to disc
bool writeBinaryFile( const char *_filename, const SplatCloudNode *_splatCloudNode ) /*const*/;
bool writeTextFile ( const char *_filename, const SplatCloudNode *_splatCloudNode ) /*const*/;
......@@ -162,6 +169,7 @@ private:
QWidget *saveOptions_;
// options in the loading menu
QComboBox *loadType_;
QCheckBox *loadBinaryFile_;
QCheckBox *loadNormals_;
QCheckBox *loadPointsizes_;
......@@ -194,6 +202,3 @@ private slots:
//================================================================
#endif // FILEPTSPLUGIN_HH