BWAPI
|
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/Ray_3.h $ 00019 // $Id: Ray_3.h 42932 2008-04-17 10:13:31Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Stefan Schirra 00023 00024 #ifndef CGAL_RAY_3_H 00025 #define CGAL_RAY_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 Ray_3 : public R_::Kernel_base::Ray_3 00037 { 00038 typedef typename R_::RT RT; 00039 typedef typename R_::Point_3 Point_3; 00040 typedef typename R_::Direction_3 Direction_3; 00041 typedef typename R_::Vector_3 Vector_3; 00042 typedef typename R_::Line_3 Line_3; 00043 typedef typename R_::Aff_transformation_3 Aff_transformation_3; 00044 00045 typedef Ray_3 Self; 00046 BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Ray_3>::value)); 00047 00048 public: 00049 00050 typedef Dimension_tag<3> Ambient_dimension; 00051 typedef Dimension_tag<1> Feature_dimension; 00052 00053 typedef typename R_::Kernel_base::Ray_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 Ray_3() {} 00068 00069 Ray_3(const Rep& r) 00070 : Rep(r) {} 00071 00072 Ray_3(const Point_3& sp, const Point_3& secondp) 00073 : Rep(typename R::Construct_ray_3()(Return_base_tag(), sp, secondp)) {} 00074 00075 Ray_3(const Point_3& sp, const Vector_3& v) 00076 : Rep(typename R::Construct_ray_3()(Return_base_tag(), sp, v)) {} 00077 00078 Ray_3(const Point_3& sp, const Direction_3& d) 00079 : Rep(typename R::Construct_ray_3()(Return_base_tag(), sp, d)) {} 00080 00081 Ray_3(const Point_3& sp, const Line_3& l) 00082 : Rep(typename R::Construct_ray_3()(Return_base_tag(), sp, l)) {} 00083 00084 Ray_3 transform(const Aff_transformation_3 &t) const 00085 { 00086 return Ray_3(t.transform(this->source()), 00087 t.transform(this->second_point())); 00088 // NB : Homogeneous used direction() instead of second_point(). 00089 } 00090 00091 /* 00092 const Point_3 & start() const; 00093 const Point_3 & source() const 00094 { 00095 return get(base).e0; 00096 } 00097 00098 Direction_3 direction() const; 00099 Vector_3 to_vector() const; 00100 Line_3 supporting_line() const; 00101 Ray_3 opposite() const; 00102 00103 bool is_degenerate() const; 00104 bool collinear_has_on(const Point_3 &p) const; 00105 */ 00106 00107 Point_3 point(int i) const // TODO : use Qrt 00108 { 00109 return R().construct_point_on_3_object()(*this, i); 00110 } 00111 00112 // FIXME : Use Qrt 00113 //typename Qualified_result_of<typename R_::Construct_source_3, Ray_3 >::type 00114 Point_3 00115 source() const 00116 { 00117 return R().construct_source_3_object()(*this); 00118 } 00119 00120 Point_3 second_point() const // TODO : use Qrt 00121 { 00122 return R().construct_second_point_3_object()(*this); 00123 } 00124 00125 Point_3 // FIXME : Use Qrt 00126 start() const 00127 { 00128 return source(); 00129 } 00130 00131 bool has_on(const Point_3 &p) const 00132 { 00133 return R().has_on_3_object()(*this, p); 00134 } 00135 00136 Direction_3 00137 direction() const 00138 { 00139 typename R::Construct_vector_3 construct_vector; 00140 typename R::Construct_direction_3 construct_direction; 00141 return construct_direction( construct_vector(source(), second_point()) ); 00142 } 00143 00144 Ray_3 00145 opposite() const 00146 { 00147 return Ray_3( source(), - direction() ); 00148 } 00149 00150 Vector_3 00151 to_vector() const 00152 { 00153 typename R::Construct_vector_3 construct_vector; 00154 return construct_vector(source(), second_point()); 00155 } 00156 00157 Line_3 00158 supporting_line() const 00159 { 00160 return R().construct_line_3_object()(source(), second_point()); 00161 } 00162 00163 bool is_degenerate() const 00164 { 00165 return R().is_degenerate_3_object()(*this); 00166 } 00167 00168 }; 00169 00170 00171 template <class R > 00172 std::ostream& 00173 insert(std::ostream& os, const Ray_3<R>& r, const Cartesian_tag&) 00174 { 00175 switch(os.iword(IO::mode)) { 00176 case IO::ASCII : 00177 return os << r.start() << ' ' << r.direction(); 00178 case IO::BINARY : 00179 return os<< r.start() << r.direction(); 00180 default: 00181 return os << "RayC3(" << r.start() << ", " << r.direction() << ")"; 00182 } 00183 } 00184 00185 template <class R > 00186 std::ostream& 00187 insert(std::ostream& os, const Ray_3<R>& r, const Homogeneous_tag&) 00188 { 00189 switch(os.iword(IO::mode)) 00190 { 00191 case IO::ASCII : 00192 return os << r.start() << ' ' << r.direction(); 00193 case IO::BINARY : 00194 return os<< r.start() << r.direction(); 00195 default: 00196 return os << "RayH3(" << r.start() << ", " << r.direction() << ")"; 00197 } 00198 } 00199 00200 template < class R > 00201 std::ostream& 00202 operator<<(std::ostream& os, const Ray_3<R>& r) 00203 { 00204 return insert(os, r, typename R::Kernel_tag() ); 00205 } 00206 00207 00208 template <class R > 00209 std::istream& 00210 extract(std::istream& is, Ray_3<R>& r, const Cartesian_tag&) 00211 { 00212 typename R::Point_3 p; 00213 typename R::Direction_3 d; 00214 00215 is >> p >> d; 00216 00217 if (is) 00218 r = Ray_3<R>(p, d); 00219 return is; 00220 } 00221 00222 template <class R > 00223 std::istream& 00224 extract(std::istream& is, Ray_3<R>& r, const Homogeneous_tag&) 00225 { 00226 typename R::Point_3 p; 00227 typename R::Direction_3 d; 00228 is >> p >> d; 00229 if (is) 00230 r = Ray_3<R>(p, d); 00231 return is; 00232 } 00233 00234 template < class R > 00235 std::istream& 00236 operator>>(std::istream& is, Ray_3<R>& r) 00237 { 00238 return extract(is, r, typename R::Kernel_tag() ); 00239 } 00240 00241 CGAL_END_NAMESPACE 00242 00243 #endif // CGAL_RAY_3_H