Commit ba2af218 authored by Jan Möbius's avatar Jan Möbius
Browse files

Implement arbitrary ordering for binary files

parent 585c2439
......@@ -199,7 +199,7 @@ private :
FilePTSPlugin::FilePTSPlugin() :
loadOptions_( 0 ),
loadOptions_( nullptr ),
saveOptions_( 0 ),
saveBinaryFile_( 0 ),
saveNormals_ ( 0 ),
......@@ -207,7 +207,6 @@ FilePTSPlugin::FilePTSPlugin() :
saveColors_ ( 0 ),
saveColorRange_( 0 ),
saveIndices_ ( 0 ),
loadMakeDefaultButton_( 0 ),
saveMakeDefaultButton_( 0 )
{ }
......@@ -355,90 +354,99 @@ bool FilePTSPlugin::readBinaryFile( const char *_filename, SplatCloud &_splatClo
if (fileType < 3)
{
// read positions
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
float pos[3];
fread(pos, sizeof(float), 3, file);
std::vector<ReadObject> readObject = getReadObjectOrder();
SplatCloud::Position position;
position[0] = pos[0];
position[1] = pos[1];
position[2] = pos[2];
for ( const ReadObject& element : readObject) {
_splatCloud.positions(i) = position;
}
}
// read normals
if (loadNormals)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
float nrm[3];
fread(nrm, sizeof(float), 3, file);
// read positions
if ( element == PointPos)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
float pos[3];
fread(pos, sizeof(float), 3, file);
SplatCloud::Normal normal;
normal[0] = nrm[0];
normal[1] = nrm[1];
normal[2] = nrm[2];
SplatCloud::Position position;
position[0] = pos[0];
position[1] = pos[1];
position[2] = pos[2];
_splatCloud.normals(i) = normal;
}
}
_splatCloud.positions(i) = position;
}
}
// read pointsizes
if (loadPointsizes)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
float ps = 0.0f;
fread(&ps, sizeof(float), 1, file);
// read normals
if ( element == PointNormal && loadNormals)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
float nrm[3];
fread(nrm, sizeof(float), 3, file);
SplatCloud::Pointsize pointsize;
pointsize = ps;
SplatCloud::Normal normal;
normal[0] = nrm[0];
normal[1] = nrm[1];
normal[2] = nrm[2];
_splatCloud.pointsizes(i) = pointsize;
}
}
_splatCloud.normals(i) = normal;
}
}
// read colors
if (loadColors)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
unsigned int col = 0;
fread(&col, sizeof(unsigned int), 1, file);
// read pointsizes
if (element == PointSize && loadPointsizes)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
float ps = 0.0f;
fread(&ps, sizeof(float), 1, file);
SplatCloud::Color color; // ignore colorrange
color[0] = (unsigned char)((col >> 16) & 0xFF);
color[1] = (unsigned char)((col >> 8) & 0xFF);
color[2] = (unsigned char)((col) & 0xFF);
SplatCloud::Pointsize pointsize;
pointsize = ps;
_splatCloud.colors(i) = color;
}
}
_splatCloud.pointsizes(i) = pointsize;
}
}
// read indices
if (loadIndices)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
int idx = -1;
fread(&idx, sizeof(idx), 1, file);
// read colors
if (element == PointColor && loadColors)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
unsigned int col = 0;
fread(&col, sizeof(unsigned int), 1, file);
SplatCloud::Color color; // ignore colorrange
color[0] = (unsigned char)((col >> 16) & 0xFF);
color[1] = (unsigned char)((col >> 8) & 0xFF);
color[2] = (unsigned char)((col) & 0xFF);
_splatCloud.colors(i) = color;
}
}
// read indices
if (element == PointIndex && loadIndices)
{
unsigned int i;
for (i = 0; i < numSplats; ++i)
{
int idx = -1;
fread(&idx, sizeof(idx), 1, file);
SplatCloud::Index index;
index = idx;
SplatCloud::Index index;
index = idx;
_splatCloud.indices(i) = index;
}
}
_splatCloud.indices(i) = index;
}
}
}
else if (fileType == 3)
{
......@@ -546,20 +554,7 @@ bool FilePTSPlugin::readBinaryFile( const char *_filename, SplatCloud &_splatClo
//----------------------------------------------------------------
bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor ) {
// clear Mesh
_adaptor.clear();
// set default options
bool pointCount = OpenFlipperSettings().value( "FilePTS/Load/PointCount", true ).toBool();
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();
enum ReadObject{ pos,normal,color,size,index };
std::vector<ReadObject> FilePTSPlugin::getReadObjectOrder() {
std::vector<ReadObject> readObject;
......@@ -567,23 +562,23 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor
if ( loadOptions_->listWidget->item(i)->isSelected() ) {
if (loadOptions_->listWidget->item(i)->text() == "Position" ) {
readObject.push_back(pos);
readObject.push_back(PointPos);
}
if (loadOptions_->listWidget->item(i)->text() == "Normal" ) {
readObject.push_back(normal);
readObject.push_back(PointNormal);
}
if (loadOptions_->listWidget->item(i)->text() == "Color" ) {
readObject.push_back(color);
readObject.push_back(PointColor);
}
if (loadOptions_->listWidget->item(i)->text() == "PointSize" ) {
readObject.push_back(size);
readObject.push_back(PointSize);
}
if (loadOptions_->listWidget->item(i)->text() == "Index" ) {
readObject.push_back(index);
readObject.push_back(PointIndex);
}
}
}
......@@ -591,21 +586,43 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor
QString input_order;
for ( const ReadObject& i : readObject) {
if ( i == pos )
if ( i == PointPos )
input_order += " Position";
if ( i == normal )
if ( i == PointNormal )
input_order += " Normal";
if ( i == color )
if ( i == PointColor )
input_order += " Color";
if ( i == size )
if ( i == PointSize )
input_order += " Pointsize";
if ( i == index )
if ( i == PointIndex )
input_order += " Index";
}
emit log(LOGINFO,"Reading data in this order:" + input_order);
if ( readObject[0] != pos ) {
}
//----------------------------------------------------------------
bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor ) {
// clear Mesh
_adaptor.clear();
// set default options
bool pointCount = OpenFlipperSettings().value( "FilePTS/Load/PointCount", true ).toBool();
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();
std::vector<ReadObject> readObject = getReadObjectOrder();
if ( readObject[0] != PointPos ) {
emit log(LOGERR,"Position Attribute has to be first in the File!");
return false;
}
......@@ -666,7 +683,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor
// Read a position, which should be always here:
if ( i == pos )
if ( i == PointPos )
{
double pos[3];
in >> pos[0] >> pos[1] >> pos[2];
......@@ -679,7 +696,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor
}
// Read color, if it has been selected
if( i == color && loadColors )
if( i == PointColor && loadColors )
{
if( loadColorRange == COLORRANGE_0_1 )
{
......@@ -718,7 +735,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor
}
// read normal
if( i==normal && loadNormals )
if( i == PointNormal && loadNormals )
{
double nrm[3];
in >> nrm[0] >> nrm[1] >> nrm[2];
......@@ -738,7 +755,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor
}
// read pointsize
if( i == size && loadPointsizes )
if( i == PointSize && loadPointsizes )
{
float ps;
......@@ -757,7 +774,7 @@ bool FilePTSPlugin::readTextFile ( const char *_filename, AdaptorBase& _adaptor
}
// read index
if( i == index && loadIndices )
if( i == PointNormal && loadIndices )
{
int idx = -1;
......@@ -1309,27 +1326,6 @@ bool FilePTSPlugin::saveObject( int _objectId, QString _filename )
QWidget *FilePTSPlugin::loadOptionsWidget( QString /*_currentFilter*/ )
{
// if( loadOptions_ == 0 )
// {
// slotUpdateLoadColorRange();
// // connect events to slots
// connect( loadBinaryFile_, SIGNAL( stateChanged(int) ), this, SLOT( slotUpdateLoadColorRange() ) );
// connect( loadColors_, SIGNAL( stateChanged(int) ), this, SLOT( slotUpdateLoadColorRange() ) );
// 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() );
// pointCount_-> setChecked ( OpenFlipperSettings().value( "FilePTS/Load/PointCount", true ).toBool() );
// loadNormals_-> setChecked ( OpenFlipperSettings().value( "FilePTS/Load/Normals", true ).toBool() );
// loadPointsizes_-> setChecked ( OpenFlipperSettings().value( "FilePTS/Load/Pointsizes", true ).toBool() );
// loadColors_-> setChecked ( OpenFlipperSettings().value( "FilePTS/Load/Colors", true ).toBool() );
// loadColorRange_-> setCurrentIndex( OpenFlipperSettings().value( "FilePTS/Load/ColorRange", 0 ).toInt() );
// loadIndices_-> setChecked ( OpenFlipperSettings().value( "FilePTS/Load/Indices", true ).toBool() );
// }
if ( loadOptions_ == nullptr) {
loadOptions_ = new ptsLoadWiget();
......@@ -1377,7 +1373,7 @@ QWidget *FilePTSPlugin::loadOptionsWidget( QString /*_currentFilter*/ )
}
return loadOptions_;
return loadOptions_;
}
......@@ -1476,25 +1472,25 @@ void FilePTSPlugin::slotLoadMakeDefaultButtonClicked()
QString order = "";
for ( auto i = 0 ; i < loadOptions_->listWidget->count() ; ++i ) {
if (loadOptions_->listWidget->item(i)->text() == "Position" ) {
order +="position,";
}
if (loadOptions_->listWidget->item(i)->text() == "Position" ) {
order +="position,";
}
if (loadOptions_->listWidget->item(i)->text() == "Normal" ) {
order +="normal,";
}
if (loadOptions_->listWidget->item(i)->text() == "Normal" ) {
order +="normal,";
}
if (loadOptions_->listWidget->item(i)->text() == "Color" ) {
order +="color,";
}
if (loadOptions_->listWidget->item(i)->text() == "Color" ) {
order +="color,";
}
if (loadOptions_->listWidget->item(i)->text() == "PointSize" ) {
order +="size,";
}
if (loadOptions_->listWidget->item(i)->text() == "PointSize" ) {
order +="size,";
}
if (loadOptions_->listWidget->item(i)->text() == "Index" ) {
order +="index,";
}
if (loadOptions_->listWidget->item(i)->text() == "Index" ) {
order +="index,";
}
}
// remove last ","
......
......@@ -114,7 +114,8 @@ class ptsLoadWiget : public QWidget, public Ui::ptsLoadWidget
explicit ptsLoadWiget(QWidget *parent = 0) : QWidget(parent) { setupUi(this); };
};
/// Enum defining read Order
enum ReadObject{ PointPos,PointNormal,PointColor,PointSize,PointIndex };
class FilePTSPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface, LoggingInterface, ScriptInterface, RPCInterface, AboutInfoInterface
{
......@@ -194,6 +195,8 @@ private:
// read and decompress a binary chunk from file stream (snappy compression)
bool readCompressedBinaryChunk( FILE* _file, size_t _compressedSize, char* _dst );
// Get a read Object Order from ui
std::vector<ReadObject> getReadObjectOrder();
// widgets
ptsLoadWiget *loadOptions_;
......@@ -208,7 +211,6 @@ private:
QCheckBox *saveIndices_;
// buttons
QPushButton *loadMakeDefaultButton_;
QPushButton *saveMakeDefaultButton_;
private slots:
......
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