BWAPI
|
00001 // Copyright (c) 2005 Stanford University (USA). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License as 00006 // published by the Free Software Foundation; version 2.1 of the License. 00007 // See the file LICENSE.LGPL distributed with CGAL. 00008 // 00009 // Licensees holding a valid commercial license may use this file in 00010 // accordance with the commercial license agreement provided with the software. 00011 // 00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 // 00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kinetic_data_structures/include/CGAL/Kinetic/internal/Kernel/Cartesian_moving_point_3.h $ 00016 // $Id: Cartesian_moving_point_3.h 39777 2007-08-08 15:30:58Z spion $ 00017 // 00018 // 00019 // Author(s) : Daniel Russel <drussel@alumni.princeton.edu> 00020 00021 #ifndef CGAL_KINETIC_CARTESIAN_MOVING_POINT_3_H_ 00022 #define CGAL_KINETIC_CARTESIAN_MOVING_POINT_3_H_ 00023 #include <CGAL/Kinetic/basic.h> 00024 #include <iostream> 00025 00026 CGAL_KINETIC_BEGIN_INTERNAL_NAMESPACE; 00027 00028 template <class Coordinate_t> 00029 class Cartesian_moving_point_3 00030 { 00031 protected: 00032 typedef Cartesian_moving_point_3<Coordinate_t> This; 00033 00035 typedef typename Coordinate_t::NT NT; 00036 public: 00037 //typedef Static_point_t Static_point; 00038 00040 typedef Coordinate_t Coordinate; 00041 00043 Cartesian_moving_point_3(const Coordinate &x, const Coordinate &y, 00044 const Coordinate &z) { 00045 _coords[0]=x; 00046 _coords[1]=y; 00047 _coords[2]=z; 00048 } 00049 00051 template <class Static_point> 00052 explicit Cartesian_moving_point_3(const Static_point &pt) { 00053 _coords[0]=Coordinate(typename Coordinate::NT(pt.x())); 00054 _coords[1]=Coordinate(typename Coordinate::NT(pt.y())); 00055 _coords[2]=Coordinate(typename Coordinate::NT(pt.z())); 00056 } 00057 00059 Cartesian_moving_point_3(){} 00060 00062 const Coordinate &hx() const 00063 { 00064 return _coords[0]; 00065 } 00066 00068 const Coordinate &hy() const 00069 { 00070 return _coords[1]; 00071 } 00072 00074 const Coordinate &hz() const 00075 { 00076 return _coords[2]; 00077 } 00078 00080 const Coordinate hw() const 00081 { 00082 return Coordinate(1); 00083 } 00084 00086 const Coordinate &x() const 00087 { 00088 return _coords[0]; 00089 } 00090 00092 const Coordinate &y() const 00093 { 00094 return _coords[1]; 00095 } 00096 00098 const Coordinate &z() const 00099 { 00100 return _coords[2]; 00101 } 00102 00103 bool is_constant() const 00104 { 00105 for (unsigned int i=0; i< 3; ++i) { 00106 if (_coords[i].degree()>0) return false; 00107 } 00108 return true; 00109 } 00110 bool operator==(const This &o) const 00111 { 00112 return x()==o.x() && y()==o.y() && z()==o.z(); 00113 } 00114 #if 0 00115 00116 00118 Static_point operator()(const NT &t) const 00119 { 00120 return Static_point(hx(t), hy(t), hz(t)); 00121 } 00122 00124 Static_point value_at( NT time) { 00125 return operator()(time); 00126 } 00127 #endif 00128 00129 00131 template <class NV> 00132 This transformed_coordinates(const NV &nv) const 00133 { 00134 return This(nv(_coords[0]), nv(_coords[1]), nv(_coords[2])); 00135 } 00136 00137 template <class SK> 00138 struct Static_traits 00139 { 00140 typedef typename SK::Point_3 Static_type; 00141 static Static_type to_static(const This &o, const typename SK::FT &t, const SK &) { 00142 return Static_type(o.x()(t), o.y()(t), o.z()(t)); 00143 } 00144 }; 00145 template <class Converter> 00146 struct Coordinate_converter 00147 { 00148 Coordinate_converter(const Converter &c): c_(c){} 00149 typedef Cartesian_moving_point_3<typename Converter::argument_type> argument_type; 00150 typedef Cartesian_moving_point_3<typename Converter::result_type> result_type; 00151 00152 result_type operator()(const argument_type &i) const 00153 { 00154 return result_type(c_(i.x()), c_(i.y()), c_(i.z())); 00155 } 00156 00157 Converter c_; 00158 }; 00159 protected: 00160 Coordinate _coords[3]; 00161 }; 00162 00163 template <class Coordinate> 00164 std::ostream &operator<<(std::ostream &out, const Cartesian_moving_point_3<Coordinate> &point) 00165 { 00166 out << point.x() << ", " << point.y() << ", " << point.z(); 00167 return out; 00168 } 00169 00170 00171 template <class Coordinate> 00172 std::istream &operator>>(std::istream &in, 00173 Cartesian_moving_point_3<Coordinate> &point) 00174 { 00175 Coordinate x, y, z; 00176 in >> x; 00177 char c; 00178 do { 00179 in >> c; 00180 } 00181 while (std::isspace(c,std::locale::classic() )); 00182 00183 if (c != ',') { 00184 in.setstate(std::ios_base::failbit); 00185 return in; 00186 } 00187 in >> y; 00188 do { 00189 in >> c; 00190 } while (std::isspace(c, std::locale::classic())); 00191 if (c != ',') { 00192 in.setstate(std::ios_base::failbit); 00193 return in; 00194 } 00195 in >> z; 00196 point= Cartesian_moving_point_3<Coordinate>(x,y,z); 00197 return in; 00198 } 00199 00200 00201 CGAL_KINETIC_END_INTERNAL_NAMESPACE; 00202 00203 /*CGAL_KINETIC_BEGIN_NAMESPACE; 00204 00205 template <> 00206 template <class Coord, class SK> 00207 class To_static<typename internal::Cartesian_moving_point_3<Coord>, SK>: 00208 public To_static_base<typename Coord::NT> { 00209 public: 00210 To_static(){} 00211 To 00212 typedef typename internal::Cartesian_moving_point_3<Coord> argument_type; 00213 typedef typename SK::Point_3 result_type; 00214 result_type operator()(const argument_type &arg) const { 00215 return result_type(arg.x()(time()), 00216 arg.y()(time()), 00217 arg.z()(time())); 00218 } 00219 }; 00220 CGAL_KINETIC_END_NAMESPACE*/ 00221 #endif