FilePTS.cc 25.2 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
//================================================================
//
/*===========================================================================*\
*                                                                            *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 *                              OpenFlipper                                   *
 *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
 *                           www.openflipper.org                              *
 *                                                                            *
 *--------------------------------------------------------------------------- *
 *  This file is part of OpenFlipper.                                         *
 *                                                                            *
 *  OpenFlipper is free software: you can redistribute it and/or modify       *
 *  it under the terms of the GNU Lesser General Public License as            *
 *  published by the Free Software Foundation, either version 3 of            *
 *  the License, or (at your option) any later version with the               *
 *  following exceptions:                                                     *
 *                                                                            *
 *  If other files instantiate templates or use macros                        *
 *  or inline functions from this file, or you compile this file and          *
 *  link it with other files to produce an executable, this file does         *
 *  not by itself cause the resulting executable to be covered by the         *
 *  GNU Lesser General Public License. This exception does not however        *
 *  invalidate any other reasons why the executable file might be             *
 *  covered by the GNU Lesser General Public License.                         *
 *                                                                            *
 *  OpenFlipper is distributed in the hope that it will be useful,            *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
 *  GNU Lesser General Public License for more details.                       *
 *                                                                            *
 *  You should have received a copy of the GNU LesserGeneral Public           *
 *  License along with OpenFlipper. If not,                                   *
 *  see <http://www.gnu.org/licenses/>.                                       *
 *                                                                            *
 \*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
36
37
38

/*===========================================================================*\
*                                                                            *
Jan Möbius's avatar
Jan Möbius committed
39
40
41
42
43
 *   $Revision$                                                       *
 *   $LastChangedBy$                                                *
 *   $Date$                     *
 *                                                                            *
 \*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

//================================================================
//
//  CLASS FilePTSPlugin - IMPLEMENTATION
//
//================================================================
//== INCLUDES ====================================================
#include "FilePTS.hh"

#include <QtGui>
#include <QFileInfo>
#include <QSettings>

#include <iostream>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

#include <OpenMesh/Core/IO/IOManager.hh>

//== CONSTANTS ===================================================

Jan Möbius's avatar
Jan Möbius committed
66
// constants of colorrange drop down box
Jan Möbius's avatar
Jan Möbius committed
67
static const int COLORRANGE_0_1 = 0;
Jan Möbius's avatar
Jan Möbius committed
68
static const int COLORRANGE_0_255 = 1;
Jan Möbius's avatar
Jan Möbius committed
69
70
71

//== IMPLEMENTATION ==============================================

Jan Möbius's avatar
Jan Möbius committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
FilePTSPlugin::FilePTSPlugin() :
        loadOptions_(0),
        saveOptions_(0),
        loadBinaryFile_(0),
        loadNormals_(0),
        loadPointsizes_(0),
        loadColors_(0),
        loadColorRange_(0),
        loadNormalizeSize_(0),
        saveBinaryFile_(0),
        saveNormals_(0),
        savePointsizes_(0),
        saveColors_(0),
        saveColorRange_(0),
        loadMakeDefaultButton_(0),
        saveMakeDefaultButton_(0)

{

}


94
bool FilePTSPlugin::readBinaryFile( std::ifstream &_instream, SplatCloud *_splatCloud )
Jan Möbius's avatar
Jan Möbius committed
95
{
Jan Möbius's avatar
Jan Möbius committed
96
97
  // set default options
  bool loadNormals = true;
Jan Möbius's avatar
Jan Möbius committed
98
99
  bool loadPointsizes = false;
  bool loadColors = false;
Jan Möbius's avatar
Jan Möbius committed
100
//	int  loadColorRange = 0;
Jan Möbius's avatar
Jan Möbius committed
101

Jan Möbius's avatar
Jan Möbius committed
102
103
104
105
106
// get options
  if (OpenFlipper::Options::gui() && loadOptions_) {
    loadNormals = loadNormals_->isChecked();
    loadPointsizes = loadPointsizes_->isChecked();
    loadColors = loadColors_->isChecked();
Jan Möbius's avatar
Jan Möbius committed
107
//		loadColorRange = loadColorRange_->currentIndex();
Jan Möbius's avatar
Jan Möbius committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  }

  // read file type
  int fileType;
  _instream.read((char *) &fileType, sizeof(int));

  // check file type
  if (fileType != 1 && fileType != 2)
    return false; // return failure

  // read number of points
  unsigned int numPoints;
  _instream.read((char *) &numPoints, sizeof(unsigned int));

  // read points
  {
    unsigned int i;
    for (i = 0; i < numPoints; ++i) {
      float pnt[3];
      _instream.read((char *) pnt, 3 * sizeof(float));

      SplatCloud::Point point;
      point[0] = pnt[0];
      point[1] = pnt[1];
      point[2] = pnt[2];

134
      _splatCloud->addPoint(point);
Jan Möbius's avatar
Jan Möbius committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    }
  }

  // read normals
  if (loadNormals) {
    unsigned int i;
    for (i = 0; i < numPoints; ++i) {
      float nrm[3];
      _instream.read((char *) nrm, 3 * sizeof(float));

      SplatCloud::Normal normal;
      normal[0] = nrm[0];
      normal[1] = nrm[1];
      normal[2] = nrm[2];

150
      _splatCloud->addNormal(normal);
Jan Möbius's avatar
Jan Möbius committed
151
152
153
154
155
156
157
158
159
160
161
162
163
    }
  }

  // read pointsizes
  if (loadPointsizes) {
    unsigned int i;
    for (i = 0; i < numPoints; ++i) {
      float ps;
      _instream.read((char *) &ps, sizeof(float));

      SplatCloud::Pointsize pointsize;
      pointsize = ps;

164
      _splatCloud->addPointsize(pointsize);
Jan Möbius's avatar
Jan Möbius committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    }
  }

  // read colors
  if (loadColors) {
    unsigned int i;
    for (i = 0; i < numPoints; ++i) {
      unsigned int col;
      _instream.read((char *) &col, sizeof(unsigned int));

      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);

180
      _splatCloud->addColor(color);
Jan Möbius's avatar
Jan Möbius committed
181
182
183
184
185
    }
  }

  // return success
  return true;
Jan Möbius's avatar
Jan Möbius committed
186
187
188
189
}

//----------------------------------------------------------------

190
bool FilePTSPlugin::readTextFile( std::ifstream &_instream, SplatCloud *_splatCloud )
Jan Möbius's avatar
Jan Möbius committed
191
{
Jan Möbius's avatar
Jan Möbius committed
192
193
  // set default options
  bool loadNormals = true;
Jan Möbius's avatar
Jan Möbius committed
194
195
  bool loadPointsizes = false;
  bool loadColors = false;
Jan Möbius's avatar
Jan Möbius committed
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  int loadColorRange = 0;

  // get options
  if (OpenFlipper::Options::gui() && loadOptions_) {
    loadNormals = loadNormals_->isChecked();
    loadPointsizes = loadPointsizes_->isChecked();
    loadColors = loadColors_->isChecked();
    loadColorRange = loadColorRange_->currentIndex();
  }

  char buffer[4096];

  while (true) {
    _instream.getline(buffer, 4096, '\n');
    std::string strbuffer(buffer);
    std::stringstream sstream(strbuffer);

    if (_instream.eof())
      break;

    // read point
    {
      float pnt[3];
      sstream >> pnt[0];
      sstream >> pnt[1];
      sstream >> pnt[2];

      SplatCloud::Point point;
      point[0] = pnt[0];
      point[1] = pnt[1];
      point[2] = pnt[2];

228
      _splatCloud->addPoint(point);
Jan Möbius's avatar
Jan Möbius committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
    }

    // read color
    if (loadColors) {
      float col[3];
      sstream >> col[0];
      sstream >> col[1];
      sstream >> col[2];

      SplatCloud::Color color;

      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];
      }

251
      _splatCloud->addColor(color);
Jan Möbius's avatar
Jan Möbius committed
252
253
254
255
256
257
258
259
260
261
262
263
264
265
    }

    // read normal
    if (loadNormals) {
      float nrm[3];
      sstream >> nrm[0];
      sstream >> nrm[1];
      sstream >> nrm[2];

      SplatCloud::Normal normal;
      normal[0] = nrm[0];
      normal[1] = nrm[1];
      normal[2] = nrm[2];

266
      _splatCloud->addNormal(normal);
Jan Möbius's avatar
Jan Möbius committed
267
268
269
270
271
272
273
274
275
276
    }

    // read pointsize
    if (loadPointsizes) {
      float ps;
      sstream >> ps;

      SplatCloud::Pointsize pointsize;
      pointsize = ps;

277
      _splatCloud->addPointsize(pointsize);
Jan Möbius's avatar
Jan Möbius committed
278
279
280
281
282
    }
  }

  // return success
  return true;
Jan Möbius's avatar
Jan Möbius committed
283
284
285
286
}

//----------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
287
bool FilePTSPlugin::writeBinaryFile(std::ofstream &_outstream, const SplatCloudNode *_splatCloudNode)
Jan Möbius's avatar
Jan Möbius committed
288
{
Jan Möbius's avatar
Jan Möbius committed
289
290
  // set default options
  bool saveNormals = true;
Jan Möbius's avatar
Jan Möbius committed
291
292
  bool savePointsizes = false;
  bool saveColors = false;
Jan Möbius's avatar
Jan Möbius committed
293
//	int  saveColorRange = 0;
294

Jan Möbius's avatar
Jan Möbius committed
295
  // get current translation and scaling
296
297
  float s = 1.0f / _splatCloudNode->splatCloud().scaleFactor();
  SplatCloud::Point t = -_splatCloudNode->splatCloud().translation();
298

Jan Möbius's avatar
Jan Möbius committed
299
300
301
302
303
  // get options
  if (OpenFlipper::Options::gui() && saveOptions_) {
    saveNormals = saveNormals_->isChecked();
    savePointsizes = savePointsizes_->isChecked();
    saveColors = saveColors_->isChecked();
Jan Möbius's avatar
Jan Möbius committed
304
//		saveColorRange = saveColorRange_->currentIndex();
Jan Möbius's avatar
Jan Möbius committed
305
306
307
308
309
310
311
  }

  // write file type
  int fileType = 1;
  _outstream.write((char *) &fileType, sizeof(int));

  // write number of points
312
  unsigned int numPoints = _splatCloudNode->splatCloud().numPoints();
Jan Möbius's avatar
Jan Möbius committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
  _outstream.write((char *) &numPoints, sizeof(unsigned int));

  // write points
  {
    unsigned int i;
    for (i = 0; i < numPoints; ++i) {
      const SplatCloud::Point &point = _splatCloudNode->getPoint(i);

      float pnt[3];
      pnt[0] = s * point[0] + t[0];
      pnt[1] = s * point[1] + t[1];
      pnt[2] = s * point[2] + t[2];

      _outstream.write((char *) pnt, 3 * sizeof(float));
    }
  }

  // write normals
  if (saveNormals) {
    unsigned int i;
    for (i = 0; i < numPoints; ++i) {
      const SplatCloud::Normal &normal = _splatCloudNode->getNormal(i);

      float nrm[3];
      nrm[0] = normal[0];
      nrm[1] = normal[1];
      nrm[2] = normal[2];

      _outstream.write((char *) nrm, 3 * sizeof(float));
    }
  }

  // write pointsizes
  if (savePointsizes) {
    unsigned int i;
    for (i = 0; i < numPoints; ++i) {
      const SplatCloud::Pointsize &pointsize = _splatCloudNode->getPointsize(i);

      float ps;
      ps = s * pointsize;

      _outstream.write((char *) &ps, sizeof(float));
    }
  }

  // write colors
  if (saveColors) {
    unsigned int i;
    for (i = 0; i < numPoints; ++i) {
      const SplatCloud::Color &color = _splatCloudNode->getColor(i);

      unsigned int col; // ignore colorrange
      col = (0xFF << 24) | (color[0] << 16) | (color[1] << 8) | (color[2]);

      _outstream.write((char *) &col, sizeof(unsigned int));
    }
  }

  // return success
  return true;
Jan Möbius's avatar
Jan Möbius committed
373
374
375
376
}

//----------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
377
bool FilePTSPlugin::writeTextFile(std::ofstream &_outstream, const SplatCloudNode *_splatCloudNode)
Jan Möbius's avatar
Jan Möbius committed
378
{
Jan Möbius's avatar
Jan Möbius committed
379
380
  // set default options
  bool saveNormals = true;
Jan Möbius's avatar
Jan Möbius committed
381
382
  bool savePointsizes = false;
  bool saveColors = false;
Jan Möbius's avatar
Jan Möbius committed
383
384
385
  int saveColorRange = 0;

  // get current translation and scale factor
386
387
  float s = 1.0f / _splatCloudNode->splatCloud().scaleFactor();
  SplatCloud::Point t = -_splatCloudNode->splatCloud().translation();
Jan Möbius's avatar
Jan Möbius committed
388
389
390
391
392
393
394
395
396
397

  // get options
  if (OpenFlipper::Options::gui() && saveOptions_) {
    saveNormals = saveNormals_->isChecked();
    savePointsizes = savePointsizes_->isChecked();
    saveColors = saveColors_->isChecked();
    saveColorRange = saveColorRange_->currentIndex();
  }

  // for all points...
398
  unsigned int i, numPoints = _splatCloudNode->splatCloud().numPoints();
Jan Möbius's avatar
Jan Möbius committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
  for (i = 0; i < numPoints; ++i) {
    // write point
    {
      const SplatCloud::Point &point = _splatCloudNode->getPoint(i);

      float pnt[3];
      pnt[0] = s * point[0] + t[0];
      pnt[1] = s * point[1] + t[1];
      pnt[2] = s * point[2] + t[2];

      _outstream << pnt[0];
      _outstream << " " << pnt[1];
      _outstream << " " << pnt[2];
    }

    // write color
    if (saveColors) {
      const SplatCloud::Color &color = _splatCloudNode->getColor(i);

      if (saveColorRange == COLORRANGE_0_1) {
        static const float RCP255 = 1.0f / 255.0f;

        float col[3];
        col[0] = RCP255 * color[0];
        col[1] = RCP255 * color[1];
        col[2] = RCP255 * color[2];

        _outstream << " " << col[0];
        _outstream << " " << col[1];
        _outstream << " " << col[2];
      } else // saveColorRange == COLORRANGE_0_255
      {
        int col[3]; // use int, *not* unsigned char !
        col[0] = color[0];
        col[1] = color[1];
        col[2] = color[2];

        _outstream << " " << col[0];
        _outstream << " " << col[1];
        _outstream << " " << col[2];
      }
    }

    // write normal
    if (saveNormals) {
      const SplatCloud::Normal &normal = _splatCloudNode->getNormal(i);

      float nrm[3];
      nrm[0] = normal[0];
      nrm[1] = normal[1];
      nrm[2] = normal[2];

      _outstream << " " << nrm[0];
      _outstream << " " << nrm[1];
      _outstream << " " << nrm[2];
    }

    // write pointsize
    if (savePointsizes) {
      const SplatCloud::Pointsize &pointsize = _splatCloudNode->getPointsize(i);

      float ps;
      ps = s * pointsize;

      _outstream << " " << ps;
    }

    _outstream << std::endl;
  }

  // return success
  return true;
Jan Möbius's avatar
Jan Möbius committed
471
472
473
474
}

//----------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
475
int FilePTSPlugin::loadObject(QString _filename)
Jan Möbius's avatar
Jan Möbius committed
476
{
Jan Möbius's avatar
Jan Möbius committed
477
  // set default options
Jan Möbius's avatar
Jan Möbius committed
478
479
  bool loadBinaryFile = false;
  bool loadNormalizeSize = false;
Jan Möbius's avatar
Jan Möbius committed
480
481
482
483
484
485
486
487
488

  // get options
  if (OpenFlipper::Options::gui() && loadOptions_) {
    loadBinaryFile = loadBinaryFile_->isChecked();
    loadNormalizeSize = loadNormalizeSize_->isChecked();
  }

  // add a new, empty splatcloud object
  int id = -1;
Jan Möbius's avatar
Jan Möbius committed
489
  emit addEmptyObject(DATA_SPLATCLOUD, id);
Jan Möbius's avatar
Jan Möbius committed
490
491
492
493
494
495
496
497
498
499

  // get splatcloud-object by id
  SplatCloudObject *splatCloudObject = 0;
  if (!PluginFunctions::getObject(id, splatCloudObject))
    return 0; // failure, but empty object was added

  // check if splatcloud-object is okay
  if (!splatCloudObject)
    return 0; // failure, but empty object was added

500
501
  // get splatcloud and scenegraph splatcloud-node
  SplatCloud     *splatCloud     = splatCloudObject->splatCloud();
Jan Möbius's avatar
Jan Möbius committed
502
503
504
  SplatCloudNode *splatCloudNode = splatCloudObject->splatCloudNode();

  // check if splatcloud-node if okay
505
  if( !splatCloud || !splatCloudNode )
Jan Möbius's avatar
Jan Möbius committed
506
507
508
509
510
511
512
513
514
515
516
517
    return 0; // failure, but empty object was added

  // open file
  char *fn = QByteArray(_filename.toLatin1()).data();
  std::ifstream instream(fn, loadBinaryFile ? (std::ios::in | std::ios::binary) : std::ios::in);

  // check if file was opened
  if (!instream.is_open())
    return 0; // failure, but empty object was added

  // read file
  if (loadBinaryFile) {
518
    if (!readBinaryFile(instream, splatCloud))
Jan Möbius's avatar
Jan Möbius committed
519
520
      return 0; // failure, but empty object was added
  } else {
521
    if (!readTextFile(instream, splatCloud))
Jan Möbius's avatar
Jan Möbius committed
522
523
524
525
526
527
528
529
530
531
532
533
      return 0; // failure, but empty object was added
  }

  // check if something went wrong
  if (instream.bad())
    return 0; // failure, but empty object was added

  // close file
  instream.close();

  // normalize size
  if (loadNormalizeSize) {
534
    splatCloud->normalizeSize();
Jan Möbius's avatar
Jan Möbius committed
535
536
537
538
539
540
  }

  // remember filename
  splatCloudObject->setFromFileName(_filename);

  // emit signals that the object has to be updated and that a file was opened
Jan Möbius's avatar
Jan Möbius committed
541
542
  emit updatedObject(splatCloudObject->id(), UPDATE_ALL);
  emit openedFile(splatCloudObject->id());
Jan Möbius's avatar
Jan Möbius committed
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566

  // 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);
    }
  }

  // return the id of the new splatcloud object
  return id;
Jan Möbius's avatar
Jan Möbius committed
567
568
569
570
}

//----------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
571
bool FilePTSPlugin::saveObject(int _id, QString _filename)
Jan Möbius's avatar
Jan Möbius committed
572
{
Jan Möbius's avatar
Jan Möbius committed
573
  // set default options
Jan Möbius's avatar
Jan Möbius committed
574
  bool saveBinaryFile = false;
Jan Möbius's avatar
Jan Möbius committed
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593

  // get options
  if (OpenFlipper::Options::gui() && saveOptions_) {
    saveBinaryFile = saveBinaryFile_->isChecked();
  }

  // get splatcloud-object by id
  SplatCloudObject *splatCloudObject = 0;
  if (!PluginFunctions::getObject(_id, splatCloudObject))
    return false; // failure

  // check if splatcloud-object is okay
  if (!splatCloudObject)
    return false; // failure

  // get scenegraph splatcloud-node
  const SplatCloudNode *splatCloudNode = splatCloudObject->splatCloudNode();

  // check if splatcloud-node if okay
594
  if( !splatCloudNode )
Jan Möbius's avatar
Jan Möbius committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
    return 0; // failure, but empty object was added

  // open file
  char *fn = QByteArray(_filename.toLatin1()).data();
  std::ofstream outstream(fn, saveBinaryFile ? (std::ios::out | std::ios::binary) : std::ios::out);

  // check if file was opened
  if (!outstream.is_open())
    return false; // failure

  // write file
  if (saveBinaryFile) {
    if (!writeBinaryFile(outstream, splatCloudNode))
      return false; // failure
  } else {
    if (!writeTextFile(outstream, splatCloudNode))
      return false; // failure
  }

  // check if something went wrong
  if (outstream.bad())
    return false;

  // close file
  outstream.close();

  // return success
  return true;
Jan Möbius's avatar
Jan Möbius committed
623
624
625
626
}

//----------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
627
QWidget *FilePTSPlugin::loadOptionsWidget(QString /*_currentFilter*/)
Jan Möbius's avatar
Jan Möbius committed
628
{
Jan Möbius's avatar
Jan Möbius committed
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
  if (loadOptions_ == 0) {
    // create new widget (including Load Options and buttons)

    loadBinaryFile_ = new QCheckBox("Load as Binary File");

    loadNormals_ = new QCheckBox("Contains Normals");
    loadPointsizes_ = new QCheckBox("Contains Pointsizes");
    loadColors_ = new QCheckBox("Contains Colors");

    loadColorRange_ = new QComboBox();
    loadColorRange_->addItem("[0..1]");
    loadColorRange_->addItem("[0..255]");
    slotUpdateLoadColorRange();

    QHBoxLayout *loadColorsLayout = new QHBoxLayout();
    loadColorsLayout->setSpacing(6);
    loadColorsLayout->addWidget(loadColors_);
    loadColorsLayout->addWidget(loadColorRange_);

    QVBoxLayout *loadStructureLayout = new QVBoxLayout();
    loadStructureLayout->setSpacing(6);
    loadStructureLayout->addWidget(loadNormals_);
    loadStructureLayout->addWidget(loadPointsizes_);
    loadStructureLayout->addItem(loadColorsLayout);

    QGroupBox *loadStructureGroupBox = new QGroupBox("Internal File Structure");
    loadStructureGroupBox->setLayout(loadStructureLayout);

    loadNormalizeSize_ = new QCheckBox("Normalize Size");

    loadMakeDefaultButton_ = new QPushButton("Make Default");

    QVBoxLayout *loadLayout = new QVBoxLayout();
    loadLayout->setAlignment(Qt::AlignTop);
    loadLayout->setSpacing(6);
    loadLayout->addWidget(loadBinaryFile_);
    loadLayout->addWidget(loadStructureGroupBox);
    loadLayout->addWidget(loadNormalizeSize_);
    loadLayout->addWidget(loadMakeDefaultButton_);

    loadOptions_ = new QWidget();
    loadOptions_->setLayout(loadLayout);

    // connect events to slots
Jan Möbius's avatar
Jan Möbius committed
673
674
675
    connect( loadBinaryFile_, SIGNAL( stateChanged(int) ), this, SLOT( slotUpdateLoadColorRange() ) );
    connect( loadColors_, SIGNAL( stateChanged(int) ), this, SLOT( slotUpdateLoadColorRange() ) );
    connect(loadMakeDefaultButton_, SIGNAL(clicked()), this, SLOT(slotLoadMakeDefaultButtonClicked()));
Jan Möbius's avatar
Jan Möbius committed
676
677
678
679
680
681
682
683
684
685
686

    // get Load Options from OpenFlipper (from disc)
    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());
    loadColors_->setChecked(OpenFlipperSettings().value("FilePTS/Load/Colors", true).toBool());
    loadColorRange_->setCurrentIndex(OpenFlipperSettings().value("FilePTS/Load/ColorRange", 0).toInt());
    loadNormalizeSize_->setChecked(OpenFlipperSettings().value("FilePTS/Load/NormalizeSize", true).toBool());
  }

  return loadOptions_;
Jan Möbius's avatar
Jan Möbius committed
687
688
689
690
}

//----------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
691
QWidget *FilePTSPlugin::saveOptionsWidget(QString _currentFilter)
Jan Möbius's avatar
Jan Möbius committed
692
{
Jan Möbius's avatar
Jan Möbius committed
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
  if (saveOptions_ == 0) {
    // create new widget (including Save Options and buttons)

    saveBinaryFile_ = new QCheckBox("Save as Binary File");

    saveNormals_ = new QCheckBox("Save Normals");
    savePointsizes_ = new QCheckBox("Save Pointsizes");
    saveColors_ = new QCheckBox("Save Colors");

    saveColorRange_ = new QComboBox();
    saveColorRange_->addItem("[0..1]");
    saveColorRange_->addItem("[0..255]");
    slotUpdateSaveColorRange();

    QHBoxLayout *saveColorsLayout = new QHBoxLayout();
    saveColorsLayout->setSpacing(6);
    saveColorsLayout->addWidget(saveColors_);
    saveColorsLayout->addWidget(saveColorRange_);

    QVBoxLayout *saveStructureLayout = new QVBoxLayout();
    saveStructureLayout->setSpacing(6);
    saveStructureLayout->addWidget(saveNormals_);
    saveStructureLayout->addWidget(savePointsizes_);
    saveStructureLayout->addItem(saveColorsLayout);

    QGroupBox *saveStructureGroupBox = new QGroupBox("Internal File Structure");
    saveStructureGroupBox->setLayout(saveStructureLayout);

    saveMakeDefaultButton_ = new QPushButton("Make Default");

    QVBoxLayout *saveLayout = new QVBoxLayout();
    saveLayout->setAlignment(Qt::AlignTop);
    saveLayout->setSpacing(6);
    saveLayout->addWidget(saveBinaryFile_);
    saveLayout->addWidget(saveStructureGroupBox);
    saveLayout->addWidget(saveMakeDefaultButton_);

    saveOptions_ = new QWidget();
    saveOptions_->setLayout(saveLayout);

    // connect events to slots
Jan Möbius's avatar
Jan Möbius committed
734
735
736
    connect( saveBinaryFile_, SIGNAL( stateChanged(int) ), this, SLOT( slotUpdateSaveColorRange() ) );
    connect( saveColors_, SIGNAL( stateChanged(int) ), this, SLOT( slotUpdateSaveColorRange() ) );
    connect(saveMakeDefaultButton_, SIGNAL(clicked()), this, SLOT(slotSaveMakeDefaultButtonClicked()));
Jan Möbius's avatar
Jan Möbius committed
737
738
739
740
741
742
743
744
745
746

    // get Save Options from OpenFlipper (from disc)
    saveBinaryFile_->setChecked(OpenFlipperSettings().value("FilePTS/Save/BinaryFile", true).toBool());
    saveNormals_->setChecked(OpenFlipperSettings().value("FilePTS/Save/Normals", true).toBool());
    savePointsizes_->setChecked(OpenFlipperSettings().value("FilePTS/Save/Pointsizes", true).toBool());
    saveColors_->setChecked(OpenFlipperSettings().value("FilePTS/Save/Colors", true).toBool());
    saveColorRange_->setCurrentIndex(OpenFlipperSettings().value("FilePTS/Save/ColorRange", 0).toInt());
  }

  return saveOptions_;
Jan Möbius's avatar
Jan Möbius committed
747
748
749
750
}

//----------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
751
752
void FilePTSPlugin::slotUpdateLoadColorRange()
{
Jan Möbius's avatar
Jan Möbius committed
753
  loadColorRange_->setEnabled(loadColors_->isChecked() && !loadBinaryFile_->isChecked());
Jan Möbius's avatar
Jan Möbius committed
754
755
756
757
758
759
}

//----------------------------------------------------------------

void FilePTSPlugin::slotUpdateSaveColorRange()
{
Jan Möbius's avatar
Jan Möbius committed
760
  saveColorRange_->setEnabled(saveColors_->isChecked() && !saveBinaryFile_->isChecked());
Jan Möbius's avatar
Jan Möbius committed
761
762
763
764
}

//----------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
765
766
void FilePTSPlugin::slotLoadMakeDefaultButtonClicked()
{
Jan Möbius's avatar
Jan Möbius committed
767
768
769
770
771
772
773
  // pass our Load Options to OpenFlipper (to disc)
  OpenFlipperSettings().setValue("FilePTS/Load/BinaryFile", loadBinaryFile_->isChecked());
  OpenFlipperSettings().setValue("FilePTS/Load/Normals", loadNormals_->isChecked());
  OpenFlipperSettings().setValue("FilePTS/Load/Pointsizes", loadPointsizes_->isChecked());
  OpenFlipperSettings().setValue("FilePTS/Load/Colors", loadColors_->isChecked());
  OpenFlipperSettings().setValue("FilePTS/Load/ColorRange", loadColorRange_->currentIndex());
  OpenFlipperSettings().setValue("FilePTS/Load/NormalizeSize", loadNormalizeSize_->isChecked());
Jan Möbius's avatar
Jan Möbius committed
774
775
776
777
778
779
780
781

//	OpenFlipperSettings().setValue( "Core/File/UseLoadDefaults", true );
}

//----------------------------------------------------------------

void FilePTSPlugin::slotSaveMakeDefaultButtonClicked()
{
Jan Möbius's avatar
Jan Möbius committed
782
783
784
785
786
787
  // pass our Save Options to OpenFlipper (to disc)
  OpenFlipperSettings().setValue("FilePTS/Save/BinaryFile", saveBinaryFile_->isChecked());
  OpenFlipperSettings().setValue("FilePTS/Save/Normals", saveNormals_->isChecked());
  OpenFlipperSettings().setValue("FilePTS/Save/Pointsizes", savePointsizes_->isChecked());
  OpenFlipperSettings().setValue("FilePTS/Save/Colors", saveColors_->isChecked());
  OpenFlipperSettings().setValue("FilePTS/Save/ColorRange", saveColorRange_->currentIndex());
Jan Möbius's avatar
Jan Möbius committed
788
789
790
791
}

//================================================================

Jan Möbius's avatar
Jan Möbius committed
792
Q_EXPORT_PLUGIN2( fileptsplugin, FilePTSPlugin );