Developer Documentation
FilePTS.cc
1 //================================================================
2 //
3 /*===========================================================================*\
4 * *
5  * OpenFlipper *
6  * Copyright (c) 2001-2015, RWTH-Aachen University *
7  * Department of Computer Graphics and Multimedia *
8  * All rights reserved. *
9  * www.openflipper.org *
10  * *
11  *---------------------------------------------------------------------------*
12  * This file is part of OpenFlipper. *
13  *---------------------------------------------------------------------------*
14  * *
15  * Redistribution and use in source and binary forms, with or without *
16  * modification, are permitted provided that the following conditions *
17  * are met: *
18  * *
19  * 1. Redistributions of source code must retain the above copyright notice, *
20  * this list of conditions and the following disclaimer. *
21  * *
22  * 2. Redistributions in binary form must reproduce the above copyright *
23  * notice, this list of conditions and the following disclaimer in the *
24  * documentation and/or other materials provided with the distribution. *
25  * *
26  * 3. Neither the name of the copyright holder nor the names of its *
27  * contributors may be used to endorse or promote products derived from *
28  * this software without specific prior written permission. *
29  * *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
32  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
33  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
34  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
35  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
36  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
37  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
38  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
39  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
40  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
41  * *
42  \*===========================================================================*/
43 
44 /*===========================================================================*\
45 * *
46  * $Revision$ *
47  * $LastChangedBy$ *
48  * $Date$ *
49  * *
50  \*===========================================================================*/
51 
52 
53 //================================================================
54 //
55 // CLASS FilePTSPlugin - IMPLEMENTATION
56 //
57 //================================================================
58 
59 
60 //== INCLUDES ====================================================
61 
62 
63 #include "FilePTS.hh"
64 
65 #if QT_VERSION >= 0x050000
66  #include <QtWidgets>
67 #else
68  #include <QtGui>
69 #endif
70 
73 
74 
75 //== CONSTANTS ===================================================
76 
77 
78 // constants of color range drop down box
79 static const int COLORRANGE_0_1 = 0;
80 //static const int COLORRANGE_0_255 = 1;
81 
82 
83 //== IMPLEMENTATION ==============================================
84 
85 
86 FilePTSPlugin::FilePTSPlugin() :
87  loadOptions_( 0 ),
88  saveOptions_( 0 ),
89  loadBinaryFile_( 0 ),
90  loadNormals_ ( 0 ),
91  loadPointsizes_( 0 ),
92  loadColors_ ( 0 ),
93  loadColorRange_( 0 ),
94  loadIndices_ ( 0 ),
95  saveBinaryFile_( 0 ),
96  saveNormals_ ( 0 ),
97  savePointsizes_( 0 ),
98  saveColors_ ( 0 ),
99  saveColorRange_( 0 ),
100  saveIndices_ ( 0 ),
101  loadMakeDefaultButton_( 0 ),
102  saveMakeDefaultButton_( 0 )
103 { }
104 
105 
106 //----------------------------------------------------------------
107 
108 
109 bool FilePTSPlugin::readBinaryFile( const char *_filename, SplatCloud &_splatCloud ) /*const*/
110 {
111  // clear splatcloud
112  _splatCloud.clear();
113 
114  // set default options
115  bool loadNormals = OpenFlipperSettings().value( "FilePTS/Load/Normals", true ).toBool();
116  bool loadPointsizes = OpenFlipperSettings().value( "FilePTS/Load/Pointsizes", false ).toBool();
117  bool loadColors = OpenFlipperSettings().value( "FilePTS/Load/Colors", false ).toBool();
118 //int loadColorRange = 0;
119  bool loadIndices = OpenFlipperSettings().value( "FilePTS/Load/Indices", false ).toBool();
120 
121  // get options
122  if( OpenFlipper::Options::gui() && loadOptions_ )
123  {
124  loadNormals = loadNormals_-> isChecked();
125  loadPointsizes = loadPointsizes_->isChecked();
126  loadColors = loadColors_-> isChecked();
127 // loadColorRange = loadColorRange_->currentIndex();
128  loadIndices = loadIndices_-> isChecked();
129  }
130 
131  // request properties
132  bool success = true;
133  { if( !_splatCloud.requestPositions() ) success = false; }
134  if( loadNormals ) { if( !_splatCloud.requestNormals() ) success = false; }
135  if( loadPointsizes ) { if( !_splatCloud.requestPointsizes() ) success = false; }
136  if( loadColors ) { if( !_splatCloud.requestColors() ) success = false; }
137  if( loadIndices ) { if( !_splatCloud.requestIndices() ) success = false; }
138 
139  // check success of requests
140  if( !success )
141  {
142  emit log( LOGERR, tr("Out of memory for input file \"%1\".\n").arg( _filename ) );
143  return false; // return failure
144  }
145 
146  // open file
147  FILE *file = fopen( _filename, "rb" );
148  if( !file )
149  {
150  emit log( LOGERR, tr("Could not open input file \"%1\".\n").arg( _filename ) );
151  return false;
152  }
153 
154  // read file type
155  int fileType = 0;
156  fread( &fileType, sizeof(int), 1, file );
157 
158  // check file type
159  if( fileType != 1 && fileType != 2 )
160  {
161  emit log( LOGERR, tr("Bad filetype (%1) in input file \"%2\".\n").arg( QString::number( fileType ), _filename ) );
162  fclose( file );
163  return false; // return failure
164  }
165 
166  // read number of splats
167  unsigned int numSplats = 0;
168  fread( &numSplats, sizeof(unsigned int), 1, file );
169 
170  // set number of splats
171  _splatCloud.resizeSplats( numSplats );
172 
173  // read positions
174  {
175  unsigned int i;
176  for( i=0; i<numSplats; ++i )
177  {
178  float pos[3];
179  fread( pos, sizeof(float), 3, file );
180 
181  SplatCloud::Position position;
182  position[0] = pos[0];
183  position[1] = pos[1];
184  position[2] = pos[2];
185 
186  _splatCloud.positions( i ) = position;
187  }
188  }
189 
190  // read normals
191  if( loadNormals )
192  {
193  unsigned int i;
194  for( i=0; i<numSplats; ++i )
195  {
196  float nrm[3];
197  fread( nrm, sizeof(float), 3, file );
198 
199  SplatCloud::Normal normal;
200  normal[0] = nrm[0];
201  normal[1] = nrm[1];
202  normal[2] = nrm[2];
203 
204  _splatCloud.normals( i ) = normal;
205  }
206  }
207 
208  // read pointsizes
209  if( loadPointsizes )
210  {
211  unsigned int i;
212  for( i=0; i<numSplats; ++i )
213  {
214  float ps = 0.0f;
215  fread( &ps, sizeof(float), 1, file );
216 
217  SplatCloud::Pointsize pointsize;
218  pointsize = ps;
219 
220  _splatCloud.pointsizes( i ) = pointsize;
221  }
222  }
223 
224  // read colors
225  if( loadColors )
226  {
227  unsigned int i;
228  for( i=0; i<numSplats; ++i )
229  {
230  unsigned int col = 0;
231  fread( &col, sizeof(unsigned int), 1, file );
232 
233  SplatCloud::Color color; // ignore colorrange
234  color[0] = (unsigned char) ((col >> 16) & 0xFF);
235  color[1] = (unsigned char) ((col >> 8) & 0xFF);
236  color[2] = (unsigned char) ((col ) & 0xFF);
237 
238  _splatCloud.colors( i ) = color;
239  }
240  }
241 
242  // read indices
243  if( loadIndices )
244  {
245  unsigned int i;
246  for( i=0; i<numSplats; ++i )
247  {
248  int idx = -1;
249  fread( &idx, sizeof(idx), 1, file );
250 
251  SplatCloud::Index index;
252  index = idx;
253 
254  _splatCloud.indices( i ) = index;
255  }
256  }
257 
258  // check for errors
259  if( ferror( file ) )
260  {
261  emit log( LOGERR, tr("Could not read input file \"%1\".\n").arg( _filename ) );
262  fclose( file );
263  return false; // return failure
264  }
265  if( feof( file ) )
266  {
267  emit log( LOGERR, tr("Unexpected end in input file \"%1\".\n").arg( _filename ) );
268  fclose( file );
269  return false; // return failure
270  }
271 
272  // close file
273  fclose( file );
274 
275  // return success
276  return true;
277 }
278 
279 
280 //----------------------------------------------------------------
281 
282 
283 bool FilePTSPlugin::readTextFile( const char *_filename, SplatCloud &_splatCloud ) /*const*/
284 {
285  // clear splatcloud
286  _splatCloud.clear();
287 
288  // set default options
289  bool loadNormals = OpenFlipperSettings().value( "FilePTS/Load/Normals", true ).toBool();
290  bool loadPointsizes = OpenFlipperSettings().value( "FilePTS/Load/Pointsizes", false ).toBool();
291  bool loadColors = OpenFlipperSettings().value( "FilePTS/Load/Colors", false ).toBool();
292  int loadColorRange = OpenFlipperSettings().value( "FilePTS/Load/ColorRange",0 ).toInt();
293  bool loadIndices = OpenFlipperSettings().value( "FilePTS/Load/Indices", false ).toBool();
294 
295  // get options
296  if( OpenFlipper::Options::gui() && loadOptions_ )
297  {
298  loadNormals = loadNormals_ ->isChecked();
299  loadPointsizes = loadPointsizes_->isChecked();
300  loadColors = loadColors_ ->isChecked();
301  loadColorRange = loadColorRange_->currentIndex();
302  loadIndices = loadIndices_ ->isChecked();
303  }
304 
305  // request properties
306  bool success = true;
307  { if( !_splatCloud.requestPositions() ) success = false; }
308  if( loadNormals ) { if( !_splatCloud.requestNormals() ) success = false; }
309  if( loadPointsizes ) { if( !_splatCloud.requestPointsizes() ) success = false; }
310  if( loadColors ) { if( !_splatCloud.requestColors() ) success = false; }
311  if( loadIndices ) { if( !_splatCloud.requestIndices() ) success = false; }
312 
313  // check success of requests
314  if( !success )
315  {
316  emit log( LOGERR, tr("Out of memory for input file \"%1\".\n").arg( _filename ) );
317  return false; // return failure
318  }
319 
320  // open file
321  FILE *file = fopen( _filename, "rb" );
322  if( !file )
323  {
324  emit log( LOGERR, tr("Could not open input file \"%1\".\n").arg( _filename ) );
325  return false;
326  }
327 
328  int splatIdx;
329  for( splatIdx = 0; ; ++splatIdx )
330  {
331  // read position
332  {
333  float pos[3];
334  if( fscanf( file, "%32f %32f %32f", &pos[0], &pos[1], &pos[2] ) != 3 )
335  break;
336 
337  // increase number of splats
338  _splatCloud.pushbackSplat();
339 
340  SplatCloud::Position position;
341  position[0] = pos[0];
342  position[1] = pos[1];
343  position[2] = pos[2];
344 
345  _splatCloud.positions( splatIdx ) = position;
346  }
347 
348  // read color
349  if( loadColors )
350  {
351  float col[3];
352  fscanf( file, "%32f %32f %32f", &col[0], &col[1], &col[2] );
353 
354  SplatCloud::Color color;
355 
356  if( loadColorRange == COLORRANGE_0_1 )
357  {
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]);
361  }
362  else // loadColorRange == COLORRANGE_0_255
363  {
364  color[0] = (unsigned char) col[0];
365  color[1] = (unsigned char) col[1];
366  color[2] = (unsigned char) col[2];
367  }
368 
369  _splatCloud.colors( splatIdx ) = color;
370  }
371 
372  // read normal
373  if( loadNormals )
374  {
375  float nrm[3];
376  fscanf( file, "%32f %32f %32f", &nrm[0], &nrm[1], &nrm[2] );
377 
378  SplatCloud::Normal normal;
379  normal[0] = nrm[0];
380  normal[1] = nrm[1];
381  normal[2] = nrm[2];
382 
383  _splatCloud.normals( splatIdx ) = normal;
384  }
385 
386  // read pointsize
387  if( loadPointsizes )
388  {
389  float ps = 0.0f;
390  fscanf( file, "%32f", &ps );
391 
392  SplatCloud::Pointsize pointsize;
393  pointsize = ps;
394 
395  _splatCloud.pointsizes( splatIdx ) = pointsize;
396  }
397 
398  // read index
399  if( loadIndices )
400  {
401  int idx = -1;
402  fscanf( file, "%16i", &idx );
403 
404  SplatCloud::Index index;
405  index = idx;
406 
407  _splatCloud.indices( splatIdx ) = index;
408  }
409 
410  // check for errors
411  if( ferror( file ) )
412  {
413  emit log( LOGERR, tr("Could not read input file \"%1\".\n").arg( _filename ) );
414  fclose( file );
415  return false; // return failure
416  }
417  if( feof( file ) )
418  {
419  emit log( LOGERR, tr("Unexpected end in input file \"%1\".\n").arg( _filename ) );
420  fclose( file );
421  return false; // return failure
422  }
423  }
424 
425  // check for errors
426  if( !feof( file ) ) // if end-of-file is *not* reached, something went wrong
427  {
428  emit log( LOGERR, tr("Bad file format of input file \"%1\".\n").arg( _filename ) );
429  fclose( file );
430  return false; // return failure
431  }
432 
433  // close file
434  fclose( file );
435 
436  // return success
437  return true;
438 }
439 
440 
441 //----------------------------------------------------------------
442 
443 
444 bool FilePTSPlugin::writeBinaryFile( const char *_filename, const SplatCloudNode *_splatCloudNode ) /*const*/
445 {
446  // set default options
447  bool saveNormals = OpenFlipperSettings().value( "FilePTS/Save/Normals", true ).toBool();
448  bool savePointsizes = OpenFlipperSettings().value( "FilePTS/Save/Pointsizes", false ).toBool();
449  bool saveColors = OpenFlipperSettings().value( "FilePTS/Save/Colors", false ).toBool();
450 //int saveColorRange = 0;
451  bool saveIndices = OpenFlipperSettings().value( "FilePTS/Save/Indices", false ).toBool();
452 
453  // get options
454  if( OpenFlipper::Options::gui() && saveOptions_ )
455  {
456  saveNormals = saveNormals_-> isChecked();
457  savePointsizes = savePointsizes_->isChecked();
458  saveColors = saveColors_-> isChecked();
459 // saveColorRange = saveColorRange_->currentIndex();
460  saveIndices = saveIndices_-> isChecked();
461  }
462 
463  // use default values instead of returning a failure
464 
466 //if( ( !_splatCloudNode->splatCloud().hasPositions() ) ||
467 // (saveNormals && !_splatCloudNode->splatCloud().hasNormals()) ) ||
468 // (savePointsizes && !_splatCloudNode->splatCloud().hasPointsizes()) ||
469 // (saveColors && !_splatCloudNode->splatCloud().hasColors() ) ||
470 // (saveIndices && !_splatCloudNode->splatCloud().hasIndices() )
471 //{
472 // emit log( LOGERR, tr("Desired properties not available for output file \"%1\".\n").arg( _filename ) );
473 // return false; // return failure
474 //}
475 
476  // open file
477  FILE *file = fopen( _filename, "wb" );
478  if( !file )
479  {
480  emit log( LOGERR, tr("Could not open output file \"%1\".\n").arg( _filename ) );
481  return false;
482  }
483 
484  // write file type
485  int fileType = 1;
486  fwrite( &fileType, sizeof(int), 1, file );
487 
488  // write number of splats
489  unsigned int numSplats = _splatCloudNode->splatCloud().numSplats();
490  fwrite( &numSplats, sizeof(unsigned int), 1, file );
491 
492  // write positions
493  {
494  unsigned int i;
495  for( i=0; i<numSplats; ++i )
496  {
497  const SplatCloud::Position &position = _splatCloudNode->getPosition( i );
498 
499  float pos[3];
500  pos[0] = position[0];
501  pos[1] = position[1];
502  pos[2] = position[2];
503 
504  fwrite( pos, sizeof(float), 3, file );
505  }
506  }
507 
508  // write normals
509  if( saveNormals )
510  {
511  unsigned int i;
512  for( i=0; i<numSplats; ++i )
513  {
514  const SplatCloud::Normal &normal = _splatCloudNode->getNormal( i );
515 
516  float nrm[3];
517  nrm[0] = normal[0];
518  nrm[1] = normal[1];
519  nrm[2] = normal[2];
520 
521  fwrite( nrm, sizeof(float), 3, file );
522  }
523  }
524 
525  // write pointsizes
526  if( savePointsizes )
527  {
528  unsigned int i;
529  for( i=0; i<numSplats; ++i )
530  {
531  const SplatCloud::Pointsize &pointsize = _splatCloudNode->getPointsize( i );
532 
533  float ps;
534  ps = pointsize;
535 
536  fwrite( &ps, sizeof(float), 1, file );
537  }
538  }
539 
540  // write colors
541  if( saveColors )
542  {
543  unsigned int i;
544  for( i=0; i<numSplats; ++i )
545  {
546  const SplatCloud::Color &color = _splatCloudNode->getColor( i );
547 
548  unsigned int col; // ignore colorrange
549  col = (0xFF << 24) | (color[0] << 16) | (color[1] << 8) | (color[2]);
550 
551  fwrite( &col, sizeof(unsigned int), 1, file );
552  }
553  }
554 
555  // write indices
556  if( saveIndices )
557  {
558  unsigned int i;
559  for( i=0; i<numSplats; ++i )
560  {
561  const SplatCloud::Index &index = _splatCloudNode->getIndex( i );
562 
563  int idx;
564  idx = index;
565 
566  fwrite( &idx, sizeof(int), 1, file );
567  }
568  }
569 
570  // check for errors
571  if( ferror( file ) )
572  {
573  emit log( LOGERR, tr("Could not write output file \"%1\".\n").arg( _filename ) );
574  fclose( file );
575  return false; // return failure
576  }
577 
578  // close file
579  fclose( file );
580 
581  // return success
582  return true;
583 }
584 
585 
586 //----------------------------------------------------------------
587 
588 
589 bool FilePTSPlugin::writeTextFile( const char *_filename, const SplatCloudNode *_splatCloudNode ) /*const*/
590 {
591  // set default options
592  bool saveNormals = OpenFlipperSettings().value( "FilePTS/Save/Normals", true ).toBool();
593  bool savePointsizes = OpenFlipperSettings().value( "FilePTS/Save/Pointsizes", false ).toBool();
594  bool saveColors = OpenFlipperSettings().value( "FilePTS/Save/Colors", false ).toBool();
595  int saveColorRange = OpenFlipperSettings().value( "FilePTS/Save/ColorRange",0 ).toInt();
596  bool saveIndices = OpenFlipperSettings().value( "FilePTS/Save/Indices", false ).toBool();
597 
598  // get options
599  if( OpenFlipper::Options::gui() && saveOptions_ )
600  {
601  saveNormals = saveNormals_-> isChecked();
602  savePointsizes = savePointsizes_->isChecked();
603  saveColors = saveColors_-> isChecked();
604  saveColorRange = saveColorRange_->currentIndex();
605  saveIndices = saveIndices_-> isChecked();
606  }
607 
608  // use default values instead of returning a failure
609 
611 //if( ( !_splatCloudNode->splatCloud().hasPositions() ) ||
612 // (saveNormals && !_splatCloudNode->splatCloud().hasNormals()) ) ||
613 // (savePointsizes && !_splatCloudNode->splatCloud().hasPointsizes()) ||
614 // (saveColors && !_splatCloudNode->splatCloud().hasColors() ) ||
615 // (saveIndices && !_splatCloudNode->splatCloud().hasIndices() )
616 //{
617 // emit log( LOGERR, tr("Desired properties not available for output file \"%1\".\n").arg( _filename) );
618 // return false; // return failure
619 //}
620 
621  // open file
622  FILE *file = fopen( _filename, "wt" );
623  if( !file )
624  {
625  emit log( LOGERR, tr("Could not open output file \"%1\".\n").arg( _filename ) );
626  return false;
627  }
628 
629  // for all splats...
630  unsigned int i, numSplats = _splatCloudNode->splatCloud().numSplats();
631  for( i=0; i<numSplats; ++i )
632  {
633  // write position
634  {
635  const SplatCloud::Position &position = _splatCloudNode->getPosition( i );
636 
637  float pos[3];
638  pos[0] = position[0];
639  pos[1] = position[1];
640  pos[2] = position[2];
641 
642  fprintf( file, "%.6g %.6g %.6g", pos[0], pos[1], pos[2] );
643  }
644 
645  // write color
646  if( saveColors )
647  {
648  const SplatCloud::Color &color = _splatCloudNode->getColor( i );
649 
650  if( saveColorRange == COLORRANGE_0_1 )
651  {
652  static const float RCP255 = 1.0f / 255.0f;
653 
654  float col[3];
655  col[0] = RCP255 * color[0];
656  col[1] = RCP255 * color[1];
657  col[2] = RCP255 * color[2];
658 
659  fprintf( file, " %.6g %.6g %.6g", col[0], col[1], col[2] );
660  }
661  else // saveColorRange == COLORRANGE_0_255
662  {
663  int col[3]; // use int, *not* unsigned char !
664  col[0] = color[0];
665  col[1] = color[1];
666  col[2] = color[2];
667 
668  fprintf( file, " %i %i %i", col[0], col[1], col[2] );
669  }
670  }
671 
672  // write normal
673  if( saveNormals )
674  {
675  const SplatCloud::Normal &normal = _splatCloudNode->getNormal( i );
676 
677  float nrm[3];
678  nrm[0] = normal[0];
679  nrm[1] = normal[1];
680  nrm[2] = normal[2];
681 
682  fprintf( file, " %.6g %.6g %.6g", nrm[0], nrm[1], nrm[2] );
683  }
684 
685  // write pointsize
686  if( savePointsizes )
687  {
688  const SplatCloud::Pointsize &pointsize = _splatCloudNode->getPointsize( i );
689 
690  float ps;
691  ps = pointsize;
692 
693  fprintf( file, " %.6g", ps );
694  }
695 
696  // write index
697  if( saveIndices )
698  {
699  const SplatCloud::Index &index = _splatCloudNode->getIndex( i );
700 
701  int idx;
702  idx = index;
703 
704  fprintf( file, " %i", idx );
705  }
706 
707  fprintf( file, "\n" );
708  }
709 
710  // check for errors
711  if( ferror( file ) )
712  {
713  emit log( LOGERR, tr("Could not write output file \"%1\".\n").arg( _filename ) );
714  fclose( file );
715  return false; // return failure
716  }
717 
718  // close file
719  fclose( file );
720 
721  // return success
722  return true;
723 }
724 
725 
726 //----------------------------------------------------------------
727 
728 
729 int FilePTSPlugin::loadObject( QString _filename )
730 {
731  // set default options
732  bool loadBinaryFile = OpenFlipperSettings().value( "FilePTS/Load/BinaryFile", false ).toBool();
733 
734  // get options
735  if( OpenFlipper::Options::gui() && loadOptions_ )
736  {
737  loadBinaryFile = loadBinaryFile_->isChecked();
738  }
739 
740  // add a new, empty splatcloud-object
741  int splatCloudObjectId = -1;
742  emit addEmptyObject( DATA_SPLATCLOUD, splatCloudObjectId );
743  if( splatCloudObjectId != -1 )
744  {
745  // create list of ids and add id of splatcloud-object
746  IdList objectIDs;
747  objectIDs.push_back( splatCloudObjectId );
748 
749  // get splatcloud-object by id
751  if( PluginFunctions::getObject( splatCloudObjectId, splatCloudObject ) )
752  {
753  // set name of splatcloud-object to filename
754  splatCloudObject->setFromFileName( _filename );
755  splatCloudObject->setName( splatCloudObject->filename() );
756 
757  // get splatcloud and scenegraph splatcloud-node
758  SplatCloud *splatCloud = splatCloudObject->splatCloud();
759  SplatCloudNode *splatCloudNode = splatCloudObject->splatCloudNode();
760  if( (splatCloud != 0) && (splatCloudNode != 0) )
761  {
762  // read splatcloud from disk
763  if( loadBinaryFile ? readBinaryFile( _filename.toLatin1(), *splatCloud ) : readTextFile( _filename.toLatin1(), *splatCloud ) )
764  {
765  // emit signals that the object has to be updated and that a file was opened
766  emit updatedObject( splatCloudObjectId, UPDATE_ALL );
767  emit openedFile( splatCloudObjectId );
768 
769  // get drawmodes
773 
774  // if drawmodes don't exist something went wrong
775  if( splatsDrawMode == ACG::SceneGraph::DrawModes::NONE ||
776  dotsDrawMode == ACG::SceneGraph::DrawModes::NONE ||
777  pointsDrawMode == ACG::SceneGraph::DrawModes::NONE )
778  {
779  emit log( LOGERR, tr("Shader DrawModes for SplatCloud not existent!") );
780  }
781  else
782  {
783  // get global drawmode
785 
786  // if global drawmode does *not* contain any of 'Splats', 'Dots' or 'Points' drawmode, add 'Points'
787  if( !drawmode.containsAtomicDrawMode( splatsDrawMode ) &&
788  !drawmode.containsAtomicDrawMode( dotsDrawMode ) &&
789  !drawmode.containsAtomicDrawMode( pointsDrawMode ) )
790  {
791  drawmode |= pointsDrawMode;
792  PluginFunctions::setDrawMode( drawmode );
793  }
794  }
795 
796  // group objects
797  int groupObjectId = RPC::callFunctionValue<int>( "datacontrol", "groupObjects", objectIDs );
798  if( groupObjectId != -1 )
799  {
800  // everything is okay, so return id of group-object
801  return groupObjectId;
802  }
803  }
804  }
805  }
806 
807  // something went wrong, so delete objects
808  unsigned int i, num = objectIDs.size();
809  for( i=0; i<num; ++i )
810  emit deleteObject( objectIDs[ i ] );
811  }
812 
813  // return failure
814  return -1;
815 }
816 
817 
818 //----------------------------------------------------------------
819 
820 
821 bool FilePTSPlugin::saveObject( int _objectId, QString _filename )
822 {
823  // set default options
824  bool saveBinaryFile = OpenFlipperSettings().value( "FilePTS/Save/BinaryFile", false ).toBool();
825 
826  // get options
827  if( OpenFlipper::Options::gui() && saveOptions_ )
828  {
829  saveBinaryFile = saveBinaryFile_->isChecked();
830  }
831 
832  // get splatcloud-object by id
833  SplatCloudObject *splatCloudObject = 0;
834  if( PluginFunctions::getObject( _objectId, splatCloudObject ) )
835  {
836  // change name of splatcloud-object to filename
837  splatCloudObject->setFromFileName( _filename );
838  splatCloudObject->setName( splatCloudObject->filename() );
839 
840  // get splatcloud-node
841  const SplatCloudNode *splatCloudNode = splatCloudObject->splatCloudNode();
842  if( splatCloudNode != 0 )
843  {
844  // write splatcloud to disk
845  if( saveBinaryFile ? writeBinaryFile( _filename.toLatin1(), splatCloudNode ) : writeTextFile( _filename.toLatin1(), splatCloudNode ) )
846  {
847  // return success
848  return true;
849  }
850  }
851  }
852 
853  // return failure
854  return false;
855 }
856 
857 
858 //----------------------------------------------------------------
859 
860 
861 QWidget *FilePTSPlugin::loadOptionsWidget( QString /*_currentFilter*/ )
862 {
863  if( loadOptions_ == 0 )
864  {
865  // create new widget (including Load Options and buttons)
866 
867  loadBinaryFile_ = new QCheckBox( tr("Load as Binary File") );
868 
869  loadNormals_ = new QCheckBox( tr("Contains Normals") );
870  loadPointsizes_ = new QCheckBox( tr("Contains Pointsizes") );
871  loadColors_ = new QCheckBox( tr("Contains Colors") );
872 
873  loadColorRange_ = new QComboBox();
874  loadColorRange_->addItem( "[0..1]" );
875  loadColorRange_->addItem( "[0..255]" );
876  slotUpdateLoadColorRange();
877 
878  QHBoxLayout *loadColorsLayout = new QHBoxLayout();
879  loadColorsLayout->setSpacing( 6 );
880  loadColorsLayout->addWidget( loadColors_ );
881  loadColorsLayout->addWidget( loadColorRange_ );
882 
883  loadIndices_ = new QCheckBox( tr("Contains Indices") );
884 
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_ );
891 
892  QGroupBox *loadStructureGroupBox = new QGroupBox( tr("Internal File Structure") );
893  loadStructureGroupBox->setLayout( loadStructureLayout );
894 
895  loadMakeDefaultButton_ = new QPushButton( tr("Make Default") );
896 
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_ );
903 
904  loadOptions_ = new QWidget();
905  loadOptions_->setLayout( loadLayout );
906 
907  // connect events to slots
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() ) );
911 
912  // get Load Options from OpenFlipper (from disc)
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() );
919  }
920 
921  return loadOptions_;
922 }
923 
924 
925 //----------------------------------------------------------------
926 
927 
928 QWidget *FilePTSPlugin::saveOptionsWidget( QString _currentFilter )
929 {
930  if( saveOptions_ == 0 )
931  {
932  // create new widget (including Save Options and buttons)
933 
934  saveBinaryFile_ = new QCheckBox( tr("Save as Binary File") );
935 
936  saveNormals_ = new QCheckBox( tr("Save Normals") );
937  savePointsizes_ = new QCheckBox( tr("Save Pointsizes") );
938  saveColors_ = new QCheckBox( tr("Save Colors") );
939 
940  saveColorRange_ = new QComboBox();
941  saveColorRange_->addItem( "[0..1]" );
942  saveColorRange_->addItem( "[0..255]" );
943  slotUpdateSaveColorRange();
944 
945  QHBoxLayout *saveColorsLayout = new QHBoxLayout();
946  saveColorsLayout->setSpacing( 6 );
947  saveColorsLayout->addWidget( saveColors_ );
948  saveColorsLayout->addWidget( saveColorRange_ );
949 
950  saveIndices_ = new QCheckBox( tr("Save Indices") );
951 
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_ );
958 
959  QGroupBox *saveStructureGroupBox = new QGroupBox( tr("Internal File Structure") );
960  saveStructureGroupBox->setLayout( saveStructureLayout );
961 
962  saveMakeDefaultButton_ = new QPushButton( tr("Make Default") );
963 
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_ );
970 
971  saveOptions_ = new QWidget();
972  saveOptions_->setLayout( saveLayout );
973 
974  // connect events to slots
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() ) );
978 
979  // get Save Options from OpenFlipper (from disc)
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() );
986  }
987 
988  return saveOptions_;
989 }
990 
991 
992 //----------------------------------------------------------------
993 
994 
995 void FilePTSPlugin::slotUpdateLoadColorRange()
996 {
997  loadColorRange_->setEnabled( loadColors_->isChecked() && !loadBinaryFile_->isChecked() );
998 }
999 
1000 
1001 //----------------------------------------------------------------
1002 
1003 
1004 void FilePTSPlugin::slotUpdateSaveColorRange()
1005 {
1006  saveColorRange_->setEnabled( saveColors_->isChecked() && !saveBinaryFile_->isChecked() );
1007 }
1008 
1009 
1010 //----------------------------------------------------------------
1011 
1012 
1013 void FilePTSPlugin::slotLoadMakeDefaultButtonClicked()
1014 {
1015  // pass our Load Options to OpenFlipper (to disc)
1016  OpenFlipperSettings().setValue( "FilePTS/Load/BinaryFile", loadBinaryFile_->isChecked() );
1017  OpenFlipperSettings().setValue( "FilePTS/Load/Normals", loadNormals_-> isChecked() );
1018  OpenFlipperSettings().setValue( "FilePTS/Load/Pointsizes", loadPointsizes_->isChecked() );
1019  OpenFlipperSettings().setValue( "FilePTS/Load/Colors", loadColors_-> isChecked() );
1020  OpenFlipperSettings().setValue( "FilePTS/Load/ColorRange", loadColorRange_->currentIndex() );
1021  OpenFlipperSettings().setValue( "FilePTS/Load/Indices", loadIndices_-> isChecked() );
1022 
1023 // OpenFlipperSettings().setValue( "Core/File/UseLoadDefaults", true );
1024 }
1025 
1026 
1027 //----------------------------------------------------------------
1028 
1029 
1030 void FilePTSPlugin::slotSaveMakeDefaultButtonClicked()
1031 {
1032  // pass our Save Options to OpenFlipper (to disc)
1033  OpenFlipperSettings().setValue( "FilePTS/Save/BinaryFile", saveBinaryFile_->isChecked() );
1034  OpenFlipperSettings().setValue( "FilePTS/Save/Normals", saveNormals_-> isChecked() );
1035  OpenFlipperSettings().setValue( "FilePTS/Save/Pointsizes", savePointsizes_->isChecked() );
1036  OpenFlipperSettings().setValue( "FilePTS/Save/Colors", saveColors_-> isChecked() );
1037  OpenFlipperSettings().setValue( "FilePTS/Save/ColorRange", saveColorRange_->currentIndex() );
1038  OpenFlipperSettings().setValue( "FilePTS/Save/Indices", saveIndices_-> isChecked() );
1039 }
1040 
1041 
1042 //================================================================
1043 #if QT_VERSION < 0x050000
1044  Q_EXPORT_PLUGIN2( fileptsplugin, FilePTSPlugin );
1045 #endif
1046 
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.
Definition: DrawModes.cc:813
SplatCloud * splatCloud()
Get SplatCloud.
QString filename() const
return the filename of the object
Definition: BaseObject.cc:717
bool getObject(int _identifier, BSplineCurveObject *&_object)
QWidget * loadOptionsWidget(QString)
Definition: FilePTS.cc:861
Normal & normals(int _idx)
Get a reference of the predefined property&#39;s value.
Definition: SplatCloud.hh:641
void clear()
Remove all properties and reset the number of splats.
Definition: SplatCloud.cc:190
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
#define DATA_SPLATCLOUD
Definition: SplatCloud.hh:65
void setFromFileName(const QString &_filename)
Definition: BaseObject.cc:727
bool requestPointsizes()
Request the predefined property.
Definition: SplatCloud.hh:570
bool requestNormals()
Request the predefined property.
Definition: SplatCloud.hh:569
void pushbackSplat()
Add one element at the end of the data vector of all splat-properties.
Definition: SplatCloud.cc:237
void resizeSplats(unsigned int _num)
Resize the data vector of all splat-properties.
Definition: SplatCloud.cc:252
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&#39;s value.
Definition: SplatCloud.hh:643
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.
Definition: SplatCloud.hh:185
Position & positions(int _idx)
Get a reference of the predefined property&#39;s value.
Definition: SplatCloud.hh:637
bool requestColors()
Request the predefined property.
Definition: SplatCloud.hh:568
bool requestPositions()
Request the predefined property.
Definition: SplatCloud.hh:567
QWidget * saveOptionsWidget(QString)
Definition: FilePTS.cc:928
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
Color & colors(int _idx)
Get a reference of the predefined property&#39;s value.
Definition: SplatCloud.hh:639
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:77
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&#39;s value.
Definition: SplatCloud.hh:645
bool containsAtomicDrawMode(DrawMode _atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
bool requestIndices()
Request the predefined property.
Definition: SplatCloud.hh:571
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&#39;s scenegraph Node.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .