Uksin
Uksin

Reputation: 106

OpenMesh edge index after reopening a modified mesh

I modified a mesh, and some edges were added.

Then I saved the modified mesh to a .obj file. When I open this .obj file using OpenMesh read function, the indices of edges are different from the indices of edges when I saved the mesh, because the .obj file only has information about vertices and faces.

I need to save an additional edge information file in the edge index order when saving the modified mesh. But according to what I mentioned above, the order is different, so the edge information is wrong after reopening the modified mesh.

I have a solution. I save the modified mesh(old mesh), then read the saved file as new mesh. Check every edge of the new mesh in index order, and find the same edge in old mesh. Then I can output the edge information in edge index order of new mesh.

Is there a simple solution without reopening? For example, an OpenMesh function that recalculate the edge indices?

Thanks

Upvotes: 2

Views: 280

Answers (1)

hc_
hc_

Reputation: 2628

From what you say I figure that you are probably using (or at least should be using) a custom edge property where you store your additional information. Ideally like so:

auto edge_pm = OpenMesh::makePropertyManagerFromExistingOrNew<
        OpenMesh::EPropHandleT<std::string> >(mesh, "edge_info");
// Set some random edge info.
edge_pm[mesh.edge_handle(23)] = "foo";

You could use OpenMesh's native .om format which allows you to store custom properties. Have a look at the unit tests in /src/Unittests/unittests_read_write_OM.cc, specifically the WriteTriangleVertexBoolProperty one which implements an example where a mesh with a custom property is saved to a .om file and then read from that file again. For the example above it would look something like this:

// Flag property so it gets serialized.
mesh.property(edge_pm.getRawProperty()).set_persistent(true);
bool ok = OpenMesh::IO::write_mesh(mesh, "bar.om");

When you load the mesh from file, be sure to first create the property:

Mesh new_mesh;
auto new_edge_pm = OpenMesh::makePropertyManagerFromExistingOrNew<
        OpenMesh::EPropHandleT<std::string> >(new_mesh, "edge_info");
bool ok = OpenMesh::IO::read_mesh(new_mesh, "bar.om");

Afterwards your property should be restored:

std::cout << new_edge_pm[new_mesh.edge_handle(23)] << std::endl;
// Should print "foo"

Upvotes: 2

Related Questions