BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Direction_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/Direction_3.h $
00019 // $Id: Direction_3.h 49257 2009-05-09 16:08:19Z spion $
00020 // 
00021 //
00022 // Author(s)     : Andreas Fabri, Stefan Schirra
00023  
00024 #ifndef CGAL_DIRECTION_3_H
00025 #define CGAL_DIRECTION_3_H
00026 
00027 #include <boost/static_assert.hpp>
00028 #include <boost/type_traits.hpp>
00029 #include <CGAL/Kernel/Return_base_tag.h>
00030 #include <CGAL/representation_tags.h>
00031 #include <CGAL/Dimension.h>
00032 
00033 CGAL_BEGIN_NAMESPACE
00034 
00035 template <class R_>
00036 class Direction_3 : public R_::Kernel_base::Direction_3
00037 {
00038   typedef typename R_::RT                    RT;
00039   typedef typename R_::Vector_3              Vector_3;
00040   typedef typename R_::Line_3                Line_3;
00041   typedef typename R_::Ray_3                 Ray_3;
00042   typedef typename R_::Segment_3             Segment_3;
00043   typedef typename R_::Aff_transformation_3  Aff_transformation_3;
00044 
00045   typedef Direction_3                        Self;
00046   BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Direction_3>::value));
00047 
00048 public:
00049 
00050   typedef Dimension_tag<3>  Ambient_dimension;
00051   typedef Dimension_tag<0>  Feature_dimension;
00052 
00053   typedef typename R_::Kernel_base::Direction_3 Rep;
00054 
00055   const Rep& rep() const
00056   {
00057     return *this;
00058   }
00059 
00060   Rep& rep()
00061   {
00062     return *this;
00063   }
00064 
00065   typedef          R_                       R;
00066 
00067   Direction_3() {}
00068 
00069   Direction_3(const Rep& d)
00070     : Rep(d) {}
00071 
00072   explicit Direction_3(const Vector_3& v)
00073     : Rep(typename R::Construct_direction_3()(Return_base_tag(), v)) {}
00074 
00075   explicit Direction_3(const Line_3& l)
00076     : Rep(typename R::Construct_direction_3()(Return_base_tag(), l)) {}
00077 
00078   explicit Direction_3(const Ray_3& r)
00079     : Rep(typename R::Construct_direction_3()(Return_base_tag(), r)) {}
00080 
00081   explicit Direction_3(const Segment_3& s)
00082     : Rep(typename R::Construct_direction_3()(Return_base_tag(), s)) {}
00083 
00084   Direction_3(const RT& hx, const RT& hy, const RT& hz)
00085     : Rep(typename R::Construct_direction_3()(Return_base_tag(), hx, hy, hz)) {}
00086 
00087   Direction_3 transform(const Aff_transformation_3 &t) const
00088   {
00089     return t.transform(*this);
00090   }
00091  
00092   Direction_3
00093   operator-() const
00094   {
00095     return R().construct_opposite_direction_3_object()(*this);
00096   } 
00097   
00098   Vector_3 to_vector() const
00099   {
00100     return R().construct_vector_3_object()(*this);
00101   }
00102 
00103   Vector_3 vector() const { return to_vector(); }
00104 
00105 
00106   typename Qualified_result_of<typename R::Compute_dx_3, Direction_3>::type
00107   dx() const
00108   {
00109     return R().compute_dx_3_object()(*this);
00110   }
00111 
00112   typename Qualified_result_of<typename R::Compute_dy_3, Direction_3>::type
00113   dy() const
00114   {
00115     return R().compute_dy_3_object()(*this);
00116   }
00117 
00118   typename Qualified_result_of<typename R::Compute_dz_3, Direction_3>::type
00119   dz() const
00120   {
00121     return R().compute_dz_3_object()(*this);
00122   }
00123 
00124   typename Qualified_result_of<typename R::Compute_dx_3, Direction_3>::type
00125   delta(int i) const
00126   {
00127     CGAL_kernel_precondition( i >= 0 && i <= 2 );
00128     if (i==0) return dx();
00129     if (i==1) return dy();
00130     return dz();
00131   }
00132 
00133 };
00134 
00135 
00136 template <class R >
00137 std::ostream&
00138 insert(std::ostream& os, const Direction_3<R>& d, const Cartesian_tag&) 
00139 {
00140   typename R::Vector_3 v = d.to_vector();
00141   switch(os.iword(IO::mode)) {
00142     case IO::ASCII :
00143       return os << v.x() << ' ' << v.y()  << ' ' << v.z();
00144     case IO::BINARY :
00145       write(os, v.x());
00146       write(os, v.y());
00147       write(os, v.z());
00148       return os;
00149     default:
00150       os << "DirectionC3(" << v.x() << ", " << v.y() << ", " << v.z() << ")";
00151       return os;
00152   }
00153 }
00154 
00155 template <class R >
00156 std::ostream&
00157 insert(std::ostream& os, const Direction_3<R>& d, const Homogeneous_tag&)
00158 {
00159   switch(os.iword(IO::mode))
00160   {
00161     case IO::ASCII :
00162         return os << d.dx() << ' ' << d.dy() << ' ' << d.dz();
00163     case IO::BINARY :
00164         write(os, d.dx());
00165         write(os, d.dy());
00166         write(os, d.dz());
00167         return os;
00168     default:
00169         return os << "DirectionH3(" << d.dx() << ", "
00170                                     << d.dy() << ", "
00171                                     << d.dz() << ')';
00172   }
00173 }
00174 
00175 template < class R >
00176 std::ostream&
00177 operator<<(std::ostream& os, const Direction_3<R>& d)
00178 {
00179   return insert(os, d, typename R::Kernel_tag() );
00180 }
00181 
00182 
00183 template <class R >
00184 std::istream&
00185 extract(std::istream& is, Direction_3<R>& d, const Cartesian_tag&) 
00186 {
00187   typename R::FT x, y, z;
00188   switch(is.iword(IO::mode)) {
00189     case IO::ASCII :
00190       is >> x >> y >> z;
00191       break;
00192     case IO::BINARY :
00193       read(is, x);
00194       read(is, y);
00195       read(is, z);
00196       break;
00197     default:
00198       std::cerr << "" << std::endl;
00199       std::cerr << "Stream must be in ascii or binary mode" << std::endl;
00200       break;
00201   }
00202   if (is)
00203       d = Direction_3<R>(x, y, z);
00204   return is;
00205 }
00206 
00207 template <class R >
00208 std::istream&
00209 extract(std::istream& is, Direction_3<R>& d, const Homogeneous_tag&) 
00210 {
00211   typename R::RT x, y, z;
00212   switch(is.iword(IO::mode))
00213   {
00214     case IO::ASCII :
00215         is >> x >> y >> z;
00216         break;
00217     case IO::BINARY :
00218         read(is, x);
00219         read(is, y);
00220         read(is, z);
00221         break;
00222     default:
00223         std::cerr << "" << std::endl;
00224         std::cerr << "Stream must be in ascii or binary mode" << std::endl;
00225         break;
00226   }
00227   if (is)
00228     d = Direction_3<R>(x, y, z);
00229   return is;
00230 }
00231 
00232 template < class R >
00233 std::istream&
00234 operator>>(std::istream& is, Direction_3<R>& d)
00235 {
00236   return extract(is, d, typename R::Kernel_tag() );
00237 }
00238 
00239 CGAL_END_NAMESPACE
00240 
00241 #endif // CGAL_DIRECTION_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines