60 #include "SplatCloudObjectSelectionPlugin.hh"
71 #define VERTEX_TYPE "selection_splat.png"
78 #define V_SELECT_ALL "Select All Splats"
79 #define V_CLEAR "Clear Splat Selection"
80 #define V_INVERT "Invert Splat Selection"
81 #define V_DELETE "Delete Splat Selection"
82 #define V_COLORIZE "Colorize Splat Selection"
88 void SplatCloudObjectSelectionPlugin::initializePlugin()
98 void SplatCloudObjectSelectionPlugin::pluginsInitialized()
103 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
105 emit addSelectionEnvironment(
"SplatCloud Object Selections",
"Select SplatCloud object primitives (vertices/points).", iconPath +
"selections.png" ,
environmentHandle_ );
123 QStringList vertexOperations;
124 vertexOperations.append( V_SELECT_ALL );
125 vertexOperations.append( V_CLEAR );
126 vertexOperations.append( V_INVERT );
127 vertexOperations.append( V_DELETE );
128 vertexOperations.append( V_COLORIZE );
133 emit registerKeyShortcut( Qt::Key_A, Qt::ControlModifier );
134 emit registerKeyShortcut( Qt::Key_C, Qt::NoModifier );
135 emit registerKeyShortcut( Qt::Key_I, Qt::NoModifier );
136 emit registerKeyShortcut( Qt::Key_Delete, Qt::NoModifier );
145 emit setSlotDescription(
"selectVertices(int,IdList)", tr(
"Select the specified vertices" ), QString (
"objectId,vertexList" ).split(
"," ), QString (
"Id of object,List of vertices" ).split(
"," ) );
146 emit setSlotDescription(
"unselectVertices(int,IdList)", tr(
"Unselect the specified vertices" ), QString (
"objectId,vertexList" ).split(
"," ), QString (
"Id of object,List of vertices" ).split(
"," ) );
147 emit setSlotDescription(
"selectAllVertices(int)", tr(
"Select all vertices of an object" ), QStringList(
"objectId" ), QStringList(
"Id of object" ) );
148 emit setSlotDescription(
"clearVertexSelection(int)", tr(
"Clear vertex selection of an object" ), QStringList(
"objectId" ), QStringList(
"Id of an object" ) );
149 emit setSlotDescription(
"invertVertexSelection(int)", tr(
"Invert vertex selection of an object"), QStringList(
"objectId" ), QStringList(
"Id of an object" ) );
150 emit setSlotDescription(
"deleteVertexSelection(int)", tr(
"Delete selected vertices" ), QStringList(
"objectId" ), QStringList(
"Id of an object" ) );
151 emit setSlotDescription(
"colorizeVertexSelection(int,int,int,int)", tr(
"Colorize the selected vertices" ), QString (
"objectId,r,g,b" ).split(
"," ), QString (
"Id of an object,Red,Green,Blue" ).split(
"," ) );
152 emit setSlotDescription(
"loadSelection(int,QString)", tr(
"Load selection from selection file" ), QString (
"objectId,filename" ).split(
"," ), QString (
"Id of an object,Selection file" ).split(
"," ) );
161 SelectionInterface::PrimitiveType type = 0u;
162 emit getActivePrimitiveType( type );
168 bool targetsOnly =
false;
169 emit targetObjectsOnly( targetsOnly );
172 if( _operation == V_SELECT_ALL )
177 if( o_it->visible() )
186 else if( _operation == V_CLEAR )
191 if( o_it->visible() )
200 else if( _operation == V_INVERT )
205 if( o_it->visible() )
214 else if( _operation == V_DELETE )
219 if( o_it->visible() )
221 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreOriginalColors") );
222 emit createBackup ( o_it->id(),
"Pre Deletion",
UPDATE_ALL );
227 emit createBackup ( o_it->id(),
"Delete Selection",
UPDATE_ALL );
228 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreColormodeColors") );
234 else if( _operation == V_COLORIZE )
239 if( o_it->visible() )
241 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreOriginalColors") );
242 emit createBackup ( o_it->id(),
"Pre Colorization",
UPDATE_COLOR );
247 emit createBackup ( o_it->id(),
"Colorize Selection",
UPDATE_COLOR );
248 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreColormodeColors") );
262 QColor c = QColorDialog::getColor( Qt::red, 0, tr(
"Choose color"), QColorDialog::ShowAlphaChannel );
284 unsigned int node_idx, target_idx;
322 unsigned int node_idx, target_idx;
337 if ( _event->type() == QEvent::MouseButtonRelease )
353 if( _event->type() == QEvent::MouseButtonPress )
360 if( _event->type() == QEvent::MouseButtonDblClick )
385 if( _event->type() == QEvent::MouseButtonPress )
392 if( _event->type() == QEvent::MouseButtonDblClick )
399 QRegion region = QRegion( p );
415 void SplatCloudObjectSelectionPlugin::loadSelection(
int _objectId,
const QString &_filename )
420 if( !file.
connect( _filename,
false ) )
422 emit log(
LOGERR, QString(
"Could not read file '%1'!" ).arg( _filename ) );
427 loadIniFile( file, _objectId );
434 void SplatCloudObjectSelectionPlugin::loadIniFile(
INIFile &_ini,
int _objectId )
439 emit log(
LOGERR, tr(
"Cannot find object for id ") + QString::number( _objectId ) + tr(
" in saveFile") );
443 std::vector<int> ids;
445 bool updated_selection =
false;
446 bool updated_modeling_regions =
false;
448 QString sectionName =
object->name();
450 if( _ini.
get_entry( ids, sectionName,
"VertexSelection" ) )
453 _ini.
get_entry( invert, sectionName,
"InvertVertexSelection" );
466 updated_selection =
true;
469 if( updated_modeling_regions )
474 else if( updated_selection )
480 if( updated_modeling_regions || updated_selection )
488 void SplatCloudObjectSelectionPlugin::saveIniFile(
INIFile &_ini,
int _objectId )
493 emit log(
LOGERR, tr(
"Cannot find object for id ") + QString::number( _objectId ) + tr(
" in saveFile") );
498 QString sectionName =
object->name();
501 emit log(
LOGERR, tr(
"Cannot find object section id ") + QString::number( _objectId ) + tr(
" in saveFile") );
520 QString section = QString(
"SplatCloudObjectSelection" ) +
"//" + o_it->name();
525 std::vector<int> ids;
527 _file.
get_entry( ids, section,
"VertexSelection" );
548 QString section = QString(
"SplatCloudObjectSelection" ) +
"//" + o_it->name();
561 SelectionInterface::PrimitiveType type = 0u;
562 emit getActivePrimitiveType( type );
570 bool targetsOnly =
false;
571 emit targetObjectsOnly( targetsOnly );
574 if( _key == Qt::Key_A && _modifiers == Qt::ControlModifier )
578 if( o_it->visible() )
587 else if( _key == Qt::Key_C && _modifiers == Qt::NoModifier )
591 if( o_it->visible() )
600 else if( _key == Qt::Key_I && _modifiers == Qt::NoModifier )
604 if( o_it->visible() )
613 else if( _key == Qt::Key_Delete && _modifiers == Qt::NoModifier )
617 if( o_it->visible() )
619 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreOriginalColors") );
620 emit createBackup ( o_it->id(),
"Pre Deletion",
UPDATE_ALL );
625 emit createBackup ( o_it->id(),
"Delete Selection",
UPDATE_ALL );
626 emit updatedObject( o_it->id(),
addUpdateType(
"RestoreColormodeColors") );
641 QList< QPair<unsigned int,unsigned int> > list;
647 std::set<int> alreadySelectedObjects;
649 for(
int i=0; i<list.size(); ++i )
651 if( alreadySelectedObjects.count( list[i].first ) != 0 )
660 for(
int j=0; j<list.size(); ++j )
662 if( list[j].first == list[i].first )
664 elements.push_back( list[j].second );
668 alreadySelectedObjects.insert( list[i].first );
686 bool selected =
false;
690 selected = plugin_->splatCloudVolumeSelection( sc, state_, ®ion_, type_, deselection_ );
706 #if QT_VERSION < 0x050000
void slotSphereSelection(QMouseEvent *_event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a sphere selection.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
const QStringList ALL_OBJECTS
Iterable object range.
SelectionInterface::PrimitiveType vertexType_
Primitive type handle.
SelectionInterface::PrimitiveType allSupportedTypes_
Primitive type handle.
void lassoSelect(QRegion &_region, PrimitiveType _primitiveType, bool _deselection)
Lasso selection tool.
pick any of the prior targets (should be implemented for all nodes)
void clearVertexSelection(int _objectId)
Unselect all vertices.
QPolygon lasso_2Dpoints_
Used for lasso selection tool.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
UpdateType addUpdateType(QString _name, bool _resetNeeded)
Adds a updateType and returns the id for the new type.
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int _a)
Colorize the vertex selection.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
bool dataType(DataType _type) const
picks verices (may not be implemented for all nodes)
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
bool scenegraphRegionPick(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< unsigned int, unsigned int > > &_list, QVector< float > *_depths, QVector< ACG::Vec3d > *_points)
Traverse the scenegraph and call the selection function for all mesh nodes.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
void setColorForSelection(const int _objectId, const PrimitiveType _primitiveType)
Set color for selection.
void selectVertices(int _objectId, IdList _vertexList)
Select given vertices.
QString environmentHandle_
Handle to selection environment.
picks only visible front verices (may not be implemented for all nodes)
void slotSelectionOperation(QString _operation)
A specific operation is requested.
IdList getVertexSelection(int _objectId)
Return a list of all selected vertices.
Class for the handling of simple configuration files.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle 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.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void updateSlotDescriptions()
Set descriptions for local public slots.
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
void invertVertexSelection(int _objectId)
Invert the current vertex selection.
void deleteVertexSelection(int _objectId)
Delete vertices that are currently selected.
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 slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
QVector< QPoint > volumeLassoPoints_
Used for volume lasso tool.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
QStringList IteratorRestriction
Iterable object range.
void unselectVertices(int _objectId, IdList _vertexList)
Unselect given vertices.
void selectAllVertices(int _objectId)
Select all vertices.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
void slotLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a lasso selection.
ACG::GLState & glState()
Get the glState of the Viewer.
void traverse(BaseNode *_node, Action &_action)
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
bool updateGL() const
should GL matrices be updated after each matrix operation
virtual bool picked(uint _node_idx)
detect if the node has been picked