BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Point_3.h
Go to the documentation of this file.
00001 // Copyright (c) 1999  Utrecht University (The Netherlands),
00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
00005 // and Tel-Aviv University (Israel).  All rights reserved.
00006 //
00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License as
00009 // published by the Free Software Foundation; version 2.1 of the License.
00010 // See the file LICENSE.LGPL distributed with CGAL.
00011 //
00012 // Licensees holding a valid commercial license may use this file in
00013 // accordance with the commercial license agreement provided with the software.
00014 //
00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 //
00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kernel_23/include/CGAL/Point_3.h $
00019 // $Id: Point_3.h 43244 2008-05-21 13:48:05Z spion $
00020 //
00021 //
00022 // Author(s)     : Andreas Fabri, Stefan Schirra
00023 
00024 #ifndef CGAL_POINT_3_H
00025 #define CGAL_POINT_3_H
00026 
00027 #include <CGAL/Origin.h>
00028 #include <CGAL/representation_tags.h>
00029 #include <boost/static_assert.hpp>
00030 #include <boost/type_traits.hpp>
00031 #include <CGAL/Kernel/Return_base_tag.h>
00032 #include <CGAL/Bbox_3.h>
00033 #include <CGAL/representation_tags.h>
00034 #include <CGAL/Dimension.h>
00035 
00036 CGAL_BEGIN_NAMESPACE
00037 
00038 template <class R_>
00039 class Point_3 : public R_::Kernel_base::Point_3
00040 {
00041   typedef typename R_::RT                    RT;
00042   typedef typename R_::FT                    FT;
00043   typedef typename R_::Vector_3              Vector_3;
00044   typedef typename R_::Aff_transformation_3  Aff_transformation_3;
00045 
00046   typedef Point_3                            Self;
00047   BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Point_3>::value));
00048 
00049 public:
00050 
00051   typedef Dimension_tag<3>  Ambient_dimension;
00052   typedef Dimension_tag<0>  Feature_dimension;
00053 
00054   typedef typename R_::Kernel_base::Point_3  Rep;
00055   typedef typename R_::Cartesian_const_iterator_3 Cartesian_const_iterator;
00056 
00057   const Rep& rep() const
00058   {
00059     return *this;
00060   }
00061 
00062   Rep& rep()
00063   {
00064     return *this;
00065   }
00066 
00067   typedef          R_                       R;
00068 
00069   Point_3() {}
00070 
00071   Point_3(const Origin& o)
00072     : Rep(typename R::Construct_point_3()(Return_base_tag(), o))
00073   {}
00074 
00075   Point_3(const Rep& p)
00076       : Rep(p) {}
00077 
00078   template < typename T1, typename T2, typename T3 >
00079   Point_3(const T1& x, const T2& y, const T3& z)
00080     : Rep(typename R::Construct_point_3()(Return_base_tag(), x, y, z))
00081   {}
00082 
00083   Point_3(const RT& hx, const RT& hy, const RT& hz, const RT& hw)
00084     : Rep(typename R::Construct_point_3()(Return_base_tag(), hx, hy, hz, hw))
00085   {}
00086 
00087   typename Qualified_result_of<typename R::Compute_x_3, Point_3>::type
00088   x() const
00089   {
00090     return typename R::Compute_x_3()(*this);
00091   }
00092 
00093   typename Qualified_result_of<typename R::Compute_y_3, Point_3>::type
00094   y() const
00095   {
00096     return typename R::Compute_y_3()(*this);
00097   }
00098 
00099   typename Qualified_result_of<typename R::Compute_z_3, Point_3>::type
00100   z() const
00101   {
00102     return typename R::Compute_z_3()(*this);
00103   }
00104 
00105   typename Qualified_result_of<typename R::Compute_hx_3, Point_3>::type
00106   hx() const
00107   {
00108     return R().compute_hx_3_object()(*this);
00109   }
00110 
00111   typename Qualified_result_of<typename R::Compute_hy_3, Point_3>::type
00112   hy() const
00113   {
00114     return R().compute_hy_3_object()(*this);
00115   }
00116 
00117   typename Qualified_result_of<typename R::Compute_hz_3, Point_3>::type
00118   hz() const
00119   {
00120     return R().compute_hz_3_object()(*this);
00121   }
00122 
00123   typename Qualified_result_of<typename R::Compute_hw_3, Point_3>::type
00124   hw() const
00125   {
00126     return R().compute_hw_3_object()(*this);
00127   }
00128 
00129   typename Qualified_result_of<typename R::Compute_x_3, Point_3>::type
00130   cartesian(int i) const
00131   {
00132     CGAL_kernel_precondition( (i == 0) || (i == 1) || (i == 2) );
00133     if (i==0) return x();
00134     if (i==1) return y();
00135     return z();
00136   }
00137 
00138   RT
00139   homogeneous(int i) const
00140   {
00141     CGAL_kernel_precondition( (i >= 0) || (i <= 3) );
00142     if (i==0) return hx();
00143     if (i==1) return hy();
00144     if (i==2) return hz();
00145     return hw();
00146   }
00147 
00148   typename Qualified_result_of<typename R::Compute_x_3,Point_3>::type
00149   operator[](int i) const
00150   {
00151       return cartesian(i);
00152   }
00153 
00154   Cartesian_const_iterator cartesian_begin() const
00155   {
00156     return typename R::Construct_cartesian_const_iterator_3()(*this);
00157   }
00158 
00159   Cartesian_const_iterator cartesian_end() const
00160   {
00161     return typename R::Construct_cartesian_const_iterator_3()(*this,3);
00162   }
00163 
00164   int dimension() const
00165   {
00166       return 3;
00167   }
00168 
00169   Bbox_3 bbox() const
00170   {
00171     return R().construct_bbox_3_object()(*this);
00172   }
00173 
00174   Point_3 transform(const Aff_transformation_3 &t) const
00175   {
00176     return t.transform(*this);
00177   }
00178 
00179 };
00180 
00181 template <class R>
00182 inline
00183 bool
00184 operator==(const Origin& o, const Point_3<R>& p)
00185 { return p == o; }
00186 
00187 template <class R>
00188 inline
00189 bool
00190 operator!=(const Origin& o, const Point_3<R>& p)
00191 { return p != o; }
00192 
00193 
00194 template <class R >
00195 std::ostream&
00196 insert(std::ostream& os, const Point_3<R>& p,const Cartesian_tag&)
00197 {
00198     switch(os.iword(IO::mode)) {
00199     case IO::ASCII :
00200         return os << p.x() << ' ' << p.y() << ' ' << p.z();
00201     case IO::BINARY :
00202         write(os, p.x());
00203         write(os, p.y());
00204         write(os, p.z());
00205         return os;
00206     default:
00207         return os << "PointC3(" << p.x() << ", " << p.y()
00208                                          << ", " << p.z() << ')';
00209     }
00210 }
00211 
00212 template <class R >
00213 std::ostream&
00214 insert(std::ostream& os, const Point_3<R>& p,const Homogeneous_tag&)
00215 {
00216   switch(os.iword(IO::mode))
00217   {
00218     case IO::ASCII :
00219         return os << p.hx() << ' ' << p.hy() << ' ' << p.hz() << ' ' << p.hw();
00220     case IO::BINARY :
00221         write(os, p.hx());
00222         write(os, p.hy());
00223         write(os, p.hz());
00224         write(os, p.hw());
00225         return os;
00226     default:
00227         return os << "PointH3(" << p.hx() << ", "
00228                                 << p.hy() << ", "
00229                                 << p.hz() << ", "
00230                                 << p.hw() << ')';
00231   }
00232 }
00233 
00234 template < class R >
00235 std::ostream&
00236 operator<<(std::ostream& os, const Point_3<R>& p)
00237 {
00238   return insert(os, p, typename R::Kernel_tag() );
00239 }
00240 
00241 
00242 template <class R >
00243 std::istream&
00244 extract(std::istream& is, Point_3<R>& p, const Cartesian_tag&)
00245 {
00246     typename R::FT x, y, z;
00247     switch(is.iword(IO::mode)) {
00248     case IO::ASCII :
00249         is >> x >> y >> z;
00250         break;
00251     case IO::BINARY :
00252         read(is, x);
00253         read(is, y);
00254         read(is, z);
00255         break;
00256     default:
00257         std::cerr << "" << std::endl;
00258         std::cerr << "Stream must be in ascii or binary mode" << std::endl;
00259         break;
00260     }
00261     if (is)
00262         p = Point_3<R>(x, y, z);
00263     return is;
00264 }
00265 
00266 
00267 template <class R >
00268 std::istream&
00269 extract(std::istream& is, Point_3<R>& p, const Homogeneous_tag&)
00270 {
00271   typename R::RT hx, hy, hz, hw;
00272   switch(is.iword(IO::mode))
00273   {
00274     case IO::ASCII :
00275         is >> hx >> hy >> hz >> hw;
00276         break;
00277     case IO::BINARY :
00278         read(is, hx);
00279         read(is, hy);
00280         read(is, hz);
00281         read(is, hw);
00282         break;
00283     default:
00284         std::cerr << "" << std::endl;
00285         std::cerr << "Stream must be in ascii or binary mode" << std::endl;
00286         break;
00287   }
00288   if (is)
00289     p = Point_3<R>(hx, hy, hz, hw);
00290   return is;
00291 }
00292 
00293 template < class R >
00294 std::istream&
00295 operator>>(std::istream& is, Point_3<R>& p)
00296 {
00297   return extract(is, p, typename R::Kernel_tag() );
00298 }
00299 
00300 CGAL_END_NAMESPACE
00301 
00302 #endif // CGAL_POINT_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines