Commit 7a279e30 authored by Mike Kremer's avatar Mike Kremer
Browse files

Added create mesh from selection functions

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8012 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ebd6ef21
......@@ -634,6 +634,96 @@ void SelectionPlugin::forEachObject(QList<QPair<unsigned int, unsigned int> > &_
}
}
/// Create a mesh containing the selection of the given mesh
int SelectionPlugin::createMeshFromSelection( int _objectId ){
// get object
BaseObjectData *obj = 0;
PluginFunctions::getObject(_objectId, obj);
if (obj == 0){
emit log(LOGERR, tr("Unable to get object"));
return -1;
}
if ( obj->dataType(DATA_TRIANGLE_MESH) ) {
TriMesh* mesh = PluginFunctions::triMesh(obj);
if ( mesh == 0 ) {
emit log(LOGERR, tr("Unable to get mesh"));
return -1;
}
//add an empty mesh
int id = -1;
emit addEmptyObject(DATA_TRIANGLE_MESH, id);
if (id == -1){
emit log(LOGERR, tr("Unable to add empty object"));
return -1;
}
BaseObjectData *newObj;
PluginFunctions::getObject(id, newObj);
TriMesh* newMesh = PluginFunctions::triMesh(newObj);
if ( newMesh == 0 ) {
emit log(LOGERR, tr("Unable to get mesh"));
return -1;
}
//fill the empty mesh with the selection
createMeshFromSelection( *mesh, *newMesh);
emit updatedObject(_objectId);
emit updatedObject(id);
return id;
} else if( obj->dataType(DATA_POLY_MESH) ) {
PolyMesh* mesh = PluginFunctions::polyMesh(obj);
if ( mesh == 0 ) {
emit log(LOGERR, tr("Unable to get mesh"));
return -1;
}
//add an empty mesh
int id;
emit addEmptyObject(DATA_POLY_MESH, id);
if (id == -1){
emit log(LOGERR, tr("Unable to add empty object"));
return -1;
}
BaseObjectData *newObj;
PluginFunctions::getObject(id, newObj);
PolyMesh* newMesh = PluginFunctions::polyMesh(newObj);
if ( newMesh == 0 ) {
emit log(LOGERR, tr("Unable to get mesh"));
return -1;
}
//fill the empty mesh with the selection
createMeshFromSelection( *mesh, *newMesh);
emit updatedObject(_objectId);
emit updatedObject(id);
return id;
}else {
emit log(LOGERR, tr("DataType not supported"));
return -1;
}
}
/// Traverse the scenegraph and call the selection function for nodes
bool SelectVolumeAction::operator()(BaseNode* _node, ACG::GLState& _state)
{
......
......@@ -667,3 +667,80 @@ bool SelectionPlugin::volumeSelection(MeshT* _mesh, ACG::GLState& _state, QRegio
return rv;
}
//***********************************************************************************
/** \brief Create a new mesh from the selection
*
* @param _mesh a mesh
* @param _newMesh the resulting mesh containing only the selected elements
*/
template< class MeshT >
void SelectionPlugin::createMeshFromSelection( MeshT& _mesh, MeshT& _newMesh){
OpenMesh::VPropHandleT< typename MeshT::VertexHandle > copyHandle;
_mesh.add_property(copyHandle,"copyHandle Property" );
//first copy vertices
typename MeshT::VertexIter v_it, v_end = _mesh.vertices_end();
for( v_it = _mesh.vertices_begin(); v_it != v_end; ++v_it ){
bool copy = false;
//if the vertex belongs to the selection copy it
if ( selectionType_ == VERTEX )
copy = _mesh.status( v_it.handle() ).selected();
else if (selectionType_ & EDGE){
for ( typename MeshT::VertexOHalfedgeIter voh_it(_mesh, v_it); voh_it; ++voh_it)
if ( _mesh.status( _mesh.edge_handle(voh_it.handle()) ).selected() ){
copy = true;
break;
}
} else if (selectionType_ & FACE){
for ( typename MeshT::VertexFaceIter vf_it(_mesh, v_it); vf_it; ++vf_it)
if ( _mesh.status( vf_it.handle() ).selected() ){
copy = true;
break;
}
}
//copy it
if ( copy ){
typename MeshT::VertexHandle newVH = _newMesh.add_vertex( _mesh.point(v_it) );
_mesh.property( copyHandle, v_it ) = newVH;
} else {
_mesh.property( copyHandle, v_it ) = typename MeshT::VertexHandle(-1);
}
}
//now check all faces
//if all vertices of the face exist in the new mesh -> copy it
typename MeshT::FaceIter f_it, f_end = _mesh.faces_end();
for( f_it = _mesh.faces_begin(); f_it != f_end; ++f_it ){
std::vector< typename MeshT::VertexHandle > v;
bool skip = false;
for (typename MeshT::FaceVertexIter fv_it(_mesh, f_it); fv_it; ++fv_it)
if ( _mesh.property(copyHandle, fv_it).is_valid() )
v.push_back( _mesh.property(copyHandle, fv_it) );
else{
skip = true;
break;
}
if (!skip)
_newMesh.add_face( v );
}
_newMesh.update_normals();
_mesh.remove_property( copyHandle );
}
......@@ -59,7 +59,6 @@
#include "OpenFlipper/INIFile/INIFile.hh"
#include <OpenFlipper/common/Types.hh>
#include <QFileDialog>
/** \brief Default Constructor
......@@ -221,6 +220,8 @@ void SelectionPlugin::pluginsInitialized() {
emit addHiddenPickMode(SURFACE_LASSO_SELECTION);
emit addHiddenPickMode(CONNECTED_COMPONENT_SELECTION);
emit addHiddenPickMode(FLOOD_FILL_SELECTION);
emit addPickMode(CREATEMESH);
emit setPickModeMouseTracking(PAINT_SPHERE_SELECTION, true);
emit setPickModeMouseTracking(LASSO_SELECTION, true);
......@@ -334,6 +335,16 @@ void SelectionPlugin::pluginsInitialized() {
tr("<B>Flood Fill</B><br>Select a planar region surrounding the clicked element."), toolBarActions_ );
floodFillAction_->setCheckable( true );
toolBar_->addAction( floodFillAction_ );
//createMeshFromSelection
createMeshFromSelAction_ = new QAction(tr("&Create Mesh from selection"), toolBarActions_);
createMeshFromSelAction_->setCheckable( true );
createMeshFromSelAction_->setStatusTip(tr("Create a mesh from the current selection of a target object"));
createMeshFromSelAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scissor_createMeshSelection.png") );
connect(createMeshFromSelAction_, SIGNAL(triggered()), this, SLOT(slotCreateMeshFromSelection()) );
toolBar_->addAction( createMeshFromSelAction_ );
connect( toolBarActions_, SIGNAL( triggered(QAction*) ), this, SLOT(toolBarActionClicked(QAction*)) );
connect( toolBarTypes_, SIGNAL( triggered(QAction*) ), this, SLOT(toolBarActionClicked(QAction*)) );
......@@ -471,7 +482,8 @@ void SelectionPlugin::slotMouseEvent( QMouseEvent* _event ) {
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); else
if ( PluginFunctions::pickMode() == FLOOD_FILL_SELECTION) floodFillSelection(_event);
if ( PluginFunctions::pickMode() == FLOOD_FILL_SELECTION) floodFillSelection(_event); else
if ( PluginFunctions::pickMode() == CREATEMESH ) createMeshFromSelection( _event );
#ifdef ENABLE_POLYLINE_SUPPORT
else
if ( PluginFunctions::pickMode() == SURFACE_LASSO_SELECTION) surfaceLassoSelection(_event);
......@@ -515,6 +527,7 @@ void SelectionPlugin::slotPickModeChanged( const std::string& _mode) {
volumeLassoAction_->setChecked( _mode == VOLUME_LASSO_SELECTION );
connectedAction_->setChecked( _mode == CONNECTED_COMPONENT_SELECTION );
floodFillAction_->setChecked( _mode == FLOOD_FILL_SELECTION );
createMeshFromSelAction_->setChecked(_mode == CREATEMESH );
if ( _mode != PAINT_SPHERE_SELECTION && sphere_node_->visible() ){
sphere_node_->hide();
......@@ -607,6 +620,8 @@ void SelectionPlugin::toolBarActionClicked(QAction * _action)
PluginFunctions::pickMode( CONNECTED_COMPONENT_SELECTION );
else if (_action == floodFillAction_)
PluginFunctions::pickMode( FLOOD_FILL_SELECTION );
else if (_action == createMeshFromSelAction_)
PluginFunctions::pickMode( CREATEMESH );
else if (_action == surfaceLassoAction_){
waitingForPolyLineSelection_ = true;
PluginFunctions::pickMode("PolyLine");
......@@ -818,6 +833,43 @@ void SelectionPlugin::slotToggleSelectionRestriction(){
//******************************************************************************
/** \brief CreateMeshFromSelection Button
*
*/
void SelectionPlugin::slotCreateMeshFromSelection( )
{
PluginFunctions::actionMode( Viewer::PickingMode );
PluginFunctions::pickMode( CREATEMESH );
}
//******************************************************************************
/** \brief Create Mesh from Selection (triggered by pickMode)
*
* @param _event the mouse event that occured
*/
void SelectionPlugin::createMeshFromSelection(QMouseEvent * _event)
{
if (_event->type() == QEvent::MouseButtonPress )
{
unsigned int node_idx, target_idx;
ACG::Vec3d* sourcePoint3D = 0;
if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE,
_event->pos(),
node_idx,
target_idx,
sourcePoint3D))
{
BaseObjectData *obj;
PluginFunctions::getPickedObject(node_idx, obj);
createMeshFromSelection( obj->id() );
}
}
}
//******************************************************************************
/** \brief store selections of a given object to a given ini file
*
* @param _ini reference to the ini file
......
......@@ -82,7 +82,6 @@
#include <QGroupBox>
#define TOGGLE_SELECTION "Select (Toggle)"
#define PAINT_SPHERE_SELECTION "Select (Paint Sphere)"
#define CLOSEST_BOUNDARY_SELECTION "Select (Closest Boundary)"
......@@ -91,6 +90,7 @@
#define SURFACE_LASSO_SELECTION "Select (Surface Lasso)"
#define CONNECTED_COMPONENT_SELECTION "Select (Connected Component)"
#define FLOOD_FILL_SELECTION "Select (Flood Fill)"
#define CREATEMESH "Create Mesh from Selection"
enum SelectionPrimitive {
VERTEX = 0x01,
......@@ -122,6 +122,7 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
//PickingInterface
void addHiddenPickMode( const std::string _mode );
void addPickMode( const std::string _mode );
void setPickModeMouseTracking( const std::string _mode, bool _mouseTracking);
void setPickModeCursor( const std::string _mode, QCursor _cursor);
......@@ -151,6 +152,7 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
//LoadSaveInterface
void deleteObject( int _id );
void addEmptyObject( DataType _type, int& _id);
private slots:
......@@ -207,12 +209,19 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
QAction* surfaceLassoAction_;
QAction* connectedAction_;
QAction* floodFillAction_;
QAction* createMeshFromSelAction_;
private slots:
/// Switch selection mode dependent which buttons are pressed in the toolbar
void toolBarActionClicked(QAction* _action);
private :
//===========================================================================
/** @name Template Functions
* @{ */
//===========================================================================
/// Update face selection to correspond to the vertex selection
template< typename MeshType >
void update_regions(MeshType* _mesh);
......@@ -248,6 +257,14 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// Colorize a selection
template< typename MeshT >
void colorizeSelection(MeshT* _mesh, SelectionPrimitive _type, int _red, int _green, int _blue);
//=================================================================
/// Create a new mesh from the selection
template< class MeshT >
void createMeshFromSelection( MeshT& _mesh, MeshT& _newMesh);
/** @} */
/// when SHIFT key is pressed do source-selection instead of target selection in object-mode
bool sourceSelection_;
......@@ -535,6 +552,11 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// load Selection of one object
void loadSelection( int _objectId , QString _filename);
//=====================================================
/// Create a mesh containing the selection of the given mesh
int createMeshFromSelection( int _objectId );
private slots:
......@@ -572,6 +594,14 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// Select for each selected face the adjacent edges and
/// unselect the face after (if _unselectAfter = true)
void convertFtoESelection(bool _unselectAfter = true);
//==========================================================
/// Create Mesh from Selection Button
void slotCreateMeshFromSelection();
/// Create mesh from selection of picked object
void createMeshFromSelection(QMouseEvent* _event);
/** @} */
......
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