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

adj_higher_dim_connected_n_face_iter.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_ADJ_HIGHER_DIM_CONNECTED_N_FACE_ITER_HH
00027 # define MLN_TOPO_ADJ_HIGHER_DIM_CONNECTED_N_FACE_ITER_HH
00028 
00034 
00035 # include <set>
00036 
00037 # include <mln/topo/internal/complex_relative_iterator_base.hh>
00038 # include <mln/topo/algebraic_face.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   namespace topo
00045   {
00046 
00047     // Forward declarations.
00048     template <unsigned D> class complex;
00049     namespace internal
00050     {
00051       template <unsigned D> class adj_higher_dim_connected_n_face_iterator;
00052     }
00053 
00054 
00055     /*----------------------------------------------------.
00056     | topo::adj_higher_dim_connected_n_face_fwd_iter<D>.  |
00057     `----------------------------------------------------*/
00058 
00063     //
00064     template <unsigned D>
00065     class adj_higher_dim_connected_n_face_fwd_iter
00066       : public internal::forward_complex_relative_iterator_base< topo::face<D>,
00067                                                                  algebraic_face<D>,
00068                                                                  adj_higher_dim_connected_n_face_fwd_iter<D> >,
00069         private internal::adj_higher_dim_connected_n_face_iterator<D>
00070     {
00071       // Tech note: we use topo::face to help g++-2.95.
00072     private:
00073       typedef adj_higher_dim_connected_n_face_fwd_iter<D> self_;
00074       typedef internal::forward_complex_relative_iterator_base< topo::face<D>,
00075                                                                 algebraic_face<D>,
00076                                                                 self_ > super_;
00077 
00078     public:
00081       adj_higher_dim_connected_n_face_fwd_iter();
00082       template <typename Fref>
00083       adj_higher_dim_connected_n_face_fwd_iter(const Fref& f_ref);
00085 
00090       void update_adj_faces_();
00091     };
00092 
00093 
00094     /*----------------------------------------------------.
00095     | topo::adj_higher_dim_connected_n_face_bkd_iter<D>.  |
00096     `----------------------------------------------------*/
00097 
00102     //
00103     template <unsigned D>
00104     class adj_higher_dim_connected_n_face_bkd_iter
00105       : public internal::backward_complex_relative_iterator_base< topo::face<D>,
00106                                                                   algebraic_face<D>,
00107                                                                   adj_higher_dim_connected_n_face_bkd_iter<D> >,
00108         private internal::adj_higher_dim_connected_n_face_iterator<D>
00109     {
00110       // Tech note: we use topo::face to help g++-2.95.
00111     private:
00112       typedef adj_higher_dim_connected_n_face_bkd_iter<D> self_;
00113       typedef internal::backward_complex_relative_iterator_base< topo::face<D>,
00114                                                                  algebraic_face<D>,
00115                                                                  self_ > super_;
00116 
00117     public:
00120       adj_higher_dim_connected_n_face_bkd_iter();
00121       template <typename Fref>
00122       adj_higher_dim_connected_n_face_bkd_iter(const Fref& f_ref);
00124 
00129       void update_adj_faces_();
00130     };
00131 
00132 
00133     /*--------------------------------------------------------------.
00134     | topo::internal::adj_higher_dim_connected_n_face_iterator<D>.  |
00135     `--------------------------------------------------------------*/
00136 
00137     namespace internal
00138     {
00139 
00140       template <unsigned D>
00141       class adj_higher_dim_connected_n_face_iterator
00142       {
00143       protected:
00146         void update_adj_faces__(const topo::face<D>& center,
00147                                 std::vector< algebraic_face<D> >& adj_faces);
00148       };
00149 
00150     } // end of namespace mln::topo::internal
00151 
00152 
00153 
00154 # ifndef MLN_INCLUDE_ONLY
00155 
00156     /*----------------------------------------------------.
00157     | topo::adj_higher_dim_connected_n_face_fwd_iter<D>.  |
00158     `----------------------------------------------------*/
00159 
00160     template <unsigned D>
00161     inline
00162     adj_higher_dim_connected_n_face_fwd_iter<D>::adj_higher_dim_connected_n_face_fwd_iter()
00163     {
00164     }
00165 
00166     template <unsigned D>
00167     template <typename Fref>
00168     inline
00169     adj_higher_dim_connected_n_face_fwd_iter<D>::adj_higher_dim_connected_n_face_fwd_iter(const Fref& f_ref)
00170       : super_(f_ref)
00171     {
00172     }
00173 
00174     /* FIXME: Most of this code is shared by
00175        adj_higher_dim_connected_n_face_{fwd,bkd}_iter<D> and
00176        adj_higher_dim_connected_n_face_{fwd,bkd}_iter<D>).  Find a way
00177        to factor this, maybe through a common (implementation) base
00178        class.  */
00179     template <unsigned D>
00180     inline
00181     void
00182     adj_higher_dim_connected_n_face_fwd_iter<D>::update_adj_faces_()
00183     {
00184       mln_precondition(this->c_);
00185       // Delegate computation to base class.
00186       this->update_adj_faces__(*this->c_, this->adj_faces_);
00187     }
00188 
00189 
00190     /*----------------------------------------------------.
00191     | topo::adj_higher_dim_connected_n_face_bkd_iter<D>.  |
00192     `----------------------------------------------------*/
00193 
00194     template <unsigned D>
00195     inline
00196     adj_higher_dim_connected_n_face_bkd_iter<D>::adj_higher_dim_connected_n_face_bkd_iter()
00197     {
00198     }
00199 
00200     template <unsigned D>
00201     template <typename Fref>
00202     inline
00203     adj_higher_dim_connected_n_face_bkd_iter<D>::adj_higher_dim_connected_n_face_bkd_iter(const Fref& f_ref)
00204       : super_(f_ref)
00205     {
00206     }
00207 
00208     template <unsigned D>
00209     inline
00210     void
00211     adj_higher_dim_connected_n_face_bkd_iter<D>::update_adj_faces_()
00212     {
00213       mln_precondition(this->c_);
00214       // Delegate computation to base class.
00215       this->update_adj_faces__(*this->c_, this->adj_faces_);
00216     }
00217 
00218 
00219     /*--------------------------------------------------------------.
00220     | topo::internal::adj_higher_dim_connected_n_face_iterator<D>.  |
00221     `--------------------------------------------------------------*/
00222 
00223     namespace internal
00224     {
00225 
00226       /* FIXME: Factor
00227          topo::internal::adj_lower_dim_connected_n_face_iterator<D> and
00228          topo::internal::adj_higher_dim_connected_n_face_iterator<D>.  */
00229 
00230       template <unsigned D>
00231       inline
00232       void
00233       adj_higher_dim_connected_n_face_iterator<D>::update_adj_faces__(const topo::face<D>& center,
00234                                                                       std::vector< algebraic_face<D> >& adj_faces)
00235       {
00236         // Reset the result container.
00237         adj_faces.clear();
00238 
00239         /* A set of faces containing the same values as ADJ_FACES, used
00240            to quickly check whether a candidate face has already been
00241            added to the pool of adjacent faces. We use an std::set
00242            because the lookup is cheaper (O(log(n)) vs O(n) for a
00243            vector, where n is the size of the containers.  */
00244         std::set< algebraic_face<D> > faces_set;
00245         typedef std::vector< algebraic_face<D> > faces_t;
00246 
00247         // The set of (n+1)-faces adjacent to CENTER.
00248         faces_t shared_higher_faces = center.higher_dim_adj_faces();
00249         for (typename faces_t::const_iterator slf = shared_higher_faces.begin();
00250              slf != shared_higher_faces.end(); ++slf)
00251           {
00252             /* The n-faces sharing an adjacent (n+1)-face with CENTER.
00253                Note that this set contains CENTER itself.  */
00254             faces_t adj_n_faces = slf->lower_dim_adj_faces();
00255             for (typename faces_t::const_iterator af = adj_n_faces.begin();
00256                  af != adj_n_faces.end(); ++af)
00257               {
00258                 /* Ensure that 1. we are not adding CENTER to the result;
00259                    and 2. that we are not adding an already added
00260                    processed face.  */
00261                 if (*af != center &&
00262                     faces_set.find(*af) == faces_set.end())
00263                   {
00264                     adj_faces.push_back(*af);
00265                     faces_set.insert(*af);
00266                   }
00267               }
00268           }
00269       }
00270 
00271     } // end of namespace mln::topo::internal
00272 
00273 # endif // ! MLN_INCLUDE_ONLY
00274 
00275   } // end of namespace mln::topo
00276 
00277 } // end of namespace mln
00278 
00279 #endif // ! MLN_TOPO_ADJ_HIGHER_DIM_CONNECTED_N_FACE_ITER_HH

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