Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Inheriting from Extended_homogeneous

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Inheriting from Extended_homogeneous


Chronological Thread 
  • From: "Tomislav Maric" <>
  • To:
  • Subject: Re: [cgal-discuss] Inheriting from Extended_homogeneous
  • Date: Tue, 24 Apr 2012 09:41:12 +0200

Why not change the vertex class instead of a Point?

Vertex::Point
The type of the geometric information associated to a vertex.

Extending vertex with additional information is explained here:

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Polyhedron/Chapter_main.html#Section_25.5

I'm trying to use another class for Point, but along the way, I will need to
extend the Vertex to
hold additional information too. The extended example
polyhedron_prog_my_point.cpp is attached as well
as the Point<T> class (simple Point class that I am using to learn this
stuff). Unfortunaltely for
me, there is a problem with the class
CGAL::Polyhedron_scan_OFF<HDS>::operator() for input of Polyhedron
from an .off file (you don't care about this part of the example).

You just need to take a look at My_vertex struct: instead of "double x",
define your own data and
make sure the class is then defined properly.

Copy both files to examples/Polyhedron and run make.

Hope this helps...

Tomislav

> ----- Original Message -----
> From: Johannes Ulén
> Sent: 04/24/12 09:14 AM
> To:
>
> Subject: Re: [cgal-discuss] Inheriting from Extended_homogeneous
>
> Thank you for the reply.
> Is there a way to change the point construct?
>
> Let me very breifly explain what I want to do and my problem might
> become clearer.
> 1) I want to create a polytope where each vertex starts with boolean
> value set to false.
> 2) For each vertex which is false I do some calculations and perform
> an intersection with a halfspace. The polytope is now reshaped and has
> more vertices.
> 3) A certain opertaion will mark a vertex as "true" and I then dont
> need to bother with it anymore.
>
> My programing instict tells me that the easiet way to to do this would
> be to change point class, but I might be wrong?
>
> -- Johannes
>
>
> Den 24 april 2012 08:37 skrev Sebastien Loriot (GeometryFactory)
> <>:
> > On 04/23/2012 02:55 PM,
> >
> > wrote:
> >>
> >> I'm trying the add one property to the point class.
> >>
> >> By help from  StackOverflow I was directed to Manual Chapter 11.5
> >> Extensible
> >> Kernel using this I wrote the code below.
> >>
> >> The code  will not compile and I get the error:
> >> ‘typename CGAL::Extended_homogeneous::Base’ names
> >> 'CGAL::Extended_homogeneous::Base’, which is not a class template|
> >>
> >> == CODE ==
> >> #include<CGAL/Extended_homogeneous.h>
> >>
> >> template<  typename K_, typename K_Base>
> >> class My_base  : public K_Base::template Base<K_>::Type
> >> {
> >>   typedef typename K_Base::template Base<K_>::Type   OldK;
> >>
> >> public:
> >>   typedef K_                               Kernel;
> >>
> >>   template<  typename Kernel2>
> >>   struct Base { typedef My_base<Kernel2, K_Base>   Type; };
> >>  };
> >>
> >> template<  typename RT_>
> >> struct MyKernel  : public
> >> CGAL::Type_equality_wrapper<My_base<MyKernel<RT_>,
> >> CGAL::Homogeneous<RT_>  >,  MyKernel<RT_>  >
> >> {};
> >>
> >> #include<CGAL/Nef_polyhedron_3.h>
> >> typedef MyKernel<CGAL::Gmpz>    Kernel;
> >>
> >> typedef CGAL::Nef_polyhedron_3<Kernel>  Nef_Polyhedron;
> >> typedef Nef_Polyhedron::Plane_3  Plane;
> >>
> >> int main()
> >> {
> >>   Nef_Polyhedron half_space(Plane(1,1,1,1), Nef_Polyhedron::EXCLUDED);
> >>
> >>   return 0;
> >> }
> >> ====
> >>
> >> If the inhertiance is changed to "public K_Base::Base::template
> >> B<K_>::Type" it
> >> will compile but Then I miss the propeties from Extentensions I guess?
> >> Because
> >> I get the error "Constructor not available for this kernel" when I run
> >> the
> >> program.
> >
> >
> > The point constructors are not changed by this mechanism. This means that
> > only those documented are available. If you want to initialize your extra
> > data, you need to first create an object of type My_point and then init a
> > point of type MyKernel::Point_3 with it.
> >
> > The class in the kernel is a kind of interface while My_point is the
> > representation.
> >
> > Sebastien.
> >
> >
> >
> >
> >
> > --
> > You are currently subscribed to cgal-discuss.
> > To unsubscribe or access the archives, go to
> > https://lists-sop.inria.fr/wws/info/cgal-discuss
> >
>
>
>
> --
> - Johannes
>
> --
> You are currently subscribed to cgal-discuss.
> To unsubscribe or access the archives, go to
> https://lists-sop.inria.fr/wws/info/cgal-discuss

#ifndef POINT_HPP
#define POINT_HPP

template <class T>
class Point;

template<class T>
std::ostream& operator << (std::ostream& os, const Point<T>& v);
template<class T>
std::istream& operator >> (std::istream& is, const Point<T>& v);

template<class T>
class Point 
{
    private:
        T v_[3];

    public:
        Point()
            :
                v_()
        {

        }

        Point(T c1, T c2, T c3=0)
        {

            v_[0] = c1;
            v_[1] = c2;
            v_[2] = c3;
        }

        Point(const Point& v)
        {
            v_[0] = v.v_[0];
            v_[1] = v.v_[1];
            v_[2] = v.v_[2];
        }
        
        const Point& operator = (const Point& v)
        {

            v_[0] = v.v_[0];
            v_[1] = v.v_[1];
            v_[2] = v.v_[2];

            return *this;
        }

        const Point& operator + (const Point& v)
        {
            v_[0] = v_[0]+ v.v_[0];
            v_[1] = v_[1]+ v.v_[1];
            v_[2] = v_[2]+ v.v_[2];

            return *this;
        }

        const Point& operator += (const Point& v)
        {
            return this->operator+(v);
        }

        const Point& operator - (const Point& v)
        {
            v_[0] = v_[0]- v.v_[0];
            v_[1] = v_[1]- v.v_[1];
            v_[2] = v_[2]- v.v_[2];

            return *this;
        }

        const Point& operator -= (const Point& v)
        {
            return this->operator-(v);
        }

        friend std::ostream& operator << <> (std::ostream& , 
                                             const Point<T>&);

        friend std::istream& operator >> <> (std::istream& , 
                                             const Point<T>&);
};

template<class T>
std::ostream& operator << (std::ostream& os, const Point<T>& v)
{
    os  << v.v_[0] << " " << v.v_[1] << " " << v.v_[2];
    return os;
}

template<class T>
std::istream& operator >> (std::istream& is, const Point<T>& v)
{
    is  >> v.v_[0] >> v.v_[1] >> v.v_[2];
    return is;
}

#endif
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <iostream>

#include "point.hpp"

#include<fstream>
#include <CGAL/IO/Polyhedron_iostream.h>

// A face type with a color member variable.
template <class Refs>
struct My_face : public CGAL::HalfedgeDS_face_base<Refs> {
    CGAL::Color color;
};

template <class Refs, class T, class Point>
struct My_vertex: public CGAL::HalfedgeDS_vertex_base<Refs, T, Point> 
{
    double x;

    My_vertex()
    :
        CGAL::HalfedgeDS_vertex_base<Refs, T, Point> ()
    {};

    My_vertex(const Point& p)
    :
        CGAL::HalfedgeDS_vertex_base<Refs, T, Point>(p)
    {
    };

    My_vertex(const Point& p, double X)
    :
        CGAL::HalfedgeDS_vertex_base<Refs, T, Point>(p), 
        x(X)
    {};

};


// An items type using my face.
struct My_items : public CGAL::Polyhedron_items_3 {

    template <class Refs, class Traits>
    struct Face_wrapper {
        typedef My_face<Refs> Face;
    };

    template <class Refs, class Traits>
    struct Vertex_wrapper {
        typedef typename Traits::Point_3 Point;
        typedef My_vertex<Refs, CGAL::Tag_true, Point> Vertex;
    };
};


// Define the PolyhedronTraits_3 concept and take the Point directly from point.hpp
template <class Kernel>
struct My_Polyhedron_traits_3
:
    public CGAL::Polyhedron_traits_3<Kernel>
{
    // Redefine Point_3 to be my Point<double>
    typedef Point<double> Point_3;
    typedef typename Kernel::Plane_3 Plane_3;

    My_Polyhedron_traits_3()
    :
        CGAL::Polyhedron_traits_3<Kernel>()
    {};

    My_Polyhedron_traits_3(Kernel kernel)
    :
        CGAL::Polyhedron_traits_3<Kernel>(kernel)
    {};

    My_Polyhedron_traits_3(const My_Polyhedron_traits_3& r)
    :
        CGAL::Polyhedron_traits_3<Kernel>(r)
    {}

    My_Polyhedron_traits_3& operator=(const My_Polyhedron_traits_3& r)
    {
        CGAL::Polyhedron_traits_3<Kernel>::operator=(r);
    }
};

    


typedef CGAL::Simple_cartesian<double>        Kernel;
//typedef CGAL::Polyhedron_3<Kernel, My_items>  Polyhedron;
typedef CGAL::Polyhedron_3<My_Polyhedron_traits_3<Kernel>, My_items>  Polyhedron;
typedef Polyhedron::Halfedge_handle           Halfedge_handle;

//typedef CGAL::Simple_cartesian<double>               Kernel;
typedef Kernel::Point_3                              Point_3;
//typedef CGAL::Polyhedron_3<Kernel>                   Polyhedron;
typedef Polyhedron::Facet_iterator                   Facet_iterator;
typedef Polyhedron::Halfedge_around_facet_circulator Halfedge_facet_circulator;

int main() {

    // Kernel::Point_3
    //Point_3 p( 0.0, 0.0, 0.0);
    //Point_3 q( 1.0, 0.0, 0.0);
    //Point_3 r( 0.0, 1.0, 0.0);
    //Point_3 s( 0.0, 0.0, 1.0);
    
    Point<double> p( 0.0, 0.0, 0.0);
    Point<double> q( 1.0, 0.0, 0.0);
    Point<double> r( 0.0, 1.0, 0.0);
    Point<double> s( 0.0, 0.0, 1.0);

    //Polyhedron P;
    //P.make_tetrahedron( p, q, r, s);
    
    Polyhedron P;

    //std::ifstream is ("input.off");
    //is >> P;

    // Write polyhedron in Object File Format (OFF).
    //CGAL::set_ascii_mode( std::cout);
    //std::cout << "OFF" << std::endl << P.size_of_vertices() << ' '
              //<< P.size_of_facets() << " 0" << std::endl;
    //std::copy( P.points_begin(), P.points_end(),
               //std::ostream_iterator< Point<double> >( std::cout, "\n"));
    //for (  Facet_iterator i = P.facets_begin(); i != P.facets_end(); ++i) {
        //Halfedge_facet_circulator j = i->facet_begin();
        //// Facets in polyhedral surfaces are at least triangles.
        //CGAL_assertion( CGAL::circulator_size(j) >= 3);
        //std::cout << CGAL::circulator_size(j) << ' ';
        //do {
            //std::cout << ' ' << std::distance(P.vertices_begin(), j->vertex());
        //} while ( ++j != i->facet_begin());
        //std::cout << std::endl;
    //}
    return 0;
}



Archive powered by MHonArc 2.6.16.

Top of Page