Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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 <cstdlib> 00027 00028 #include <string> 00029 00030 #include <mln/core/image/complex_image.hh> 00031 #include <mln/core/image/complex_neighborhoods.hh> 00032 #include <mln/core/image/complex_windows.hh> 00033 00034 #include <mln/value/int_u8.hh> 00035 #include <mln/value/label_16.hh> 00036 00037 #include <mln/data/fill.hh> 00038 #include <mln/math/diff_abs.hh> 00039 #include <mln/literal/zero.hh> 00040 00041 #include <mln/io/off/load.hh> 00042 #include <mln/io/off/save.hh> 00043 #include <mln/labeling/colorize.hh> 00044 00045 #include "chain.hh" 00046 00047 00048 // FIXME: Should be rewritten using a diff_abs-based accumulator 00049 // taking values from triangles (and checking that exactly two values 00050 // where taken, of course). 00051 template <unsigned D, typename G, typename V> 00052 inline 00053 mln::complex_image<D, G, V> 00054 gradient_on_edges(const mln::complex_image<D, G, V>& input) 00055 { 00056 typedef mln::complex_image<D, G, V> ima_t; 00057 ima_t output (input.domain()); 00058 mln::data::fill(output, mln::literal::zero); 00059 00060 // Values on edges. 00061 mln::p_n_faces_fwd_piter<D, G> e(input.domain(), 1); 00062 // Edge-to-triangle adjacency. 00063 typedef mln::complex_higher_neighborhood<D, G> e2t_t; 00064 e2t_t e2t; 00065 mln_niter(e2t_t) t(e2t, e); 00066 // Iterate on edges (1-faces). 00067 for_all(e) 00068 { 00069 t.start(); 00070 // An edge should be adjacent to at least one triangle. 00071 if (!t.is_valid()) 00072 abort(); 00073 V v1 = input(t); 00074 t.next(); 00075 // If E is adjacent to two triangles, compute the absolute 00076 // difference between their values. 00077 if (t.is_valid()) 00078 { 00079 V v2 = input(t); 00080 output(e) = mln::math::diff_abs(v1, v2); 00081 // There should be no more adjacent triangles. 00082 t.next(); 00083 mln_assertion(!t.is_valid()); 00084 } 00085 } 00086 return output; 00087 } 00088 00089 00090 int main(int argc, char* argv[]) 00091 { 00092 if (argc != 4) 00093 { 00094 std::cerr << "usage: " << argv[0] << " input.off lambda output.off" 00095 << std::endl; 00096 std::exit(1); 00097 } 00098 std::string input_filename = argv[1]; 00099 unsigned lambda = atoi(argv[2]); 00100 std::string output_filename = argv[3]; 00101 00102 using namespace mln; 00103 00104 typedef float val; 00105 typedef value::label_16 label; 00106 // Input and output types. 00107 typedef mln::float_2complex_image3df input; 00108 typedef mln_ch_value_(input, label) output; 00109 static const unsigned dim = input::dim; 00110 typedef mln_geom_(input) geom; 00111 complex_lower_dim_connected_n_face_neighborhood<dim, geom> nbh; 00112 complex_lower_dim_connected_n_face_window_p<dim, geom> win; 00113 label nbasins; 00114 00115 // Load, process, save. 00116 /* FIXME: The domain of IMA should be limited to 2-faces. Alas, we 00117 do not have (yet) an mln::pcomplex_subset site set type. Anyway, 00118 this should not alter the results, only slow the computation 00119 down. */ 00120 input ima; 00121 io::off::load(ima, input_filename); 00122 00123 // Gradient on edges. 00124 input g = gradient_on_edges(ima); 00125 output s = chain(ima, nbh, lambda, nbasins); 00126 io::off::save(labeling::colorize(value::rgb8(), s, nbasins), 00127 output_filename); 00128 }