50#include "Snappy/snappy.h"
64static const int COLORRANGE_0_1 = 0;
70template <
typename MeshT>
79 void clear()
override {
88 mesh_.set_normal( currentPoint_,_normal );
92 mesh_.set_color( currentPoint_,_color );
96 mesh_.set_color( currentPoint_, OpenMesh::color_cast <typename MeshT::Color>(_color));
99 void setPointSize(
float )
override {
103 void setIndex(
int )
override {
107 void request_vertex_normals()
override {
108 mesh_.request_vertex_normals();
111 void request_vertex_colors()
override {
112 mesh_.request_vertex_colors();
115 virtual void request_point_sizes()
override {
119 virtual void request_indices()
override {
123 void reserve(
size_t _size)
override {
124 mesh_.reserve(_size,0,0);
127 virtual DataType adaptorType()
override {
133 typename MeshT::VertexHandle currentPoint_;
150 void clear()
override {
162 cloud_.
normals( splatIdx_ ) = _normal;
166 cloud_.
colors( splatIdx_ ) = OpenMesh::color_cast<SplatCloud::Color>(_color);
170 cloud_.
colors( splatIdx_) = _color;
173 void setPointSize(
float _size )
override {
177 void setIndex(
int _index )
override {
178 cloud_.
indices(splatIdx_) = _index;
181 void request_vertex_normals()
override {
185 void request_vertex_colors()
override {
189 virtual void request_point_sizes()
override {
193 virtual void request_indices()
override {
197 void reserve(
size_t )
override {
200 virtual DataType adaptorType()
override {
211FilePTSPlugin::FilePTSPlugin() :
212 loadOptions_( nullptr ),
213 saveOptions_( nullptr ),
214 saveBinaryFile_( nullptr ),
215 saveNormals_ ( nullptr ),
216 savePointsizes_( nullptr ),
217 saveColors_ ( nullptr ),
218 saveColorRange_( nullptr ),
219 saveIndices_ ( nullptr ),
220 saveMakeDefaultButton_( nullptr )
225void FilePTSPlugin::initializePlugin()
228 "This plugin is based on the Snappy compression library by google<br> "
230 "The following license applies to their code: <br> "
231 "Copyright 2005 Google Inc.All Rights Reserved. <br>"
233 "Redistribution and use in source and binary forms, with or without <br>"
234 "modification, are permitted provided that the following conditions are <br>"
237 " *Redistributions of source code must retain the above copyright <br>"
238 "notice, this list of conditions and the following disclaimer. <br>"
239 " * Redistributions in binary form must reproduce the above <br>"
240 "copyright notice, this list of conditions and the following disclaimer <br>"
241 "in the documentation and / or other materials provided with the <br>"
243 " * Neither the name of Google Inc.nor the names of its <br>"
244 "contributors may be used to endorse or promote products derived from <br>"
245 "this software without specific prior written permission. <br>"
247 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS <br>"
248 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT <br>"
249 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR <br>"
250 "A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT <br>"
251 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, <br>"
252 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT <br>"
253 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, <br>"
254 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY <br>"
255 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT <br>"
256 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE <br>"
257 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
259 emit addAboutInfo(info,
"FilePTS");
264namespace SplatDataFileFormat
300bool FilePTSPlugin::readBinaryFile(
const char *_filename,
SplatCloud &_splatCloud )
306 bool loadPositions = OpenFlipperSettings().
value(
"FilePTS/Load/Positions",
true ).toBool();
307 bool loadNormals = OpenFlipperSettings().
value(
"FilePTS/Load/Normals",
true ).toBool();
308 bool loadPointsizes = OpenFlipperSettings().
value(
"FilePTS/Load/Pointsizes",
false ).toBool();
309 bool loadColors = OpenFlipperSettings().
value(
"FilePTS/Load/Colors",
false ).toBool();
311 bool loadIndices = OpenFlipperSettings().
value(
"FilePTS/Load/Indices",
false ).toBool();
314 if( OpenFlipper::Options::gui() && loadOptions_ )
316 loadPositions = loadOptions_->listWidget->findItems(
"Position",Qt::MatchExactly)[0]->isSelected();
317 loadNormals = loadOptions_->listWidget->findItems(
"Normal",Qt::MatchExactly)[0]->isSelected();
318 loadPointsizes = loadOptions_->listWidget->findItems(
"PointSize",Qt::MatchExactly)[0]->isSelected();
319 loadColors = loadOptions_->listWidget->findItems(
"Color",Qt::MatchExactly)[0]->isSelected();
320 loadIndices = loadOptions_->listWidget->findItems(
"Index",Qt::MatchExactly)[0]->isSelected();
326 if( loadNormals ) {
if( !_splatCloud.
requestNormals() ) success =
false; }
328 if( loadColors ) {
if( !_splatCloud.
requestColors() ) success =
false; }
329 if( loadIndices ) {
if( !_splatCloud.
requestIndices() ) success =
false; }
334 emit log(
LOGERR, tr(
"Out of memory for input file \"%1\".\n").arg( _filename ) );
339 FILE *file = fopen( _filename,
"rb" );
342 emit log(
LOGERR, tr(
"Could not open input file \"%1\".\n").arg( _filename ) );
348 fread( &fileType,
sizeof(
int), 1, file );
351 if( fileType != 1 && fileType != 2 && fileType != 3 )
353 emit log(
LOGERR, tr(
"Bad filetype (%1) in input file \"%2\".\n").arg( QString::number( fileType ), _filename ) );
359 unsigned int numSplats = 0;
360 fread( &numSplats,
sizeof(
unsigned int), 1, file );
367 std::vector<ReadObject> readObject = getReadObjectOrder();
369 for (
const ReadObject& element : readObject) {
373 if ( element == PointPos)
376 for (i = 0; i < numSplats; ++i)
379 fread(pos,
sizeof(
float), 3, file);
382 position[0] = pos[0];
383 position[1] = pos[1];
384 position[2] = pos[2];
391 if ( element == PointNormal && loadNormals)
394 for (i = 0; i < numSplats; ++i)
397 fread(nrm,
sizeof(
float), 3, file);
404 _splatCloud.
normals(i) = normal;
409 if (element == PointSize && loadPointsizes)
412 for (i = 0; i < numSplats; ++i)
415 fread(&ps,
sizeof(
float), 1, file);
417 SplatCloud::Pointsize pointsize;
425 if (element == PointColor && loadColors)
428 for (i = 0; i < numSplats; ++i)
430 unsigned int col = 0;
431 fread(&col,
sizeof(
unsigned int), 1, file);
434 color[0] = (
unsigned char)((col >> 16) & 0xFF);
435 color[1] = (
unsigned char)((col >> 8) & 0xFF);
436 color[2] = (
unsigned char)((col) & 0xFF);
438 _splatCloud.
colors(i) = color;
443 if (element == PointIndex && loadIndices)
446 for (i = 0; i < numSplats; ++i)
449 fread(&idx,
sizeof(idx), 1, file);
451 SplatCloud::Index index;
454 _splatCloud.
indices(i) = index;
461 else if (fileType == 3)
465 int numProperties = 0;
466 fread(&numProperties,
sizeof(
int), 1, file);
468 for (
int propID = 0; propID < numProperties; ++propID)
474 fread(&propNameLen,
sizeof(
int), 1, file);
475 std::string propName(propNameLen, 0);
477 fread(&propName[0], 1, propNameLen, file);
481 fread(&dataType,
sizeof(
int), 1, file);
484 quint64 compressedSize = 0;
485 fread(&compressedSize,
sizeof(quint64), 1, file);
486 size_t compressedSizeT =
static_cast<size_t>(compressedSize);
491 if (dataType == SplatDataFileFormat::FLOATVEC3)
493 if (propName ==
"Points")
494 readCompressedBinaryChunk(file, compressedSizeT,
reinterpret_cast<char*
>(&_splatCloud.
positions(0)));
495 else if (propName ==
"Normals" && loadNormals)
496 readCompressedBinaryChunk(file, compressedSizeT,
reinterpret_cast<char*
>(&_splatCloud.
normals(0)));
498 fseek(file,
static_cast<long>(compressedSizeT), SEEK_CUR);
500 else if (dataType == SplatDataFileFormat::FLOAT)
502 if (propName ==
"Radii" && loadPointsizes)
503 readCompressedBinaryChunk(file, compressedSizeT,
reinterpret_cast<char*
>(&_splatCloud.
pointsizes(0)));
505 fseek(file,
static_cast<long>(compressedSizeT), SEEK_CUR);
507 else if (dataType == SplatDataFileFormat::UINT16)
509 fseek(file,
static_cast<long>(compressedSizeT), SEEK_CUR);
511 else if (dataType == SplatDataFileFormat::UINT32)
513 if (propName ==
"Colors" && loadColors)
515 std::vector<ACG::Vec4uc> fileColors(numSplats);
516 readCompressedBinaryChunk(file, compressedSizeT,
reinterpret_cast<char*
>(&fileColors[0]));
518 for (uint i = 0; i < numSplats; ++i)
520 for (
int k = 0; k < 3; ++k)
521 _splatCloud.
colors(i)[k] = fileColors[i][k];
525 fseek(file,
static_cast<long>(compressedSizeT), SEEK_CUR);
527 else if (dataType == SplatDataFileFormat::INT32)
529 fseek(file,
static_cast<long>(compressedSizeT), SEEK_CUR);
533 emit log(
LOGWARN, tr(
"Unknown Property type. \"%1\".\n").arg(_filename));
534 fseek(file,
static_cast<long>(compressedSizeT), SEEK_CUR);
545 emit log(
LOGERR, tr(
"Could not read input file \"%1\".\n").arg( _filename ) );
551 emit log(
LOGERR, tr(
"Unexpected end in input file \"%1\".\n").arg( _filename ) );
567std::vector<ReadObject> FilePTSPlugin::getReadObjectOrder() {
569 std::vector<ReadObject> readObject;
571 for (
auto i = 0 ; i < loadOptions_->listWidget->count() ; ++i ) {
572 if ( loadOptions_->listWidget->item(i)->isSelected() ) {
574 if (loadOptions_->listWidget->item(i)->text() ==
"Position" ) {
575 readObject.push_back(PointPos);
578 if (loadOptions_->listWidget->item(i)->text() ==
"Normal" ) {
579 readObject.push_back(PointNormal);
582 if (loadOptions_->listWidget->item(i)->text() ==
"Color" ) {
583 readObject.push_back(PointColor);
586 if (loadOptions_->listWidget->item(i)->text() ==
"PointSize" ) {
587 readObject.push_back(PointSize);
590 if (loadOptions_->listWidget->item(i)->text() ==
"Index" ) {
591 readObject.push_back(PointIndex);
597 for (
const ReadObject& i : readObject) {
600 input_order +=
" Position";
601 if ( i == PointNormal )
602 input_order +=
" Normal";
603 if ( i == PointColor )
604 input_order +=
" Color";
605 if ( i == PointSize )
606 input_order +=
" Pointsize";
607 if ( i == PointIndex )
608 input_order +=
" Index";
611 emit log(
LOGINFO,
"Reading data in this order:" + input_order);
619bool FilePTSPlugin::readTextFile (
const char *_filename,
AdaptorBase& _adaptor ) {
624 bool pointCount = OpenFlipperSettings().
value(
"FilePTS/Load/PointCount",
true ).toBool();
625 bool loadNormals = OpenFlipperSettings().
value(
"FilePTS/Load/Normals",
true ).toBool();
626 bool loadPointsizes = OpenFlipperSettings().
value(
"FilePTS/Load/Pointsizes",
false ).toBool();
627 bool loadColors = OpenFlipperSettings().
value(
"FilePTS/Load/Colors",
false ).toBool();
628 int loadColorRange = OpenFlipperSettings().
value(
"FilePTS/Load/ColorRange",0 ).toInt();
629 bool loadIndices = OpenFlipperSettings().
value(
"FilePTS/Load/Indices",
false ).toBool();
632 std::vector<ReadObject> readObject;
634 readObject = getReadObjectOrder();
637 if(OpenFlipperSettings().value(
"FilePTS/Load/Positions",
false ).toBool())
638 readObject.emplace_back(PointPos);
640 readObject.emplace_back(PointNormal);
642 readObject.emplace_back(PointColor);
644 readObject.emplace_back(PointSize);
646 readObject.emplace_back(PointIndex);
651 if ( readObject[0] != PointPos ) {
652 emit log(
LOGERR,
"Position Attribute has to be first in the File!");
659 if( OpenFlipper::Options::gui() && loadOptions_ )
661 loadNormals = loadOptions_->listWidget->findItems(
"Normal",Qt::MatchExactly)[0]->isSelected();
662 loadPointsizes = loadOptions_->listWidget->findItems(
"PointSize",Qt::MatchExactly)[0]->isSelected();
663 loadColors = loadOptions_->listWidget->findItems(
"Color",Qt::MatchExactly)[0]->isSelected();
664 loadIndices = loadOptions_->listWidget->findItems(
"Index",Qt::MatchExactly)[0]->isSelected();
665 pointCount = loadOptions_->pointCount->isChecked();
666 loadColorRange = loadOptions_->comboColor->currentIndex();
671 if( loadNormals ) { _adaptor.request_vertex_normals(); }
672 if( loadColors ) { _adaptor.request_vertex_colors(); }
673 if( loadPointsizes ) { _adaptor.request_point_sizes(); }
674 if( loadIndices ) { _adaptor.request_indices(); }
679 if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
680 emit log(
LOGERR, tr(
"Could not open input file \"%1\".\n").arg( _filename ) );
686 QString line = in.readLine();
691 const int size = line.toInt(&ok);
693 emit log(
LOGINFO, tr(
"Point count in header: \"%1\"").arg( size ) );
694 _adaptor.reserve(size);
696 emit log(
LOGERR, tr(
"Failed to read point count header. Got \"%1\"").arg( line ) );
701 int currentPoint = 0;
703 while (!in.atEnd()) {
705 if ( (currentPoint % 100000) == 0 )
706 emit log(
LOGINFO, tr(
"Reading point %1\n").arg( currentPoint ) );
708 for (
const ReadObject& i : readObject) {
715 in >> pos[0] >> pos[1] >> pos[2];
716 if ( in.status() == QTextStream::Ok ) {
719 emit log(
LOGERR, tr(
"Failed to read postion for point %1\n").arg( currentPoint ) );
725 if( i == PointColor && loadColors )
727 if( loadColorRange == COLORRANGE_0_1 )
731 in >> color[0] >> color[1] >> color[2];
733 if ( in.status() == QTextStream::Ok ) {
734 _adaptor.setColor(color);
736 emit log(
LOGERR, tr(
"Failed to read color for point %1\n").arg( currentPoint ) );
744 in >> col[0] >> col[1] >> col[2];
749 color[0] = (
unsigned char) col[0];
750 color[1] = (
unsigned char) col[1];
751 color[2] = (
unsigned char) col[2];
754 if ( in.status() == QTextStream::Ok ) {
755 _adaptor.setColor(color);
757 emit log(
LOGERR, tr(
"Failed to read color for point %1\n").arg( currentPoint ) );
764 if( i == PointNormal && loadNormals )
767 in >> nrm[0] >> nrm[1] >> nrm[2];
769 if ( in.status() == QTextStream::Ok ) {
775 _adaptor.setNormal(normal);
777 emit log(
LOGERR, tr(
"Failed to read normal for point %1\n").arg( currentPoint ) );
784 if( i == PointSize && loadPointsizes )
791 if ( in.status() == QTextStream::Ok ) {
792 _adaptor.setPointSize(ps);
794 emit log(
LOGERR, tr(
"Failed to read point size for point %1\n").arg( currentPoint ) );
798 emit log(
LOGERR,
"Pointsize not implemented for meshes");
803 if( i == PointNormal && loadIndices )
810 if ( in.status() == QTextStream::Ok ) {
811 _adaptor.setIndex(idx);
813 emit log(
LOGERR, tr(
"Failed to read index for point %1\n").arg( currentPoint ) );
817 emit log(
LOGERR,
"Index not implemented for meshes, skipped");
824 line = in.readLine();
828 if ( in.status() != QTextStream::Ok ) {
829 emit log(
LOGERR, tr(
"Input File Stream Status not ok! Points read: %1\n").arg( currentPoint ) );
834 emit log(
LOGERR, tr(
"Not at end of file! Points read: %1\n").arg( currentPoint ) );
847bool FilePTSPlugin::writeBinaryFile(
const char *_filename,
const SplatCloudNode *_splatCloudNode )
850 bool saveNormals = OpenFlipperSettings().
value(
"FilePTS/Save/Normals",
true ).toBool();
851 bool savePointsizes = OpenFlipperSettings().
value(
"FilePTS/Save/Pointsizes",
false ).toBool();
852 bool saveColors = OpenFlipperSettings().
value(
"FilePTS/Save/Colors",
false ).toBool();
854 bool saveIndices = OpenFlipperSettings().
value(
"FilePTS/Save/Indices",
false ).toBool();
857 if( OpenFlipper::Options::gui() && saveOptions_ )
859 saveNormals = saveNormals_-> isChecked();
860 savePointsizes = savePointsizes_->isChecked();
861 saveColors = saveColors_-> isChecked();
863 saveIndices = saveIndices_-> isChecked();
880 FILE *file = fopen( _filename,
"wb" );
883 emit log(
LOGERR, tr(
"Could not open output file \"%1\".\n").arg( _filename ) );
889 fwrite( &fileType,
sizeof(
int), 1, file );
892 unsigned int numSplats = _splatCloudNode->splatCloud().
numSplats();
893 fwrite( &numSplats,
sizeof(
unsigned int), 1, file );
898 for( i=0; i<numSplats; ++i )
903 pos[0] = position[0];
904 pos[1] = position[1];
905 pos[2] = position[2];
907 fwrite( pos,
sizeof(
float), 3, file );
915 for( i=0; i<numSplats; ++i )
924 fwrite( nrm,
sizeof(
float), 3, file );
932 for( i=0; i<numSplats; ++i )
934 const SplatCloud::Pointsize &pointsize = _splatCloudNode->getPointsize( i );
939 fwrite( &ps,
sizeof(
float), 1, file );
947 for( i=0; i<numSplats; ++i )
952 col = (0xFF << 24) | (color[0] << 16) | (color[1] << 8) | (color[2]);
954 fwrite( &col,
sizeof(
unsigned int), 1, file );
962 for( i=0; i<numSplats; ++i )
964 const SplatCloud::Index &index = _splatCloudNode->getIndex( i );
969 fwrite( &idx,
sizeof(
int), 1, file );
976 emit log(
LOGERR, tr(
"Could not write output file \"%1\".\n").arg( _filename ) );
992bool FilePTSPlugin::writeTextFile(
const char *_filename,
const SplatCloudNode *_splatCloudNode )
995 bool saveNormals = OpenFlipperSettings().
value(
"FilePTS/Save/Normals",
true ).toBool();
996 bool savePointsizes = OpenFlipperSettings().
value(
"FilePTS/Save/Pointsizes",
false ).toBool();
997 bool saveColors = OpenFlipperSettings().
value(
"FilePTS/Save/Colors",
false ).toBool();
998 int saveColorRange = OpenFlipperSettings().
value(
"FilePTS/Save/ColorRange",0 ).toInt();
999 bool saveIndices = OpenFlipperSettings().
value(
"FilePTS/Save/Indices",
false ).toBool();
1002 if( OpenFlipper::Options::gui() && saveOptions_ )
1004 saveNormals = saveNormals_-> isChecked();
1005 savePointsizes = savePointsizes_->isChecked();
1006 saveColors = saveColors_-> isChecked();
1007 saveColorRange = saveColorRange_->currentIndex();
1008 saveIndices = saveIndices_-> isChecked();
1012 FILE *file = fopen( _filename,
"wt" );
1015 emit log(
LOGERR, tr(
"Could not open output file \"%1\".\n").arg( _filename ) );
1020 unsigned int i, numSplats = _splatCloudNode->splatCloud().
numSplats();
1021 for( i=0; i<numSplats; ++i )
1028 pos[0] = position[0];
1029 pos[1] = position[1];
1030 pos[2] = position[2];
1032 fprintf( file,
"%.6g %.6g %.6g", pos[0], pos[1], pos[2] );
1040 if( saveColorRange == COLORRANGE_0_1 )
1042 static const float RCP255 = 1.0f / 255.0f;
1045 col[0] = RCP255 * color[0];
1046 col[1] = RCP255 * color[1];
1047 col[2] = RCP255 * color[2];
1049 fprintf( file,
" %.6g %.6g %.6g", col[0], col[1], col[2] );
1058 fprintf( file,
" %i %i %i", col[0], col[1], col[2] );
1072 fprintf( file,
" %.6g %.6g %.6g", nrm[0], nrm[1], nrm[2] );
1076 if( savePointsizes )
1078 const SplatCloud::Pointsize &pointsize = _splatCloudNode->getPointsize( i );
1083 fprintf( file,
" %.6g", ps );
1089 const SplatCloud::Index &index = _splatCloudNode->getIndex( i );
1094 fprintf( file,
" %i", idx );
1097 fprintf( file,
"\n" );
1101 if( ferror( file ) )
1103 emit log(
LOGERR, tr(
"Could not write output file \"%1\".\n").arg( _filename ) );
1119bool FilePTSPlugin::readCompressedBinaryChunk(FILE* _file,
size_t _compressedSize,
char* _dst)
1121 std::vector<char> compressedData(_compressedSize);
1122 fread(&compressedData[0], 1, _compressedSize, _file);
1123 return snappy::RawUncompress(&compressedData[0], _compressedSize, _dst);
1129int FilePTSPlugin::loadObject( QString _filename )
1132 bool loadBinaryFile = OpenFlipperSettings().
value(
"FilePTS/Load/BinaryFile",
false ).toBool();
1133 enum dataType{ splatcloud,
1135 polymesh } loadType = splatcloud;
1137 if( OpenFlipper::Options::gui() && loadOptions_ )
1139 if (loadOptions_->type->currentText() ==
"TriangleMesh") {
1140 loadType = trianglemesh;
1141 }
else if (loadOptions_->type->currentText() ==
"PolyMesh") {
1142 loadType = polymesh;
1144 loadType = splatcloud;
1147 loadBinaryFile = loadOptions_->binary->isChecked();
1151 if ( loadType == splatcloud ) {
1154 int splatCloudObjectId = -1;
1156 if( splatCloudObjectId != -1 )
1160 objectIDs.push_back( splatCloudObjectId );
1173 if( (splatCloud != 0) && (splatCloudNode != 0) )
1178 if( loadBinaryFile ? readBinaryFile( _filename.toLatin1(), *splatCloud ) : readTextFile( _filename.toLatin1(), adaptor ) )
1181 emit updatedObject( splatCloudObjectId,
UPDATE_ALL );
1182 emit openedFile( splatCloudObjectId );
1194 emit log(
LOGERR, tr(
"Shader DrawModes for SplatCloud not existent!") );
1206 drawmode |= pointsDrawMode;
1212 int groupObjectId = RPC::callFunctionValue<int>(
"datacontrol",
"groupObjects", objectIDs );
1213 if( groupObjectId != -1 )
1216 return groupObjectId;
1223 size_t i, num = objectIDs.size();
1224 for( i=0; i<num; ++i )
1225 emit deleteObject( objectIDs[ i ] );
1227 }
else if ( loadType == trianglemesh ) {
1230 int triangleMeshID = -1;
1232 if( triangleMeshID != -1 ) {
1246 if ( loadBinaryFile ) {
1247 emit log(
LOGERR,
"Binary not supported for mesh target!");
1251 readTextFile( _filename.toLatin1(), adaptor ) ;
1254 emit updatedObject( triangleMeshID,
UPDATE_ALL );
1255 emit openedFile( triangleMeshID );
1259 triObject->
meshNode()->drawMode(pointsDrawMode);
1260 return triangleMeshID;
1268 int polyMeshID = -1;
1270 if( polyMeshID != -1 ) {
1284 if ( loadBinaryFile ) {
1285 emit log(
LOGERR,
"Binary not supported for mesh target!");
1289 readTextFile( _filename.toLatin1(), adaptor ) ;
1292 emit updatedObject( polyMeshID,
UPDATE_ALL );
1293 emit openedFile( polyMeshID );
1297 triObject->
meshNode()->drawMode(pointsDrawMode);
1313bool FilePTSPlugin::saveObject(
int _objectId, QString _filename )
1316 bool saveBinaryFile = OpenFlipperSettings().
value(
"FilePTS/Save/BinaryFile",
false ).toBool();
1319 if( OpenFlipper::Options::gui() && saveOptions_ )
1321 saveBinaryFile = saveBinaryFile_->isChecked();
1334 if( splatCloudNode != 0 )
1337 if( saveBinaryFile ? writeBinaryFile( _filename.toLatin1(), splatCloudNode ) : writeTextFile( _filename.toLatin1(),
splatCloudNode ) )
1355 if ( loadOptions_ ==
nullptr) {
1358 loadOptions_->listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
1360 QStringList order = OpenFlipperSettings().
value(
"FilePTS/Load/Order",
"position,normal,color,size,index" ).toString().split(
",");
1362 loadOptions_->listWidget->clear();
1364 for (
const QString&
name : order ) {
1366 if (
name ==
"position" ) {
1367 loadOptions_->listWidget->addItem(
"Position");
1370 if (
name ==
"normal" ) {
1371 loadOptions_->listWidget->addItem(
"Normal");
1374 if (
name ==
"color" ) {
1375 loadOptions_->listWidget->addItem(
"Color");
1378 if (
name ==
"size" ) {
1379 loadOptions_->listWidget->addItem(
"PointSize");
1382 if (
name ==
"index" ) {
1383 loadOptions_->listWidget->addItem(
"Index");
1388 loadOptions_->type->setCurrentIndex ( OpenFlipperSettings().
value(
"FilePTS/Load/LoadType", 0 ).toInt() );
1389 loadOptions_->binary->setChecked ( OpenFlipperSettings().
value(
"FilePTS/Load/BinaryFile",
true ).toBool() );
1390 loadOptions_->pointCount->setChecked ( OpenFlipperSettings().
value(
"FilePTS/Load/PointCount",
true ).toBool() );
1391 loadOptions_->listWidget->findItems(
"Position",Qt::MatchExactly)[0]->setSelected( OpenFlipperSettings().
value(
"FilePTS/Load/Position",
true ).toBool() );
1392 loadOptions_->listWidget->findItems(
"Normal",Qt::MatchExactly)[0]->setSelected( OpenFlipperSettings().
value(
"FilePTS/Load/Normals",
true ).toBool() );
1393 loadOptions_->listWidget->findItems(
"PointSize",Qt::MatchExactly)[0]->setSelected(OpenFlipperSettings().
value(
"FilePTS/Load/Pointsizes",
true ).toBool()) ;
1394 loadOptions_->comboColor->setCurrentIndex(OpenFlipperSettings().
value(
"FilePTS/Load/ColorRange", 0 ).toInt() );
1395 loadOptions_->listWidget->findItems(
"Color",Qt::MatchExactly)[0]->setSelected(OpenFlipperSettings().
value(
"FilePTS/Load/Colors",
true ).toBool()) ;
1396 loadOptions_->listWidget->findItems(
"Index",Qt::MatchExactly)[0]->setSelected(OpenFlipperSettings().
value(
"FilePTS/Load/Indices",
true ).toBool() );
1398 connect(loadOptions_->defaultButton,SIGNAL( clicked() ) ,
this, SLOT(slotLoadMakeDefaultButtonClicked() ) );
1399 connect(loadOptions_->defaultButton,SIGNAL( clicked() ) ,
this, SLOT(slotLoadMakeDefaultButtonClicked() ) );
1403 return loadOptions_;
1412 if( saveOptions_ == 0 )
1416 saveBinaryFile_ =
new QCheckBox( tr(
"Save as Binary File") );
1418 saveNormals_ =
new QCheckBox( tr(
"Save Normals") );
1419 savePointsizes_ =
new QCheckBox( tr(
"Save Pointsizes") );
1420 saveColors_ =
new QCheckBox( tr(
"Save Colors") );
1422 saveColorRange_ =
new QComboBox();
1423 saveColorRange_->addItem(
"[0..1]" );
1424 saveColorRange_->addItem(
"[0..255]" );
1425 slotUpdateSaveColorRange();
1427 QHBoxLayout *saveColorsLayout =
new QHBoxLayout();
1428 saveColorsLayout->setSpacing( 6 );
1429 saveColorsLayout->addWidget( saveColors_ );
1430 saveColorsLayout->addWidget( saveColorRange_ );
1432 saveIndices_ =
new QCheckBox( tr(
"Save Indices") );
1434 QVBoxLayout *saveStructureLayout =
new QVBoxLayout();
1435 saveStructureLayout->setSpacing( 6 );
1436 saveStructureLayout->addWidget( saveNormals_ );
1437 saveStructureLayout->addWidget( savePointsizes_ );
1438 saveStructureLayout->addItem ( saveColorsLayout );
1439 saveStructureLayout->addWidget( saveIndices_ );
1441 QGroupBox *saveStructureGroupBox =
new QGroupBox( tr(
"Internal File Structure") );
1442 saveStructureGroupBox->setLayout( saveStructureLayout );
1444 saveMakeDefaultButton_ =
new QPushButton( tr(
"Make Default") );
1446 QVBoxLayout *saveLayout =
new QVBoxLayout();
1447 saveLayout->setAlignment( Qt::AlignTop );
1448 saveLayout->setSpacing( 6 );
1449 saveLayout->addWidget( saveBinaryFile_ );
1450 saveLayout->addWidget( saveStructureGroupBox );
1451 saveLayout->addWidget( saveMakeDefaultButton_ );
1453 saveOptions_ =
new QWidget();
1454 saveOptions_->setLayout( saveLayout );
1457 connect( saveBinaryFile_, SIGNAL( stateChanged(
int) ),
this, SLOT( slotUpdateSaveColorRange() ) );
1458 connect( saveColors_, SIGNAL( stateChanged(
int) ),
this, SLOT( slotUpdateSaveColorRange() ) );
1459 connect( saveMakeDefaultButton_, SIGNAL( clicked() ),
this, SLOT( slotSaveMakeDefaultButtonClicked() ) );
1462 saveBinaryFile_->setChecked ( OpenFlipperSettings().value(
"FilePTS/Save/BinaryFile",
true ).toBool() );
1463 saveNormals_-> setChecked ( OpenFlipperSettings().value(
"FilePTS/Save/Normals",
true ).toBool() );
1464 savePointsizes_->setChecked ( OpenFlipperSettings().value(
"FilePTS/Save/Pointsizes",
true ).toBool() );
1465 saveColors_-> setChecked ( OpenFlipperSettings().value(
"FilePTS/Save/Colors",
true ).toBool() );
1466 saveColorRange_->setCurrentIndex( OpenFlipperSettings().value(
"FilePTS/Save/ColorRange", 0 ).toInt() );
1467 saveIndices_-> setChecked ( OpenFlipperSettings().value(
"FilePTS/Save/Indices",
true ).toBool() );
1470 return saveOptions_;
1476void FilePTSPlugin::slotUpdateSaveColorRange()
1478 saveColorRange_->setEnabled( saveColors_->isChecked() && !saveBinaryFile_->isChecked() );
1485void FilePTSPlugin::slotLoadMakeDefaultButtonClicked()
1489 OpenFlipperSettings().
setValue(
"FilePTS/Load/LoadType", loadOptions_->type->currentIndex() );
1490 OpenFlipperSettings().
setValue(
"FilePTS/Load/PointCount", loadOptions_->pointCount->isChecked() );
1491 OpenFlipperSettings().
setValue(
"FilePTS/Load/BinaryFile", loadOptions_->binary->isChecked() );
1492 OpenFlipperSettings().
setValue(
"FilePTS/Load/Positions", loadOptions_->listWidget->findItems(
"Position",Qt::MatchExactly)[0]->isSelected() );
1493 OpenFlipperSettings().
setValue(
"FilePTS/Load/Normals", loadOptions_->listWidget->findItems(
"Normal",Qt::MatchExactly)[0]->isSelected() );
1494 OpenFlipperSettings().
setValue(
"FilePTS/Load/Pointsizes", loadOptions_->listWidget->findItems(
"PointSize",Qt::MatchExactly)[0]->isSelected() );
1495 OpenFlipperSettings().
setValue(
"FilePTS/Load/Colors", loadOptions_->listWidget->findItems(
"Color",Qt::MatchExactly)[0]->isSelected() );
1496 OpenFlipperSettings().
setValue(
"FilePTS/Load/ColorRange", loadOptions_->comboColor->currentIndex() );
1497 OpenFlipperSettings().
setValue(
"FilePTS/Load/Indices", loadOptions_->listWidget->findItems(
"Index",Qt::MatchExactly)[0]->isSelected() );
1501 for (
auto i = 0 ; i < loadOptions_->listWidget->count() ; ++i ) {
1502 if (loadOptions_->listWidget->item(i)->text() ==
"Position" ) {
1503 order +=
"position,";
1506 if (loadOptions_->listWidget->item(i)->text() ==
"Normal" ) {
1510 if (loadOptions_->listWidget->item(i)->text() ==
"Color" ) {
1514 if (loadOptions_->listWidget->item(i)->text() ==
"PointSize" ) {
1518 if (loadOptions_->listWidget->item(i)->text() ==
"Index" ) {
1526 OpenFlipperSettings().
setValue(
"FilePTS/Load/Order", order );
1533void FilePTSPlugin::slotSaveMakeDefaultButtonClicked()
1536 OpenFlipperSettings().
setValue(
"FilePTS/Save/BinaryFile", saveBinaryFile_->isChecked() );
1537 OpenFlipperSettings().
setValue(
"FilePTS/Save/Normals", saveNormals_-> isChecked() );
1538 OpenFlipperSettings().
setValue(
"FilePTS/Save/Pointsizes", savePointsizes_->isChecked() );
1539 OpenFlipperSettings().
setValue(
"FilePTS/Save/Colors", saveColors_-> isChecked() );
1540 OpenFlipperSettings().
setValue(
"FilePTS/Save/ColorRange", saveColorRange_->currentIndex() );
1541 OpenFlipperSettings().
setValue(
"FilePTS/Save/Indices", saveIndices_-> isChecked() );
std::vector< int > IdList
Standard Type for id Lists used for scripting.
#define DATA_TRIANGLE_MESH
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
const Position & getPosition(int _idx) const
if the data array exists, the entry with the given index is returned, otherwise the default value is ...
QString filename() const
return the filename of the object
void setFromFileName(const QString &_filename)
QString name()
Return a name for the plugin.
QWidget * loadOptionsWidget(QString)
QWidget * saveOptionsWidget(QString)
ACG::SceneGraph::MeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
MeshT * mesh()
return a pointer to the mesh
void setName(QString _name)
Set the name of the Object.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
Kernel::Normal Normal
Normal type.
Kernel::Point Point
Coordinate type.
VertexHandle add_vertex(const VecT &_p)
Add a geometric point to the mesh.
virtual void clear(bool _clearProps=true)
Clear whole mesh.
Type for a Meshobject containing a poly mesh.
SplatCloudNode * splatCloudNode()
Get SplatCloud's scenegraph Node.
SplatCloud * splatCloud()
Get SplatCloud.
void setName(QString _name)
Set the name of the Object.
Pointsize & pointsizes(int _idx)
Get a reference of the predefined property's value.
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.
unsigned int numSplats() const
Get the number of splats.
bool requestNormals()
Request the predefined property.
bool requestPointsizes()
Request the predefined property.
Position & positions(int _idx)
Get a reference of the predefined property's value.
bool requestColors()
Request the predefined property.
bool requestIndices()
Request the predefined property.
Index & indices(int _idx)
Get a reference of the predefined property's value.
Normal & normals(int _idx)
Get a reference of the predefined property's value.
Color & colors(int _idx)
Get a reference of the predefined property's value.
bool requestPositions()
Request the predefined property.
void clear()
Remove all properties and reset the number of splats.
Type for a MeshObject containing a triangle mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
DrawMode NONE
not a valid draw mode
SplatCloudObject * splatCloudObject(BaseObjectData *_object)
Cast an SplatCloudObject to a SplatCloudObject if possible.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
SplatCloudNode * splatCloudNode(BaseObjectData *_object)
Get a SplatCloudNode from an object.