Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_TOPO_ALGEBRAIC_N_FACE_HH 00027 # define MLN_TOPO_ALGEBRAIC_N_FACE_HH 00028 00031 00032 #include <mln/topo/n_face.hh> 00033 00034 00035 namespace mln 00036 { 00037 00038 namespace topo 00039 { 00040 00041 /*-------------------. 00042 | Algebraic n-Face. | 00043 `-------------------*/ 00044 00049 template <unsigned N, unsigned D> 00050 class algebraic_n_face : public n_face<N, D> 00051 { 00052 typedef n_face<N, D> super_; 00053 00054 public: 00056 algebraic_n_face(); 00058 algebraic_n_face(complex<D>& complex, unsigned face_id, bool sign); 00060 algebraic_n_face(const n_face<N, D>& f, bool sign); 00061 00065 bool sign() const; 00067 void set_sign(bool sign); 00069 00070 private: 00071 bool sign_; 00072 }; 00073 00074 00076 template <unsigned N, unsigned D> 00077 algebraic_n_face<N, D> 00078 make_algebraic_n_face(const n_face<N, D>& f, bool sign); 00079 00080 00083 template <unsigned N, unsigned D> 00084 algebraic_n_face<N, D> 00085 operator-(const n_face<N, D>& f); 00086 00087 template <unsigned N, unsigned D> 00088 algebraic_n_face<N, D> 00089 operator-(const algebraic_n_face<N, D>& f); 00091 00092 00095 00100 template <unsigned N, unsigned D> 00101 bool 00102 operator==(const algebraic_n_face<N, D>& lhs, 00103 const algebraic_n_face<N, D>& rhs); 00104 00109 template <unsigned N, unsigned D> 00110 bool 00111 operator!=(const algebraic_n_face<N, D>& lhs, 00112 const algebraic_n_face<N, D>& rhs); 00113 00121 template <unsigned N, unsigned D> 00122 bool 00123 operator< (const algebraic_n_face<N, D>& lhs, 00124 const algebraic_n_face<N, D>& rhs); 00125 00127 00128 00130 template <unsigned N, unsigned D> 00131 std::ostream& 00132 operator<<(std::ostream& ostr, const algebraic_n_face<N, D>& f); 00133 00134 00137 00155 template <unsigned D> 00156 algebraic_n_face<1, D> 00157 edge(const n_face<0, D>& f1, const n_face<0, D>& f2); 00159 00160 00161 00162 # ifndef MLN_INCLUDE_ONLY 00163 00164 template <unsigned N, unsigned D> 00165 inline 00166 algebraic_n_face<N, D>::algebraic_n_face() 00167 : super_(), sign_(true) 00168 { 00169 // Ensure N is compatible with D. 00170 metal::bool_< N <= D >::check(); 00171 mln_postcondition(!this->is_valid()); 00172 } 00173 00174 template <unsigned N, unsigned D> 00175 inline 00176 algebraic_n_face<N, D>::algebraic_n_face(complex<D>& c, unsigned face_id, 00177 bool sign) 00178 : super_(c, face_id), sign_(sign) 00179 { 00180 // Ensure N is compatible with D. 00181 metal::bool_< N <= D >::check(); 00182 } 00183 00184 template <unsigned N, unsigned D> 00185 inline 00186 algebraic_n_face<N, D>::algebraic_n_face(const n_face<N, D>& f, bool sign) 00187 : super_(f), sign_(sign) 00188 { 00189 // Ensure N is compatible with D. 00190 metal::bool_< N <= D >::check(); 00191 } 00192 00193 00194 template <unsigned N, unsigned D> 00195 inline 00196 bool 00197 algebraic_n_face<N, D>::sign() const 00198 { 00199 return sign_; 00200 } 00201 00202 template <unsigned N, unsigned D> 00203 inline 00204 void 00205 algebraic_n_face<N, D>::set_sign(bool sign) 00206 { 00207 sign_ = sign; 00208 } 00209 00210 00211 template <unsigned N, unsigned D> 00212 algebraic_n_face<N, D> 00213 make_algebraic_n_face(const n_face<N, D>& f, bool sign) 00214 { 00215 return algebraic_n_face<N, D>(f, sign); 00216 } 00217 00218 00219 template <unsigned N, unsigned D> 00220 algebraic_n_face<N, D> 00221 operator-(const n_face<N, D>& f) 00222 { 00223 return algebraic_n_face<N, D>(f, false); 00224 } 00225 00226 template <unsigned N, unsigned D> 00227 algebraic_n_face<N, D> 00228 operator-(const algebraic_n_face<N, D>& f) 00229 { 00230 algebraic_n_face<N, D> f2(f); 00231 f2.set_sign(!f.sign()); 00232 return f2; 00233 } 00234 00235 00236 template <unsigned N, unsigned D> 00237 inline 00238 bool 00239 operator==(const algebraic_n_face<N, D>& lhs, 00240 const algebraic_n_face<N, D>& rhs) 00241 { 00242 // Ensure LHS and RHS belong to the same complex. 00243 mln_precondition(lhs.cplx() == rhs.cplx()); 00244 return lhs.face_id() == rhs.face_id() && lhs.sign() == rhs.sign(); 00245 } 00246 00247 template <unsigned N, unsigned D> 00248 inline 00249 bool 00250 operator!=(const algebraic_n_face<N, D>& lhs, 00251 const algebraic_n_face<N, D>& rhs) 00252 { 00253 // Ensure LHS and RHS belong to the same complex. 00254 mln_precondition(lhs.cplx() == rhs.cplx()); 00255 return !(lhs == rhs); 00256 } 00257 00258 template <unsigned N, unsigned D> 00259 inline 00260 bool 00261 operator< (const algebraic_n_face<N, D>& lhs, 00262 const algebraic_n_face<N, D>& rhs) 00263 { 00264 // Ensure LHS and RHS belong to the same complex. 00265 mln_precondition(lhs.cplx() == rhs.cplx()); 00266 return lhs.face_id() < rhs.face_id(); 00267 } 00268 00269 00270 template <unsigned N, unsigned D> 00271 inline 00272 std::ostream& 00273 operator<<(std::ostream& ostr, const algebraic_n_face<N, D>& f) 00274 { 00275 return 00276 ostr << "(cplx = " << f.cplx().addr() << ", dim = " << f.n() 00277 << ", id = " << f.face_id() << ", sign = " << f.sign()<< ')'; 00278 } 00279 00280 /*----------. 00281 | Helpers. | 00282 `----------*/ 00283 00284 template <unsigned D> 00285 algebraic_n_face<1, D> 00286 edge(const n_face<0, D>& f1, const n_face<0, D>& f2) 00287 { 00288 typedef std::vector< algebraic_n_face<0, D> > n0_faces_t; 00289 typedef std::vector< algebraic_n_face<1, D> > n1_faces_t; 00290 00291 n1_faces_t f1_adj_edges = f1.higher_dim_adj_faces(); 00292 for (typename n1_faces_t::const_iterator e = f1_adj_edges.begin(); 00293 e != f1_adj_edges.end(); ++e) 00294 { 00295 n0_faces_t e_adj_vertices = e->lower_dim_adj_faces(); 00296 for (typename n0_faces_t::const_iterator w = e_adj_vertices.begin(); 00297 w != e_adj_vertices.end(); ++w) 00298 if (*w == f2) 00299 // E is the edge linking F1 and F2. 00300 return *e; 00301 } 00302 00303 // If no shared edge was found, retun an empty (invalid) 1-face. 00304 return algebraic_n_face<1, D>(); 00305 } 00306 00307 # endif // ! MLN_INCLUDE_ONLY 00308 00309 } // end of namespace mln::topo 00310 00311 } // end of namespace mln 00312 00313 #endif // ! MLN_TOPO_ALGEBRAIC_N_FACE_HH