Developer Documentation
SplatCloudObjectSelectionPlugin.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 //================================================================
51 //
52 // CLASS SplatCloudObjectSelectionPlugin - IMPLEMENTATION
53 //
54 //================================================================
55 
56 
57 //== INCLUDES ====================================================
58 
59 
60 #include "SplatCloudObjectSelectionPlugin.hh"
61 
62 #include <set>
63 
65 
66 
67 //== DEFINES =====================================================
68 
69 
70 // Primitive type icons
71 #define VERTEX_TYPE "selection_splat.png"
72 
73 // =======================================
74 // Define operations
75 // =======================================
76 
77 // Vertices:
78 #define V_SELECT_ALL "Select All Splats"
79 #define V_CLEAR "Clear Splat Selection"
80 #define V_INVERT "Invert Splat Selection"
81 #define V_DELETE "Delete Splat Selection"
82 #define V_COLORIZE "Colorize Splat Selection"
83 
84 
85 //== IMPLEMENTATION ==============================================
86 
87 
88 void SplatCloudObjectSelectionPlugin::initializePlugin()
89 {
90  // Tell core about all scriptable slots
92 }
93 
94 
95 //----------------------------------------------------------------
96 
97 
98 void SplatCloudObjectSelectionPlugin::pluginsInitialized()
99 {
100  // Create new selection environment for SplatCloud objects
101  // and register SplatCloud type for the environment.
102 
103  QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
104 
105  emit addSelectionEnvironment( "SplatCloud Object Selections", "Select SplatCloud object primitives (vertices/points).", iconPath + "selections.png" , environmentHandle_ );
106 
107  // Register SplatCloud object type
108  emit registerType( environmentHandle_, DATA_SPLATCLOUD );
109 
110  // Register SplatCloud primitive types
111  emit addPrimitiveType( environmentHandle_, "Select Splats", iconPath + VERTEX_TYPE , vertexType_ );
112 
113  // Combine all supported types
115 
116  // Determine, which selection modes are requested
117  emit showToggleSelectionMode ( environmentHandle_, true, allSupportedTypes_ );
118  emit showSphereSelectionMode ( environmentHandle_, true, allSupportedTypes_ );
119 // emit showLassoSelectionMode ( environmentHandle_, true, allSupportedTypes_ );
120  emit showVolumeLassoSelectionMode( environmentHandle_, true, allSupportedTypes_ );
121 
122  // Define vertex operations
123  QStringList vertexOperations;
124  vertexOperations.append( V_SELECT_ALL );
125  vertexOperations.append( V_CLEAR );
126  vertexOperations.append( V_INVERT );
127  vertexOperations.append( V_DELETE );
128  vertexOperations.append( V_COLORIZE );
129 
130  emit addSelectionOperations( environmentHandle_, vertexOperations, "Splat Operations", vertexType_ );
131 
132  // Register key shortcuts
133  emit registerKeyShortcut( Qt::Key_A, Qt::ControlModifier ); // Select (a)ll
134  emit registerKeyShortcut( Qt::Key_C, Qt::NoModifier ); // (C)lear selection
135  emit registerKeyShortcut( Qt::Key_I, Qt::NoModifier ); // (I)nvert selection
136  emit registerKeyShortcut( Qt::Key_Delete, Qt::NoModifier ); // Delete selected entities
137 }
138 
139 
140 //----------------------------------------------------------------
141 
142 
144 {
145  emit setSlotDescription( "selectVertices(int,IdList)", tr("Select the specified vertices" ), QString ( "objectId,vertexList" ).split( "," ), QString ( "Id of object,List of vertices" ).split( "," ) );
146  emit setSlotDescription( "unselectVertices(int,IdList)", tr("Unselect the specified vertices" ), QString ( "objectId,vertexList" ).split( "," ), QString ( "Id of object,List of vertices" ).split( "," ) );
147  emit setSlotDescription( "selectAllVertices(int)", tr("Select all vertices of an object" ), QStringList( "objectId" ), QStringList( "Id of object" ) );
148  emit setSlotDescription( "clearVertexSelection(int)", tr("Clear vertex selection of an object" ), QStringList( "objectId" ), QStringList( "Id of an object" ) );
149  emit setSlotDescription( "invertVertexSelection(int)", tr("Invert vertex selection of an object"), QStringList( "objectId" ), QStringList( "Id of an object" ) );
150  emit setSlotDescription( "deleteVertexSelection(int)", tr("Delete selected vertices" ), QStringList( "objectId" ), QStringList( "Id of an object" ) );
151  emit setSlotDescription( "colorizeVertexSelection(int,int,int,int)", tr("Colorize the selected vertices" ), QString ( "objectId,r,g,b" ).split( "," ), QString ( "Id of an object,Red,Green,Blue" ).split( "," ) );
152  emit setSlotDescription( "loadSelection(int,QString)", tr("Load selection from selection file" ), QString ( "objectId,filename" ).split( "," ), QString ( "Id of an object,Selection file" ).split( "," ) );
153 }
154 
155 
156 //----------------------------------------------------------------
157 
158 
160 {
161  SelectionInterface::PrimitiveType type = 0u;
162  emit getActivePrimitiveType( type );
163 
164  if( (type & allSupportedTypes_) == 0 )
165  return;
166 
167  // Test if operation should be applied to target objects only
168  bool targetsOnly = false;
169  emit targetObjectsOnly( targetsOnly );
171 
172  if( _operation == V_SELECT_ALL )
173  {
174  // Select all vertices
175  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
176  {
177  if( o_it->visible() )
178  {
179  if( type & vertexType_ )
180  selectAllVertices( o_it->id() );
181  emit updatedObject( o_it->id(), UPDATE_SELECTION );
182  emit createBackup ( o_it->id(), "Select All", UPDATE_SELECTION );
183  }
184  }
185  }
186  else if( _operation == V_CLEAR )
187  {
188  // Clear vertex selection
189  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
190  {
191  if( o_it->visible() )
192  {
193  if( type & vertexType_ )
194  clearVertexSelection( o_it->id() );
195  emit updatedObject( o_it->id(), UPDATE_SELECTION );
196  emit createBackup ( o_it->id(), "Clear Selection", UPDATE_SELECTION );
197  }
198  }
199  }
200  else if( _operation == V_INVERT )
201  {
202  // Invert vertex selection
203  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
204  {
205  if( o_it->visible() )
206  {
207  if( type & vertexType_ )
208  invertVertexSelection( o_it->id() );
209  emit updatedObject( o_it->id(), UPDATE_SELECTION );
210  emit createBackup ( o_it->id(), "Invert Selection", UPDATE_SELECTION );
211  }
212  }
213  }
214  else if( _operation == V_DELETE )
215  {
216  // Delete vertex selection
217  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
218  {
219  if( o_it->visible() )
220  {
221  emit updatedObject( o_it->id(), addUpdateType("RestoreOriginalColors") );
222  emit createBackup ( o_it->id(), "Pre Deletion", UPDATE_ALL );
223 
224  if( type & vertexType_ )
225  deleteVertexSelection( o_it->id() );
226 
227  emit createBackup ( o_it->id(), "Delete Selection", UPDATE_ALL );
228  emit updatedObject( o_it->id(), addUpdateType("RestoreColormodeColors") );
229 
230  emit updatedObject( o_it->id(), UPDATE_ALL );
231  }
232  }
233  }
234  else if( _operation == V_COLORIZE )
235  {
236  // Colorize vertex selection
237  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
238  {
239  if( o_it->visible() )
240  {
241  emit updatedObject( o_it->id(), addUpdateType("RestoreOriginalColors") );
242  emit createBackup ( o_it->id(), "Pre Colorization", UPDATE_COLOR );
243 
244  if( type & vertexType_ )
245  setColorForSelection( o_it->id(), vertexType_ );
246 
247  emit createBackup ( o_it->id(), "Colorize Selection", UPDATE_COLOR );
248  emit updatedObject( o_it->id(), addUpdateType("RestoreColormodeColors") );
249 
250  emit updatedObject( o_it->id(), UPDATE_COLOR );
251  }
252  }
253  }
254 }
255 
256 
257 //----------------------------------------------------------------
258 
259 
260 void SplatCloudObjectSelectionPlugin::setColorForSelection( const int _objectId, const PrimitiveType _primitiveTypes )
261 {
262  QColor c = QColorDialog::getColor( Qt::red, 0, tr("Choose color"), QColorDialog::ShowAlphaChannel );
263 
264  if( c.isValid() )
265  {
266  if( _primitiveTypes & vertexType_ )
267  {
268  // Vertex colorization
269  colorizeVertexSelection( _objectId, c.red(), c.green(), c.blue(), c.alpha() );
270  }
271  }
272 }
273 
274 
275 //----------------------------------------------------------------
276 
277 
278 void SplatCloudObjectSelectionPlugin::slotToggleSelection( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect )
279 {
280  // Return if none of the currently active types is handled by this plugin
281  if( (_currentType & allSupportedTypes_) == 0 )
282  return;
283 
284  unsigned int node_idx, target_idx;
285  ACG::Vec3d hit_point;
286 
287  // First of all, pick anything to find all possible objects
288  if( PluginFunctions::scenegraphPick( ACG::SceneGraph::PICK_ANYTHING, _event->pos(), node_idx, target_idx, &hit_point ) )
289  {
290  BaseObjectData *object = 0;
291  PluginFunctions::getPickedObject( node_idx, object );
292  if( !object )
293  return;
294 
295  if( object->dataType() == DATA_SPLATCLOUD )
296  {
297  // Pick SplatCloud
298  if( PluginFunctions::scenegraphPick( ACG::SceneGraph::PICK_VERTEX, _event->pos(), node_idx, target_idx, &hit_point ) )
299  {
300  if( object->dataType( DATA_SPLATCLOUD ) )
301  {
302  splatCloudToggleSelection( PluginFunctions::splatCloud( object ), target_idx, hit_point, _currentType );
303  }
304  }
305  }
306 
307  emit updatedObject( object->id(), UPDATE_SELECTION );
308  emit createBackup ( object->id(), "Toggle Selection", UPDATE_SELECTION );
309  }
310 }
311 
312 
313 //----------------------------------------------------------------
314 
315 
316 void SplatCloudObjectSelectionPlugin::slotSphereSelection( QMouseEvent *_event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect )
317 {
318  // Return if none of the currently active types is handled by this plugin
319  if( (_currentType & allSupportedTypes_) == 0 )
320  return;
321 
322  unsigned int node_idx, target_idx;
323  ACG::Vec3d hit_point;
324 
325  if( PluginFunctions::scenegraphPick( ACG::SceneGraph::PICK_VERTEX, _event->pos(), node_idx, target_idx, &hit_point) )
326  {
327  BaseObjectData *object = 0;
328 
329  if( PluginFunctions::getPickedObject( node_idx, object ) )
330  {
331  if( object->picked( node_idx ) && object->dataType( DATA_SPLATCLOUD ) )
332  {
333  splatCloudSphereSelection( PluginFunctions::splatCloud( object ), target_idx, hit_point, _radius, _currentType, _deselect );
334  }
335 
336  emit updatedObject( object->id(), UPDATE_SELECTION );
337  if ( _event->type() == QEvent::MouseButtonRelease )
338  emit createBackup( object->id(), "Sphere Selection", UPDATE_SELECTION );
339  }
340  }
341 }
342 
343 
344 //----------------------------------------------------------------
345 
346 
347 void SplatCloudObjectSelectionPlugin::slotLassoSelection( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect )
348 {
349  // Return if none of the currently active types is handled by this plugin
350  if( (_currentType & allSupportedTypes_) == 0 )
351  return;
352 
353  if( _event->type() == QEvent::MouseButtonPress )
354  {
355  // Add picked point
356  lasso_2Dpoints_.push_back( _event->pos() );
357  return;
358  }
359 
360  if( _event->type() == QEvent::MouseButtonDblClick )
361  {
362  // Finish surface lasso selection
363  if( lasso_2Dpoints_.size() > 2 )
364  {
365  QRegion region( lasso_2Dpoints_ );
366  lassoSelect( region, _currentType, _deselect );
367  }
368 
369  // Clear points
370  lasso_2Dpoints_.clear();
371  return;
372  }
373 }
374 
375 
376 //----------------------------------------------------------------
377 
378 
379 void SplatCloudObjectSelectionPlugin::slotVolumeLassoSelection( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect )
380 {
381  // Return if none of the currently active types is handled by this plugin
382  if( (_currentType & allSupportedTypes_) == 0 )
383  return;
384 
385  if( _event->type() == QEvent::MouseButtonPress )
386  {
387  // Add point on viewing plane to selection polygon
388  volumeLassoPoints_.append( _event->pos() );
389  return;
390  }
391 
392  if( _event->type() == QEvent::MouseButtonDblClick )
393  {
395  bool updateGL = state.updateGL();
396  state.set_updateGL( false );
397 
398  QPolygon p( volumeLassoPoints_ );
399  QRegion region = QRegion( p );
400 
401  SelectVolumeAction action( region, this, _currentType, _deselect, state );
403 
404  state.set_updateGL( updateGL );
405 
406  // Clear lasso points
407  volumeLassoPoints_.clear();
408  }
409 }
410 
411 
412 //----------------------------------------------------------------
413 
414 
415 void SplatCloudObjectSelectionPlugin::loadSelection( int _objectId, const QString &_filename )
416 {
417  // Load ini file
418  INIFile file;
419 
420  if( !file.connect( _filename, false ) )
421  {
422  emit log( LOGERR, QString( "Could not read file '%1'!" ).arg( _filename ) );
423  return;
424  }
425 
426  // Load selection from file
427  loadIniFile( file, _objectId );
428 }
429 
430 
431 //----------------------------------------------------------------
432 
433 
434 void SplatCloudObjectSelectionPlugin::loadIniFile( INIFile &_ini, int _objectId )
435 {
436  BaseObjectData *object = 0;
437  if( !PluginFunctions::getObject( _objectId, object ) )
438  {
439  emit log( LOGERR, tr("Cannot find object for id ") + QString::number( _objectId ) + tr(" in saveFile") );
440  return;
441  }
442 
443  std::vector<int> ids;
444 
445  bool updated_selection = false;
446  bool updated_modeling_regions = false;
447 
448  QString sectionName = object->name();
449 
450  if( _ini.get_entry( ids, sectionName, "VertexSelection" ) )
451  {
452  bool invert = false;
453  _ini.get_entry( invert, sectionName, "InvertVertexSelection" );
454 
455  if( invert )
456  {
457  selectAllVertices( object->id() );
458  unselectVertices( object->id(), ids );
459  }
460  else
461  {
462  clearVertexSelection( object->id() );
463  selectVertices( object->id(), ids );
464  }
465 
466  updated_selection = true;
467  }
468 
469  if( updated_modeling_regions )
470  {
471  emit updatedObject( object->id(), UPDATE_ALL );
472  emit updateView();
473  }
474  else if( updated_selection )
475  {
476  emit updatedObject( object->id(), UPDATE_SELECTION );
477  emit updateView();
478  }
479 
480  if( updated_modeling_regions || updated_selection )
481  emit createBackup( object->id(), "Load Selection", UPDATE_SELECTION );
482 }
483 
484 
485 //----------------------------------------------------------------
486 
487 
488 void SplatCloudObjectSelectionPlugin::saveIniFile( INIFile &_ini, int _objectId )
489 {
490  BaseObjectData *object = 0;
491  if( !PluginFunctions::getObject( _objectId, object ) )
492  {
493  emit log( LOGERR, tr("Cannot find object for id ") + QString::number( _objectId ) + tr(" in saveFile") );
494  return;
495  }
496 
497  // The objects section should already exist
498  QString sectionName = object->name();
499  if( !_ini.section_exists( sectionName ) )
500  {
501  emit log( LOGERR, tr("Cannot find object section id ") + QString::number( _objectId ) + tr(" in saveFile") );
502  return;
503  }
504 
505  _ini.add_entry( sectionName, "VertexSelection", getVertexSelection( object->id() ) );
506 }
507 
508 
509 //----------------------------------------------------------------
510 
511 
513 {
514  // Iterate over all SplatCloud objects in the scene and save
515  // the selections for all supported entity types
517  {
518  // Read section for each object
519  // Append object name to section identifier
520  QString section = QString( "SplatCloudObjectSelection" ) + "//" + o_it->name();
521 
522  if( !_file.section_exists( section ) )
523  continue;
524 
525  std::vector<int> ids;
526  // Load vertex selection:
527  _file.get_entry( ids, section, "VertexSelection" );
528  selectVertices( o_it->id(), ids );
529  ids.clear();
530 
531  emit updatedObject( o_it->id(), UPDATE_SELECTION );
532  emit createBackup ( o_it->id(), "Load Selection", UPDATE_SELECTION );
533  }
534 }
535 
536 
537 //----------------------------------------------------------------
538 
539 
541 {
542  // Iterate over all SplatCloud objects in the scene and save
543  // the selections for all supported entity types
545  {
546  // Create section for each object
547  // Append object name to section identifier
548  QString section = QString( "SplatCloudObjectSelection" ) + "//" + o_it->name();
549 
550  // Store vertex selection:
551  _file.add_entry( section, "VertexSelection", getVertexSelection( o_it->id() ) );
552  }
553 }
554 
555 
556 //----------------------------------------------------------------
557 
558 
559 void SplatCloudObjectSelectionPlugin::slotKeyShortcutEvent( int _key, Qt::KeyboardModifiers _modifiers )
560 {
561  SelectionInterface::PrimitiveType type = 0u;
562  emit getActivePrimitiveType( type );
563 
564  if( (type & allSupportedTypes_) == 0 )
565  {
566  // No supported type is active
567  return;
568  }
569 
570  bool targetsOnly = false;
571  emit targetObjectsOnly( targetsOnly );
573 
574  if( _key == Qt::Key_A && _modifiers == Qt::ControlModifier )
575  {
576  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
577  {
578  if( o_it->visible() )
579  {
580  if( type & vertexType_ )
581  selectAllVertices( o_it->id() );
582  emit updatedObject( o_it->id(), UPDATE_SELECTION );
583  emit createBackup ( o_it->id(), "Select All", UPDATE_SELECTION );
584  }
585  }
586  }
587  else if( _key == Qt::Key_C && _modifiers == Qt::NoModifier )
588  {
589  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
590  {
591  if( o_it->visible() )
592  {
593  if( type & vertexType_ )
594  clearVertexSelection( o_it->id() );
595  emit updatedObject( o_it->id(), UPDATE_SELECTION );
596  emit createBackup ( o_it->id(), "Clear Selection", UPDATE_SELECTION );
597  }
598  }
599  }
600  else if( _key == Qt::Key_I && _modifiers == Qt::NoModifier )
601  {
602  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
603  {
604  if( o_it->visible() )
605  {
606  if( type & vertexType_ )
607  invertVertexSelection( o_it->id() );
608  emit updatedObject( o_it->id(), UPDATE_SELECTION );
609  emit createBackup ( o_it->id(), "Invert Selection", UPDATE_SELECTION );
610  }
611  }
612  }
613  else if( _key == Qt::Key_Delete && _modifiers == Qt::NoModifier )
614  {
615  for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
616  {
617  if( o_it->visible() )
618  {
619  emit updatedObject( o_it->id(), addUpdateType("RestoreOriginalColors") );
620  emit createBackup ( o_it->id(), "Pre Deletion", UPDATE_ALL );
621 
622  if( type & vertexType_ )
623  deleteVertexSelection( o_it->id() );
624 
625  emit createBackup ( o_it->id(), "Delete Selection", UPDATE_ALL );
626  emit updatedObject( o_it->id(), addUpdateType("RestoreColormodeColors") );
627 
628  emit updatedObject( o_it->id(), UPDATE_ALL );
629  }
630  }
631  }
632 }
633 
634 
635 //----------------------------------------------------------------
636 
637 
638 void SplatCloudObjectSelectionPlugin::lassoSelect( QRegion &_region, PrimitiveType _primitiveType, bool _deselection )
639 {
640  // <object id, primitive id>
641  QList< QPair<unsigned int,unsigned int> > list;
642 
643  if( _primitiveType & vertexType_)
644  {
646 
647  std::set<int> alreadySelectedObjects;
648 
649  for( int i=0; i<list.size(); ++i )
650  {
651  if( alreadySelectedObjects.count( list[i].first ) != 0 )
652  continue;
653 
654  BaseObjectData *bod = 0;
655  PluginFunctions::getPickedObject( list[i].first, bod );
656 
657  if( bod && (bod->dataType() == DATA_SPLATCLOUD ) )
658  {
659  IdList elements;
660  for( int j=0; j<list.size(); ++j )
661  {
662  if( list[j].first == list[i].first )
663  {
664  elements.push_back( list[j].second );
665  }
666  }
667  selectVertices( bod->id(), elements );
668  alreadySelectedObjects.insert( list[i].first );
669  emit updatedObject( bod->id(), UPDATE_SELECTION );
670  emit createBackup ( bod->id(), "Lasso Selection", UPDATE_SELECTION );
671  }
672  }
673  }
674 }
675 
676 
677 //----------------------------------------------------------------
678 
679 
682 {
683  BaseObjectData *object = 0;
684  if( PluginFunctions::getPickedObject( _node->id(), object ) )
685  {
686  bool selected = false;
687  if( object->dataType( DATA_SPLATCLOUD ) )
688  {
689  SplatCloud *sc = PluginFunctions::splatCloud( object );
690  selected = plugin_->splatCloudVolumeSelection( sc, state_, &region_, type_, deselection_ );
691  }
692 
693  if( selected )
694  {
695  emit plugin_->updatedObject( object->id(), UPDATE_SELECTION );
696  emit plugin_->createBackup ( object->id(), "Lasso Selection", UPDATE_SELECTION );
697  }
698  }
699 
700  return true;
701 }
702 
703 
704 //----------------------------------------------------------------
705 
706 #if QT_VERSION < 0x050000
707  Q_EXPORT_PLUGIN2( splatcloudobjectselectionplugin, SplatCloudObjectSelectionPlugin );
708 #endif
709 
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
QStringList IteratorRestriction
Iterable object range.
bool updateGL() const
should GL matrices be updated after each matrix operation
Definition: GLState.hh:240
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
Predefined datatypes.
Definition: DataTypes.hh:96
SelectionInterface::PrimitiveType allSupportedTypes_
Primitive type handle.
void setColorForSelection(const int _objectId, const PrimitiveType _primitiveType)
Set color for selection.
ACG::GLState & glState()
Get the glState of the Viewer.
bool getObject(int _identifier, BSplineCurveObject *&_object)
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void invertVertexSelection(int _objectId)
Invert the current vertex selection.
void lassoSelect(QRegion &_region, PrimitiveType _primitiveType, bool _deselection)
Lasso selection tool.
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
IdList getVertexSelection(int _objectId)
Return a list of all selected vertices.
#define DATA_SPLATCLOUD
Definition: SplatCloud.hh:65
Traverse the scenegraph and call the selection function for all mesh nodes.
int id() const
Definition: BaseObject.cc:201
const QStringList ALL_OBJECTS
Iterable object range.
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
void slotSphereSelection(QMouseEvent *_event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a sphere selection.
unsigned int id() const
Definition: BaseNode.hh:454
virtual bool picked(uint _node_idx)
detect if the node has been picked
QVector< QPoint > volumeLassoPoints_
Used for volume lasso tool.
void splatCloudToggleSelection(SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, PrimitiveType _primitiveType)
Toggle SplatCloud selection.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
Definition: INIFile.cc:439
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
void slotSelectionOperation(QString _operation)
A specific operation is requested.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void clearVertexSelection(int _objectId)
Unselect all vertices.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
Definition: INIFile.cc:233
bool operator()(BaseNode *_node)
Traverse the scenegraph and call the selection function for all mesh nodes.
SelectionInterface::PrimitiveType vertexType_
Primitive type handle.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Definition: INIFile.cc:76
Class for the handling of simple configuration files.
Definition: INIFile.hh:105
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
QString environmentHandle_
Handle to selection environment.
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:143
picks verices (may not be implemented for all nodes)
Definition: BaseNode.hh:108
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
UpdateType addUpdateType(QString _name, bool _resetNeeded)
Adds a updateType and returns the id for the new type.
Definition: UpdateType.cc:236
picks only visible front verices (may not be implemented for all nodes)
Definition: BaseNode.hh:115
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int _a)
Colorize the vertex selection.
QPolygon lasso_2Dpoints_
Used for lasso selection tool.
void splatCloudSphereSelection(SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, double _radius, PrimitiveType _primitiveTypes, bool _deselection)
Use the event to paint selection with a sphere.
void unselectVertices(int _objectId, IdList _vertexList)
Unselect given vertices.
bool scenegraphRegionPick(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< unsigned int, unsigned int > > &_list, QVector< float > *_depths, QVector< ACG::Vec3d > *_points)
void selectAllVertices(int _objectId)
Select all vertices.
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
void updateSlotDescriptions()
Set descriptions for local public slots.
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void deleteVertexSelection(int _objectId)
Delete vertices that are currently selected.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Definition: INIFile.cc:263
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
Definition: GLState.hh:242
void selectVertices(int _objectId, IdList _vertexList)
Select given vertices.
void slotLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a lasso selection.