How to read .OFF file color information ?

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

How to read .OFF file color information ?

J. Scheurich
Hi,

How to read .OFF file color information via CGaL ?

I wrote the following test program accoording to

https://stackoverflow.com/questions/55955579/cgal-how-can-i-access-vertex-colors-after-loading-an-off-file

$ cat readoff.cpp


// compile:   g++ -g -O0 readoff.cpp -lCGAL
// test data: https://people.sc.fsu.edu/~jburkardt/data/off/facecube.off
// 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::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;
     if (colorExists )
         printf("color exists\n");
     else
         printf("color do not exist\n");
}

What is the problem ?


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


Reply | Threaded
Open this post in threaded view
|

Re: How to read .OFF file color information ?

Sebastien Loriot (GeometryFactory)
OFF should be replaced by COFF according to the file format (or CNOFF if
you have normals).

Sebastien.



On 1/20/20 11:51 AM, J. Scheurich wrote:

> Hi,
>
> How to read .OFF file color information via CGaL ?
>
> I wrote the following test program accoording to
>
> https://stackoverflow.com/questions/55955579/cgal-how-can-i-access-vertex-colors-after-loading-an-off-file 
>
>
> $ cat readoff.cpp
>
>
> // compile:   g++ -g -O0 readoff.cpp -lCGAL
> // test data: https://people.sc.fsu.edu/~jburkardt/data/off/facecube.off
> // 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::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;
>      if (colorExists )
>          printf("color exists\n");
>      else
>          printf("color do not exist\n");
> }
>
> What is the problem ?
>
>
> 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


Reply | Threaded
Open this post in threaded view
|

Re: How to read .OFF file color information ?

J. Scheurich


On 21.01.20 21:35, Sebastien Loriot (GeometryFactory) wrote:
> OFF should be replaced by COFF according to the file format (or CNOFF
> if you have normals).

If i add COFF instead of OFF in facecube.off, i still get "color do not
exist" in the test program.

https://github.com/CGAL/cgal/pull/1013

talks about Scanner_OFF.h, how to use it ?

so long
MUFTI

>> How to read .OFF file color information via CGaL ?
>>
>> I wrote the following test program accoording to
>>
>> https://stackoverflow.com/questions/55955579/cgal-how-can-i-access-vertex-colors-after-loading-an-off-file
>>
>>
>> $ cat readoff.cpp
>>
>>
>> // compile:   g++ -g -O0 readoff.cpp -lCGAL
>> // test data: https://people.sc.fsu.edu/~jburkardt/data/off/facecube.off
>> // 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::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;
>>      if (colorExists )
>>          printf("color exists\n");
>>      else
>>          printf("color do not exist\n");
>> }
>>

--
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 .OFF file color information ?

Maxime Gimeno
In reply to this post by J. Scheurich
Your test data does not have any color per vertex, they are all per face. In the SO message you refer to, it is written
"[...] If there are colors per face you can access it similarly but by searching for the property map called "f:color". [...]"

So you should use a property map like that :
  SurfaceMesh::Property_map<SurfaceMesh::Face_index, CGAL::Color>
fcolors =
        mesh->property_map<SurfaceMesh::Face_index, CGAL::Color >
        ("f:color").first;

Le ven. 24 janv. 2020 à 11:47, J. Scheurich <[hidden email]> a écrit :
Hi,

How to read .OFF file color information via CGaL ?

I wrote the following test program accoording to

https://stackoverflow.com/questions/55955579/cgal-how-can-i-access-vertex-colors-after-loading-an-off-file

$ cat readoff.cpp


// compile:   g++ -g -O0 readoff.cpp -lCGAL
// test data: https://people.sc.fsu.edu/~jburkardt/data/off/facecube.off
// 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::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;
     if (colorExists )
         printf("color exists\n");
     else
         printf("color do not exist\n");
}

What is the problem ?


so long

MUFTI

Reply | Threaded
Open this post in threaded view
|

Re: How to read .OFF file color information ?

J. Scheurich

> Your test data does not have any color per vertex, they are all per
> face. In the SO message you refer to, it is written
> "[...] If there are colors per face you can access it similarly but by
> searching for the property map called "f:color". [...]"
>
> So you should use a property map like that :
>   SurfaceMesh::Property_map<SurfaceMesh::Face_index, CGAL::Color>
> fcolors =
>         mesh->property_map<SurfaceMesh::Face_index, CGAL::Color >
>         ("f:color").first;

I changed the test program to Face_Index, but still get "color do not
exist" 8-(

$ cat readoff.cpp
    // compile:   g++ -g -O0 readoff.cpp -lCGAL
    // test data: https://people.sc.fsu.edu/~jburkardt/data/off/facecube.off
    // 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 >
             ("v:color").first;

         bool colorExists = mesh->property_map
             <SurfaceMesh::Face_index, CGAL::Color>("v:color").second;
         if (colorExists )
             printf("color exists\n");
         else
             printf("color do not exist\n");
    }

Any idears ?

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


Reply | Threaded
Open this post in threaded view
|

Re: How to read .OFF file color information ?

Maxime Gimeno
I told you the name must also become f:color instead of v:color.

Le sam. 25 janv. 2020 à 11:07, J. Scheurich <[hidden email]> a écrit :

> Your test data does not have any color per vertex, they are all per
> face. In the SO message you refer to, it is written
> "[...] If there are colors per face you can access it similarly but by
> searching for the property map called "f:color". [...]"
>
> So you should use a property map like that :
>   SurfaceMesh::Property_map<SurfaceMesh::Face_index, CGAL::Color>
> fcolors =
>         mesh->property_map<SurfaceMesh::Face_index, CGAL::Color >
>         ("f:color").first;

I changed the test program to Face_Index, but still get "color do not
exist" 8-(

$ cat readoff.cpp
    // compile:   g++ -g -O0 readoff.cpp -lCGAL
    // test data: https://people.sc.fsu.edu/~jburkardt/data/off/facecube.off
    // 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 >
             ("v:color").first;

         bool colorExists = mesh->property_map
             <SurfaceMesh::Face_index, CGAL::Color>("v:color").second;
         if (colorExists )
             printf("color exists\n");
         else
             printf("color do not exist\n");
    }

Any idears ?

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