Using Hole filling using inherited Polyhedron class

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

Using Hole filling using inherited Polyhedron class

calvin_cw
Hi,

     I am trying to compile a sample hole filling code using an inherited
polyhedron class. The code is reproduced below. I keep getting the error
related to sparse matrix class. Hope someone can assist to point out the
error. thanks!

regards
Calvin

<<<< Start code

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_mesh_processing/triangulate_hole.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/OFF_reader.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <CGAL/Polyhedron_items_with_id_3.h>


typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;

template <class Refs, class ID>
class feEdge_Surf : public CGAL::HalfedgeDS_halfedge_base< Refs,
CGAL::Tag_true, CGAL::Tag_true, CGAL::Tag_true >
{
        typedef ID size_type;
private:
        size_type mID;
public:
        size_type&       id() { return mID; }
        size_type const& id() const { return mID; }
};

template <class Refs, class Traits, class ID>
class feFace_Surf : public CGAL::HalfedgeDS_face_base<Refs, CGAL::Tag_true,
typename Traits::Plane_3>
{
        typedef ID size_type;
private:

        size_type mID;
public:
        size_type&       id() { return mID; }
        size_type const& id() const { return mID; }
};

template <class Refs, class Traits, class ID>
class feNode_Surf : public CGAL::HalfedgeDS_vertex_base< Refs,
CGAL::Tag_true, typename Traits::Point_3 >
{

        typedef typename Traits::Point_3 Point_3;
        typedef ID size_type;
private:
        size_type mID;
public:
        size_type&       id() { return mID; }
        size_type const& id() const { return mID; }

        feNode_Surf(const Point_3& p) : CGAL::HalfedgeDS_vertex_base< Refs,
CGAL::Tag_true, Point_3>(p)
        {}

        feNode_Surf() : CGAL::HalfedgeDS_vertex_base< Refs, CGAL::Tag_true,
Point_3>()
        {}

};


class feSurf_Elements : public CGAL::Polyhedron_items_3
{
public:
        template <class Refs, class Traits>
        struct Vertex_wrapper {
                typedef feNode_Surf<Refs, Traits, std::size_t> Vertex;
        };

        template <class Refs, class Traits>
        struct Halfedge_wrapper {
                typedef feEdge_Surf<Refs, std::size_t> Halfedge;

        };
        template <class Refs, class Traits>
        struct Face_wrapper {
                typedef feFace_Surf<Refs, Traits, std::size_t> Face;
        };

};

typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements>::Point_3 Point_fe;

typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements> Poly_3;
template<class Kernel, class feSurf_Elements>
class feSurfMesh : public Poly_3
{
public:
        typedef Point_fe Base;
};

typedef feSurfMesh<Kernel, feSurf_Elements> feSurfaceMesh;

namespace boost {
        template <>
        struct graph_traits<feSurfaceMesh> :
                public graph_traits<Poly_3>
        {};
} // namespace boost

namespace boost {
        template <class Tag>
        struct property_map<feSurfaceMesh, Tag> :
                public property_map<Poly_3, Tag>
        {};
} //namespace boost

namespace CGAL {
        template <typename T>
        struct graph_has_property<feSurfaceMesh, T>
                : public CGAL::graph_has_property<Poly_3, T>
        {};
}

typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements>::Halfedge_handle
HalfEdge_handle;
typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements>::Facet_handle
Facet_handle;
typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements>::Vertex_handle
SurfPt_handle;


int main(int argc, char* argv[])
{
        const char* filename = (argc > 1) ? argv[1] : "data/mech-holes-shark.off";
        std::ifstream input(filename);

        feSurfaceMesh feMesh;
        CGAL::read_off(input, feMesh);

        // Incrementally fill the holes
        unsigned int nb_holes = 0;
        for (HalfEdge_handle h : halfedges(feMesh))
        {
                if (h->is_border())
                {
                        std::vector<Facet_handle>  patch_facets;
                        std::vector<SurfPt_handle> patch_vertices;
                        bool success = std::get<0>(
                                CGAL::Polygon_mesh_processing::triangulate_refine_and_fair_hole(
                                        feMesh,
                                        h,
                                        std::back_inserter(patch_facets),
                                        std::back_inserter(patch_vertices),
                               
CGAL::Polygon_mesh_processing::parameters::vertex_point_map(get(CGAL::vertex_point,
feMesh)).geom_traits(Kernel())));

                        std::cout << " Number of facets in constructed patch: " <<
patch_facets.size() << std::endl;
                        std::cout << " Number of vertices in constructed patch: " <<
patch_vertices.size() << std::endl;
                        std::cout << " Fairing : " << (success ? "succeeded" : "failed") <<
std::endl;
                        ++nb_holes;
                }
        }

        std::cout << std::endl;
        std::cout << nb_holes << " holes have been filled" << std::endl;

        std::ofstream out("filled.off");
        out.precision(17);
        out << feMesh << std::endl;
        return 0;
}





--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
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: Using Hole filling using inherited Polyhedron class

Sebastien Loriot (GeometryFactory)
Have a look at this PR that contains a convenience header to ease
the use of CGAL algorithm with dereived classes.

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

This example is using Polyhedron:
https://github.com/CGAL/cgal/pull/4938/files#diff-a9b02a9ba5a7ef7823d5cf4e47187e2e

If I get it right the macros in your case must be:

#define CGAL_GRAPH_TRAITS_INHERITANCE_TEMPLATE_PARAMS class Kernel,
class feSurf_Elements
#define CGAL_GRAPH_TRAITS_INHERITANCE_CLASS_NAME feSurfMesh<Kernel,
feSurf_Elements>
#define CGAL_GRAPH_TRAITS_INHERITANCE_BASE_CLASS_NAME
Polyhedron_3<Kernel, feSurf_Elements>

Best regards,

Sebastien.


On 9/9/20 9:22 AM, calvin_cw ([hidden email] via cgal-discuss
Mailing List) wrote:

> Hi,
>
>       I am trying to compile a sample hole filling code using an inherited
> polyhedron class. The code is reproduced below. I keep getting the error
> related to sparse matrix class. Hope someone can assist to point out the
> error. thanks!
>
> regards
> Calvin
>
> <<<< Start code
>
> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
> #include <CGAL/Polygon_mesh_processing/triangulate_hole.h>
> #include <CGAL/Polyhedron_3.h>
> #include <CGAL/IO/OFF_reader.h>
> #include <iostream>
> #include <fstream>
> #include <vector>
> #include <CGAL/Polyhedron_items_with_id_3.h>
>
>
> typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
>
> template <class Refs, class ID>
> class feEdge_Surf : public CGAL::HalfedgeDS_halfedge_base< Refs,
> CGAL::Tag_true, CGAL::Tag_true, CGAL::Tag_true >
> {
> typedef ID size_type;
> private:
> size_type mID;
> public:
> size_type&       id() { return mID; }
> size_type const& id() const { return mID; }
> };
>
> template <class Refs, class Traits, class ID>
> class feFace_Surf : public CGAL::HalfedgeDS_face_base<Refs, CGAL::Tag_true,
> typename Traits::Plane_3>
> {
> typedef ID size_type;
> private:
>
> size_type mID;
> public:
> size_type&       id() { return mID; }
> size_type const& id() const { return mID; }
> };
>
> template <class Refs, class Traits, class ID>
> class feNode_Surf : public CGAL::HalfedgeDS_vertex_base< Refs,
> CGAL::Tag_true, typename Traits::Point_3 >
> {
>
> typedef typename Traits::Point_3 Point_3;
> typedef ID size_type;
> private:
> size_type mID;
> public:
> size_type&       id() { return mID; }
> size_type const& id() const { return mID; }
>
> feNode_Surf(const Point_3& p) : CGAL::HalfedgeDS_vertex_base< Refs,
> CGAL::Tag_true, Point_3>(p)
> {}
>
> feNode_Surf() : CGAL::HalfedgeDS_vertex_base< Refs, CGAL::Tag_true,
> Point_3>()
> {}
>
> };
>
>
> class feSurf_Elements : public CGAL::Polyhedron_items_3
> {
> public:
> template <class Refs, class Traits>
> struct Vertex_wrapper {
> typedef feNode_Surf<Refs, Traits, std::size_t> Vertex;
> };
>
> template <class Refs, class Traits>
> struct Halfedge_wrapper {
> typedef feEdge_Surf<Refs, std::size_t> Halfedge;
>
> };
> template <class Refs, class Traits>
> struct Face_wrapper {
> typedef feFace_Surf<Refs, Traits, std::size_t> Face;
> };
>
> };
>
> typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements>::Point_3 Point_fe;
>
> typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements> Poly_3;
> template<class Kernel, class feSurf_Elements>
> class feSurfMesh : public Poly_3
> {
> public:
> typedef Point_fe Base;
> };
>
> typedef feSurfMesh<Kernel, feSurf_Elements> feSurfaceMesh;
>
> namespace boost {
> template <>
> struct graph_traits<feSurfaceMesh> :
> public graph_traits<Poly_3>
> {};
> } // namespace boost
>
> namespace boost {
> template <class Tag>
> struct property_map<feSurfaceMesh, Tag> :
> public property_map<Poly_3, Tag>
> {};
> } //namespace boost
>
> namespace CGAL {
> template <typename T>
> struct graph_has_property<feSurfaceMesh, T>
> : public CGAL::graph_has_property<Poly_3, T>
> {};
> }
>
> typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements>::Halfedge_handle
> HalfEdge_handle;
> typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements>::Facet_handle
> Facet_handle;
> typedef CGAL::Polyhedron_3<Kernel, feSurf_Elements>::Vertex_handle
> SurfPt_handle;
>
>
> int main(int argc, char* argv[])
> {
> const char* filename = (argc > 1) ? argv[1] : "data/mech-holes-shark.off";
> std::ifstream input(filename);
>
> feSurfaceMesh feMesh;
> CGAL::read_off(input, feMesh);
>
> // Incrementally fill the holes
> unsigned int nb_holes = 0;
> for (HalfEdge_handle h : halfedges(feMesh))
> {
> if (h->is_border())
> {
> std::vector<Facet_handle>  patch_facets;
> std::vector<SurfPt_handle> patch_vertices;
> bool success = std::get<0>(
> CGAL::Polygon_mesh_processing::triangulate_refine_and_fair_hole(
> feMesh,
> h,
> std::back_inserter(patch_facets),
> std::back_inserter(patch_vertices),
>
> CGAL::Polygon_mesh_processing::parameters::vertex_point_map(get(CGAL::vertex_point,
> feMesh)).geom_traits(Kernel())));
>
> std::cout << " Number of facets in constructed patch: " <<
> patch_facets.size() << std::endl;
> std::cout << " Number of vertices in constructed patch: " <<
> patch_vertices.size() << std::endl;
> std::cout << " Fairing : " << (success ? "succeeded" : "failed") <<
> std::endl;
> ++nb_holes;
> }
> }
>
> std::cout << std::endl;
> std::cout << nb_holes << " holes have been filled" << std::endl;
>
> std::ofstream out("filled.off");
> out.precision(17);
> out << feMesh << std::endl;
> return 0;
> }
>
>
>
>
>
> --
> Sent from: http://cgal-discuss.949826.n4.nabble.com/
>

--
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: Using Hole filling using inherited Polyhedron class

Sebastien Loriot (GeometryFactory)
Like in the example mentioned, right after having defined the macros you
need to include the header

#include <CGAL/boost/graph/graph_traits_inheritance_macros.h>

Best regards,

Sebastien.

On 9/10/20 8:31 AM, calvin_cw ([hidden email] via cgal-discuss
Mailing List) wrote:

> Hi Sebastien,
>
>        Not sure if i understand how to use the macros you stated. I tried
> including them in the code, but the same error persisted.
>
>        Hope you are able to expand further on its usage, thanks!
>
> regards
> Calvin
>
>
>
> --
> Sent from: http://cgal-discuss.949826.n4.nabble.com/
>

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