Commit 32e9ee6d authored by Jan Möbius's avatar Jan Möbius
Browse files

Dennis:

Added-volume-lasso-selection

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5315 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 6d165247
......@@ -345,7 +345,7 @@ void SelectionPlugin::surfaceLassoSelection(QMouseEvent* _event){
*
* @param _event mouse event that occurred
*/
void SelectionPlugin::handleLassoSelection(QMouseEvent* _event) {
void SelectionPlugin::handleLassoSelection(QMouseEvent* _event, bool _volume) {
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
ACG::Vec3f hit_pointf;
......@@ -370,41 +370,55 @@ void SelectionPlugin::handleLassoSelection(QMouseEvent* _event) {
QList <QPair<unsigned int, unsigned int> >list;
QSet <unsigned int> objects;
if (selectionType_ & (FACE | OBJECT) && PluginFunctions::scenegraphRegionPick(ACG::SceneGraph::PICK_FACE, region, list))
if (!_volume)
{
for (QList<QPair<unsigned int, unsigned int> >::iterator it = list.begin();
it != list.end(); ++it)
if (selectionType_ & (FACE | OBJECT) && PluginFunctions::scenegraphRegionPick(ACG::SceneGraph::PICK_FACE, region, list))
{
objects << (*it).first;
for (QList<QPair<unsigned int, unsigned int> >::iterator it = list.begin();
it != list.end(); ++it)
{
objects << (*it).first;
}
if (selectionType_ & FACE)
forEachObject (list, FACE);
}
if (selectionType_ & VERTEX && PluginFunctions::scenegraphRegionPick(ACG::SceneGraph::PICK_FRONT_VERTEX, region, list))
{
forEachObject (list, VERTEX);
}
if (selectionType_ & EDGE && PluginFunctions::scenegraphRegionPick(ACG::SceneGraph::PICK_FRONT_EDGE, region, list))
{
forEachObject (list, EDGE);
}
// Object selection
if (selectionType_ & OBJECT) {
BaseObjectData* object(0);
foreach (unsigned int i, objects)
if(PluginFunctions::getPickedObject(i, object))
{
if (sourceSelection_){
object->source( !deselection_ );
emit updatedObject(object->id());
} else {
object->target( !deselection_ );
emit activeObjectChanged();
emit updatedObject(object->id());
}
}
}
if (selectionType_ & FACE)
forEachObject (list, FACE);
}
if (selectionType_ & VERTEX && PluginFunctions::scenegraphRegionPick(ACG::SceneGraph::PICK_FRONT_VERTEX, region, list))
{
forEachObject (list, VERTEX);
}
if (selectionType_ & EDGE && PluginFunctions::scenegraphRegionPick(ACG::SceneGraph::PICK_FRONT_EDGE, region, list))
else
{
forEachObject (list, EDGE);
}
ACG::GLState &state = PluginFunctions::viewerProperties().glState();
bool updateGL = state.updateGL ();
state.set_updateGL (false);
// Object selection
if (selectionType_ & OBJECT) {
BaseObjectData* object(0);
foreach (unsigned int i, objects)
if(PluginFunctions::getPickedObject(i, object))
{
if (sourceSelection_){
object->source( !deselection_ );
emit updatedObject(object->id());
SelectVolumeAction action(&region, this);
ACG::SceneGraph::traverse (PluginFunctions::getRootNode(), action, state);
} else {
object->target( !deselection_ );
emit activeObjectChanged();
emit updatedObject(object->id());
}
}
state.set_updateGL (updateGL);
}
lasso_selection_ = false;
......@@ -531,6 +545,41 @@ void SelectionPlugin::forEachObject(QList<QPair<unsigned int, unsigned int> > &_
}
}
/// Traverse the scenegraph and call the selection function for nodes
bool SelectVolumeAction::operator()(BaseNode* _node, ACG::GLState& _state)
{
BaseObjectData *object = 0;
if (PluginFunctions::getPickedObject(_node->id (), object))
{
bool selected = false;
if ( object->dataType(DATA_TRIANGLE_MESH) ) {
TriMesh* m = PluginFunctions::triMesh(object);
selected = plugin_->volumeSelection (m, _state, region_);
} else if ( object->dataType(DATA_POLY_MESH) ) {
PolyMesh* m = PluginFunctions::polyMesh(object);
selected = plugin_->volumeSelection (m, _state, region_);
}
if (selected && plugin_->selectionType_ & OBJECT) {
if (plugin_->sourceSelection_){
object->source( !plugin_->deselection_ );
} else {
object->target( !plugin_->deselection_ );
emit plugin_->activeObjectChanged();
}
}
if (selected)
emit plugin_->updatedObject(object->id());
}
return true;
}
......@@ -509,3 +509,65 @@ void SelectionPlugin::componentSelection(MeshT* _mesh, uint _fh) {
}
}
//***********************************************************************************
/** \brief Select all primitves that are projected to the given region
*
* @param _mesh a mesh
* @param _state current gl state
* @param _region region
* @return was something selected
*/
template< class MeshT >
bool SelectionPlugin::volumeSelection(MeshT* _mesh, ACG::GLState& _state, QRegion *_region)
{
bool rv = false;
ACG::Vec3d proj;
//reset tagged status
typename MeshT::VertexIter v_it, v_end( _mesh->vertices_end() );
for (v_it=_mesh->vertices_begin(); v_it!=v_end; ++v_it)
_mesh->status(v_it).set_tagged(false);
printf("Volume selection\n");
//tag all vertives that are projected into region
for (v_it=_mesh->vertices_begin(); v_it!=v_end; ++v_it)
{
proj = _state.project (_mesh->point (v_it));
if (_region->contains (QPoint (proj[0], _state.context_height () - proj[1])))
{
_mesh->status(v_it).set_tagged(true);
rv = true;
if (selectionType_ & VERTEX)
{
_mesh->status(v_it).set_selected( !deselection_ );
}
}
}
if (selectionType_ & EDGE) {
typename MeshT::EdgeIter e_it, e_end(_mesh->edges_end());
for (e_it=_mesh->edges_begin(); e_it!=e_end; ++e_it)
{
if (_mesh->status(_mesh->to_vertex_handle(_mesh->halfedge_handle(e_it, 0))).tagged () ||
_mesh->status(_mesh->to_vertex_handle(_mesh->halfedge_handle(e_it, 1))).tagged ())
_mesh->status(e_it).set_selected ( !deselection_ );
}
}
if (selectionType_ & FACE) {
typename MeshT::FaceIter f_it, f_end(_mesh->faces_end());
for (f_it=_mesh->faces_begin(); f_it!=f_end; ++f_it)
{
bool select = false;
for (typename MeshT::FaceVertexIter fv_it(*_mesh,f_it); fv_it; ++fv_it)
if (_mesh->status (fv_it).tagged())
select = true;
if (select)
_mesh->status(f_it).set_selected ( !deselection_ );
}
}
return rv;
}
......@@ -130,6 +130,7 @@ void SelectionPlugin::pluginsInitialized() {
emit addHiddenPickMode(PAINT_SPHERE_SELECTION);
emit addHiddenPickMode(CLOSEST_BOUNDARY_SELECTION);
emit addHiddenPickMode(LASSO_SELECTION);
emit addHiddenPickMode(VOLUME_LASSO_SELECTION);
emit addHiddenPickMode(SURFACE_LASSO_SELECTION);
emit addHiddenPickMode(CONNECTED_COMPONENT_SELECTION);
......@@ -210,9 +211,13 @@ void SelectionPlugin::pluginsInitialized() {
toggleAction_->setCheckable( true );
toolBar_->addAction( toggleAction_ );
lassoAction_ = new QAction( QIcon(iconPath + "selection_lasso.png"),
"<B>Lasso Selection</B><br>Draw a Lasso to select elements.", toolBarActions_ );
"<B>Lasso Selection</B><br>Draw a Lasso to select elements on the surface.", toolBarActions_ );
lassoAction_->setCheckable( true );
toolBar_->addAction( lassoAction_ );
volumeLassoAction_ = new QAction( QIcon(iconPath + "selection_lasso.png"),
"<B>Volume Lasso Selection</B><br>Draw a Lasso to select elements in the drawn volume.", toolBarActions_ );
volumeLassoAction_->setCheckable( true );
toolBar_->addAction( volumeLassoAction_ );
paintSphereAction_ = new QAction( QIcon(iconPath + "selection_paintSphere.png"),
"<B>Sphere Selection</B><br>Select elements by painting with a sphere.", toolBarActions_ );
paintSphereAction_->setCheckable( true );
......@@ -397,7 +402,8 @@ void SelectionPlugin::slotMouseEvent( QMouseEvent* _event ) {
if ( PluginFunctions::pickMode() == TOGGLE_SELECTION) toggleSelection(_event); else
if ( PluginFunctions::pickMode() == PAINT_SPHERE_SELECTION) paintSphereSelection(_event); else
if ( PluginFunctions::pickMode() == CLOSEST_BOUNDARY_SELECTION) closestBoundarySelection(_event); else
if ( PluginFunctions::pickMode() == LASSO_SELECTION) handleLassoSelection(_event); else
if ( PluginFunctions::pickMode() == LASSO_SELECTION) handleLassoSelection(_event, false); else
if ( PluginFunctions::pickMode() == VOLUME_LASSO_SELECTION) handleLassoSelection(_event, true); else
if ( PluginFunctions::pickMode() == CONNECTED_COMPONENT_SELECTION) componentSelection(_event);
#ifdef ENABLE_POLYLINE_SUPPORT
else
......@@ -439,6 +445,7 @@ void SelectionPlugin::slotPickModeChanged( const std::string& _mode) {
paintSphereAction_->setChecked( _mode == PAINT_SPHERE_SELECTION );
boundaryAction_->setChecked( _mode == CLOSEST_BOUNDARY_SELECTION );
lassoAction_->setChecked( _mode == LASSO_SELECTION );
volumeLassoAction_->setChecked( _mode == VOLUME_LASSO_SELECTION );
connectedAction_->setChecked( _mode == CONNECTED_COMPONENT_SELECTION );
if ( _mode != PAINT_SPHERE_SELECTION && sphere_node_->visible() ){
......@@ -518,6 +525,8 @@ void SelectionPlugin::toolBarActionClicked(QAction * _action)
PluginFunctions::pickMode( CLOSEST_BOUNDARY_SELECTION );
else if (_action == lassoAction_)
PluginFunctions::pickMode( LASSO_SELECTION );
else if (_action == volumeLassoAction_)
PluginFunctions::pickMode( VOLUME_LASSO_SELECTION );
else if (_action == connectedAction_)
PluginFunctions::pickMode( CONNECTED_COMPONENT_SELECTION );
else if (_action == surfaceLassoAction_){
......
......@@ -54,7 +54,6 @@
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
......@@ -77,6 +76,7 @@
#define PAINT_SPHERE_SELECTION "Select (Paint Sphere)"
#define CLOSEST_BOUNDARY_SELECTION "Select (Closest Boundary)"
#define LASSO_SELECTION "Select (Lasso)"
#define VOLUME_LASSO_SELECTION "Select (Volume Lasso)"
#define SURFACE_LASSO_SELECTION "Select (Surface Lasso)"
#define CONNECTED_COMPONENT_SELECTION "Select (Connected Component)"
......@@ -157,6 +157,8 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
QString name() { return (QString("Selections")); };
QString description( ) { return (QString("Allows to select parts of Objects")); };
friend class SelectVolumeAction;
private :
//GUI objects
/// Widget for Toolbox
......@@ -174,6 +176,7 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
QAction* paintSphereAction_;
QAction* boundaryAction_;
QAction* lassoAction_;
QAction* volumeLassoAction_;
QAction* surfaceLassoAction_;
QAction* connectedAction_;
......@@ -252,7 +255,11 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
void componentSelection(MeshT* _mesh, uint _fh);
/// Handle Mouse move event for lasso selection
void handleLassoSelection(QMouseEvent* _event);
void handleLassoSelection(QMouseEvent* _event, bool _volume);
/// Select all primitves that are projected to the given region
template< class MeshT >
bool volumeSelection(MeshT* _mesh, ACG::GLState& _state, QRegion *_region);
/** @} */
private slots:
......@@ -592,6 +599,23 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
};
/// Traverse the scenegraph and call the selection function for mesh nodes
class SelectVolumeAction
{
public:
SelectVolumeAction(QRegion *_region, SelectionPlugin *_plugin) :
region_(_region), plugin_(_plugin) {}
bool operator()(BaseNode* _node, ACG::GLState& _state);
private:
QRegion *region_;
SelectionPlugin *plugin_;
};
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(SELECTIONPLUGINT_C)
#define SELECTIONPLUGINT_TEMPLATES
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment