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/Plane_3.h $ 00019 // $Id: Plane_3.h 50060 2009-06-25 05:55:14Z sloriot $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Stefan Schirra 00023 00024 #ifndef CGAL_PLANE_3_H 00025 #define CGAL_PLANE_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/Dimension.h> 00031 00032 CGAL_BEGIN_NAMESPACE 00033 00034 template <class R_> 00035 class Plane_3 : public R_::Kernel_base::Plane_3 00036 { 00037 typedef typename R_::RT RT; 00038 typedef typename R_::Point_2 Point_2; 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_::Segment_3 Segment_3; 00043 typedef typename R_::Line_3 Line_3; 00044 typedef typename R_::Ray_3 Ray_3; 00045 typedef typename R_::Circle_3 Circle_3; 00046 typedef typename R_::Aff_transformation_3 Aff_transformation_3; 00047 00048 typedef Plane_3 Self; 00049 BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Plane_3>::value)); 00050 00051 public: 00052 00053 typedef Dimension_tag<3> Ambient_dimension; 00054 typedef Dimension_tag<2> Feature_dimension; 00055 00056 typedef typename R_::Kernel_base::Plane_3 Rep; 00057 00058 const Rep& rep() const 00059 { 00060 return *this; 00061 } 00062 00063 Rep& rep() 00064 { 00065 return *this; 00066 } 00067 00068 typedef R_ R; 00069 00070 Plane_3() {} 00071 00072 Plane_3(const Rep& p) 00073 : Rep(p) {} 00074 00075 Plane_3(const Point_3& p, const Point_3& q, const Point_3& r) 00076 : Rep(typename R::Construct_plane_3()(Return_base_tag(), p, q, r)) {} 00077 00078 Plane_3(const Point_3& p, const Direction_3& d) 00079 : Rep(typename R::Construct_plane_3()(Return_base_tag(), p, d)) {} 00080 00081 Plane_3(const Point_3& p, const Vector_3& v) 00082 : Rep(typename R::Construct_plane_3()(Return_base_tag(), p, v)) {} 00083 00084 Plane_3(const RT& a, const RT& b, const RT& c, const RT& d) 00085 : Rep(typename R::Construct_plane_3()(Return_base_tag(), a, b, c, d)) {} 00086 00087 Plane_3(const Line_3& l, const Point_3& p) 00088 : Rep(typename R::Construct_plane_3()(Return_base_tag(), l, p)) {} 00089 00090 Plane_3(const Segment_3& s, const Point_3& p) 00091 : Rep(typename R::Construct_plane_3()(Return_base_tag(), s, p)) {} 00092 00093 Plane_3(const Ray_3& r, const Point_3& p) 00094 : Rep(typename R::Construct_plane_3()(Return_base_tag(), r, p)) {} 00095 00096 explicit Plane_3(const Circle_3& c) 00097 : Rep(typename R::Construct_plane_3()(c)) {} 00098 00099 Plane_3 transform(const Aff_transformation_3 &t) const 00100 { 00101 return t.transform(*this); 00102 } 00103 00104 Plane_3 opposite() const 00105 { 00106 return R().construct_opposite_plane_3_object()(*this); 00107 } 00108 00109 //Vector_3 orthogonal_vector() const; 00110 Direction_3 orthogonal_direction() const 00111 { 00112 return Direction_3(a(), b(), c()); 00113 } 00114 00115 typename Qualified_result_of<typename R::Compute_a_3, Plane_3>::type 00116 a() const 00117 { 00118 return R().compute_a_3_object()(*this); 00119 } 00120 00121 typename Qualified_result_of<typename R::Compute_b_3, Plane_3>::type 00122 b() const 00123 { 00124 return R().compute_b_3_object()(*this); 00125 } 00126 00127 typename Qualified_result_of<typename R::Compute_c_3, Plane_3>::type 00128 c() const 00129 { 00130 return R().compute_c_3_object()(*this); 00131 } 00132 00133 typename Qualified_result_of<typename R::Compute_d_3, Plane_3>::type 00134 d() const 00135 { 00136 return R().compute_d_3_object()(*this); 00137 } 00138 00139 bool has_on(const Point_3 &p) const 00140 { 00141 return R().has_on_3_object()(*this, p); 00142 } 00143 00144 bool has_on(const Circle_3 &c) const 00145 { 00146 return R().has_on_3_object()(*this, c); 00147 } 00148 00149 bool has_on(const Line_3 &l) const 00150 { 00151 return R().has_on_3_object()(*this, l); 00152 } 00153 00154 Line_3 perpendicular_line(const Point_3 &p) const 00155 { 00156 return R().construct_perpendicular_line_3_object()(*this, p); 00157 } 00158 00159 Point_3 projection(const Point_3 &p) const 00160 { 00161 return R().construct_projected_point_3_object()(*this, p); 00162 } 00163 00164 Point_3 point() const 00165 { 00166 return R().construct_point_on_3_object()(*this); 00167 } 00168 00169 Vector_3 base1() const 00170 { 00171 return R().construct_base_vector_3_object()(*this, 1); 00172 } 00173 00174 Vector_3 base2() const 00175 { 00176 return R().construct_base_vector_3_object()(*this, 2); 00177 } 00178 00179 Vector_3 orthogonal_vector() const 00180 { 00181 return R().construct_orthogonal_vector_3_object()(*this); 00182 } 00183 00184 Point_2 to_2d(const Point_3 &p) const 00185 { 00186 return R().construct_projected_xy_point_2_object()(*this, p); 00187 } 00188 00189 Point_3 to_3d(const Point_2 &p) const 00190 { 00191 return R().construct_lifted_point_3_object()(*this, p); 00192 } 00193 00194 00195 //Point_3 projection(const Point_3 &p) const; 00196 //Direction_3 orthogonal_direction() const; 00197 00198 Oriented_side oriented_side(const Point_3 &p) const 00199 { 00200 return R().oriented_side_3_object()(*this, p); 00201 } 00202 00203 bool has_on_positive_side(const Point_3 &p) const 00204 { 00205 return R().has_on_positive_side_3_object()(*this, p); 00206 } 00207 00208 bool has_on_negative_side(const Point_3 &p) const 00209 { 00210 return R().has_on_negative_side_3_object()(*this, p); 00211 } 00212 00213 /* 00214 bool has_on(const Point_3 &p) const 00215 { 00216 return oriented_side(p) == ON_ORIENTED_BOUNDARY; 00217 } 00218 bool has_on(const Line_3 &l) const 00219 { 00220 return has_on(l.point()) 00221 && has_on(l.point() + l.direction().to_vector()); 00222 } 00223 */ 00224 00225 bool is_degenerate() const 00226 { 00227 return R().is_degenerate_3_object()(*this); 00228 } 00229 00230 }; 00231 00232 00233 template < class R > 00234 std::ostream & 00235 operator<<(std::ostream &os, const Plane_3<R> &p) 00236 { 00237 switch(os.iword(IO::mode)) { 00238 case IO::ASCII : 00239 return os << p.a() << ' ' << p.b() << ' ' << p.c() << ' ' << p.d(); 00240 case IO::BINARY : 00241 write(os, p.a()); 00242 write(os, p.b()); 00243 write(os, p.c()); 00244 write(os, p.d()); 00245 return os; 00246 default: 00247 os << "Plane_3(" << p.a() << ", " << p.b() << ", "; 00248 os << p.c() << ", " << p.d() <<")"; 00249 return os; 00250 } 00251 } 00252 00253 template < class R > 00254 std::istream & 00255 operator>>(std::istream &is, Plane_3<R> &p) 00256 { 00257 typename R::RT a, b, c, d; 00258 switch(is.iword(IO::mode)) { 00259 case IO::ASCII : 00260 is >> a >> b >> c >> d; 00261 break; 00262 case IO::BINARY : 00263 read(is, a); 00264 read(is, b); 00265 read(is, c); 00266 read(is, d); 00267 break; 00268 default: 00269 std::cerr << "" << std::endl; 00270 std::cerr << "Stream must be in ascii or binary mode" << std::endl; 00271 break; 00272 } 00273 if (is) 00274 p = Plane_3<R>(a, b, c, d); 00275 return is; 00276 } 00277 00278 CGAL_END_NAMESPACE 00279 00280 #endif // CGAL_PLANE_3_H