Commit 859fde74 authored by Jan Möbius's avatar Jan Möbius
Browse files

Dennis:

New lasso selection

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5269 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 16d9cdcf
......@@ -256,68 +256,6 @@ void SelectionPlugin::componentSelection(QMouseEvent* _event) {
}
//***********************************************************************************
/** \brief Slots calls the actual selection function after QtLasso finished selecting
*
* @param _event mouse event that occurred
*/
void SelectionPlugin::slotLassoSelection(ACG::QtLasso::SelectionMode /*_mode*/) {
PluginFunctions::IteratorRestriction targets;
if ( tool_->selectOnAll->isChecked() || (selectionType_ & OBJECT) )
targets = PluginFunctions::ALL_OBJECTS;
else
targets = PluginFunctions::TARGET_OBJECTS;
for ( PluginFunctions::ObjectIterator o_it(targets) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->visible() ){
if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) {
bool sel = lassoSelection(*(PluginFunctions::triMesh(*o_it)));
if ( (selectionType_ & OBJECT) && sel ){
if (sourceSelection_){
o_it->source( !deselection_ );
emit updatedObject(o_it->id());
} else {
o_it->target( !deselection_ );
emit activeObjectChanged();
emit updatedObject(o_it->id());
}
}
}
if ( o_it->dataType( DATA_POLY_MESH ) ) {
bool sel = lassoSelection(*(PluginFunctions::polyMesh(*o_it)));
if ( (selectionType_ & OBJECT) && sel ){
if (sourceSelection_){
o_it->source( !deselection_ );
emit updatedObject(o_it->id());
} else {
o_it->target( !deselection_ );
emit activeObjectChanged();
emit updatedObject(o_it->id());
}
}
}
o_it->update();
emit createBackup(o_it->id(),"Lasso Selection");
}
}
lasso_->reset();
emit updateView();
}
//-----------------------------------------------------------------------------
#ifdef ENABLE_POLYLINE_SUPPORT
......@@ -399,6 +337,197 @@ void SelectionPlugin::surfaceLassoSelection(QMouseEvent* _event){
}
}
/** \brief Handle Mouse move event for sphere painting selection
*
* @param _event mouse event that occurred
*/
void SelectionPlugin::handleLassoSelection(QMouseEvent* _event) {
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
ACG::Vec3f hit_pointf;
int y = PluginFunctions::viewerProperties().glState().context_height() - _event->pos().y();
if ( _event->button() == Qt::RightButton ){
//do not bother the context menu
line_node_->hide();
return;
}
switch ( _event->type() ) {
case QEvent::MouseButtonDblClick :
if (lasso_selection_) {
line_node_->add_point(lasso_points_[0]);
line_node_->hide();
lasso_2Dpoints_ << lasso_2Dpoints_[0];
QRegion region (lasso_2Dpoints_);
QList <QPair<unsigned int, unsigned int> >list;
QSet <unsigned int> objects;
if (selectionType_ & (FACE | OBJECT) && PluginFunctions::scenegraphRegionPick(ACG::SceneGraph::PICK_FACE, region, list))
{
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());
}
}
}
lasso_selection_ = false;
}
break;
case QEvent::MouseButtonPress :
if (!lasso_selection_)
{
line_node_->show();
line_node_->clear();
lasso_points_.clear();
lasso_2Dpoints_.clear();
lasso_selection_ = true;
}
if (deselection_)
line_node_->set_color(ACG::Vec4f(1.0, 0.0, 0.0, 1.0));
else
line_node_->set_color(ACG::Vec4f(0.0, 1.0, 0.0, 1.0));
if (!PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE, _event->pos(),node_idx, target_idx, &hit_point))
hit_point = PluginFunctions::viewerProperties().glState().unproject(ACG::Vec3d(_event->pos().x(),y,0.5));
hit_pointf = hit_point;
lasso_points_.push_back (hit_pointf);
line_node_->clear();
for (std::vector< ACG::Vec3f >::iterator it = lasso_points_.begin();
it != lasso_points_.end(); ++it)
line_node_->add_point(*it);
line_node_->add_point(lasso_points_[0]);
lasso_2Dpoints_ << _event->pos();
break;
case QEvent::MouseMove :
if (lasso_selection_)
{
if (deselection_)
line_node_->set_color(ACG::Vec4f(1.0, 0.0, 0.0, 1.0));
else
line_node_->set_color(ACG::Vec4f(0.0, 1.0, 0.0, 1.0));
if (!PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE, _event->pos(),node_idx, target_idx, &hit_point))
hit_point = PluginFunctions::viewerProperties().glState().unproject(ACG::Vec3d(_event->pos().x(),y,0.5));
hit_pointf = hit_point;
if (!_event->buttons() && lasso_points_.size () > 1)
{
lasso_points_.pop_back ();
lasso_2Dpoints_.pop_back ();
}
lasso_points_.push_back (hit_pointf);
line_node_->clear();
for (std::vector< ACG::Vec3f >::iterator it = lasso_points_.begin();
it != lasso_points_.end(); ++it)
line_node_->add_point(*it);
line_node_->add_point(lasso_points_[0]);
lasso_2Dpoints_ << _event->pos();
}
break;
default:
break;
}
emit updateView();
}
/** \brief Execute mesh element selection for each object
*
* @param _list object/element pair list
* @param _type selection type
*/
void SelectionPlugin::forEachObject(QList<QPair<unsigned int, unsigned int> > &_list, SelectionPrimitive _type)
{
QSet <unsigned int> objects;
idList elements;
BaseObjectData* object(0);
for (QList<QPair<unsigned int, unsigned int> >::iterator it = _list.begin();
it != _list.end(); ++it)
{
objects << (*it).first;
}
foreach (unsigned int obj, objects)
{
elements.clear();
for (QList<QPair<unsigned int, unsigned int> >::iterator it = _list.begin();
it != _list.end(); ++it)
{
if ((*it).first == obj)
elements.push_back((*it).second);
}
if(PluginFunctions::getPickedObject(obj, object))
{
switch (_type)
{
case VERTEX:
if (deselection_)
unselectVertices (object->id (), elements);
else
selectVertices (object->id (), elements);
break;
case FACE:
if (deselection_)
unselectFaces (object->id (), elements);
else
selectFaces (object->id (), elements);
break;
case EDGE:
if (deselection_)
unselectEdges (object->id (), elements);
else
selectEdges (object->id (), elements);
break;
default:
break;
}
}
}
}
#endif
......
......@@ -509,128 +509,3 @@ void SelectionPlugin::componentSelection(MeshT* _mesh, uint _fh) {
}
}
//***********************************************************************************
/** \brief Select primitives inside the region of the lasso
*
* @param _mesh a mesh
* @return false if the selectionType is != OBJECT otherwise it returns true if the object is completly inside the lasso region
*/
template< class MeshT>
bool SelectionPlugin::lassoSelection(MeshT& _mesh){
// initialize everything
if (selectionType_ & VERTEX){
//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);
}
if (selectionType_ & EDGE){
//reset tagged status
typename MeshT::EdgeIter e_it, e_end( _mesh.edges_end() );
for (e_it=_mesh.edges_begin(); e_it!=e_end; ++e_it)
_mesh.status(e_it).set_tagged(false);
}
if (selectionType_ & FACE){
//reset tagged status
typename MeshT::FaceIter f_it, f_end( _mesh.faces_end() );
for (f_it=_mesh.faces_begin(); f_it!=f_end; ++f_it)
_mesh.status(f_it).set_tagged(false);
}
//tag primitives inside lasso region
typename MeshT::FaceIter f_it, f_end = _mesh.faces_end();
for (f_it = _mesh.faces_begin(); f_it != f_end ; ++f_it ) {
// Check which points of the face lie inside the lasso selection
uint fVertices = 0;
uint verticesInside = 0;
bool lastVertexInside = false;
std::vector<typename MeshT::VertexHandle> vertex_handles;
std::vector<typename MeshT::EdgeHandle> edge_handles;
for (typename MeshT::FaceHalfedgeIter fh_it(_mesh,f_it); fh_it; ++fh_it){
typename MeshT::VertexHandle vh = _mesh.from_vertex_handle( fh_it.handle() );
if ( lasso_->is_vertex_selected( (ACG::Vec3d)_mesh.point(vh)) ){
if (selectionType_ & VERTEX)
_mesh.status( vh ).set_tagged(true);
if (selectionType_ & EDGE){
if (lastVertexInside)
_mesh.status( _mesh.edge_handle( fh_it.handle() ) ).set_tagged(true);
lastVertexInside = true;
}
verticesInside++;
}else{
lastVertexInside = false;
if (selectionType_ & OBJECT)
return false; //this doesn't work for multiple selectionTypes
}
fVertices++;
}
//perhaps check the first edge again
if ( (selectionType_ & EDGE) && lastVertexInside){
typename MeshT::FaceHalfedgeIter fh_it(_mesh,f_it);
typename MeshT::VertexHandle vh = _mesh.from_vertex_handle( fh_it.handle() );
if ( lasso_->is_vertex_selected( (ACG::Vec3d)_mesh.point(vh)) )
_mesh.status( _mesh.edge_handle( fh_it.handle() ) ).set_tagged(true);
}
//tag faces
if (selectionType_ & FACE){
if (verticesInside == fVertices)
_mesh.status(f_it).set_tagged(true);
}
}
// finally do the selection
//vertex selection
if (selectionType_ & VERTEX){
typename MeshT::VertexIter v_it, v_end( _mesh.vertices_end() );
for (v_it=_mesh.vertices_begin(); v_it!=v_end; ++v_it){
if ( _mesh.status(v_it).tagged() && !_mesh.status(v_it).hidden() )
_mesh.status(v_it).set_selected( !deselection_ );
}
}
//edge selection
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(e_it).tagged() && !_mesh.status(e_it).hidden() )
_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){
if ( _mesh.status(f_it).tagged() && !_mesh.status(f_it).hidden() )
_mesh.status(f_it).set_selected( !deselection_ );
}
}
return true;
}
......@@ -52,7 +52,6 @@
/** \brief Default Constructor
*/
SelectionPlugin::SelectionPlugin() :
lasso_(0),
waitingForPolyLineSelection_(false),
polyLineID_(-1)
{
......@@ -60,6 +59,7 @@ SelectionPlugin::SelectionPlugin() :
sourceSelection_ = false;
deselection_ = false;
lasso_selection_ = false;
}
/*******************************************************************************
......@@ -93,6 +93,10 @@ void SelectionPlugin::initializePlugin() {
sphere_selection_ = false;
line_node_ = new ACG::SceneGraph::LineNode (ACG::SceneGraph::LineNode::PolygonMode,
PluginFunctions::getRootNode(), "Lasso line");
line_node_->set_line_width (2.0);
line_node_->hide();
//register keys for the plugin
emit registerKey(Qt::Key_C, Qt::NoModifier, "Clear Selection");
......@@ -130,6 +134,7 @@ void SelectionPlugin::pluginsInitialized() {
emit addHiddenPickMode(CONNECTED_COMPONENT_SELECTION);
emit setPickModeMouseTracking(PAINT_SPHERE_SELECTION, true);
emit setPickModeMouseTracking(LASSO_SELECTION, true);
emit setPickModeCursor(SURFACE_LASSO_SELECTION, Qt::CrossCursor);
// CONTEXT MENU
......@@ -386,17 +391,7 @@ 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) {
if ( lasso_ == 0 ) {
// create lasso For screen lasso selection
lasso_ = new ACG::QtLasso(PluginFunctions::viewerProperties().glState());
connect(lasso_ , SIGNAL(signalLassoSelection(ACG::QtLasso::SelectionMode)),
this , SLOT(slotLassoSelection(ACG::QtLasso::SelectionMode)));
}
lasso_->slotMouseEvent(_event);
} else
if ( PluginFunctions::pickMode() == LASSO_SELECTION) handleLassoSelection(_event); else
if ( PluginFunctions::pickMode() == CONNECTED_COMPONENT_SELECTION) componentSelection(_event);
#ifdef ENABLE_POLYLINE_SUPPORT
else
......@@ -445,12 +440,6 @@ void SelectionPlugin::slotPickModeChanged( const std::string& _mode) {
emit updateView();
}
if ( (_mode != LASSO_SELECTION) && (lasso_ != 0) ) {
lasso_->reset();
delete lasso_;
lasso_ = 0;
}
#ifdef ENABLE_POLYLINE_SUPPORT
bool check = (_mode == SURFACE_LASSO_SELECTION) || (_mode == "PolyLine" && waitingForPolyLineSelection_);
surfaceLassoAction_->setChecked(check);
......
......@@ -49,8 +49,8 @@
#include <OpenFlipper/BasePlugin/INIInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <ACG/QtWidgets/QtLasso.hh>
#include <ACG/Scenegraph/GlutPrimitiveNode.hh>
#include <ACG/Scenegraph/LineNode.hh>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
......@@ -251,6 +251,9 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
template< class MeshT >
void componentSelection(MeshT* _mesh, uint _fh);
/// Handle Mouse move event for lasso selection
void handleLassoSelection(QMouseEvent* _event);
/** @} */
private slots:
......@@ -269,13 +272,10 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// Delete all selected elements of the target meshes
void slotDeleteSelection();
/// Called by lasso after user has selected a region
void slotLassoSelection(ACG::QtLasso::SelectionMode);
private:
/// Select regions of the mesh that are encapsulated by the lasso
template< class MeshT>
bool lassoSelection(MeshT& _mesh);
/// Select mesh elements for each object in the list
void forEachObject(QList<QPair<unsigned int, unsigned int> > &_list, SelectionPrimitive _type);
//===========================================================================
/** @name Button slots
......@@ -486,6 +486,9 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// Sphere Node
ACG::SceneGraph::GlutPrimitiveNode* sphere_node_;
/// Line Node
ACG::SceneGraph::LineNode* line_node_;
/// Current radius of the sphere
float sphere_radius_;
......@@ -495,20 +498,18 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// vector containing all object-id's whose selection has changed
std::vector< int > selection_changes_;
/** @} */
/// vector containing all projected lasso points
std::vector< ACG::Vec3f > lasso_points_;
//===========================================================================
/** @name Variables for Lasso Scene Selection
* @{ */
//===========================================================================
/// vector containing all lasso points
QPolygon lasso_2Dpoints_;
/// The lasso widget
ACG::QtLasso* lasso_;
/// true if currently selecting with lasso
bool lasso_selection_;
/** @} */
//===========================================================================
/** @name Variables for Surface-Lasso Selection
* @{ */
......
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