Commit 35b605a3 authored by Mike Kremer's avatar Mike Kremer
Browse files

Store edge selections as vertex pairs since edge ids are not stable (differ...

Store edge selections as vertex pairs since edge ids are not stable (differ depending on the file reader).

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12515 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1f5c99da
......@@ -264,6 +264,117 @@ IdList MeshObjectSelectionPlugin::getEdgeSelection( int objectId ) {
//=========================================================
IdList MeshObjectSelectionPlugin::convertEdgesToVertexPairs(int _id, const IdList& _edges) {
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 = _edges.begin(); it != _edges.end(); ++it) {
vertex_pairs.push_back(mesh->from_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
vertex_pairs.push_back(mesh->to_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).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 = _edges.begin(); it != _edges.end(); ++it) {
vertex_pairs.push_back(mesh->from_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
vertex_pairs.push_back(mesh->to_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
}
}
return vertex_pairs;
}
//=========================================================
IdList MeshObjectSelectionPlugin::convertVertexPairsToEdges(int _id, const IdList& _vertices) {
if(_vertices.size() % 2 != 0) {
emit log(LOGERR, "Number of vertices is not even!");
return IdList(0);
}
IdList edges;
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)) {
edges.push_back(mesh->edge_handle(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)) {
edges.push_back(mesh->edge_handle(voh_it.handle()).idx());
continue;
}
}
}
}
return edges;
}
//=========================================================
void MeshObjectSelectionPlugin::colorizeEdgeSelection(int objectId, int r, int g, int b, int a ) {
BaseObjectData* object;
......
......@@ -1267,6 +1267,8 @@ void MeshObjectSelectionPlugin::loadIniFile(INIFile& _ini, int _id) {
invert = false;
_ini.get_entry(invert, sectionName, "InvertEdgeSelection");
ids = convertVertexPairsToEdges(_id, ids);
if(invert) {
selectAllEdges(object->id());
unselectEdges(object->id(),ids);
......@@ -1326,7 +1328,7 @@ void MeshObjectSelectionPlugin::saveIniFile(INIFile& _ini, int _id) {
}
_ini.add_entry(sectionName, "VertexSelection", getVertexSelection(object->id()));
_ini.add_entry(sectionName, "EdgeSelection" , getEdgeSelection(object->id()));
_ini.add_entry(sectionName, "EdgeSelection", convertEdgesToVertexPairs(_id, getEdgeSelection(object->id())));
if(object->dataType(DATA_POLY_MESH ) || object->dataType( DATA_TRIANGLE_MESH)) {
_ini.add_entry(sectionName, "FaceSelection", getFaceSelection(object->id()));
......@@ -1350,27 +1352,27 @@ void MeshObjectSelectionPlugin::slotLoadSelection(const INIFile& _file) {
}
std::vector<int> ids;
// Store vertex selection:
// Load vertex selection:
_file.get_entry(ids, section, "VertexSelection");
selectVertices(o_it->id(), ids);
ids.clear();
// Store edge selection:
// Load edge selection:
_file.get_entry(ids, section, "EdgeSelection");
selectEdges(o_it->id(), ids);
selectEdges(o_it->id(), convertVertexPairsToEdges(o_it->id(), ids));
ids.clear();
// Store halfedge selection:
// Load halfedge selection:
_file.get_entry(ids, section, "HalfedgeSelection");
selectHalfedges(o_it->id(), ids);
ids.clear();
// Store face selection:
// Load face selection:
_file.get_entry(ids, section, "FaceSelection");
selectFaces(o_it->id(), ids);
ids.clear();
// Store handle region:
// Load handle region:
_file.get_entry(ids, section, "HandleRegion");
selectHandleVertices(o_it->id(), ids);
ids.clear();
// Store modeling region:
// Load modeling region:
_file.get_entry(ids, section, "ModelingRegion");
selectModelingVertices(o_it->id(), ids);
ids.clear();
......@@ -1398,7 +1400,7 @@ void MeshObjectSelectionPlugin::slotSaveSelection(INIFile& _file) {
// Store vertex selection:
_file.add_entry(section, "VertexSelection", getVertexSelection(o_it->id()));
// Store edge selection:
_file.add_entry(section, "EdgeSelection", getEdgeSelection(o_it->id()));
_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()));
// Store face selection:
......
......@@ -339,6 +339,12 @@ public slots:
/// Return a list of all selected edges
IdList getEdgeSelection(int objectId);
/// Convert edge ids to vertex pairs
IdList convertEdgesToVertexPairs(int _id, const IdList& _edges);
/// Inverse of function above
IdList convertVertexPairsToEdges(int _id, const IdList& _vertices);
/// Colorize the edge selection
void colorizeEdgeSelection(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