Subject: CGAL users discussion list
List archive
- From: Kuan <>
- To:
- Subject: Extensible Kernel
- Date: Mon, 16 Jul 2007 09:25:36 +0200
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=peSNRgdre2NoQQnvc1VPq6mV7UCKBV3jza3W4+sgyQFh2Y79qX9+kU5F2y00immHzZ+2EAcKmF6KHKSewWDfizaZgi5f2Zs1MbaTQNoVuMrp2027YlNVtRJtr4R4w2x7yAuk8taTSJamFmBZJThmBJFr3DhjSNSuFNxjpi2K4Ss=
Hi all,
I have some problem about Extensible Kernel. I define a Point_3 by myself. But it works ok for Deaunay_Triangulation, but it doesn't work with Neighbor_serach and Plane_3. like below:
typedef CGAL::Search_traits_3<K> TreeTraits;
typedef CGAL::Orthogonal_k_neighbor_search<TreeTraits> Neighbor_search;
typedef Neighbor_search::Tree Tree;
and for Plane_3, it doesn't work as i define K::Plane_3(p1,p2,p3). Am i defining my Point_3 in a wrong way? I just want to add some information in it.
I define my Point_3 like this:
#ifndef MY_POINTC3_H
#define MY_POINTC3_H
#include <CGAL/Origin.h>
#include <CGAL/Bbox_3.h>
class MyPointC3 {
private:
double vec[3];
double ar; //area
bool inc; //include in crust
double val;
public:
MyPointC3()
: ar(1),val(0)
{
*vec = 0;
*(vec+1) = 0;
*(vec+2) = 0;
}
MyPointC3(const double x, const double y, const double z, double c = 1,double v = 0, bool i = true)
: ar(c),val(v),inc(i)
{
*vec = x;
*(vec+1) = y;
*(vec+2) = z;
}
const double& x() const { return *vec; }
double & x() { return *vec; }
void setX(double x){*vec = x;}
const double& y() const { return *(vec+1); }
double& y() { return *(vec+1); }
void setY(double y){*(vec+1) = y;}
const double& z() const { return *(vec+2); }
double& z() { return *(vec+2); }
void setZ(double z){*(vec+2) = z;}
double area() const { return ar; }
double& area() { return ar; }
double value() const { return val; }
double& value() { return val; }
const bool& included() const { return inc; }
bool & included(){return inc;}
bool operator==(const MyPointC3 &p) const
{
return ( *vec == *(p.vec) ) && ( *(vec+1) == *(p.vec + 1)) && ( *(vec+2) == *(p.vec + 2));
}
bool operator!=(const MyPointC3 &p) const
{
return !(*this == p);
}
};
template <class ConstructBbox_3>
class MyConstruct_bbox_3 : public ConstructBbox_3 {
public:
CGAL::Bbox_3 operator()(const MyPointC3& p) const {
return CGAL::Bbox_3(p.x(), p.y(), p.z(), p.x(), p.y(), p.z());
}
};
class MyConstruct_coord_iterator {
public:
const double* operator()(const MyPointC3& p)
{
return &p.x();
}
const double* operator()(const MyPointC3& p, int)
{
const double* pyptr = &p.z();
pyptr++;
return pyptr;
}
};
template <typename K, typename OldK>
class MyConstruct_point_3
{
typedef typename K::RT RT;
typedef typename K::Point_3 Point_3;
typedef typename K::Line_3 Line_3;
typedef typename Point_3::Rep Rep;
public:
typedef Point_3 result_type;
typedef CGAL::Arity_tag< 1 > Arity;
// Note : the CGAL::Return_base_tag is really internal CGAL stuff.
// Unfortunately it is needed for optimizing away copy-constructions,
// due to current lack of delegating constructors in the C++ standard.
Rep // Point_2
operator()(CGAL::Return_base_tag, CGAL::Origin o) const
{ return Rep(o); }
Rep // Point_2
operator()(CGAL::Return_base_tag, const RT& x, const RT& y, const RT& z) const
{ return Rep(x, y, z); }
Rep // Point_2
operator()(CGAL::Return_base_tag, const RT& x, const RT& y, const RT& z, const RT& w) const
{ return Rep(x, y, z, w); }
Point_3
operator()(CGAL::Origin o) const
{ return MyPointC3(0, 0, 0,0); }
Point_3
operator()(const RT& x, const RT& y, const RT& z) const
{
return MyPointC3(x, y, z ,0);
}
Point_3
operator()(const Line_3& l) const
{
typename OldK::Construct_point_3 base_operator;
Point_3 p = base_operator(l);
return p;
}
Point_3
operator()(const Line_3& l, int i) const
{
typename OldK::Construct_point_3 base_operator;
return base_operator(l, i);
}
// We need this one, as such a functor is in the Filtered_kernel
Point_3
operator()(const RT& x, const RT& y,const RT& z, const RT& w) const
{
if(w != 1){
return MyPointC3(x/w, y/w,z/w, 0);
} else {
return MyPointC3(x,y,z, 0);
}
}
};
std::ostream &
operator<<(std::ostream &os, const MyPointC3 &p)
{
switch(os.iword(CGAL::IO::mode)) {
case CGAL::IO::ASCII :
return os << p.x() << ' ' << p.y() <<' '<<p.z();
case CGAL::IO::BINARY :
CGAL::write(os, p.x());
CGAL::write(os, p.y());
CGAL::write(os, p.z());
return os;
default:
return os << "MyPointC3(" << p.x() << ", " << p.y()<<", "<< p.z() ;
}
}
std::istream &
operator>>(std::istream &is, MyPointC3 &p)
{
double x, y, z;
int c;
switch(is.iword(CGAL::IO::mode)) {
case CGAL::IO::ASCII :
is >> x >> y>>z;
break;
case CGAL::IO::BINARY :
CGAL::read(is, x);
CGAL::read(is, y);
CGAL::read(is, z);
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
if (is) {
p = MyPointC3(x, y,z);
}
return is;
}
#endif // MY_POINTC3_H
and use it in my kernel
#ifndef MYKERNEL_H
#define MYKERNEL_H
#include <CGAL/Cartesian.h>
#include "MyPointC3.h"
// K_ is the new kernel, and K_Base is the old kernel
template < typename K_, typename K_Base >
class MyCartesian_base
: public K_Base::template Base<K_>::Type
{
typedef typename K_Base::template Base<K_>::Type OldK;
public:
typedef K_ Kernel;
typedef MyPointC3 Point_3;
typedef MyConstruct_point_3<Kernel, OldK> Construct_point_3;
typedef const double* Cartesian_const_iterator_3;
typedef MyConstruct_coord_iterator Construct_cartesian_const_iterator_3;
typedef MyConstruct_bbox_3<typename OldK::Construct_bbox_3>
Construct_bbox_3;
Construct_point_3
construct_point_3_object() const
{ return Construct_point_3(); }
template < typename Kernel3 >
struct Base { typedef MyCartesian_base<Kernel3, K_Base> Type; };
};
template < typename FT_ >
struct MyKernel
: public CGAL::Type_equality_wrapper<
MyCartesian_base<MyKernel<FT_>, CGAL::Cartesian<FT_> >,
MyKernel<FT_> >
{};
#endif // MYKERNEL_H
best regards
Kuan
- Extensible Kernel, Kuan, 07/16/2007
- Re: Extensible Kernel, Kuan, 07/16/2007
- Re: Extensible Kernel, Kuan, 07/17/2007
- Re: [cgal-discuss] Re: Extensible Kernel, Laurent Rineau, 07/17/2007
- Re: Extensible Kernel, Kuan, 07/17/2007
- Re: Extensible Kernel, Kuan, 07/16/2007
Archive powered by MHonArc 2.6.16.