BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Root_for_spheres_2_3.h
Go to the documentation of this file.
00001 // Copyright (c) 2005-2006  INRIA Sophia-Antipolis (France).
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 // Partially supported by the IST Programme of the EU as a Shared-cost
00015 // RTD (FET Open) Project under Contract No  IST-2000-26473 
00016 // (ECG - Effective Computational Geometry for Curves and Surfaces) 
00017 // and a STREP (FET Open) Project under Contract No  IST-006413 
00018 // (ACS -- Algorithms for Complex Shapes)
00019 //
00020 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Algebraic_kernel_for_spheres/include/CGAL/Root_for_spheres_2_3.h $
00021 // $Id: Root_for_spheres_2_3.h 46224 2008-10-13 11:22:46Z pmachado $
00022 //
00023 // Author(s) : Monique Teillaud <Monique.Teillaud@sophia.inria.fr>
00024 //             Sylvain Pion
00025 //             Pedro Machado
00026 //             Julien Hazebrouck
00027 //             Damien Leroy
00028 
00029 #ifndef CGAL_ROOT_FOR_SPHERES_2_3_H
00030 #define CGAL_ROOT_FOR_SPHERES_2_3_H
00031 
00032 #include <iostream>
00033 #include <CGAL/Polynomials_1_3.h>
00034 #include <CGAL/Polynomials_2_3.h>
00035 #include <CGAL/Polynomials_for_line_3.h>
00036 #include <CGAL/Bbox_3.h>
00037 
00038 CGAL_BEGIN_NAMESPACE
00039 
00040 template < typename RT_ >
00041 class Root_for_spheres_2_3 {
00042 
00043   typedef RT_                                        RT;
00044   typedef typename Root_of_traits< RT >::RootOf_2    Root_of_2;
00045   typedef typename Root_of_traits< RT >::RootOf_1    FT;
00046   typedef CGAL::Polynomial_1_3< FT >                 Polynomial_1_3;
00047   typedef CGAL::Polynomial_for_spheres_2_3< FT >     Polynomial_for_spheres_2_3;
00048   typedef CGAL::Polynomials_for_line_3< FT >         Polynomials_for_line_3;
00049 
00050   private:
00051     Root_of_2 x_;
00052     Root_of_2 y_;
00053     Root_of_2 z_;
00054     
00055   public:
00056   Root_for_spheres_2_3(){}
00057   
00058   
00059   Root_for_spheres_2_3(const Root_of_2& r1,
00060                        const Root_of_2& r2,
00061                        const Root_of_2& r3)
00062     : x_(r1), y_(r2), z_(r3)
00063   {
00064     // This assertion sont work if Root_of_2 is 
00065     // Interval_nt (and dont have is_rational, gamma, etc..)
00066     /*CGAL_assertion(
00067                 ((r1.is_rational() && r2.is_rational()) ||
00068                  (r1.is_rational() && r3.is_rational()) ||
00069                  (r2.is_rational() && r3.is_rational()) ||
00070                  ((r1.is_rational()) && (r2.gamma() == r3.gamma())) ||
00071                  ((r2.is_rational()) && (r1.gamma() == r3.gamma())) ||
00072                  ((r3.is_rational()) && (r1.gamma() == r2.gamma())) ||
00073                  ((r1.gamma() == r2.gamma()) && (r2.gamma() == r3.gamma())))
00074     );*/
00075   }
00076 
00077   const Root_of_2& x() const 
00078   { return x_; }
00079     
00080   const Root_of_2& y() const 
00081   { return y_; }
00082 
00083   const Root_of_2& z() const 
00084   { return z_; }
00085 
00086   // On fait l'evaluation de (x,y,z) pour le plan 
00087   // aX + bY + cZ + d, donne
00088   const Root_of_2 evaluate(const Polynomial_1_3 &p) const {
00089     return (p.a() * x()) + (p.b() * y()) + (p.c() * z()) + p.d();
00090   }
00091 
00092   // On fait l'evaluation de (x,y,z) pour le plan 
00093   // (X-a)^2 + (Y-b)^2 + (Z-c)^2 - r_sq, donne
00094   const Root_of_2 evaluate(const Polynomial_for_spheres_2_3 &p) const {
00095     return square(x() - p.a()) +
00096            square(y() - p.b()) +
00097            square(z() - p.c()) -
00098            p.r_sq();
00099   }
00100 
00101   // On verifie si (x,y,z) fait partie la ligne donne
00102   bool is_on_line(const Polynomials_for_line_3 &p) const {
00103     Root_of_2 t;
00104     bool already = false;
00105     if(!is_zero(p.a1())) {
00106       t = (x() - p.b1())/p.a1(); 
00107       already = true;
00108     } else if(p.b1() != x()) return false;
00109     if(!is_zero(p.a2())) {
00110       if(!already) {
00111         t = (y() - p.b2())/p.a2(); 
00112         already = true;
00113       }
00114       else if((p.a2() * t + p.b2()) != y()) return false;
00115     } else if(p.b2() != y()) return false;
00116     if(!is_zero(p.a3())) {
00117       if(!already) return true;
00118       else if((p.a3() * t + p.b3()) != z()) return false;
00119     } else if(p.b3() != z()) return false;
00120     return true;
00121   }
00122 
00123   CGAL::Bbox_3 bbox() const
00124   {
00125     const Root_of_2 &ox = x();
00126     const Root_of_2 &oy = y();
00127     const Root_of_2 &oz = z();
00128 
00129     CGAL::Interval_nt<> 
00130         ix=to_interval(ox),
00131         iy=to_interval(oy),
00132         iz=to_interval(oz);
00133       return CGAL::Bbox_3(ix.inf(),iy.inf(),iz.inf(),
00134                         ix.sup(),iy.sup(),iz.sup());
00135     /* 
00136     // Note: This is a more efficient version
00137     // but it won't work (in the future) 
00138     // with some Lazy_Curved_kernel_3
00139     // because is_rational(), gamma(), etc.. is not defined
00140     // for Interval_nt<false> data type 
00141     const Root_of_2 &ox = x();
00142     const Root_of_2 &oy = y();
00143     const Root_of_2 &oz = z();
00144 
00145     const bool x_rat = ox.is_rational();
00146     const bool y_rat = oy.is_rational();
00147     const bool z_rat = oz.is_rational();
00148 
00149     if(((x_rat?1:0) + (y_rat?1:0) +(z_rat?1:0)) > 1) {
00150       CGAL::Interval_nt<> 
00151         ix=to_interval(ox),
00152         iy=to_interval(oy),
00153         iz=to_interval(oz);
00154       return CGAL::Bbox_3(ix.inf(),iy.inf(),iz.inf(),
00155                         ix.sup(),iy.sup(),iz.sup());
00156     }
00157 
00158     if(z_rat) {
00159       const CGAL::Interval_nt<true> alpha1 = to_interval(ox.alpha());
00160       const CGAL::Interval_nt<true> beta1 = to_interval(ox.beta());
00161       const CGAL::Interval_nt<true> alpha2 = to_interval(oy.alpha());
00162       const CGAL::Interval_nt<true> beta2 = to_interval(oy.beta());
00163       const CGAL::Interval_nt<true> g = to_interval(ox.gamma());
00164       const CGAL::Interval_nt<true> sqrtg = CGAL::sqrt(g);
00165       const CGAL::Interval_nt<true> ix = alpha1 + beta1 * sqrtg;
00166       const CGAL::Interval_nt<true> iy = alpha2 + beta2 * sqrtg;
00167       const CGAL::Interval_nt<true> iz = to_interval(oz);
00168       return CGAL::Bbox_3(ix.inf(),iy.inf(),iz.inf(),
00169                         ix.sup(),iy.sup(),iz.sup());
00170     }
00171 
00172     if(y_rat) {
00173       const CGAL::Interval_nt<true> alpha1 = to_interval(ox.alpha());
00174       const CGAL::Interval_nt<true> beta1 = to_interval(ox.beta());
00175       const CGAL::Interval_nt<true> alpha2 = to_interval(oz.alpha());
00176       const CGAL::Interval_nt<true> beta2 = to_interval(oz.beta());
00177       const CGAL::Interval_nt<true> g = to_interval(ox.gamma());
00178       const CGAL::Interval_nt<true> sqrtg = CGAL::sqrt(g);
00179       const CGAL::Interval_nt<true> ix = alpha1 + beta1 * sqrtg;
00180       const CGAL::Interval_nt<true> iz = alpha2 + beta2 * sqrtg;
00181       const CGAL::Interval_nt<true> iy = to_interval(oy);
00182       return CGAL::Bbox_3(ix.inf(),iy.inf(),iz.inf(),
00183                         ix.sup(),iy.sup(),iz.sup());
00184     }
00185 
00186     if(x_rat) {
00187       const CGAL::Interval_nt<true> alpha1 = to_interval(oy.alpha());
00188       const CGAL::Interval_nt<true> beta1 = to_interval(oy.beta());
00189       const CGAL::Interval_nt<true> alpha2 = to_interval(oz.alpha());
00190       const CGAL::Interval_nt<true> beta2 = to_interval(oz.beta());
00191       const CGAL::Interval_nt<true> g = to_interval(oy.gamma());
00192       const CGAL::Interval_nt<true> sqrtg = CGAL::sqrt(g);
00193       const CGAL::Interval_nt<true> iy = alpha1 + beta1 * sqrtg;
00194       const CGAL::Interval_nt<true> iz = alpha2 + beta2 * sqrtg;
00195       const CGAL::Interval_nt<true> ix = to_interval(ox);
00196       return CGAL::Bbox_3(ix.inf(),iy.inf(),iz.inf(),
00197                         ix.sup(),iy.sup(),iz.sup());
00198     }
00199 
00200     const CGAL::Interval_nt<true> alpha1 = to_interval(ox.alpha());
00201     const CGAL::Interval_nt<true> beta1 = to_interval(ox.beta());
00202     const CGAL::Interval_nt<true> alpha2 = to_interval(oy.alpha());
00203     const CGAL::Interval_nt<true> beta2 = to_interval(oy.beta());
00204     const CGAL::Interval_nt<true> alpha3 = to_interval(oz.alpha());
00205     const CGAL::Interval_nt<true> beta3 = to_interval(oz.beta());
00206     const CGAL::Interval_nt<true> g = to_interval(ox.gamma());
00207     const CGAL::Interval_nt<true> sqrtg = CGAL::sqrt(g);
00208     const CGAL::Interval_nt<true> ix = alpha1 + beta1 * sqrtg;
00209     const CGAL::Interval_nt<true> iy = alpha2 + beta2 * sqrtg;
00210     const CGAL::Interval_nt<true> iz = alpha3 + beta3 * sqrtg; 
00211     return CGAL::Bbox_3(ix.inf(),iy.inf(),iz.inf(),
00212                         ix.sup(),iy.sup(),iz.sup());
00213     */
00214   }
00215 
00216 };
00217 
00218 template < typename RT >
00219 bool 
00220 operator == ( const Root_for_spheres_2_3<RT>& r1,
00221               const Root_for_spheres_2_3<RT>& r2 )
00222 { return (r1.x() == r2.x()) && (r1.y() == r2.y()) && (r1.z() == r2.z()); }
00223 
00224 template < typename RT >
00225 std::ostream &
00226 operator<<(std::ostream & os, const Root_for_spheres_2_3<RT> &r)
00227 { return os << r.x() << " " << r.y() << " " << r.z() << " "; }
00228 
00229 template < typename RT >
00230 std::istream &
00231 operator>>(std::istream & is, Root_for_spheres_2_3<RT> &r)
00232 {
00233   typedef typename Root_of_traits< RT >::RootOf_2         Root_of_2;
00234   Root_of_2 x,y,z;
00235   
00236   is >> x >> y >> z;
00237   if(is)
00238     r = Root_for_spheres_2_3<RT>(x,y,z);
00239   return is;
00240 }
00241 
00242 CGAL_END_NAMESPACE
00243 
00244 #endif // CGAL_ROOT_FOR_SPHERES_2_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines