00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00032
00033 #include <cstdlib>
00034 #include <cmath>
00035
00036 #include <utility>
00037 #include <iostream>
00038
00039 #include <mln/core/image/complex_image.hh>
00040 #include <mln/core/image/complex_neighborhoods.hh>
00041
00042 #include <mln/data/fill.hh>
00043 #include <mln/literal/zero.hh>
00044
00045 #include <mln/math/max.hh>
00046 #include <mln/math/sqr.hh>
00047 #include <mln/accu/stat/min_max.hh>
00048 #include <mln/fun/v2v/linear.hh>
00049 #include <mln/data/transform.hh>
00050
00051 #include <mln/literal/white.hh>
00052
00053 #include <mln/io/off/load.hh>
00054 #include <mln/io/off/save.hh>
00055
00056 #include "trimesh/misc.hh"
00057
00058
00059
00060 static const float pi = 4 * atanf(1);
00061
00062
00063 int main(int argc, char* argv[])
00064 {
00065 if (argc != 3)
00066 {
00067 std::cerr << "usage: " << argv[0] << " input.off output.off"
00068 << std::endl;
00069 std::exit(1);
00070 }
00071
00072 std::string input_filename = argv[1];
00073 std::string output_filename = argv[2];
00074
00075
00076
00077
00078
00079
00080 typedef mln::float_2complex_image3df ima_t;
00081
00082 static const unsigned D = ima_t::dim;
00083
00084 typedef mln_geom_(ima_t) G;
00085
00086 mln::bin_2complex_image3df input;
00087 mln::io::off::load(input, input_filename);
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 std::pair<ima_t, ima_t> curv = mln::geom::mesh_curvature(input.domain());
00100
00101
00102 ima_t max_curv(input.domain());
00103 mln::data::fill(max_curv, mln::literal::zero);
00104 mln::p_n_faces_fwd_piter<D, G> v(max_curv.domain(), 0);
00105 for_all(v)
00106 max_curv(v) = mln::math::max(mln::math::sqr(curv.first(v)),
00107 mln::math::sqr(curv.second(v)));
00108
00109
00110 mln::p_n_faces_fwd_piter<D, G> t(max_curv.domain(), 2);
00111 typedef mln::complex_m_face_neighborhood<D, G> adj_vertices_nbh_t;
00112 adj_vertices_nbh_t adj_vertices_nbh;
00113 mln_niter_(adj_vertices_nbh_t) adj_v(adj_vertices_nbh, t);
00114
00115
00116 adj_v.iter().set_m(0);
00117 mln::accu::stat::min_max<float> acc;
00118
00119 for_all(t)
00120 {
00121 float s = 0.0f;
00122 unsigned n = 0;
00123
00124 for_all(adj_v)
00125 {
00126 s += max_curv(adj_v);
00127 ++n;
00128 }
00129 float m = s / n;
00130 max_curv(t) = m;
00131 acc.take(m);
00132
00133 mln_invariant(n <= 3);
00134 }
00135
00136
00137
00138
00139
00140 ima_t output(max_curv.domain());
00141 mln::data::fill(output, mln::literal::zero);
00142 std::pair<float, float> min_max(acc);
00143
00144 float min = min_max.first;
00145 float max = min_max.second;
00146 std::cout << min << std::endl;
00147 std::cout << max << std::endl;
00148
00149
00150 if (min != max)
00151 {
00152 float m = 0.0f;
00153 float M = 1.0f;
00154 float a = (M - m) / (max - min);
00155 float b = (m * max - M * min) / (max - min);
00156 mln::fun::v2v::linear<float, float, float> f(a, b);
00157 output = mln::data::transform(max_curv, f);
00158 }
00159
00160
00161 mln::io::off::save(output, output_filename);
00162 }