SplatCloudObjectSelectionPlugin.cc 24.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                      *
 *   $Author$                                                       *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/

//================================================================
//
//  CLASS SplatCloudObjectSelectionPlugin - IMPLEMENTATION
//
//================================================================


//== INCLUDES ====================================================


#include "SplatCloudObjectSelectionPlugin.hh"

#include <set>

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


//== DEFINES =====================================================


// Primitive type icons
#define VERTEX_TYPE     "selection_splat.png"

// =======================================
// Define operations
// =======================================

// Vertices:
#define V_SELECT_ALL "Select All Splats"
#define V_CLEAR      "Clear Splat Selection"
#define V_INVERT     "Invert Splat Selection"
#define V_DELETE     "Delete Splat Selection"
#define V_COLORIZE   "Colorize Splat Selection"


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


void SplatCloudObjectSelectionPlugin::initializePlugin()
{
  // Tell core about all scriptable slots
  updateSlotDescriptions();
}


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


void SplatCloudObjectSelectionPlugin::pluginsInitialized()
{
  // Create new selection environment for SplatCloud objects 
  // and register SplatCloud type for the environment.

  QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();

Jan Möbius's avatar
Jan Möbius committed
99
  emit addSelectionEnvironment( "SplatCloud Object Selections", "Select SplatCloud object primitives (vertices/points).",  iconPath + "selections.png" , environmentHandle_ );
100
101
102
103
104

  // Register SplatCloud object type
  emit registerType( environmentHandle_, DATA_SPLATCLOUD );

  // Register SplatCloud primitive types
Jan Möbius's avatar
Jan Möbius committed
105
  emit addPrimitiveType( environmentHandle_, "Select Splats",  iconPath + VERTEX_TYPE , vertexType_ );
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

  // Combine all supported types
  allSupportedTypes_ = vertexType_;

  // Determine, which selection modes are requested
  emit showToggleSelectionMode     ( environmentHandle_, true, allSupportedTypes_ );
  emit showSphereSelectionMode     ( environmentHandle_, true, allSupportedTypes_ );
//  emit showLassoSelectionMode      ( environmentHandle_, true, allSupportedTypes_ );
  emit showVolumeLassoSelectionMode( environmentHandle_, true, allSupportedTypes_ );

  // Define vertex operations
  QStringList vertexOperations;
  vertexOperations.append( V_SELECT_ALL );
  vertexOperations.append( V_CLEAR      );
  vertexOperations.append( V_INVERT     );
  vertexOperations.append( V_DELETE     );
  vertexOperations.append( V_COLORIZE   );

  emit addSelectionOperations( environmentHandle_, vertexOperations,  "Splat Operations", vertexType_ );

  // Register key shortcuts
  emit registerKeyShortcut( Qt::Key_A,      Qt::ControlModifier ); // Select (a)ll
  emit registerKeyShortcut( Qt::Key_C,      Qt::NoModifier      ); // (C)lear selection
  emit registerKeyShortcut( Qt::Key_I,      Qt::NoModifier      ); // (I)nvert selection
  emit registerKeyShortcut( Qt::Key_Delete, Qt::NoModifier      ); // Delete selected entities
}


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


void SplatCloudObjectSelectionPlugin::updateSlotDescriptions()
{
  emit setSlotDescription( "selectVertices(int,IdList)",               tr("Select the specified vertices"       ), QString    ( "objectId,vertexList" ).split( "," ), QString    ( "Id of object,List of vertices"  ).split( "," ) );
  emit setSlotDescription( "unselectVertices(int,IdList)",             tr("Unselect the specified vertices"     ), QString    ( "objectId,vertexList" ).split( "," ), QString    ( "Id of object,List of vertices"  ).split( "," ) );
  emit setSlotDescription( "selectAllVertices(int)",                   tr("Select all vertices of an object"    ), QStringList( "objectId" ),                         QStringList( "Id of object"    )                             );
  emit setSlotDescription( "clearVertexSelection(int)",                tr("Clear vertex selection of an object" ), QStringList( "objectId" ),                         QStringList( "Id of an object" )                             );
  emit setSlotDescription( "invertVertexSelection(int)",               tr("Invert vertex selection of an object"), QStringList( "objectId" ),                         QStringList( "Id of an object" )                             );
  emit setSlotDescription( "deleteVertexSelection(int)",               tr("Delete selected vertices"            ), QStringList( "objectId" ),                         QStringList( "Id of an object" )                             );
  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( "," ) );
  emit setSlotDescription( "loadSelection(int,QString)",               tr("Load selection from selection file"  ), QString    ( "objectId,filename"   ).split( "," ), QString    ( "Id of an object,Selection file" ).split( "," ) );
}


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


void SplatCloudObjectSelectionPlugin::slotSelectionOperation( QString _operation )
{
  SelectionInterface::PrimitiveType type = 0u;
  emit getActivePrimitiveType( type );

  if( (type & allSupportedTypes_) == 0 )
    return;

  // Test if operation should be applied to target objects only
  bool targetsOnly = false;
  emit targetObjectsOnly( targetsOnly );
  PluginFunctions::IteratorRestriction restriction = (targetsOnly ? PluginFunctions::TARGET_OBJECTS : PluginFunctions::ALL_OBJECTS);

  if( _operation == V_SELECT_ALL )
  {
    // Select all vertices
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        if( type & vertexType_ )
          selectAllVertices( o_it->id() );
        emit updatedObject( o_it->id(), UPDATE_SELECTION );
        emit createBackup ( o_it->id(), "Select All", UPDATE_SELECTION );
      }
    }
  }
  else if( _operation == V_CLEAR )
  {
    // Clear vertex selection
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        if( type & vertexType_ )
          clearVertexSelection( o_it->id() );
        emit updatedObject( o_it->id(), UPDATE_SELECTION );
        emit createBackup ( o_it->id(), "Clear Selection", UPDATE_SELECTION );
      }
    }
  }
  else if( _operation == V_INVERT )
  {
    // Invert vertex selection
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        if( type & vertexType_ )
          invertVertexSelection( o_it->id() );
        emit updatedObject( o_it->id(), UPDATE_SELECTION );
        emit createBackup ( o_it->id(), "Invert Selection", UPDATE_SELECTION );
      }
    }
  }
  else if( _operation == V_DELETE )
  {
    // Delete vertex selection
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        emit updatedObject( o_it->id(), addUpdateType("RestoreOriginalColors") );
        emit createBackup ( o_it->id(), "Pre Deletion", UPDATE_ALL );

        if( type & vertexType_ )
          deleteVertexSelection( o_it->id() );

        emit createBackup ( o_it->id(), "Delete Selection", UPDATE_ALL );
        emit updatedObject( o_it->id(), addUpdateType("RestoreColormodeColors") );

        emit updatedObject( o_it->id(), UPDATE_ALL );
      }
    }
  }
  else if( _operation == V_COLORIZE )
  {
    // Colorize vertex selection
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_ALL ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        emit updatedObject( o_it->id(), addUpdateType("RestoreOriginalColors") );
        emit createBackup ( o_it->id(), "Pre Colorization", UPDATE_COLOR );

        if( type & vertexType_ )
          setColorForSelection( o_it->id(), vertexType_ );

        emit createBackup ( o_it->id(), "Colorize Selection", UPDATE_COLOR );
        emit updatedObject( o_it->id(), addUpdateType("RestoreColormodeColors") );

        emit updatedObject( o_it->id(), UPDATE_COLOR );
      }
    }
  }
}


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


void SplatCloudObjectSelectionPlugin::setColorForSelection( const int _objectId, const PrimitiveType _primitiveTypes )
{
  QColor c = QColorDialog::getColor( Qt::red, 0, tr("Choose color"), QColorDialog::ShowAlphaChannel );

  if( c.isValid() )
  {
    if( _primitiveTypes & vertexType_ )
    {
      // Vertex colorization
      colorizeVertexSelection( _objectId, c.red(), c.green(), c.blue(), c.alpha() );
    }
  }
}


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


void SplatCloudObjectSelectionPlugin::slotToggleSelection( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect )
{
  // Return if none of the currently active types is handled by this plugin
  if( (_currentType & allSupportedTypes_) == 0 )
    return;

  unsigned int node_idx, target_idx;
  ACG::Vec3d hit_point;

  // First of all, pick anything to find all possible objects
  if( PluginFunctions::scenegraphPick( ACG::SceneGraph::PICK_ANYTHING, _event->pos(), node_idx, target_idx, &hit_point ) )
  {
    BaseObjectData *object = 0;
    PluginFunctions::getPickedObject( node_idx, object );
    if( !object )
      return;

    if( object->dataType() == DATA_SPLATCLOUD )
    {
      // Pick SplatCloud
      if( PluginFunctions::scenegraphPick( ACG::SceneGraph::PICK_VERTEX, _event->pos(), node_idx, target_idx, &hit_point ) )
      {
        if( object->dataType( DATA_SPLATCLOUD ) )
        {
          splatCloudToggleSelection( PluginFunctions::splatCloud( object ), target_idx, hit_point, _currentType );
        }
      }
    }

    emit updatedObject( object->id(), UPDATE_SELECTION );
    emit createBackup ( object->id(), "Toggle Selection", UPDATE_SELECTION );
  }
}


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


void SplatCloudObjectSelectionPlugin::slotSphereSelection( QMouseEvent *_event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect )
{
  // Return if none of the currently active types is handled by this plugin
  if( (_currentType & allSupportedTypes_) == 0 )
    return;

  unsigned int node_idx, target_idx;
  ACG::Vec3d hit_point;

  if( PluginFunctions::scenegraphPick( ACG::SceneGraph::PICK_VERTEX, _event->pos(), node_idx, target_idx, &hit_point) )
  {
    BaseObjectData *object = 0;

    if( PluginFunctions::getPickedObject( node_idx, object ) )
    {
      if( object->picked( node_idx ) && object->dataType( DATA_SPLATCLOUD ) )
      {
        splatCloudSphereSelection( PluginFunctions::splatCloud( object ), target_idx, hit_point, _radius, _currentType, _deselect );
      }

      emit updatedObject( object->id(), UPDATE_SELECTION );
      if ( _event->type() == QEvent::MouseButtonRelease )
        emit createBackup( object->id(), "Sphere Selection", UPDATE_SELECTION );
    }
  }
}


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


void SplatCloudObjectSelectionPlugin::slotLassoSelection( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect )
{
  // Return if none of the currently active types is handled by this plugin
  if( (_currentType & allSupportedTypes_) == 0 )
    return;

  if( _event->type() == QEvent::MouseButtonPress )
  {
    // Add picked point
    lasso_2Dpoints_.push_back( _event->pos() );
    return;
  }

  if( _event->type() == QEvent::MouseButtonDblClick )
  {    
    // Finish surface lasso selection
    if( lasso_2Dpoints_.size() > 2 )
    {
      QRegion region( lasso_2Dpoints_ );
      lassoSelect( region, _currentType, _deselect );
        }

        // Clear points
        lasso_2Dpoints_.clear();
    return;
  }
}


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


void SplatCloudObjectSelectionPlugin::slotVolumeLassoSelection( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect )
{
  // Return if none of the currently active types is handled by this plugin
  if( (_currentType & allSupportedTypes_) == 0 )
    return;

  if( _event->type() == QEvent::MouseButtonPress )
  {
    // Add point on viewing plane to selection polygon
    volumeLassoPoints_.append( _event->pos() );
        return;
    }

    if( _event->type() == QEvent::MouseButtonDblClick )
    {
    ACG::GLState &state = PluginFunctions::viewerProperties().glState();
    bool updateGL = state.updateGL();
    state.set_updateGL( false );

    QPolygon p( volumeLassoPoints_ );
    QRegion region = QRegion( p );

    SelectVolumeAction action( region, this, _currentType, _deselect, state );
    ACG::SceneGraph::traverse( PluginFunctions::getRootNode(), action );

    state.set_updateGL( updateGL );

    // Clear lasso points
    volumeLassoPoints_.clear();
  }
}


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


void SplatCloudObjectSelectionPlugin::loadSelection( int _objectId, const QString &_filename )
{
  // Load ini file
  INIFile file;

  if( !file.connect( _filename, false ) )
  {
    emit log( LOGERR, QString( "Could not read file '%1'!" ).arg( _filename ) );
    return;
  }

  // Load selection from file
  loadIniFile( file, _objectId );
}


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


void SplatCloudObjectSelectionPlugin::loadIniFile( INIFile &_ini, int _objectId )
{
  BaseObjectData *object = 0;
  if( !PluginFunctions::getObject( _objectId, object ) )
  {
    emit log( LOGERR, tr("Cannot find object for id ") + QString::number( _objectId ) + tr(" in saveFile") );
    return;
  }

  std::vector<int> ids;

  bool updated_selection = false;
  bool updated_modeling_regions = false;

  QString sectionName = object->name();

  if( _ini.get_entry( ids, sectionName, "VertexSelection" ) )
  {
Jan Möbius's avatar
Jan Möbius committed
446
    bool invert = false;
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
    _ini.get_entry( invert, sectionName, "InvertVertexSelection" );

    if( invert )
    {
      selectAllVertices( object->id() );
      unselectVertices( object->id(), ids );
    }
    else
    {
      clearVertexSelection( object->id() );
      selectVertices( object->id(), ids );
    }

    updated_selection = true;
  }

  if( updated_modeling_regions )
  {
    emit updatedObject( object->id(), UPDATE_ALL );
    emit updateView();
  }
  else if( updated_selection )
  {
    emit updatedObject( object->id(), UPDATE_SELECTION );
    emit updateView();
  }

  if( updated_modeling_regions || updated_selection )
    emit createBackup( object->id(), "Load Selection", UPDATE_SELECTION );
}


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


void SplatCloudObjectSelectionPlugin::saveIniFile( INIFile &_ini, int _objectId )
{
  BaseObjectData *object = 0;
  if( !PluginFunctions::getObject( _objectId, object ) )
  {
    emit log( LOGERR, tr("Cannot find object for id ") + QString::number( _objectId ) + tr(" in saveFile") );
    return;
  }

  // The objects section should already exist
  QString sectionName = object->name();
  if( !_ini.section_exists( sectionName ) )
  {
    emit log( LOGERR, tr("Cannot find object section id ") + QString::number( _objectId ) + tr(" in saveFile") );
    return;
  }

  _ini.add_entry( sectionName, "VertexSelection", getVertexSelection( object->id() ) );
}


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


void SplatCloudObjectSelectionPlugin::slotLoadSelection( const INIFile &_file )
{
  // Iterate over all SplatCloud objects in the scene and save
  // the selections for all supported entity types
  for( PluginFunctions::ObjectIterator o_it( PluginFunctions::ALL_OBJECTS, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it)
  {
    // Read section for each object
    // Append object name to section identifier
    QString section = QString( "SplatCloudObjectSelection" ) + "//" + o_it->name();

    if( !_file.section_exists( section ) )
      continue;

    std::vector<int> ids;
    // Load vertex selection:
    _file.get_entry( ids, section, "VertexSelection" );
    selectVertices( o_it->id(), ids );
    ids.clear();

    emit updatedObject( o_it->id(), UPDATE_SELECTION );
    emit createBackup ( o_it->id(), "Load Selection", UPDATE_SELECTION );
  }
}


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


void SplatCloudObjectSelectionPlugin::slotSaveSelection( INIFile &_file )
{
  // Iterate over all SplatCloud objects in the scene and save
  // the selections for all supported entity types
  for( PluginFunctions::ObjectIterator o_it( PluginFunctions::ALL_OBJECTS, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it)
  {
    // Create section for each object
    // Append object name to section identifier
    QString section = QString( "SplatCloudObjectSelection" ) + "//" + o_it->name();

    // Store vertex selection:
    _file.add_entry( section, "VertexSelection", getVertexSelection( o_it->id() ) );
  }
}


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


void SplatCloudObjectSelectionPlugin::slotKeyShortcutEvent( int _key, Qt::KeyboardModifiers _modifiers )
{
  SelectionInterface::PrimitiveType type = 0u;
  emit getActivePrimitiveType( type );

  if( (type & allSupportedTypes_) == 0 )
  {
    // No supported type is active
    return;
  }

  bool targetsOnly = false;
  emit targetObjectsOnly( targetsOnly );
  PluginFunctions::IteratorRestriction restriction = (targetsOnly ? PluginFunctions::TARGET_OBJECTS : PluginFunctions::ALL_OBJECTS);

  if( _key == Qt::Key_A && _modifiers == Qt::ControlModifier )
  {
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        if( type & vertexType_ )
          selectAllVertices( o_it->id() );
        emit updatedObject( o_it->id(), UPDATE_SELECTION );
        emit createBackup ( o_it->id(), "Select All", UPDATE_SELECTION );
      }
    }
  }
  else if( _key == Qt::Key_C && _modifiers == Qt::NoModifier )
  {
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        if( type & vertexType_ )
          clearVertexSelection( o_it->id() );
        emit updatedObject( o_it->id(), UPDATE_SELECTION );
        emit createBackup ( o_it->id(), "Clear Selection", UPDATE_SELECTION );
      }
    }
  }
  else if( _key == Qt::Key_I && _modifiers == Qt::NoModifier )
  {
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_SPLATCLOUD ) );  o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        if( type & vertexType_ )
          invertVertexSelection( o_it->id() );
        emit updatedObject( o_it->id(), UPDATE_SELECTION );
        emit createBackup ( o_it->id(), "Invert Selection", UPDATE_SELECTION );
            }
    }
  }
  else if( _key == Qt::Key_Delete && _modifiers == Qt::NoModifier )
  {
    for( PluginFunctions::ObjectIterator o_it( restriction, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it )
    {
      if( o_it->visible() )
      {
        emit updatedObject( o_it->id(), addUpdateType("RestoreOriginalColors") );
        emit createBackup ( o_it->id(), "Pre Deletion", UPDATE_ALL );

        if( type & vertexType_ )
          deleteVertexSelection( o_it->id() );

        emit createBackup ( o_it->id(), "Delete Selection", UPDATE_ALL );
        emit updatedObject( o_it->id(), addUpdateType("RestoreColormodeColors") );

        emit updatedObject( o_it->id(), UPDATE_ALL );
      }
    }
  }
}


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


void SplatCloudObjectSelectionPlugin::lassoSelect( QRegion &_region, PrimitiveType _primitiveType, bool _deselection )
{
  // <object id, primitive id>
  QList< QPair<unsigned int,unsigned int> > list;

  if( _primitiveType & vertexType_)
  {
    PluginFunctions::scenegraphRegionPick( ACG::SceneGraph::PICK_FRONT_VERTEX, _region, list );

    std::set<int> alreadySelectedObjects;

    for( int i=0; i<list.size(); ++i )
    {
      if( alreadySelectedObjects.count( list[i].first ) != 0 )
        continue;

      BaseObjectData *bod = 0;
      PluginFunctions::getPickedObject( list[i].first, bod );

      if( bod && (bod->dataType() == DATA_SPLATCLOUD ) )
      {
        IdList elements;
        for( int j=0; j<list.size(); ++j )
        {
          if( list[j].first == list[i].first )
          {
            elements.push_back( list[j].second );
          }
        }
        selectVertices( bod->id(), elements );
        alreadySelectedObjects.insert( list[i].first );
        emit updatedObject( bod->id(), UPDATE_SELECTION );
        emit createBackup ( bod->id(), "Lasso Selection", UPDATE_SELECTION );
      }
    }
  }
}


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


/// Traverse the scenegraph and call the selection function for all SplatCloud nodes
bool SelectVolumeAction::operator()( BaseNode *_node )
{
  BaseObjectData *object = 0;
  if( PluginFunctions::getPickedObject( _node->id(), object ) )
  {    
    bool selected = false;
    if( object->dataType( DATA_SPLATCLOUD ) )
    {
      SplatCloud *sc = PluginFunctions::splatCloud( object );
      selected = plugin_->splatCloudVolumeSelection( sc, state_, &region_, type_, deselection_ );
        }

    if( selected )
    {
      emit plugin_->updatedObject( object->id(), UPDATE_SELECTION );
      emit plugin_->createBackup ( object->id(), "Lasso Selection", UPDATE_SELECTION );
    }
  }

  return true;
}


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


Q_EXPORT_PLUGIN2( splatcloudobjectselectionplugin, SplatCloudObjectSelectionPlugin );