Search code examples
cgal

How can I use MVC_post_processor_3 on an external .obj file?


Basically, I want to use MVC_post_processor_3 on a 3D object I parameterized using my own code.

I checked documentations but didn't really find any example/demo of post processor. I'm unable to understand the parameters to the function properly. I tried to do it based on examples from "Surface_mesh_parameterization" but the output .off file just collapse the mesh at (0,0,0). I think it's because I'm unable to read the texture co-ordinates from the .obj file.

I also didn't find anything on google on how to use the post-processor.


Solution

  • You can have a look at its usage in the ARAP parameterizer:

    
    // Post processing functions
      // Use the convex virtual boundary algorithm of Karni et al.[2005] to fix
      // the (hopefully few) flips in the result.
      template <typename VertexUVMap,
                typename VertexIndexMap>
      Error_code post_process(const Triangle_mesh& mesh,
                              const Vertex_set& vertices,
                              const Faces_vector& faces,
                              halfedge_descriptor bhd,
                              VertexUVMap uvmap,
                              const VertexIndexMap vimap) const
      {
        typedef MVC_post_processor_3<Triangle_mesh>     Post_processor;
    
        Post_processor p;
        Error_code status = p.parameterize(mesh, vertices, faces, bhd, uvmap, vimap);
        if(status != OK)
          return status;
    
    #ifdef CGAL_SMP_ARAP_DEBUG
        output_uvmap("ARAP_final_post_processing.off", mesh, vertices, faces, uvmap, vimap);
    #endif
    
        return OK;
      }
    

    (https://github.com/CGAL/cgal/blob/fb48b16a37a34226e915e9e4ecf5892d6df6579f/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/ARAP_parameterizer_3.h#L1244)

    • mesh is your input 3D mesh
    • vertices and faces are optional, you can omit those. Check the internal function initialize_containers() if you want more detail.
    • bhd is a border halfedge of your input 3D mesh, meaning an halfedge without an incident face. The border on which this halfedge belongs will be fixed.
    • uvmap is a property map associating vertices of your input 3D mesh to your parameterization. In the ARAP example, that parameterization is computed with ARAP, but here you have to fill in your values. The value type is a 2D point. You can look at the package's example to see how to define and fill UV property maps (https://doc.cgal.org/latest/Surface_mesh_parameterization/Surface_mesh_parameterization_2simple_parameterization_8cpp-example.html for example).
    • vimap is another property map associating a unique index to each of your input 3D mesh's vertices [*]. You can initialize that with the internal function fill_index_map_of_cc().

    The output is written in uvmap, and you can have a look at output_uvmap() at an example of usage.

    • If your mesh has multiple connected components, then a single connected component is treated, the one that contains to bhd