00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef DSR_PDB_POINT_H
00022 #define DSR_PDB_POINT_H
00023 #include <iostream>
00024 #include <dsrpdb/config.h>
00025
00026 #ifdef PDB_USE_CGAL
00027 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
00028 #include <CGAL/squared_distance_3.h>
00029 namespace dsrpdb {
00030
00031 typedef CGAL::Exact_predicates_inexact_constructions_kernel::Point_3 Point;
00032 typedef CGAL::Exact_predicates_inexact_constructions_kernel::Vector_3 Vector;
00033
00034 struct Squared_distance{
00035 double operator()(const Point &a, const Point &b) const {
00036 return CGAL::squared_distance(a,b);
00037 }
00038 };
00039 }
00040
00041 #else
00042 namespace dsrpdb {
00044
00047 class Point {
00048 public:
00050 Point(): x_(0), y_(0), z_(0){}
00052 Point(double x, double y, double z): x_(x), y_(y), z_(z){}
00053
00055 double x() const {return x_;}
00057 double y() const {return y_;}
00058
00060 double z() const {return z_;}
00061
00063 double operator[](unsigned int i) const {
00064 switch(i) {
00065 case 0: return x_;
00066 case 1: return y_;
00067 case 2: return z_;
00068 default:
00069 assert(i < 3);
00070 return -1;
00071 }
00072 }
00073
00075 Point operator-(const Point &o) const {
00076 return Point(x_-o.x_, y_-o.y_, z_-o.z_);
00077 }
00078
00080 Point operator+(const Point &o) const {
00081 return Point(x_+o.x_, y_+o.y_, z_+o.z_);
00082 }
00083
00085 Point operator/(double d) const {
00086 return Point(x_/d, y_/d, z_/d);
00087 }
00088
00090 double operator*(const Point &o) const {
00091 return x_*o.x_ + y_*o.y_ + z_*o.z_;
00092 }
00093 protected:
00094 double x_, y_, z_;
00095 };
00096
00097 typedef Point Vector;
00098
00099 inline std::ostream &operator<<(std::ostream &o, const Point &p) {
00100 o << p.x() << " " << p.y() << " " << p.z();
00101 return o;
00102 }
00103
00104 inline std::istream &operator>>(std::istream &i, Point &p) {
00105 double x,y,z;
00106 i >> x >> y >> z;
00107 if (!i) return i;
00108 p= Point(x,y,z);
00109 return i;
00110 }
00111
00113 struct Squared_distance{
00114 double operator()(const Point &a, const Point &b) const {
00115 return (a.x()-b.x())*(a.x()-b.x())
00116 + (a.y()-b.y())*(a.y()-b.y())
00117 + (a.z()-b.z())*(a.z()-b.z());
00118 }
00119 };
00120
00121 };
00122 #endif
00123
00124 #endif