Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] using a Point class from another library

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] using a Point class from another library


Chronological Thread 
  • From: Philipp Moeller <>
  • To:
  • Subject: Re: [cgal-discuss] using a Point class from another library
  • Date: Tue, 24 Apr 2012 10:47:46 +0200
  • Organization: GeometryFactory

"Tomislav Maric"
<>
writes:

> I have managed to make Polyhedron work with my Point class, but when I want
> to read it from an .off file,
>
> this function:
>
> template < class Point> inline
> Point&
> file_scan_vertex( File_scanner_OFF& scanner, Point& p) {
>    typedef typename Point::R R;
>    typedef typename R::RT    RT;
>    double x, y, z, w;
>    scanner.scan_vertex( x, y, z, w);
>    if ( w == 1)
>        p = Point( RT(x), RT(y), RT(z));
>    else
>        p = Point( RT(x), RT(y), RT(z), RT(w));
>    return p;
> }
>
> from the file "File_scanner_OFF.h" expects my point to have a constructor
> with 4 arguments. For a simple
> example Point class that I wrote, I have added this without a problem, but
> if a Point class is coming from another
> library, it is a problem. I cannot change the library Point class. What
> should I do?
>
> Option 1) Inherit from the Point class of the other library and add a dummy
> constructor, counting on
>          implicit casting every time i call a method on the Point to cast
> it up?
>       2) Change the .off File_scanner and adapt it somehow?
>
>       ?) ?

The problem is a more complicated. Technically, Polyhedron shouldn't
make any assumptions about the concrete type of Point and use a
Construct_point_3 functor to construct them. This additional functor
would go into the traits as well.

As a workaround, I wouldn't change file_scan_vertex but add an overload
to the CGAL namespace, e.g.

namespace CGAL {
inline
MyPoint&
file_scan_vertex( File_scanner_OFF& scanner, MyPoint& p) {
// do my thing here
}
}

to change the behavior. This should work as far as I have looked at
things. If not, I'd prefer method 1.

>
> I don't need homogeneous coordinate representation of points, so this kind
> of constructor is not necessary..
>
> Working code is attached.
>
> Thank you!
>
> Tomislav

HTH,
Philipp Moeller
GeometryFactory



Archive powered by MHonArc 2.6.16.

Top of Page