How to read color information for faces with CGAL ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to read color information for faces with CGAL ?

J. Scheurich
Hi,

I am a programmer working on white_dune.
White_dune can now read colored .OFF files, but only if the color are on
vertices, not on Faces.

How to read the face information of .OFF files with CGAL ?

I have the following  test program, but i prints "color do not exist" 8-(

// compile:   g++ -g -O0 readoff.cpp -lCGAL
// test data: http://wdune.ourproject.org/examples/facecube.off
// copy of https://people.sc.fsu.edu/~jburkardt/data/off/facecube.off
without comments
// output:
// $ ./a.out
// facecube.off: Success
// color do not exist

#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 = "facecube.off";
     std::ifstream input(filename);
     SurfaceMesh *mesh = new SurfaceMesh();

     if (!input || !(input >> *mesh)) {
         perror(filename);
     }

     SurfaceMesh::Property_map<SurfaceMesh::Face_index, CGAL::Color>
vcolors =
         mesh->property_map<SurfaceMesh::Face_index, CGAL::Color >
         ("f:color").first;

     bool colorExists = mesh->property_map
         <SurfaceMesh::Face_index, CGAL::Color>("f:color").second;

     if (colorExists )
         printf("color exists\n");
     else
         printf("color do not exist\n");
}

The amazing thing is the execution of "perror(filename)" even if the
file exists.
It looks like the curŕent OFF reader (CGAL 4.11-2 on Ubuntu 18.04) can
not handle face colors 8-(

so long
MUFFTI

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


Reply | Threaded
Open this post in threaded view
|

Re: How to read color information for faces with CGAL ?

Maxime Gimeno
Hi,

Your input data is wrong. The first line should be COFF if you expect colors to be found. The reader doesn't create the property map for colors if the first line doesn't contain a C.

Le lun. 10 févr. 2020 à 00:47, J. Scheurich <[hidden email]> a écrit :
Hi,

I am a programmer working on white_dune.
White_dune can now read colored .OFF files, but only if the color are on
vertices, not on Faces.

How to read the face information of .OFF files with CGAL ?

I have the following  test program, but i prints "color do not exist" 8-(

// compile:   g++ -g -O0 readoff.cpp -lCGAL
// test data: http://wdune.ourproject.org/examples/facecube.off
// copy of https://people.sc.fsu.edu/~jburkardt/data/off/facecube.off
without comments
// output:
// $ ./a.out
// facecube.off: Success
// color do not exist

#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 = "facecube.off";
     std::ifstream input(filename);
     SurfaceMesh *mesh = new SurfaceMesh();

     if (!input || !(input >> *mesh)) {
         perror(filename);
     }

     SurfaceMesh::Property_map<SurfaceMesh::Face_index, CGAL::Color>
vcolors =
         mesh->property_map<SurfaceMesh::Face_index, CGAL::Color >
         ("f:color").first;

     bool colorExists = mesh->property_map
         <SurfaceMesh::Face_index, CGAL::Color>("f:color").second;

     if (colorExists )
         printf("color exists\n");
     else
         printf("color do not exist\n");
}

The amazing thing is the execution of "perror(filename)" even if the
file exists.
It looks like the curŕent OFF reader (CGAL 4.11-2 on Ubuntu 18.04) can
not handle face colors 8-(

so long
MUFFTI

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