BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Nef_S2/Sphere_triangle.h
Go to the documentation of this file.
00001 // Copyright (c) 1997-2002  Max-Planck-Institute Saarbruecken (Germany).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Nef_S2/include/CGAL/Nef_S2/Sphere_triangle.h $
00015 // $Id: Sphere_triangle.h 49069 2009-05-01 12:07:15Z spion $
00016 // 
00017 //
00018 // Author(s)     : Michael Seel  <seel@mpi-sb.mpg.de>
00019 
00020 #ifndef CGAL_SPHERE_TRIANGLE_H
00021 #define CGAL_SPHERE_TRIANGLE_H
00022 
00023 #include <CGAL/basic.h>
00024 #include <CGAL/Handle_for.h>
00025 #include <CGAL/array.h>
00026 
00027 CGAL_BEGIN_NAMESPACE
00028 
00029 template <class R_> class Sphere_triangle_rep 
00030 { typedef Sphere_point<R_>  Point;
00031   typedef Sphere_circle<R_> Circle;
00032   typedef Sphere_triangle_rep<R_> Rep;
00033 
00034   cpp0x::array<Point,3>  points_; 
00035   cpp0x::array<Circle,3> circles_;
00036 
00037   friend class Sphere_triangle<R_>;
00038  
00039   Sphere_triangle_rep(const Point& p1, const Point& p2, const Point& p3,
00040         const Circle& c1, const Circle& c2, const Circle& c3) :
00041     points_(CGAL::make_array(p1,p2,p3)), circles_(CGAL::make_array(c1,c2,c3)) {}
00042 public:
00043   Sphere_triangle_rep() {}
00044 };
00045 
00046 
00047 /*{\Manpage{Sphere_triangle}{R}{Triangles on the unit sphere}{t}}*/
00048 template <class R_> class Sphere_triangle : 
00049   public Handle_for< Sphere_triangle_rep<R_> > {
00050 /*{\Mdefinition An object |\Mvar| of type |\Mname| is a triangle
00051 on the surface of the unit sphere.}*/
00052 
00053 public:
00054 /*{\Mtypes 5}*/
00055 typedef R_ R;
00056 /*{\Mtypemember representation class.}*/
00057 typedef typename R::RT RT;
00058 /*{\Mtypemember ring type.}*/
00059 
00060 typedef Sphere_triangle_rep<R_> Rep;
00061 typedef Handle_for<Rep>         Base;
00062 
00063 /*{\Mcreation 5}*/
00064 Sphere_triangle() : Base() {}
00065 /*{\Mcreate creates some triangle.}*/
00066 
00067 Sphere_triangle(
00068   const Sphere_point<R>& p0, const Sphere_point<R>& p1, 
00069   const Sphere_point<R>& p2,
00070   const Sphere_circle<R>& c0, const Sphere_circle<R>& c1, 
00071   const Sphere_circle<R>& c2) : Base(Rep(p0,p1,p2,c0,c1,c2)) 
00072 /*{\Mcreate creates a triangle spanned by the three points
00073 |p0|, |p1|, |p2|, where the triangle is left of the three circles
00074 |c0|, |c1|, |c2|. \precond $c_i$ contains $p_i$ and $p_{i+1}$ mod 3.}*/
00075 { CGAL_assertion( c0.has_on(p0) && c0.has_on(p1) );
00076   CGAL_assertion( c1.has_on(p1) && c1.has_on(p2) );
00077   CGAL_assertion( c2.has_on(p2) && c0.has_on(p0) );
00078 }
00079 
00080 Sphere_triangle(const Sphere_triangle<R>& t) : Base(t) {} 
00081 
00082 /*{\Moperations 4 2}*/
00083 
00084 const Sphere_point<R>& point(unsigned i) const 
00085 /*{\Mop returns the ith point of |\Mvar|.}*/
00086 { return this->ptr()->points_[i%3]; }
00087 
00088 const Sphere_circle<R>& circle(unsigned i) const 
00089 /*{\Mop returns the ith circle of |\Mvar|.}*/
00090 { return this->ptr()->circles_[i%3]; }
00091 
00092 Sphere_triangle<R> opposite() const 
00093 /*{\Mop returns the opposite of |\Mvar|.}*/
00094 { return Sphere_triangle<R>(point(0), point(1), point(2),
00095     circle(0).opposite(), circle(1).opposite(), circle(2).opposite()); }
00096 
00097 
00098 }; // Sphere_triangle<R>
00099 
00100 
00101 template <typename R>
00102 std::ostream& operator<<(std::ostream& os, 
00103                          const CGAL::Sphere_triangle<R>& t)
00104 { for (int i=0; i<3; ++i) os << t.point(i);
00105   for (int i=0; i<3; ++i) os << t.circle(i); return os; }
00106 
00107 template <typename R>
00108 std::istream& operator>>(std::istream& is, 
00109                          CGAL::Sphere_triangle<R>& t)
00110 { CGAL::Sphere_point<R> p1,p2,p3;
00111   CGAL::Sphere_circle<R> c1,c2,c3;
00112   if ( !(is >> p1 >> p2 >> p3 >> c1 >> c2 >> c3) ) return is; 
00113   t = CGAL::Sphere_triangle<R>(p1,p2,p3,c1,c2,c3);
00114   return is; }
00115 
00116 CGAL_END_NAMESPACE
00117 #endif //CGAL_SPHERE_TRIANGLE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines