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