Commit 249a0a3e authored by Jan Möbius's avatar Jan Möbius

Reintroduce operation to create new meshes from selection. closes #461

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13921 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 02611dd8
......@@ -233,6 +233,12 @@ void MeshObjectSelectionPlugin::deleteEdgeSelection(int _objectId) {
//=========================================================
int MeshObjectSelectionPlugin::createMeshFromEdgeSelection( int _objectId) {
createMeshFromSelection(_objectId, edgeType_ );
}
//=========================================================
IdList MeshObjectSelectionPlugin::getEdgeSelection( int objectId ) {
BaseObjectData* object;
......
......@@ -211,6 +211,12 @@ void MeshObjectSelectionPlugin::deleteFaceSelection(int _objectId) {
//=========================================================
int MeshObjectSelectionPlugin::createMeshFromFaceSelection( int _objectId) {
createMeshFromSelection(_objectId, faceType_ );
}
//=========================================================
void MeshObjectSelectionPlugin::selectBoundaryFaces(int objectId) {
BaseObjectData* object;
......
......@@ -69,6 +69,7 @@
#define V_GROW "Grow Vertex Selection"
#define V_DELETE "Delete Vertex Selection"
#define V_COLORIZE "Colorize Vertex Selection"
#define V_COPYSELECTION "Create mesh from Vertex Selection"
#define V_HANDLE "Set to Handle Region"
#define V_MODELING "Set to Modeling Region"
#define V_LOAD_FLIPPER "Load Flipper Selection"
......@@ -79,6 +80,7 @@
#define E_DELETE "Delete Edge Selection"
#define E_BOUNDARY "Select Boundary Edges"
#define E_COLORIZE "Colorize Edge Selection"
#define E_COPYSELECTION "Create mesh from Edge Selection"
// Halfedges
#define HE_SELECT_ALL "Select All Halfedges"
#define HE_CLEAR "Clear Halfedge Selection"
......@@ -94,6 +96,7 @@
#define F_SHRINK "Shrink Face Selection"
#define F_GROW "Grow Face Selection"
#define F_COLORIZE "Colorize Face Selection"
#define F_COPYSELECTION "Create mesh from Face Selection"
/// Default constructor
MeshObjectSelectionPlugin::MeshObjectSelectionPlugin() :
......@@ -184,6 +187,7 @@ void MeshObjectSelectionPlugin::pluginsInitialized() {
vertexOperations.append(V_GROW);
vertexOperations.append(V_DELETE);
vertexOperations.append(V_COLORIZE);
vertexOperations.append(V_COPYSELECTION);
vertexOperations.append(V_HANDLE);
vertexOperations.append(V_MODELING);
vertexOperations.append(V_LOAD_FLIPPER);
......@@ -196,6 +200,7 @@ void MeshObjectSelectionPlugin::pluginsInitialized() {
edgeOperations.append(E_DELETE);
edgeOperations.append(E_BOUNDARY);
edgeOperations.append(E_COLORIZE);
edgeOperations.append(E_COPYSELECTION);
// Define halfedge operations
QStringList hedgeOperations;
......@@ -215,6 +220,7 @@ void MeshObjectSelectionPlugin::pluginsInitialized() {
faceOperations.append(F_SHRINK);
faceOperations.append(F_GROW);
faceOperations.append(F_COLORIZE);
faceOperations.append(F_COPYSELECTION);
emit addSelectionOperations(environmentHandle_, generalOperations, "Selection Operations");
emit addSelectionOperations(environmentHandle_, vertexOperations, "Vertex Operations", vertexType_);
......@@ -256,6 +262,9 @@ void MeshObjectSelectionPlugin::updateSlotDescriptions() {
QStringList("objectId"), QStringList("Id of an object"));
emit setSlotDescription("deleteVertexSelection(int)", tr("Delete selected vertices"),
QStringList("objectId"), QStringList("Id of an object"));
emit setSlotDescription("createMeshFromVertexSelection(int)", tr("Take vertex selection and create a new mesh from it"),
QString("objectId").split(","), QString("Id of an object where the selection should be used to create a new mesh").split(","));
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(","));
emit setSlotDescription("selectHandleVertices(int,IdList)", tr("Add specified vertices to handle area"),
......@@ -298,6 +307,8 @@ void MeshObjectSelectionPlugin::updateSlotDescriptions() {
emit setSlotDescription("colorizeEdgeSelection(int,int,int,int)", tr("Colorize the selected edges"),
QString("objectId,r,g,b").split(","), QString("Id of an object,Red,Green,Blue").split(","));
emit setSlotDescription("createMeshFromEdgeSelection(int)", tr("Take edge selection and create a new mesh from it"),
QString("objectId").split(","), QString("Id of an object where the selection should be used to create a new mesh").split(","));
emit setSlotDescription("selectHalfedges(int,IdList)", tr("Select the specified halfedges"),
QString("objectId,halfedgeList").split(","), QString("Id of an object,List of halfedges").split(","));
......@@ -333,6 +344,10 @@ void MeshObjectSelectionPlugin::updateSlotDescriptions() {
QStringList("objectId"), QStringList("Id of an object"));
emit setSlotDescription("colorizeFaceSelection(int,int,int,int)", tr("Colorize the selected faces"),
QString("objectId,r,g,b").split(","), QString("Id of an object,Red,Green,Blue").split(","));
emit setSlotDescription("createMeshFromFaceSelection(int)", tr("Take face selection and create a new mesh from it"),
QString("objectId").split(","), QString("Id of an object where the selection should be used to create a new mesh").split(","));
}
void MeshObjectSelectionPlugin::slotSelectionOperation(QString _operation) {
......@@ -427,6 +442,19 @@ void MeshObjectSelectionPlugin::slotSelectionOperation(QString _operation) {
setColorForSelection(o_it->id(), vertexType_);
}
}
} else if(_operation == V_COPYSELECTION) {
// Copy vertex selection
std::vector<int> objects;
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_ALL));
o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (o_it->visible()) {
objects.push_back(o_it->id());
}
}
for ( unsigned int i = 0 ; i < objects.size() ; ++i)
createMeshFromSelection(objects[i],vertexType_);
} else if(_operation == V_HANDLE) {
// Set vertex selection to be handle region
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_ALL));
......@@ -501,6 +529,19 @@ void MeshObjectSelectionPlugin::slotSelectionOperation(QString _operation) {
setColorForSelection(o_it->id(), edgeType_);
}
}
} else if(_operation == E_COPYSELECTION) {
// Copy edge selection
std::vector<int> objects;
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_ALL));
o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (o_it->visible()) {
objects.push_back(o_it->id());
}
}
for ( unsigned int i = 0 ; i < objects.size() ; ++i)
createMeshFromSelection(objects[i],edgeType_);
} else if(_operation == HE_SELECT_ALL) {
// Select all edges
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_ALL));
......@@ -594,6 +635,18 @@ void MeshObjectSelectionPlugin::slotSelectionOperation(QString _operation) {
setColorForSelection(o_it->id(), faceType_);
}
}
} else if(_operation == F_COPYSELECTION) {
// Copy face selection
std::vector<int> objects;
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_ALL));
o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (o_it->visible()) {
objects.push_back(o_it->id());
}
}
for ( unsigned int i = 0 ; i < objects.size() ; ++i)
createMeshFromSelection(objects[i],faceType_);
}
}
......@@ -1720,4 +1773,91 @@ bool SelectVolumeAction::operator()(BaseNode* _node) {
return true;
}
/// Create a mesh containing the selection of the given mesh
int MeshObjectSelectionPlugin::createMeshFromSelection(int _objectId, PrimitiveType _primitiveType)
{
// 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,_primitiveType);
emit updatedObject(id, UPDATE_ALL);
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,_primitiveType);
emit updatedObject(id, UPDATE_ALL);
return id;
} else {
emit log(LOGERR, tr("DataType not supported"));
return -1;
}
}
Q_EXPORT_PLUGIN2(meshobjectselectionplugin, MeshObjectSelectionPlugin);
......@@ -126,6 +126,7 @@ signals:
// LoadSaveInterface
void deleteObject(int _objectId);
void addEmptyObject( DataType _type, int& _id);
// ScriptInterface
void scriptInfo(QString _functionName);
......@@ -268,6 +269,8 @@ public slots:
/// Delete vertices and faces that are currently selected
void deleteVertexSelection(int _objectId);
int createMeshFromVertexSelection( int _objectId);
/// Colorize the vertex selection
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int a);
......@@ -345,6 +348,9 @@ public slots:
/// Inverse of function above
IdList convertVertexPairsToEdges(int _id, const IdList& _vertices);
/// Create a mesh containing the face selection of the given mesh
int createMeshFromEdgeSelection( int _objectId);
/// Colorize the edge selection
void colorizeEdgeSelection(int objectId, int r, int g, int b, int a);
......@@ -416,11 +422,18 @@ public slots:
/// Return a list of all selected faces
IdList getFaceSelection(int objectId);
/// Create a mesh containing the face selection of the given mesh
int createMeshFromFaceSelection( int _objectId);
/// Colorize the face selection
void colorizeFaceSelection(int objectId, int r, int g, int b, int a);
//===========================================================================
/// Lasso selection tool
void lassoSelection(QRegion& _region, PrimitiveType _primitiveType, bool _deselection);
......@@ -472,8 +485,23 @@ private:
template<class MeshT>
void colorizeSelection(MeshT* _mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha);
/// Create a new mesh from the selection
template< class MeshT >
void createMeshFromSelection( MeshT& _mesh, MeshT& _newMesh, PrimitiveType _primitiveType);
/** @} */
//===========================================================================
/** @name Private helper function
* @{ */
//===========================================================================
private:
/// Create a mesh containing the selection of the given mesh
int createMeshFromSelection( int _objectId , PrimitiveType _primitiveType);
/** @} */
//===========================================================================
/** @name Member variables
* @{ */
......
......@@ -841,3 +841,81 @@ void MeshObjectSelectionPlugin::colorizeSelection(MeshT* _mesh,
_mesh->set_color(h_it, color);
}
}
//***********************************************************************************
/** \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 MeshObjectSelectionPlugin::createMeshFromSelection(MeshT& _mesh, MeshT& _newMesh, PrimitiveType _primitiveType)
{
// Tracking during copy action
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 (_primitiveType & vertexType_)
copy = _mesh.status(v_it.handle()).selected();
else if (_primitiveType & edgeType_) {
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 (_primitiveType & faceType_) {
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) {
_mesh.property(copyHandle, v_it) = _newMesh.add_vertex(_mesh.point(v_it));
} 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);
}
......@@ -330,6 +330,12 @@ void MeshObjectSelectionPlugin::deleteVertexSelection(int _objectId) {
//=========================================================
int MeshObjectSelectionPlugin::createMeshFromVertexSelection( int _objectId) {
createMeshFromSelection(_objectId, vertexType_ );
}
//=========================================================
/// colorize the vertex selection
void MeshObjectSelectionPlugin::colorizeVertexSelection(int _objectId, int r, int g, int b, int a) {
......
Markdown is supported
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