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/Triangle_3.h $ 00019 // $Id: Triangle_3.h 42932 2008-04-17 10:13:31Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Stefan Schirra 00023 00024 #ifndef CGAL_TRIANGLE_3_H 00025 #define CGAL_TRIANGLE_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/Bbox_3.h> 00031 #include <CGAL/Dimension.h> 00032 00033 CGAL_BEGIN_NAMESPACE 00034 00035 template <class R_> 00036 class Triangle_3 : public R_::Kernel_base::Triangle_3 00037 { 00038 typedef typename R_::RT RT; 00039 typedef typename R_::FT FT; 00040 typedef typename R_::Point_3 Point_3; 00041 typedef typename R_::Plane_3 Plane_3; 00042 typedef typename R_::Aff_transformation_3 Aff_transformation_3; 00043 00044 typedef Triangle_3 Self; 00045 BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Triangle_3>::value)); 00046 00047 public: 00048 00049 typedef Dimension_tag<3> Ambient_dimension; 00050 typedef Dimension_tag<2> Feature_dimension; 00051 00052 typedef typename R_::Kernel_base::Triangle_3 Rep; 00053 00054 const Rep& rep() const 00055 { 00056 return *this; 00057 } 00058 00059 Rep& rep() 00060 { 00061 return *this; 00062 } 00063 00064 typedef R_ R; 00065 00066 Triangle_3() {} 00067 00068 Triangle_3(const Rep& t) 00069 : Rep(t) {} 00070 00071 Triangle_3(const Point_3& p, const Point_3& q, const Point_3& r) 00072 : Rep(typename R::Construct_triangle_3()(Return_base_tag(), p, q, r)) {} 00073 00074 Triangle_3 transform(const Aff_transformation_3 &t) const 00075 { 00076 return Triangle_3(t.transform(this->vertex(0)), 00077 t.transform(this->vertex(1)), 00078 t.transform(this->vertex(2))); 00079 } 00080 00081 Plane_3 supporting_plane() const 00082 { 00083 return R().construct_supporting_plane_3_object()(*this); 00084 } 00085 00086 bool has_on(const Point_3 &p) const 00087 { 00088 return R().has_on_3_object()(*this, p); 00089 } 00090 00091 Point_3 vertex(int i) const // TODO : use Qrt 00092 { 00093 return R().construct_vertex_3_object()(*this, i); 00094 } 00095 00096 Point_3 operator[](int i) const // TODO : use Qrt 00097 { 00098 return vertex(i); 00099 } 00100 00101 bool is_degenerate() const 00102 { 00103 return R().is_degenerate_3_object()(*this); 00104 } 00105 00106 Bbox_3 00107 bbox() const 00108 { 00109 return R().construct_bbox_3_object()(*this); 00110 } 00111 00112 FT squared_area() const // TODO : use Qrt 00113 { 00114 return R().compute_squared_area_3_object()(*this); 00115 } 00116 00117 }; 00118 00119 00120 template < class R > 00121 std::ostream & 00122 operator<<(std::ostream &os, const Triangle_3<R> &t) 00123 { 00124 switch(os.iword(IO::mode)) { 00125 case IO::ASCII : 00126 return os << t[0] << ' ' << t[1] << ' ' << t[2]; 00127 case IO::BINARY : 00128 return os << t[0] << t[1] << t[2]; 00129 default: 00130 os << "Triangle_3(" << t[0] << ", " << t[1] << ", " << t[2] <<")"; 00131 return os; 00132 } 00133 } 00134 00135 template < class R > 00136 std::istream & 00137 operator>>(std::istream &is, Triangle_3<R> &t) 00138 { 00139 typename R::Point_3 p, q, r; 00140 00141 is >> p >> q >> r; 00142 00143 if (is) 00144 t = Triangle_3<R>(p, q, r); 00145 return is; 00146 } 00147 00148 CGAL_END_NAMESPACE 00149 00150 #endif // CGAL_TRIANGLE_3_H