How do I correctly use Options and Flags to alter the read_mesh and write_mesh functions in OpenMesh?

633 views Asked by At

I was able to read and write very basic .off files in OpenMesh, but this doesn't let me see the edges connecting the vertices of my triangle mesh very well when I use the program, Geomview, to visualize the mesh. I figured out how to change the .off file to color my triangles using this format: http://www.geomview.org/docs/html/OFF.html, and Geomview accepts the way I write these files. However I can't seem to alter OpenMesh's read_mesh function so that it will read all of the triangle faces properly.

I tried to alter the read_mesh and write_mesh functions using the OpenMesh::IO::Options class from https://www.openmesh.org/media/Documentations/OpenMesh-Doc-Latest/a00212.html and what I read out of the Options.hh source code. Here is what I tried doing:

....
#include <OpenMesh/Core/IO/Options.hh>
....
int main () {

    MyMesh mesh;
    ...
    OpenMesh::IO::Options ops(OpenMesh::IO::Options::FaceColor);
    ops += OpenMesh::IO::Options::ColorFloat;

    std::cout << ops.color_is_float() << std::endl; //returns true
    std::cout << ops.face_has_color() << std::endl; //returns true

    if (!OpenMesh::IO::read_mesh(mesh, argv[2], ops, true)) {
        //when run, it does not enter this if statement
        std::cerr << "Error: cannot read mesh from << argv[2] << std::endl;
    }

    //stuff done to mesh

    std::streamsize str = 5;
    if (!OpenMesh::IO::write_mesh(mesh, argv[3], ops, str) {
        //again, it does not enter this if statement
        std::cerr << "Error ..." << std::endl;
    }

I was able to compile the program without any errors, and it runs. However, the read_mesh function does not finish reading the .off file properly.

Here is a simpler version of my .off file:

OFF
30 40 0
0 0 0
0 1 0
0 2 0
... more vertices

Then I have two ways of writing triangle faces:

Method 1)

#_of_vertices v0 v1 v2 RGB[0] RGB[1] RGB[2]
3 0 1 6 1.0 0.0 0.0
... more faces

Method 2)

#_of_vertices v0 v1 v2 #_of_color_components RGB[0] RGB[1] RGB[2]
3 0 1 6 3 1.0 0.0 0.0
.. more faces

For method 1, read_mesh only reads the first triangle face. It hits the float values for the triangles color and I'm assuming doesn't know what to do with them so it simply stops reading in values. Because when it writes the mesh out to a separate file, it only lists one face and it has update the positioning of three vertices of that particular tri face.

For method 2, I get a bunch of "PolyMeshT::add_face: complex vertex" errors.

I'm certainly not adjusting the read_mesh function properly and I was wondering if anyone had any guidance for me.

1

There are 1 answers

0
Chris87 On

I know that this question is quite old, but just in case anybody else searches for the answer; in your OFF file example, there are two main problems:

  • First, OFF files containing colors should be introduced by COFF instead of OFF. Otherwise, the reader will get confused and will misinterprete the color information nevertheless contained in the file. This should be the reason for your complex vertex errors.
  • Second, the number of color components does not need to be specified. Actually, the reader will interprete this value together with the three RGB values as a RGBA color. So the colors won't show up correctly, as the column used for the number of color components is interpreted as R component.