65 #if QT_VERSION >= 0x050000 79 static const int COLORRANGE_0_1 = 0;
86 FilePTSPlugin::FilePTSPlugin() :
101 loadMakeDefaultButton_( 0 ),
102 saveMakeDefaultButton_( 0 )
109 bool FilePTSPlugin::readBinaryFile(
const char *_filename,
SplatCloud &_splatCloud )
122 if( OpenFlipper::Options::gui() && loadOptions_ )
124 loadNormals = loadNormals_-> isChecked();
125 loadPointsizes = loadPointsizes_->isChecked();
126 loadColors = loadColors_-> isChecked();
128 loadIndices = loadIndices_-> isChecked();
134 if( loadNormals ) {
if( !_splatCloud.
requestNormals() ) success =
false; }
136 if( loadColors ) {
if( !_splatCloud.
requestColors() ) success =
false; }
137 if( loadIndices ) {
if( !_splatCloud.
requestIndices() ) success =
false; }
142 emit log(
LOGERR, tr(
"Out of memory for input file \"%1\".\n").arg( _filename ) );
147 FILE *file = fopen( _filename,
"rb" );
150 emit log(
LOGERR, tr(
"Could not open input file \"%1\".\n").arg( _filename ) );
156 fread( &fileType,
sizeof(
int), 1, file );
159 if( fileType != 1 && fileType != 2 )
161 emit log(
LOGERR, tr(
"Bad filetype (%1) in input file \"%2\".\n").arg( QString::number( fileType ), _filename ) );
167 unsigned int numSplats = 0;
168 fread( &numSplats,
sizeof(
unsigned int), 1, file );
176 for( i=0; i<numSplats; ++i )
179 fread( pos,
sizeof(
float), 3, file );
182 position[0] = pos[0];
183 position[1] = pos[1];
184 position[2] = pos[2];
194 for( i=0; i<numSplats; ++i )
197 fread( nrm,
sizeof(
float), 3, file );
204 _splatCloud.
normals( i ) = normal;
212 for( i=0; i<numSplats; ++i )
215 fread( &ps,
sizeof(
float), 1, file );
217 SplatCloud::Pointsize pointsize;
228 for( i=0; i<numSplats; ++i )
230 unsigned int col = 0;
231 fread( &col,
sizeof(
unsigned int), 1, file );
234 color[0] = (
unsigned char) ((col >> 16) & 0xFF);
235 color[1] = (
unsigned char) ((col >> 8) & 0xFF);
236 color[2] = (
unsigned char) ((col ) & 0xFF);
238 _splatCloud.
colors( i ) = color;
246 for( i=0; i<numSplats; ++i )
249 fread( &idx,
sizeof(idx), 1, file );
251 SplatCloud::Index index;
254 _splatCloud.
indices( i ) = index;
261 emit log(
LOGERR, tr(
"Could not read input file \"%1\".\n").arg( _filename ) );
267 emit log(
LOGERR, tr(
"Unexpected end in input file \"%1\".\n").arg( _filename ) );
283 bool FilePTSPlugin::readTextFile(
const char *_filename,
SplatCloud &_splatCloud )
296 if( OpenFlipper::Options::gui() && loadOptions_ )
298 loadNormals = loadNormals_ ->isChecked();
299 loadPointsizes = loadPointsizes_->isChecked();
300 loadColors = loadColors_ ->isChecked();
301 loadColorRange = loadColorRange_->currentIndex();
302 loadIndices = loadIndices_ ->isChecked();
308 if( loadNormals ) {
if( !_splatCloud.
requestNormals() ) success =
false; }
310 if( loadColors ) {
if( !_splatCloud.
requestColors() ) success =
false; }
311 if( loadIndices ) {
if( !_splatCloud.
requestIndices() ) success =
false; }
316 emit log(
LOGERR, tr(
"Out of memory for input file \"%1\".\n").arg( _filename ) );
321 FILE *file = fopen( _filename,
"rb" );
324 emit log(
LOGERR, tr(
"Could not open input file \"%1\".\n").arg( _filename ) );
329 for( splatIdx = 0; ; ++splatIdx )
334 if( fscanf( file,
"%32f %32f %32f", &pos[0], &pos[1], &pos[2] ) != 3 )
341 position[0] = pos[0];
342 position[1] = pos[1];
343 position[2] = pos[2];
345 _splatCloud.
positions( splatIdx ) = position;
352 fscanf( file,
"%32f %32f %32f", &col[0], &col[1], &col[2] );
356 if( loadColorRange == COLORRANGE_0_1 )
358 color[0] = (
unsigned char) (255.999f * col[0]);
359 color[1] = (
unsigned char) (255.999f * col[1]);
360 color[2] = (
unsigned char) (255.999f * col[2]);
364 color[0] = (
unsigned char) col[0];
365 color[1] = (
unsigned char) col[1];
366 color[2] = (
unsigned char) col[2];
369 _splatCloud.
colors( splatIdx ) = color;
376 fscanf( file,
"%32f %32f %32f", &nrm[0], &nrm[1], &nrm[2] );
383 _splatCloud.
normals( splatIdx ) = normal;
390 fscanf( file,
"%32f", &ps );
392 SplatCloud::Pointsize pointsize;
395 _splatCloud.
pointsizes( splatIdx ) = pointsize;
402 fscanf( file,
"%16i", &idx );
404 SplatCloud::Index index;
407 _splatCloud.
indices( splatIdx ) = index;
413 emit log(
LOGERR, tr(
"Could not read input file \"%1\".\n").arg( _filename ) );
419 emit log(
LOGERR, tr(
"Unexpected end in input file \"%1\".\n").arg( _filename ) );
428 emit log(
LOGERR, tr(
"Bad file format of input file \"%1\".\n").arg( _filename ) );
444 bool FilePTSPlugin::writeBinaryFile(
const char *_filename,
const SplatCloudNode *_splatCloudNode )
454 if( OpenFlipper::Options::gui() && saveOptions_ )
456 saveNormals = saveNormals_-> isChecked();
457 savePointsizes = savePointsizes_->isChecked();
458 saveColors = saveColors_-> isChecked();
460 saveIndices = saveIndices_-> isChecked();
477 FILE *file = fopen( _filename,
"wb" );
480 emit log(
LOGERR, tr(
"Could not open output file \"%1\".\n").arg( _filename ) );
486 fwrite( &fileType,
sizeof(
int), 1, file );
489 unsigned int numSplats = _splatCloudNode->splatCloud().
numSplats();
490 fwrite( &numSplats,
sizeof(
unsigned int), 1, file );
495 for( i=0; i<numSplats; ++i )
500 pos[0] = position[0];
501 pos[1] = position[1];
502 pos[2] = position[2];
504 fwrite( pos,
sizeof(
float), 3, file );
512 for( i=0; i<numSplats; ++i )
521 fwrite( nrm,
sizeof(
float), 3, file );
529 for( i=0; i<numSplats; ++i )
531 const SplatCloud::Pointsize &pointsize = _splatCloudNode->getPointsize( i );
536 fwrite( &ps,
sizeof(
float), 1, file );
544 for( i=0; i<numSplats; ++i )
549 col = (0xFF << 24) | (color[0] << 16) | (color[1] << 8) | (color[2]);
551 fwrite( &col,
sizeof(
unsigned int), 1, file );
559 for( i=0; i<numSplats; ++i )
561 const SplatCloud::Index &index = _splatCloudNode->getIndex( i );
566 fwrite( &idx,
sizeof(
int), 1, file );
573 emit log(
LOGERR, tr(
"Could not write output file \"%1\".\n").arg( _filename ) );
589 bool FilePTSPlugin::writeTextFile(
const char *_filename,
const SplatCloudNode *_splatCloudNode )
599 if( OpenFlipper::Options::gui() && saveOptions_ )
601 saveNormals = saveNormals_-> isChecked();
602 savePointsizes = savePointsizes_->isChecked();
603 saveColors = saveColors_-> isChecked();
604 saveColorRange = saveColorRange_->currentIndex();
605 saveIndices = saveIndices_-> isChecked();
622 FILE *file = fopen( _filename,
"wt" );
625 emit log(
LOGERR, tr(
"Could not open output file \"%1\".\n").arg( _filename ) );
630 unsigned int i, numSplats = _splatCloudNode->splatCloud().
numSplats();
631 for( i=0; i<numSplats; ++i )
638 pos[0] = position[0];
639 pos[1] = position[1];
640 pos[2] = position[2];
642 fprintf( file,
"%.6g %.6g %.6g", pos[0], pos[1], pos[2] );
650 if( saveColorRange == COLORRANGE_0_1 )
652 static const float RCP255 = 1.0f / 255.0f;
655 col[0] = RCP255 * color[0];
656 col[1] = RCP255 * color[1];
657 col[2] = RCP255 * color[2];
659 fprintf( file,
" %.6g %.6g %.6g", col[0], col[1], col[2] );
668 fprintf( file,
" %i %i %i", col[0], col[1], col[2] );
682 fprintf( file,
" %.6g %.6g %.6g", nrm[0], nrm[1], nrm[2] );
688 const SplatCloud::Pointsize &pointsize = _splatCloudNode->getPointsize( i );
693 fprintf( file,
" %.6g", ps );
699 const SplatCloud::Index &index = _splatCloudNode->getIndex( i );
704 fprintf( file,
" %i", idx );
707 fprintf( file,
"\n" );
713 emit log(
LOGERR, tr(
"Could not write output file \"%1\".\n").arg( _filename ) );
729 int FilePTSPlugin::loadObject( QString _filename )
735 if( OpenFlipper::Options::gui() && loadOptions_ )
737 loadBinaryFile = loadBinaryFile_->isChecked();
741 int splatCloudObjectId = -1;
743 if( splatCloudObjectId != -1 )
747 objectIDs.push_back( splatCloudObjectId );
760 if( (splatCloud != 0) && (splatCloudNode != 0) )
763 if( loadBinaryFile ? readBinaryFile( _filename.toLatin1(), *splatCloud ) : readTextFile( _filename.toLatin1(), *splatCloud ) )
767 emit openedFile( splatCloudObjectId );
779 emit log(
LOGERR, tr(
"Shader DrawModes for SplatCloud not existent!") );
791 drawmode |= pointsDrawMode;
797 int groupObjectId = RPC::callFunctionValue<int>(
"datacontrol",
"groupObjects", objectIDs );
798 if( groupObjectId != -1 )
801 return groupObjectId;
808 unsigned int i, num = objectIDs.size();
809 for( i=0; i<num; ++i )
821 bool FilePTSPlugin::saveObject(
int _objectId, QString _filename )
827 if( OpenFlipper::Options::gui() && saveOptions_ )
829 saveBinaryFile = saveBinaryFile_->isChecked();
842 if( splatCloudNode != 0 )
845 if( saveBinaryFile ? writeBinaryFile( _filename.toLatin1(), splatCloudNode ) : writeTextFile( _filename.toLatin1(), splatCloudNode ) )
863 if( loadOptions_ == 0 )
867 loadBinaryFile_ =
new QCheckBox( tr(
"Load as Binary File") );
869 loadNormals_ =
new QCheckBox( tr(
"Contains Normals") );
870 loadPointsizes_ =
new QCheckBox( tr(
"Contains Pointsizes") );
871 loadColors_ =
new QCheckBox( tr(
"Contains Colors") );
873 loadColorRange_ =
new QComboBox();
874 loadColorRange_->addItem(
"[0..1]" );
875 loadColorRange_->addItem(
"[0..255]" );
876 slotUpdateLoadColorRange();
878 QHBoxLayout *loadColorsLayout =
new QHBoxLayout();
879 loadColorsLayout->setSpacing( 6 );
880 loadColorsLayout->addWidget( loadColors_ );
881 loadColorsLayout->addWidget( loadColorRange_ );
883 loadIndices_ =
new QCheckBox( tr(
"Contains Indices") );
885 QVBoxLayout *loadStructureLayout =
new QVBoxLayout();
886 loadStructureLayout->setSpacing( 6 );
887 loadStructureLayout->addWidget( loadNormals_ );
888 loadStructureLayout->addWidget( loadPointsizes_ );
889 loadStructureLayout->addItem ( loadColorsLayout );
890 loadStructureLayout->addWidget( loadIndices_ );
892 QGroupBox *loadStructureGroupBox =
new QGroupBox( tr(
"Internal File Structure") );
893 loadStructureGroupBox->setLayout( loadStructureLayout );
895 loadMakeDefaultButton_ =
new QPushButton( tr(
"Make Default") );
897 QVBoxLayout *loadLayout =
new QVBoxLayout();
898 loadLayout->setAlignment( Qt::AlignTop );
899 loadLayout->setSpacing( 6 );
900 loadLayout->addWidget( loadBinaryFile_ );
901 loadLayout->addWidget( loadStructureGroupBox );
902 loadLayout->addWidget( loadMakeDefaultButton_ );
904 loadOptions_ =
new QWidget();
905 loadOptions_->setLayout( loadLayout );
908 connect( loadBinaryFile_, SIGNAL( stateChanged(
int) ),
this, SLOT( slotUpdateLoadColorRange() ) );
909 connect( loadColors_, SIGNAL( stateChanged(
int) ),
this, SLOT( slotUpdateLoadColorRange() ) );
910 connect( loadMakeDefaultButton_, SIGNAL( clicked() ),
this, SLOT( slotLoadMakeDefaultButtonClicked() ) );
913 loadBinaryFile_-> setChecked (
OpenFlipperSettings().value(
"FilePTS/Load/BinaryFile",
true ).toBool() );
914 loadNormals_-> setChecked (
OpenFlipperSettings().value(
"FilePTS/Load/Normals",
true ).toBool() );
915 loadPointsizes_-> setChecked (
OpenFlipperSettings().value(
"FilePTS/Load/Pointsizes",
true ).toBool() );
916 loadColors_-> setChecked (
OpenFlipperSettings().value(
"FilePTS/Load/Colors",
true ).toBool() );
917 loadColorRange_-> setCurrentIndex(
OpenFlipperSettings().value(
"FilePTS/Load/ColorRange", 0 ).toInt() );
918 loadIndices_-> setChecked (
OpenFlipperSettings().value(
"FilePTS/Load/Indices",
true ).toBool() );
930 if( saveOptions_ == 0 )
934 saveBinaryFile_ =
new QCheckBox( tr(
"Save as Binary File") );
936 saveNormals_ =
new QCheckBox( tr(
"Save Normals") );
937 savePointsizes_ =
new QCheckBox( tr(
"Save Pointsizes") );
938 saveColors_ =
new QCheckBox( tr(
"Save Colors") );
940 saveColorRange_ =
new QComboBox();
941 saveColorRange_->addItem(
"[0..1]" );
942 saveColorRange_->addItem(
"[0..255]" );
943 slotUpdateSaveColorRange();
945 QHBoxLayout *saveColorsLayout =
new QHBoxLayout();
946 saveColorsLayout->setSpacing( 6 );
947 saveColorsLayout->addWidget( saveColors_ );
948 saveColorsLayout->addWidget( saveColorRange_ );
950 saveIndices_ =
new QCheckBox( tr(
"Save Indices") );
952 QVBoxLayout *saveStructureLayout =
new QVBoxLayout();
953 saveStructureLayout->setSpacing( 6 );
954 saveStructureLayout->addWidget( saveNormals_ );
955 saveStructureLayout->addWidget( savePointsizes_ );
956 saveStructureLayout->addItem ( saveColorsLayout );
957 saveStructureLayout->addWidget( saveIndices_ );
959 QGroupBox *saveStructureGroupBox =
new QGroupBox( tr(
"Internal File Structure") );
960 saveStructureGroupBox->setLayout( saveStructureLayout );
962 saveMakeDefaultButton_ =
new QPushButton( tr(
"Make Default") );
964 QVBoxLayout *saveLayout =
new QVBoxLayout();
965 saveLayout->setAlignment( Qt::AlignTop );
966 saveLayout->setSpacing( 6 );
967 saveLayout->addWidget( saveBinaryFile_ );
968 saveLayout->addWidget( saveStructureGroupBox );
969 saveLayout->addWidget( saveMakeDefaultButton_ );
971 saveOptions_ =
new QWidget();
972 saveOptions_->setLayout( saveLayout );
975 connect( saveBinaryFile_, SIGNAL( stateChanged(
int) ),
this, SLOT( slotUpdateSaveColorRange() ) );
976 connect( saveColors_, SIGNAL( stateChanged(
int) ),
this, SLOT( slotUpdateSaveColorRange() ) );
977 connect( saveMakeDefaultButton_, SIGNAL( clicked() ),
this, SLOT( slotSaveMakeDefaultButtonClicked() ) );
980 saveBinaryFile_->setChecked (
OpenFlipperSettings().value(
"FilePTS/Save/BinaryFile",
true ).toBool() );
981 saveNormals_-> setChecked (
OpenFlipperSettings().value(
"FilePTS/Save/Normals",
true ).toBool() );
982 savePointsizes_->setChecked (
OpenFlipperSettings().value(
"FilePTS/Save/Pointsizes",
true ).toBool() );
983 saveColors_-> setChecked (
OpenFlipperSettings().value(
"FilePTS/Save/Colors",
true ).toBool() );
984 saveColorRange_->setCurrentIndex(
OpenFlipperSettings().value(
"FilePTS/Save/ColorRange", 0 ).toInt() );
985 saveIndices_-> setChecked (
OpenFlipperSettings().value(
"FilePTS/Save/Indices",
true ).toBool() );
995 void FilePTSPlugin::slotUpdateLoadColorRange()
997 loadColorRange_->setEnabled( loadColors_->isChecked() && !loadBinaryFile_->isChecked() );
1004 void FilePTSPlugin::slotUpdateSaveColorRange()
1006 saveColorRange_->setEnabled( saveColors_->isChecked() && !saveBinaryFile_->isChecked() );
1013 void FilePTSPlugin::slotLoadMakeDefaultButtonClicked()
1030 void FilePTSPlugin::slotSaveMakeDefaultButtonClicked()
1043 #if QT_VERSION < 0x050000 SplatCloudObject * splatCloudObject(BaseObjectData *_object)
Cast an SplatCloudObject to a SplatCloudObject if possible.
virtual void updatedObject(int _objectId)
An object has been changed or added by this plugin.
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
SplatCloud * splatCloud()
Get SplatCloud.
QString filename() const
return the filename of the object
bool getObject(int _identifier, BSplineCurveObject *&_object)
QWidget * loadOptionsWidget(QString)
Normal & normals(int _idx)
Get a reference of the predefined property's value.
void clear()
Remove all properties and reset the number of splats.
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void setFromFileName(const QString &_filename)
bool requestPointsizes()
Request the predefined property.
bool requestNormals()
Request the predefined property.
void pushbackSplat()
Add one element at the end of the data vector of all splat-properties.
void resizeSplats(unsigned int _num)
Resize the data vector of all splat-properties.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
Pointsize & pointsizes(int _idx)
Get a reference of the predefined property's value.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
SplatCloudNode * splatCloudNode(BaseObjectData *_object)
Get a SplatCloudNode from an object.
unsigned int numSplats() const
Get the number of splats.
Position & positions(int _idx)
Get a reference of the predefined property's value.
bool requestColors()
Request the predefined property.
bool requestPositions()
Request the predefined property.
QWidget * saveOptionsWidget(QString)
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Color & colors(int _idx)
Get a reference of the predefined property's value.
DrawMode NONE
not a valid draw mode
void setName(QString _name)
Set the name of the Object.
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
Index & indices(int _idx)
Get a reference of the predefined property's value.
bool containsAtomicDrawMode(DrawMode _atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
bool requestIndices()
Request the predefined property.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const Position & getPosition(int _idx) const
if the data array exists, the entry with the given index is returned, otherwise the default value is ...
virtual void deleteObject(int _id)
Delete an object This signal can be called from any thread. .
SplatCloudNode * splatCloudNode()
Get SplatCloud's scenegraph Node.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .