52 #include "SplatCloudObjectSelectionPlugin.hh" 58 #include <QColorDialog> 65 #define VERTEX_TYPE "selection_splat.png" 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" 82 void SplatCloudObjectSelectionPlugin::initializePlugin()
92 void SplatCloudObjectSelectionPlugin::pluginsInitialized()
97 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
99 emit addSelectionEnvironment(
"SplatCloud Object Selections",
"Select SplatCloud object primitives (vertices/points).", iconPath +
"selections.png" ,
environmentHandle_ );
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 );
127 emit registerKeyShortcut( Qt::Key_A, Qt::ControlModifier );
128 emit registerKeyShortcut( Qt::Key_C, Qt::NoModifier );
129 emit registerKeyShortcut( Qt::Key_I, Qt::NoModifier );
130 emit registerKeyShortcut( Qt::Key_Delete, Qt::NoModifier );
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(
"," ) );
155 SelectionInterface::PrimitiveType type = 0u;
156 emit getActivePrimitiveType( type );
162 bool targetsOnly =
false;
163 emit targetObjectsOnly( targetsOnly );
166 if( _operation == V_SELECT_ALL )
171 if( o_it->visible() )
180 else if( _operation == V_CLEAR )
185 if( o_it->visible() )
194 else if( _operation == V_INVERT )
199 if( o_it->visible() )
208 else if( _operation == V_DELETE )
213 if( o_it->visible() )
215 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreOriginalColors") );
216 emit createBackup ( o_it->id(),
"Pre Deletion",
UPDATE_ALL );
221 emit createBackup ( o_it->id(),
"Delete Selection",
UPDATE_ALL );
222 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreColormodeColors") );
228 else if( _operation == V_COLORIZE )
233 if( o_it->visible() )
235 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreOriginalColors") );
236 emit createBackup ( o_it->id(),
"Pre Colorization",
UPDATE_COLOR );
241 emit createBackup ( o_it->id(),
"Colorize Selection",
UPDATE_COLOR );
242 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreColormodeColors") );
256 QColor c = QColorDialog::getColor( Qt::red, 0, tr(
"Choose color"), QColorDialog::ShowAlphaChannel );
278 size_t node_idx, target_idx;
316 size_t node_idx, target_idx;
331 if ( _event->type() == QEvent::MouseButtonRelease )
347 if( _event->type() == QEvent::MouseButtonPress )
354 if( _event->type() == QEvent::MouseButtonDblClick )
379 if( _event->type() == QEvent::MouseButtonPress )
386 if( _event->type() == QEvent::MouseButtonDblClick )
393 QRegion region = QRegion( p );
409 void SplatCloudObjectSelectionPlugin::loadSelection(
int _objectId,
const QString &_filename )
414 if( !file.
connect( _filename,
false ) )
416 emit log(
LOGERR, QString(
"Could not read file '%1'!" ).arg( _filename ) );
421 loadIniFile( file, _objectId );
428 void SplatCloudObjectSelectionPlugin::loadIniFile(
INIFile &_ini,
int _objectId )
433 emit log(
LOGERR, tr(
"Cannot find object for id ") + QString::number( _objectId ) + tr(
" in saveFile") );
437 std::vector<int> ids;
439 bool updated_selection =
false;
440 bool updated_modeling_regions =
false;
442 QString sectionName =
object->name();
444 if( _ini.
get_entry( ids, sectionName,
"VertexSelection" ) )
447 _ini.
get_entry( invert, sectionName,
"InvertVertexSelection" );
460 updated_selection =
true;
463 if( updated_modeling_regions )
468 else if( updated_selection )
474 if( updated_modeling_regions || updated_selection )
482 void SplatCloudObjectSelectionPlugin::saveIniFile(
INIFile &_ini,
int _objectId )
487 emit log(
LOGERR, tr(
"Cannot find object for id ") + QString::number( _objectId ) + tr(
" in saveFile") );
492 QString sectionName =
object->name();
495 emit log(
LOGERR, tr(
"Cannot find object section id ") + QString::number( _objectId ) + tr(
" in saveFile") );
514 QString section = QString(
"SplatCloudObjectSelection" ) +
"//" + o_it->name();
519 std::vector<int> ids;
521 _file.
get_entry( ids, section,
"VertexSelection" );
542 QString section = QString(
"SplatCloudObjectSelection" ) +
"//" + o_it->name();
555 SelectionInterface::PrimitiveType type = 0u;
556 emit getActivePrimitiveType( type );
564 bool targetsOnly =
false;
565 emit targetObjectsOnly( targetsOnly );
568 if( _key == Qt::Key_A && _modifiers == Qt::ControlModifier )
572 if( o_it->visible() )
581 else if( _key == Qt::Key_C && _modifiers == Qt::NoModifier )
585 if( o_it->visible() )
594 else if( _key == Qt::Key_I && _modifiers == Qt::NoModifier )
598 if( o_it->visible() )
607 else if( _key == Qt::Key_Delete && _modifiers == Qt::NoModifier )
611 if( o_it->visible() )
613 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreOriginalColors") );
614 emit createBackup ( o_it->id(),
"Pre Deletion",
UPDATE_ALL );
619 emit createBackup ( o_it->id(),
"Delete Selection",
UPDATE_ALL );
620 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreColormodeColors") );
635 QList< QPair<size_t,size_t> > list;
641 std::set<int> alreadySelectedObjects;
643 for(
int i=0; i<list.size(); ++i )
645 if( alreadySelectedObjects.count( list[i].first ) != 0 )
654 for(
int j=0; j<list.size(); ++j )
656 if( list[j].first == list[i].first )
658 elements.push_back( list[j].second );
662 alreadySelectedObjects.insert( list[i].first );
680 bool selected =
false;
684 selected = plugin_->splatCloudVolumeSelection( sc, state_, ®ion_, type_, deselection_ );
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void invertVertexSelection(int _objectId)
Invert the current vertex selection.
void lassoSelect(QRegion &_region, PrimitiveType _primitiveType, bool _deselection)
Lasso selection tool.
QString environmentHandle_
Handle to selection environment.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
pick any of the prior targets (should be implemented for all nodes)
void setColorForSelection(const int _objectId, const PrimitiveType _primitiveType)
Set color for selection.
void unselectVertices(int _objectId, IdList _vertexList)
Unselect given vertices.
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
void updateSlotDescriptions()
Set descriptions for local public slots.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
QVector< QPoint > volumeLassoPoints_
Used for volume lasso tool.
bool dataType(DataType _type) const
const QStringList TARGET_OBJECTS("target")
Iterable object range.
QStringList IteratorRestriction
Iterable object range.
SelectionInterface::PrimitiveType allSupportedTypes_
Primitive type handle.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
void selectAllVertices(int _objectId)
Select all vertices.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
void deleteVertexSelection(int _objectId)
Delete vertices that are currently selected.
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
void slotLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a lasso selection.
const QStringList ALL_OBJECTS
Iterable object range.
IdList getVertexSelection(int _objectId)
Return a list of all selected vertices.
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
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.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
std::vector< int > IdList
Standard Type for id Lists used for scripting.
bool scenegraphRegionPick(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< size_t, size_t > > &_list, QVector< float > *_depths, QVector< ACG::Vec3d > *_points)
void selectVertices(int _objectId, IdList _vertexList)
Select given vertices.
void slotSphereSelection(QMouseEvent *_event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a sphere selection.
bool operator()(BaseNode *_node)
Traverse the scenegraph and call the selection function for all mesh nodes.
void splatCloudToggleSelection(SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, PrimitiveType _primitiveType)
Toggle SplatCloud selection.
bool updateGL() const
should GL matrices be updated after each matrix operation
void slotSelectionOperation(QString _operation)
A specific operation is requested.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Traverse the scenegraph and call the selection function for all mesh nodes.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void traverse(BaseNode *_node, Action &_action)
picks only visible front verices (may not be implemented for all nodes)
ACG::GLState & glState()
Get the glState of the Viewer.
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int _a)
Colorize the vertex selection.
virtual bool picked(uint _node_idx)
detect if the node has been picked
void clearVertexSelection(int _objectId)
Unselect all vertices.
SelectionInterface::PrimitiveType vertexType_
Primitive type handle.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
QPolygon lasso_2Dpoints_
Used for lasso selection tool.
picks verices (may not be implemented for all nodes)
Class for the handling of simple configuration files.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
UpdateType addUpdateType(QString _name, bool _resetNeeded)
Adds a updateType and returns the id for the new type.