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
56 #include <OpenFlipper/common/GlobalOptions.hh>
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
85 updateSlotDescriptions();
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
108 allSupportedTypes_ = vertexType_;
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
137 void SplatCloudObjectSelectionPlugin::updateSlotDescriptions()
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
153 void SplatCloudObjectSelectionPlugin::slotSelectionOperation( QString _operation )
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 );
164 PluginFunctions::IteratorRestriction restriction = (targetsOnly ? PluginFunctions::TARGET_OBJECTS : PluginFunctions::ALL_OBJECTS);
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 {
388 ACG::GLState &state = PluginFunctions::viewerProperties().glState();
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 );
396 ACG::SceneGraph::traverse( PluginFunctions::getRootNode(), action );
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
506 void SplatCloudObjectSelectionPlugin::slotLoadSelection( const INIFile &_file )
507 {
508 // Iterate over all SplatCloud objects in the scene and save
509 // the selections for all supported entity types
510 for( PluginFunctions::ObjectIterator o_it( PluginFunctions::ALL_OBJECTS, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it)
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
534 void SplatCloudObjectSelectionPlugin::slotSaveSelection( INIFile &_file )
535 {
536 // Iterate over all SplatCloud objects in the scene and save
537 // the selections for all supported entity types
538 for( PluginFunctions::ObjectIterator o_it( PluginFunctions::ALL_OBJECTS, DataType( DATA_SPLATCLOUD ) ); o_it != PluginFunctions::objectsEnd(); ++o_it)
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 );
566 PluginFunctions::IteratorRestriction restriction = (targetsOnly ? PluginFunctions::TARGET_OBJECTS : PluginFunctions::ALL_OBJECTS);
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 {
639 PluginFunctions::scenegraphRegionPick( ACG::SceneGraph::PICK_FRONT_VERTEX, _region, list );
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
675 bool SelectVolumeAction::operator()( BaseNode *_node )
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
SplatCloudObjectSelectionPlugin::slotKeyShortcutEvent
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
Definition: SplatCloudObjectSelectionPlugin.cc:553
SplatCloudObjectSelectionPlugin::slotLoadSelection
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
Definition: SplatCloudObjectSelectionPlugin.cc:506
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
SplatCloudObjectSelectionPlugin::invertVertexSelection
void invertVertexSelection(int _objectId)
Invert the current vertex selection.
Definition: VertexSelection.cc:184
SplatCloudObjectSelectionPlugin::lassoSelect
void lassoSelect(QRegion &_region, PrimitiveType _primitiveType, bool _deselection)
Lasso selection tool.
Definition: SplatCloudObjectSelectionPlugin.cc:632
SplatCloudObjectSelectionPlugin::environmentHandle_
QString environmentHandle_
Handle to selection environment.
Definition: SplatCloudObjectSelectionPlugin.hh:259
PluginFunctions::scenegraphPick
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Definition: PluginFunctions.cc:478
ACG::SceneGraph::PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
SplatCloudObjectSelectionPlugin::setColorForSelection
void setColorForSelection(const int _objectId, const PrimitiveType _primitiveType)
Set color for selection.
Definition: SplatCloudObjectSelectionPlugin.cc:254
SplatCloudObjectSelectionPlugin::unselectVertices
void unselectVertices(int _objectId, IdList _vertexList)
Unselect given vertices.
Definition: VertexSelection.cc:105
ACG::GLState::set_updateGL
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
Definition: GLState.hh:235
BaseObject::id
int id() const
Definition: BaseObject.cc:190
PluginFunctions::getPickedObject
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Definition: PluginFunctions.cc:259
UPDATE_SELECTION
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
SplatCloudObjectSelectionPlugin::updateSlotDescriptions
void updateSlotDescriptions()
Set descriptions for local public slots.
Definition: SplatCloudObjectSelectionPlugin.cc:137
INIFile::section_exists
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
Definition: INIFile.cc:227
SplatCloudObjectSelectionPlugin::volumeLassoPoints_
QVector< QPoint > volumeLassoPoints_
Used for volume lasso tool.
Definition: SplatCloudObjectSelectionPlugin.hh:263
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
PluginFunctions::TARGET_OBJECTS
const QStringList TARGET_OBJECTS("target")
Iterable object range.
PluginFunctions::IteratorRestriction
QStringList IteratorRestriction
Iterable object range.
Definition: PluginFunctions.hh:428
SplatCloudObjectSelectionPlugin::allSupportedTypes_
SelectionInterface::PrimitiveType allSupportedTypes_
Primitive type handle.
Definition: SplatCloudObjectSelectionPlugin.hh:261
INIFile::connect
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Definition: INIFile.cc:70
SplatCloudObjectSelectionPlugin::selectAllVertices
void selectAllVertices(int _objectId)
Select all vertices.
Definition: VertexSelection.cc:138
SplatCloudObjectSelectionPlugin::slotToggleSelection
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
Definition: SplatCloudObjectSelectionPlugin.cc:272
SplatCloudObjectSelectionPlugin::deleteVertexSelection
void deleteVertexSelection(int _objectId)
Delete vertices that are currently selected.
Definition: VertexSelection.cc:231
SplatCloudObjectSelectionPlugin::slotVolumeLassoSelection
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
Definition: SplatCloudObjectSelectionPlugin.cc:373
SplatCloudObjectSelectionPlugin::slotLassoSelection
void slotLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a lasso selection.
Definition: SplatCloudObjectSelectionPlugin.cc:341
PluginFunctions::ALL_OBJECTS
const QStringList ALL_OBJECTS
Iterable object range.
Definition: PluginFunctions.hh:430
LOGERR
Definition: LoggingInterface.hh:96
SplatCloudObjectSelectionPlugin::getVertexSelection
IdList getVertexSelection(int _objectId)
Return a list of all selected vertices.
Definition: VertexSelection.cc:207
PluginFunctions::getRootNode
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
Definition: PluginFunctions.cc:961
GlobalOptions.hh
ACG::GLState
Definition: GLState.hh:213
SplatCloudObjectSelectionPlugin::slotSaveSelection
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
Definition: SplatCloudObjectSelectionPlugin.cc:534
SplatCloudObjectSelectionPlugin::splatCloudSphereSelection
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.
Definition: SplatCloudObjectSelectionPlugin2.cc:140
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:294
PluginFunctions::viewerProperties
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
Definition: PluginFunctions.cc:609
IdList
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:179
PluginFunctions::scenegraphRegionPick
bool scenegraphRegionPick(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< size_t, size_t > > &_list, QVector< float > *_depths, QVector< ACG::Vec3d > *_points)
Definition: PluginFunctions.cc:545
SplatCloudObjectSelectionPlugin::selectVertices
void selectVertices(int _objectId, IdList _vertexList)
Select given vertices.
Definition: VertexSelection.cc:72
SplatCloudObjectSelectionPlugin::slotSphereSelection
void slotSphereSelection(QMouseEvent *_event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a sphere selection.
Definition: SplatCloudObjectSelectionPlugin.cc:310
SplatCloud
Definition: SplatCloud.hh:79
SelectVolumeAction::operator()
bool operator()(BaseNode *_node)
Traverse the scenegraph and call the selection function for all mesh nodes.
Definition: MeshObjectSelectionPlugin.cc:2045
SplatCloudObjectSelectionPlugin::splatCloudToggleSelection
void splatCloudToggleSelection(SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, PrimitiveType _primitiveType)
Toggle SplatCloud selection.
Definition: SplatCloudObjectSelectionPlugin2.cc:98
ACG::GLState::updateGL
bool updateGL() const
should GL matrices be updated after each matrix operation
Definition: GLState.hh:233
SplatCloudObjectSelectionPlugin::slotSelectionOperation
void slotSelectionOperation(QString _operation)
A specific operation is requested.
Definition: SplatCloudObjectSelectionPlugin.cc:153
PluginFunctions::splatCloud
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
Definition: PluginFunctionsSplatCloud.cc:136
INIFile::add_entry
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Definition: INIFile.cc:257
SelectVolumeAction
Traverse the scenegraph and call the selection function for all mesh nodes.
Definition: MeshObjectSelectionPlugin.hh:612
DataType
Predefined datatypes.
Definition: DataTypes.hh:83
PluginFunctions::ObjectIterator
Core Data Iterator.
Definition: PluginFunctions.hh:441
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
PluginFunctions::objectsEnd
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsIterator.cc:177
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::traverse
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:137
ACG::SceneGraph::PICK_FRONT_VERTEX
picks only visible front verices (may not be implemented for all nodes)
Definition: PickTarget.hh:89
Viewer::ViewerProperties::glState
ACG::GLState & glState()
Get the glState of the Viewer.
Definition: ViewerProperties.cc:318
SplatCloudObjectSelectionPlugin::colorizeVertexSelection
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int _a)
Colorize the vertex selection.
Definition: VertexSelection.cc:254
BaseObjectData::picked
virtual bool picked(uint _node_idx)
detect if the node has been picked
Definition: BaseObjectData.cc:311
SplatCloudObjectSelectionPlugin::clearVertexSelection
void clearVertexSelection(int _objectId)
Unselect all vertices.
Definition: VertexSelection.cc:161
BaseObjectData
Definition: BaseObjectData.hh:102
SplatCloudObjectSelectionPlugin::vertexType_
SelectionInterface::PrimitiveType vertexType_
Primitive type handle.
Definition: SplatCloudObjectSelectionPlugin.hh:260
UPDATE_COLOR
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
DATA_ALL
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
ACG::SceneGraph::BaseNode::id
unsigned int id() const
Definition: BaseNode.hh:423
SplatCloudObjectSelectionPlugin::lasso_2Dpoints_
QPolygon lasso_2Dpoints_
Used for lasso selection tool.
Definition: SplatCloudObjectSelectionPlugin.hh:262
ACG::SceneGraph::PICK_VERTEX
picks verices (may not be implemented for all nodes)
Definition: PickTarget.hh:82
INIFile
Class for the handling of simple configuration files.
Definition: INIFile.hh:99
DATA_SPLATCLOUD
#define DATA_SPLATCLOUD
Definition: SplatCloud.hh:59
INIFile::get_entry
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
Definition: INIFile.cc:433
addUpdateType
UpdateType addUpdateType(QString _name, bool _resetNeeded)
Adds a updateType and returns the id for the new type.
Definition: UpdateType.cc:229