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

tree_to_image.hh

00001 // Copyright (C) 2007, 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_UTIL_TREE_TO_IMAGE_HH
00027 # define MLN_UTIL_TREE_TO_IMAGE_HH
00028 
00033 
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/image/image2d.hh>
00036 # include <mln/util/tree.hh>
00037 # include <mln/core/site_set/p_set.hh>
00038 # include <mln/data/fill.hh>
00039 
00040 namespace mln
00041 {
00042 
00043   namespace data
00044   {
00045     template <typename I, typename D>
00046     void fill(Image<I>& ima, const D& data);
00047 
00048   }
00049 
00050   namespace util
00051   {
00052 
00058     template <typename T, typename I>
00059     void
00060     tree_to_image(tree<T>& tree, Image<I>& output_);
00061 
00067     template <typename I, typename J>
00068     void
00069     display_tree(const Image<J>& ima_, tree<I>& tree);
00070 
00071 
00077     template <typename I, typename J>
00078     void
00079     display_branch(const Image<J>& ima_, tree_node<I>* tree_node);
00080 
00081 # ifndef MLN_INCLUDE_ONLY
00082 
00083     namespace impl
00084     {
00085 
00086       template <typename T, typename I>
00087       inline
00088       void
00089       tree_to_image_rec(tree_node<T>* tree_node, Image<I>& output_)
00090       {
00091         trace::entering("util::impl::tree_to_image_rec");
00092 
00093         I& output = exact(output_);
00094 
00095         mln_piter(p_set<point2d>) p(tree_node->elt().points);
00096 
00097         for_all(p)
00098           output(p) = tree_node->elt().value;
00099 
00100         typename std::vector< util::tree_node<T>* >::const_iterator it = tree_node->children().begin();
00101 
00102         for (int i = 0;
00103              it != tree_node->children().end();
00104              ++it, ++i)
00105           {
00106             if (*it)
00107               tree_to_image_rec((*it), output);
00108           }
00109         trace::exiting("util::impl::tree_to_image_rec");
00110       }
00111 
00112       template <typename T, typename J>
00113       inline
00114       void
00115       display_tree_rec(const Image<J>& ima_, tree_node<T>* tree_node, int level)
00116       {
00117         trace::entering("util::impl::display_tree_rec");
00118 
00119         const J& ima = exact(ima_);
00120         display_set(ima, tree_node->elt().points);
00121         typename mln::util::tree_node<T>::children_t::iterator it = tree_node->children().begin();
00122         for (;
00123              it != tree_node->children().end(); ++it)
00124           display_tree_rec(ima, (*it), level + 1);
00125 
00126         trace::exiting("util::impl::display_tree_rec");
00127       }
00128 
00129 
00130       template <typename T, typename J, typename K>
00131       inline
00132       void
00133       display_branch_rec(const Image<J>& ima_, tree_node<T>* tree_node, Image<K>& output_)
00134       {
00135         trace::entering("util::impl::display_branch_rec");
00136 
00137         K& output = exact(output_);
00138         const J& ima = exact(ima_);
00139 
00140         mln_piter(p_set<point2d>) p(tree_node->elt().points);
00141         for_all(p)
00142           output(p) = true;
00143         typename mln::util::tree_node<T>::children_t::iterator it = tree_node->children().begin();
00144         for (;
00145              it != tree_node->children().end(); ++it)
00146           display_branch_rec(ima, (*it), output);
00147 
00148         trace::exiting("util::impl::display_branch_rec");
00149       }
00150 
00151 
00152       template <typename P, typename J>
00153       inline
00154       void
00155       display_set(const Image<J>& ima_, p_set<P>& s)
00156       {
00157         trace::entering("util::impl::display_set");
00158 
00159         const J& ima = exact(ima_);
00160         image2d<bool> out(ima.bbox());
00161 
00162         data::fill(out, false);
00163         mln_piter(p_set<P>) p(s);
00164         for_all(p)
00165           out(p) = true;
00166 
00167         trace::exiting("util::impl::display_set");
00168       }
00169 
00170 
00171     } // end of namespace mln::util::impl
00172 
00173 
00174 
00175     template <typename T, typename I>
00176     inline
00177     void
00178     tree_to_image(tree<T>& tree, Image<I>& output_)
00179     {
00180       trace::entering("util::tree_to_image");
00181 
00182       I& output = exact(output_);
00183       impl::tree_to_image_rec(tree.root(), output);
00184 
00185       trace::exiting("util::tree_to_image");
00186     }
00187 
00188 
00189     template <typename I, typename J>
00190     inline
00191     void
00192     display_tree(const Image<J>& ima_, tree<I>& tree)
00193     {
00194       trace::entering("util::display_tree");
00195 
00196       mln_precondition(tree.root());
00197 
00198       const J& ima = exact(ima_);
00199       int level = 0;
00200 
00201       impl::display_tree_rec(ima, tree.root(), level);
00202 
00203       trace::exiting("util::display_tree");
00204     }
00205 
00206 
00207     template <typename I, typename J>
00208     inline
00209     void
00210     display_branch(const Image<J>& ima_, tree_node<I>* tree_node)
00211     {
00212       trace::entering("util::display_branch");
00213 
00214       mln_assertion(tree_node);
00215 
00216       const J& ima = exact(ima_);
00217 
00218       image2d<bool> output(ima.domain());
00219       data::fill(output, false);
00220       impl::display_branch_rec(ima, tree_node, output);
00221 
00222       trace::exiting("util::display_branch");
00223     }
00224 
00225 
00226 # endif // ! MLN_INCLUDE_ONLY
00227 
00228   } // end of namespace mln::util
00229 
00230 } // end of namespace mln
00231 
00232 #endif // ! MLN_UTIL_TREE_TO_IMAGE_HH

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