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