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_MORPHO_TREE_UTILS_HH 00027 # define MLN_MORPHO_TREE_UTILS_HH 00028 00034 00035 # include <mln/core/concept/image.hh> 00036 # include <mln/core/site_set/p_array.hh> 00037 00038 00039 namespace mln 00040 { 00041 00042 namespace morpho 00043 { 00044 00045 namespace tree 00046 { 00047 00048 template <typename T, typename I> 00049 bool 00050 is_root(const Image<T>& parent, const mln_psite(T)& p, 00051 const Image<I>& f); 00052 00053 00054 template <typename T, typename I> 00055 bool 00056 is_a_node(const Image<T>& parent, const mln_psite(T)& p, 00057 const Image<I>& f); 00058 00059 00060 00061 template <typename T, typename I, typename S> 00062 p_array<mln_psite(T)> 00063 nodes(const Image<T>& parent, const Image<I>& f, const Site_Set<S>& s); 00064 00065 00066 # ifndef MLN_INCLUDE_ONLY 00067 00068 00069 template <typename T, typename I> 00070 inline 00071 bool 00072 is_root(const Image<T>& parent_, const mln_psite(T)& p, 00073 const Image<I>& f_) 00074 { 00075 mlc_equal(mln_value(T), mln_psite(T))::check(); 00076 00077 const T& parent = exact(parent_); 00078 const I& f = exact(f_); 00079 00080 mln_precondition(parent.is_valid()); 00081 mln_precondition(f.is_valid()); 00082 mln_precondition(parent.domain() == f.domain()); 00083 00084 return parent(p) == p; 00085 } 00086 00087 00088 template <typename T, typename I> 00089 inline 00090 bool 00091 is_a_node(const Image<T>& parent_, const mln_psite(T)& p, 00092 const Image<I>& f_) 00093 { 00094 mlc_equal(mln_value(T), mln_psite(T))::check(); 00095 00096 const T& parent = exact(parent_); 00097 const I& f = exact(f_); 00098 00099 mln_precondition(parent.is_valid()); 00100 mln_precondition(f.is_valid()); 00101 mln_precondition(parent.domain() == f.domain()); 00102 00103 return parent(p) == p || f(parent(p)) != f(p); 00104 } 00105 00106 00107 template <typename T, typename I, typename S> 00108 inline 00109 p_array<mln_psite(T)> 00110 nodes(const Image<T>& parent_, const Image<I>& f_, const Site_Set<S>& s_) 00111 { 00112 mlc_equal(mln_value(T), mln_psite(T))::check(); 00113 00114 const T& parent = exact(parent_); 00115 const I& f = exact(f_); 00116 const S& s = exact(s_); 00117 00118 mln_precondition(parent.is_valid()); 00119 mln_precondition(f.is_valid()); 00120 mln_precondition(f.domain() == parent.domain()); 00121 mln_precondition(s == f.domain()); 00122 00123 p_array<mln_psite(T)> arr; 00124 mln_bkd_piter(S) p(exact(s)); 00125 for_all(p) 00126 if (is_a_node(parent, p, f)) 00127 arr.insert(p); 00128 00129 return arr; 00130 } 00131 00132 # endif // ! MLN_INCLUDE_ONLY 00133 00134 } // end of namespace mln::morpho::tree 00135 00136 } // end of namespace mln::morpho 00137 00138 } // end of namespace mln 00139 00140 00141 #endif // ! MLN_MORPHO_TREE_UTILS_HH