Wrote my own open source .OFF reader

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Wrote my own open source .OFF reader

J. Scheurich
Hi,

I wrote my own .OFF reader cause CGALs .OFF reader fails to read

https://wdune.ourproject.org/examples/test.off

which is displayed correctly by "meshlab".

Test program:

// compile:   g++ -g -O0 readoff_vertexcolor.cpp -lCGAL
// test data:  https://wdune.ourproject.org/examples/test.off

#include <CGAL/Simple_cartesian.h>
typedef CGAL::Simple_cartesian<double> Kernel;
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/boost/graph/dijkstra_shortest_paths.h>
#include <CGAL/exceptions.h>
#include <CGAL/IO/Color.h>
#include <boost/graph/prim_minimum_spanning_tree.hpp>
#include <boost/foreach.hpp>
typedef Kernel::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Surface;
typedef CGAL::Surface_mesh<Point> SurfaceMesh;
typedef CGAL::Color Color;
typedef Surface::Vertex_index vertex_index;
typedef boost::graph_traits<Surface>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Surface>::face_descriptor face_descriptor;
typedef boost::graph_traits<Surface>::halfedge_descriptor
halfedge_descriptor;
std::vector<Point> verts;
std::vector<Color> cols;

int main(int argc, char **argv)
{
    const char *filename = "test.off";
    std::ifstream input(filename);
    SurfaceMesh *mesh = new SurfaceMesh();

    if (!input || !(input >> *mesh)) {
        fprintf(stderr, "program failed cause of: ");
        perror(filename);
    }

   SurfaceMesh::Property_map<SurfaceMesh::Vertex_index, CGAL::Color>
vcolors =
        mesh->property_map<SurfaceMesh::Vertex_index, CGAL::Color >
        ("v:color").first;
       
    bool colorExists = mesh->property_map
        <SurfaceMesh::Vertex_index, CGAL::Color>("v:color").second;

    for (SurfaceMesh::Vertex_index vi : mesh->vertices()) {
        verts.push_back(mesh->point(vi));
        if (colorExists )
            cols.push_back(vcolors[vi]);
    }
}

Program outpit:

$ ./a.out
program failed cause of: test.off: Success

If you are interested in the code, that successfully can read the test
data, see
routine "readOff" in nwdune-0.746/src/NodeIndexedFaceSet.cpp of white_dune.

so long
MUFTI


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss