Commit 43afa3d3 authored by Mike Kremer's avatar Mike Kremer
Browse files

Also store vertex pairs for halfedge selections instead of direct ids since...

Also store vertex pairs for halfedge selections instead of direct ids since they're not stable either.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12516 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 35b605a3
......@@ -241,6 +241,117 @@ IdList MeshObjectSelectionPlugin::getHalfedgeSelection(int objectId) {
//=========================================================
IdList MeshObjectSelectionPlugin::convertHalfedgesToVertexPairs(int _id, const IdList& _halfedges) {
IdList vertex_pairs;
BaseObjectData* object = 0;
if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR,tr("Cannot find object for id ") + QString::number(_id));
return IdList(0);
}
if(object->dataType() == DATA_TRIANGLE_MESH) {
TriMeshObject* obj = 0;
if(!PluginFunctions::getObject(_id, obj)) {
emit log(LOGERR, "Could not get mesh object!");
return IdList(0);
}
TriMesh* mesh = obj->mesh();
for(IdList::const_iterator it = _halfedges.begin(); it != _halfedges.end(); ++it) {
vertex_pairs.push_back(mesh->from_vertex_handle(TriMesh::HalfedgeHandle(*it)).idx());
vertex_pairs.push_back(mesh->to_vertex_handle(TriMesh::HalfedgeHandle(*it)).idx());
}
} else if(object->dataType() == DATA_POLY_MESH) {
PolyMeshObject* obj = 0;
if(!PluginFunctions::getObject(_id, obj)) {
emit log(LOGERR, "Could not get mesh object!");
return IdList(0);
}
PolyMesh* mesh = obj->mesh();
for(IdList::const_iterator it = _halfedges.begin(); it != _halfedges.end(); ++it) {
vertex_pairs.push_back(mesh->from_vertex_handle(PolyMesh::HalfedgeHandle(*it)).idx());
vertex_pairs.push_back(mesh->to_vertex_handle(PolyMesh::HalfedgeHandle(*it)).idx());
}
}
return vertex_pairs;
}
//=========================================================
IdList MeshObjectSelectionPlugin::convertVertexPairsToHalfedges(int _id, const IdList& _vertices) {
if(_vertices.size() % 2 != 0) {
emit log(LOGERR, "Number of vertices is not even!");
return IdList(0);
}
IdList halfedges;
BaseObjectData* object = 0;
if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR,tr("Cannot find object for id ") + QString::number(_id));
return IdList(0);
}
if(object->dataType() == DATA_TRIANGLE_MESH) {
TriMeshObject* obj = 0;
if(!PluginFunctions::getObject(_id, obj)) {
emit log(LOGERR, "Could not get mesh object!");
return IdList(0);
}
TriMesh* mesh = obj->mesh();
for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
TriMesh::VertexHandle vh = TriMesh::VertexHandle(*it);
if(!vh.is_valid()) continue;
for(TriMesh::VertexOHalfedgeIter voh_it = mesh->voh_iter(vh);
voh_it; ++voh_it) {
if(mesh->to_vertex_handle(voh_it.handle()).idx() == *(it+1)) {
halfedges.push_back(voh_it.handle().idx());
continue;
}
}
}
} else if(object->dataType() == DATA_POLY_MESH) {
PolyMeshObject* obj = 0;
if(!PluginFunctions::getObject(_id, obj)) {
emit log(LOGERR, "Could not get mesh object!");
return IdList(0);
}
PolyMesh* mesh = obj->mesh();
for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
PolyMesh::VertexHandle vh = PolyMesh::VertexHandle(*it);
if(!vh.is_valid()) continue;
for(PolyMesh::VertexOHalfedgeIter voh_it = mesh->voh_iter(vh);
voh_it; ++voh_it) {
if(mesh->to_vertex_handle(voh_it.handle()).idx() == *(it+1)) {
halfedges.push_back(voh_it.handle().idx());
continue;
}
}
}
}
return halfedges;
}
//=========================================================
/// colorize the halfedge selection
void MeshObjectSelectionPlugin::colorizeHalfedgeSelection(int objectId, int r, int g, int b, int a) {
......
......@@ -1362,7 +1362,7 @@ void MeshObjectSelectionPlugin::slotLoadSelection(const INIFile& _file) {
ids.clear();
// Load halfedge selection:
_file.get_entry(ids, section, "HalfedgeSelection");
selectHalfedges(o_it->id(), ids);
selectHalfedges(o_it->id(), convertVertexPairsToHalfedges(o_it->id(), ids));
ids.clear();
// Load face selection:
_file.get_entry(ids, section, "FaceSelection");
......@@ -1402,7 +1402,7 @@ void MeshObjectSelectionPlugin::slotSaveSelection(INIFile& _file) {
// Store edge selection:
_file.add_entry(section, "EdgeSelection", convertEdgesToVertexPairs(o_it->id(), getEdgeSelection(o_it->id())));
// Store halfedge selection:
_file.add_entry(section, "HalfedgeSelection", getHalfedgeSelection(o_it->id()));
_file.add_entry(section, "HalfedgeSelection", convertHalfedgesToVertexPairs(o_it->id(), getHalfedgeSelection(o_it->id())));
// Store face selection:
_file.add_entry(section, "FaceSelection", getFaceSelection(o_it->id()));
// Store handle region:
......
......@@ -373,6 +373,12 @@ public slots:
/// Return a list of all selected edges
IdList getHalfedgeSelection(int objectId);
/// Convert halfedge ids to vertex pairs
IdList convertHalfedgesToVertexPairs(int _id, const IdList& _halfedges);
/// Inverse of function above
IdList convertVertexPairsToHalfedges(int _id, const IdList& _vertices);
/// Colorize the edge selection
void colorizeHalfedgeSelection(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