• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

n_faces_set.hh

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_N_FACES_SET_HH
00027 # define MLN_TOPO_N_FACES_SET_HH
00028 
00031 
00032 #include <vector>
00033 
00034 #include <mln/core/contract.hh>
00035 #include <mln/topo/algebraic_n_face.hh>
00036 
00037 // FIXME: Rename as algebraic_n_faces_set?
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   namespace topo
00044   {
00045 
00046     // Forward declaration.
00047     template <unsigned D> class complex;
00048 
00049 
00050     /*------------------------------------.
00051     | Set of (algebraic) n-face handles.  |
00052     `------------------------------------*/
00053 
00055     template <unsigned N, unsigned D>
00056     class n_faces_set
00057     {
00058     public:
00060       void add(const algebraic_n_face<N, D>& f);
00061 
00067       void reserve(size_t n);
00068 
00070       typedef std::vector< algebraic_n_face<N, D> > faces_type;
00071 
00076       const faces_type& faces() const;
00078 
00079     private:
00080       friend class complex<D>;
00081 
00083       faces_type faces_;
00084     };
00085 
00086 
00087     /*-----------------------.
00088     | Construction helpers.  |
00089     `-----------------------*/
00090 
00091     /* FIXME: We can probably reduce the number of operators, given
00092        the fact that ``a - b'' is equivalent to ``a + (-b)''.  */
00093 
00096     template <unsigned N, unsigned D>
00097     n_faces_set<N, D>
00098     operator+(const algebraic_n_face<N, D>& f1,
00099               const algebraic_n_face<N, D>& f2);
00100 
00101     template <unsigned N, unsigned D>
00102     n_faces_set<N, D>
00103     operator+(const algebraic_n_face<N, D>& f1, const n_face<N, D>& f2);
00104 
00105     template <unsigned N, unsigned D>
00106     n_faces_set<N, D>
00107     operator+(const n_face<N, D>& f1, const algebraic_n_face<N, D>& f2);
00108 
00109     template <unsigned N, unsigned D>
00110     n_faces_set<N, D>
00111     operator+(const n_face<N, D>& f1, const n_face<N, D>& f2);
00112 
00113 
00114     template <unsigned N, unsigned D>
00115     n_faces_set<N, D>
00116     operator+(const n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f);
00117 
00118     template <unsigned N, unsigned D>
00119     n_faces_set<N, D>
00120     operator+(const n_faces_set<N, D>& fs, const n_face<N, D>& f);
00121 
00122     template <unsigned N, unsigned D>
00123     n_faces_set<N, D>&
00124     operator+=(n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f);
00126 
00129     template <unsigned N, unsigned D>
00130     n_faces_set<N, D>
00131     operator-(const algebraic_n_face<N, D>& f1,
00132               const algebraic_n_face<N, D>& f2);
00133 
00134     template <unsigned N, unsigned D>
00135     n_faces_set<N, D>
00136     operator-(const algebraic_n_face<N, D>& f1, const n_face<N, D>& f2);
00137 
00138     template <unsigned N, unsigned D>
00139     n_faces_set<N, D>
00140     operator-(const n_face<N, D>& f1, const algebraic_n_face<N, D>& f2);
00141 
00142     template <unsigned N, unsigned D>
00143     n_faces_set<N, D>
00144     operator-(const n_face<N, D>& f1, const n_face<N, D>& f2);
00145 
00146 
00147     template <unsigned N, unsigned D>
00148     n_faces_set<N, D>
00149     operator-(const n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f);
00150 
00151     template <unsigned N, unsigned D>
00152     n_faces_set<N, D>
00153     operator-(const n_faces_set<N, D>& fs, const n_face<N, D>& f);
00154 
00155     template <unsigned N, unsigned D>
00156     n_faces_set<N, D>&
00157     operator-=(n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f);
00159 
00160 
00161 
00162 # ifndef MLN_INCLUDE_ONLY
00163 
00164     /*------------------------------------.
00165     | Set of (algebraic) n-face handles.  |
00166     `------------------------------------*/
00167 
00168     template <unsigned N, unsigned D>
00169     inline
00170     void
00171     n_faces_set<N, D>::add(const algebraic_n_face<N, D>& f)
00172     {
00173       // Check consistency.
00174       if (!faces_.empty())
00175         mln_precondition(faces_.front().cplx() == f.cplx());
00176       faces_.push_back(f);
00177     }
00178 
00179     template <unsigned N, unsigned D>
00180     inline
00181     void
00182     n_faces_set<N, D>::reserve(size_t n)
00183     {
00184       faces_.reserve(n);
00185     }
00186 
00187     template <unsigned N, unsigned D>
00188     inline
00189     const std::vector< algebraic_n_face<N, D> >&
00190     n_faces_set<N, D>::faces() const
00191     {
00192       return faces_;
00193     }
00194 
00195     /*-----------------------.
00196     | Construction helpers.  |
00197     `-----------------------*/
00198 
00199     // ---------- //
00200     // Addition.  //
00201     // ---------- //
00202 
00203     template <unsigned N, unsigned D>
00204     inline
00205     n_faces_set<N, D>
00206     operator+(const algebraic_n_face<N, D>& f1,
00207               const algebraic_n_face<N, D>& f2)
00208     {
00209       n_faces_set<N, D> fs;
00210       fs.add(f1);
00211       fs.add(f2);
00212       return fs;
00213     }
00214 
00215     template <unsigned N, unsigned D>
00216     inline
00217     n_faces_set<N, D>
00218     operator+(const algebraic_n_face<N, D>& f1, const n_face<N, D>& f2)
00219     {
00220       n_faces_set<N, D> fs;
00221       fs.add(f1);
00222       fs.add(make_algebraic_n_face(f2, true));
00223       return fs;
00224     }
00225 
00226     template <unsigned N, unsigned D>
00227     inline
00228     n_faces_set<N, D>
00229     operator+(const n_face<N, D>& f1, const algebraic_n_face<N, D>& f2)
00230     {
00231       n_faces_set<N, D> fs;
00232       fs.add(make_algebraic_n_face(f1, true));
00233       fs.add(f2);
00234       return fs;
00235     }
00236 
00237     template <unsigned N, unsigned D>
00238     inline
00239     n_faces_set<N, D>
00240     operator+(const n_face<N, D>& f1, const n_face<N, D>& f2)
00241     {
00242       n_faces_set<N, D> fs;
00243       fs.add(make_algebraic_n_face(f1, true));
00244       fs.add(make_algebraic_n_face(f2, true));
00245       return fs;
00246     }
00247 
00248 
00249     template <unsigned N, unsigned D>
00250     inline
00251     n_faces_set<N, D>
00252     operator+(const n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f)
00253     {
00254       n_faces_set<N, D> fs2(fs);
00255       fs2.add(f);
00256       return fs2;
00257     }
00258 
00259     template <unsigned N, unsigned D>
00260     inline
00261     n_faces_set<N, D>
00262     operator+(const n_faces_set<N, D>& fs, const n_face<N, D>& f)
00263     {
00264       n_faces_set<N, D> fs2(fs);
00265       fs2.add(make_algebraic_n_face(f, true));
00266       return fs2;
00267     }
00268 
00269     template <unsigned N, unsigned D>
00270     n_faces_set<N, D>&
00271     operator+=(n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f)
00272     {
00273       fs.add(f);
00274       return fs;
00275     }
00276 
00277     // ------------- //
00278     // Subtraction.  //
00279     // ------------- //
00280 
00281     template <unsigned N, unsigned D>
00282     inline
00283     n_faces_set<N, D>
00284     operator-(const algebraic_n_face<N, D>& f1,
00285               const algebraic_n_face<N, D>& f2)
00286     {
00287       n_faces_set<N, D> fs;
00288       fs.add(f1);
00289       fs.add(-f2);
00290       return fs;
00291     }
00292 
00293     template <unsigned N, unsigned D>
00294     inline
00295     n_faces_set<N, D>
00296     operator-(const algebraic_n_face<N, D>& f1, const n_face<N, D>& f2)
00297     {
00298       n_faces_set<N, D> fs;
00299       fs.add(f1);
00300       fs.add(make_algebraic_n_face(f2, false));
00301       return fs;
00302     }
00303 
00304     template <unsigned N, unsigned D>
00305     inline
00306     n_faces_set<N, D>
00307     operator-(const n_face<N, D>& f1, const algebraic_n_face<N, D>& f2)
00308     {
00309       n_faces_set<N, D> fs;
00310       fs.add(make_algebraic_n_face(f1, true));
00311       fs.add(-f2);
00312       return fs;
00313     }
00314 
00315     template <unsigned N, unsigned D>
00316     inline
00317     n_faces_set<N, D>
00318     operator-(const n_face<N, D>& f1, const n_face<N, D>& f2)
00319     {
00320       n_faces_set<N, D> fs;
00321       fs.add(make_algebraic_n_face(f1, true));
00322       fs.add(make_algebraic_n_face(f2, false));
00323       return fs;
00324     }
00325 
00326 
00327     template <unsigned N, unsigned D>
00328     inline
00329     n_faces_set<N, D>
00330     operator-(const n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f)
00331     {
00332       n_faces_set<N, D> fs2(fs);
00333       fs2.add(-f);
00334       return fs2;
00335     }
00336 
00337     template <unsigned N, unsigned D>
00338     inline
00339     n_faces_set<N, D>
00340     operator-(const n_faces_set<N, D>& fs, const n_face<N, D>& f)
00341     {
00342       n_faces_set<N, D> fs2(fs);
00343       fs2.add(make_algebraic_n_face(f, false));
00344       return fs2;
00345     }
00346 
00347     template <unsigned N, unsigned D>
00348     n_faces_set<N, D>&
00349     operator-=(n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f)
00350     {
00351       fs.add(-f);
00352       return fs;
00353     }
00354 
00355 # endif // ! MLN_INCLUDE_ONLY
00356 
00357   } // end of namespace mln::topo
00358 
00359 } // end of namespace mln
00360 
00361 #endif // ! MLN_TOPO_N_FACES_SET_HH

Generated on Tue Oct 4 2011 15:24:06 for Milena (Olena) by  doxygen 1.7.1