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 #include <mln/core/image/image1d.hh> 00027 #include <mln/core/alias/neighb1d.hh> 00028 #include <mln/value/int_u8.hh> 00029 00030 #include <mln/make/image.hh> 00031 #include <mln/morpho/tree/dual_input_tree.hh> 00032 00033 template <typename V, unsigned dim, unsigned dim2> 00034 void test(V (&f_)[dim], V (&m_)[dim], V (&points_)[dim2], V (&p_)[dim2]) 00035 { 00036 using namespace mln; 00037 typedef image1d<V> I; 00038 typedef p_array< mln_psite(I) > S; 00039 typedef morpho::tree::data<I,S> tree_t; 00040 00041 00042 I f = make::image(f_); 00043 I m = make::image(m_); 00044 00045 00046 tree_t tree = morpho::tree::dual_input_max_tree(f, m, c2()); 00047 00048 mln_dn_site_piter(tree_t) p(tree); 00049 p.start(); 00050 for (unsigned i = 0; i < dim2; ++i, p.next()) 00051 { 00052 mln_assertion(p.is_valid()); 00053 mln_assertion(p == point1d(points_[i])); 00054 mln_assertion(tree.parent(p) == point1d(p_[i])); 00055 } 00056 mln_assertion(! p.is_valid()); 00057 } 00058 00059 00060 00061 int main() 00062 { 00063 00064 using namespace mln; 00065 00066 typedef value::int_u8 V; 00067 00068 //V f_[] = {10, 10, 20, 20, 30, 30, 40, 40, 30, 30, 20, 20, 30, 30, 20, 20, 10, 20, 20, 10}; 00069 //V m_[] = {10, 10, 20, 20, 30, 30, 40, 40, 30, 30, 30, 30, 30, 30, 20, 20, 15, 15, 15, 15}; 00070 00071 00072 //V f_[] = {15, 15, 10, 10, 05, 05, 8, 8, 5, 5, 10, 10, 15, 15}; 00073 //V m_[] = {20, 20, 18, 18, 25, 25, 8, 8, 5, 5, 10, 10, 15, 15}; 00074 00075 { 00076 V f[] = {15, 15, 15}; 00077 V m[] = {20, 20, 20}; 00078 V s[] = {0, 1, 2}; 00079 V p[] = {0, 0, 0}; 00080 test(f, m, s, p); 00081 } 00082 00083 { 00084 V f[] = {15, 17, 17, 19, 16}; 00085 V m[] = {15, 17, 17, 19, 16}; 00086 V s[] = {0, 4, 1, 2, 3}; 00087 V p[] = {0, 0, 4, 1, 1}; 00088 00089 00090 test(f, m, s, p); 00091 } 00092 00093 { 00094 V f[] = {15, 17, 17, 15, 18, 19}; 00095 V m[] = {15, 17, 17, 15, 18, 19}; 00096 V s[] = {0, 3, 1, 2, 4, 5}; 00097 V p[] = {0, 0, 0, 1, 0, 4}; 00098 test(f, m, s, p); 00099 } 00100 00101 // Clustering: simple connection 00102 { 00103 V f[] = {15, 17, 17, 15, 18, 19}; 00104 V m[] = {15, 18, 18, 18, 18, 19}; 00105 V s[] = {0, 3, 1, 2, 4, 5}; 00106 V p[] = {0, 0, 0, 1, 1, 4}; 00107 test(f, m, s, p); 00108 } 00109 00110 // Clustering: merge two nodes 00111 { 00112 V f[] = {15, 18, 18, 15, 18, 19}; 00113 V m[] = {15, 18, 18, 18, 18, 19}; 00114 V s[] = {0, 3, 1, 2, 4, 5}; 00115 V p[] = {0, 0, 0, 1, 1, 1}; 00116 test(f, m, s, p); 00117 } 00118 00119 // Clustering: create new node 00120 { 00121 V f[] = {18, 15, 18}; 00122 V m[] = {18, 17, 18}; 00123 V s[] = {1, 4, 0, 2}; 00124 V p[] = {1, 1, 4, 4}; 00125 test(f, m, s, p); 00126 } 00127 00128 // Clustering: create new node 00129 { 00130 V f[] = {10, 10, 12, 12}; 00131 V m[] = {11, 11, 13, 13}; 00132 V s[] = {0, 1, 4, 2, 3}; 00133 V p[] = {0, 0, 0, 4, 2}; 00134 test(f, m, s, p); 00135 } 00136 00137 // Segmentation: simple (no node creation) 00138 { 00139 V f[] = {8, 10, 10, 12, 12}; 00140 V m[] = {8, 8, 8, 12, 12}; 00141 V s[] = {0, 1, 2, 3, 4}; 00142 V p[] = {0, 0, 0, 0, 3}; 00143 test(f, m, s, p); 00144 } 00145 00146 // Segmentation: simple (no node creation) 00147 { 00148 V f[] = {8, 10, 10, 8}; 00149 V m[] = {8, 8, 8, 8}; 00150 V s[] = {0, 3, 1, 2}; 00151 V p[] = {0, 0, 0, 0}; 00152 test(f, m, s, p); 00153 } 00154 00155 // Segmentation: create node 00156 { 00157 V f[] = {8, 10, 10, 8}; 00158 V m[] = {8, 9, 9, 8}; 00159 V s[] = {0, 3, 5, 1, 2}; 00160 V p[] = {0, 0, 0, 5, 5}; 00161 test(f, m, s, p); 00162 } 00163 00164 // Segmentation: create a root node 00165 { 00166 V f[] = {8, 10, 10, 8}; 00167 V m[] = {8, 5, 9, 8}; 00168 V s[] = {5, 0, 3, 1, 6, 2}; // Or {5, 0, 3, 6, 1, 2} for a strict sort 00169 V p[] = {5, 5, 5, 5, 3, 6}; 00170 test(f, m, s, p); 00171 } 00172 00173 }