27 #ifndef MLN_IO_OFF_SAVE_HH
28 # define MLN_IO_OFF_SAVE_HH
44 # include <mln/core/alias/complex_image.hh>
45 # include <mln/core/image/complex_neighborhoods.hh>
46 # include <mln/core/image/complex_neighborhood_piter.hh>
66 const std::string& filename);
76 const std::string& filename);
87 const std::string& filename);
97 const std::string& filename);
103 template <
typename I,
typename E>
104 struct off_saver :
public Object<E>
107 typedef mln_value(I) value;
110 static const
unsigned D = 2;
116 void operator()(const I& ima, const std::
string& filename) const;
126 void write_face_data(std::ostream& ostr,
const value& v)
const;
129 struct int_u8_off_saver
130 :
public off_saver< int_u8_2complex_image3df, int_u8_off_saver >
133 void write_face_data(std::ostream& ostr,
const value& v)
const;
140 struct float_off_saver
141 :
public off_saver< float_2complex_image3df, float_off_saver >
144 void write_face_data(std::ostream& ostr,
const value& v)
const;
148 struct rgb8_off_saver
149 :
public off_saver< rgb8_2complex_image3df, rgb8_off_saver >
152 void write_face_data(std::ostream& ostr,
const value& v)
const;
159 # ifndef MLN_INCLUDE_ONLY
169 trace::entering(
"mln::io::off::save");
170 internal::bin_off_saver()(ima, filename);
171 trace::exiting(
"mln::io::off::save");
178 trace::entering(
"mln::io::off::save");
179 internal::int_u8_off_saver()(ima, filename);
180 trace::exiting(
"mln::io::off::save");
187 trace::entering(
"mln::io::off::save");
188 internal::float_off_saver()(ima, filename);
189 trace::exiting(
"mln::io::off::save");
196 trace::entering(
"mln::io::off::save");
197 internal::rgb8_off_saver()(ima, filename);
198 trace::exiting(
"mln::io::off::save");
213 template <
typename I,
typename E>
214 off_saver<I, E>::off_saver()
217 void (E::*m1)(std::ostream&,
const value&)
const =
223 template <
typename I,
typename E>
225 off_saver<I, E>::operator()(
const I& ima,
226 const std::string& filename)
const
228 const std::string me =
"mln::io::off::save";
230 std::ofstream ostr(filename.c_str());
233 std::cerr << me <<
": `" << filename <<
"' invalid file."
252 ostr <<
"OFF" << std::endl;
255 ostr <<
"# Generated by Milena 1.0 http://olena.lrde.epita.fr\n"
256 <<
"# EPITA Research and Development Laboratory (LRDE)"
270 ostr << ima.domain().cplx().template nfaces_of_static_dim<0>() <<
' '
271 << ima.domain().cplx().template nfaces_of_static_dim<2>() <<
' '
272 << ima.domain().cplx().template nfaces_of_static_dim<1>()
283 typedef mln_geom(I) G;
293 p_n_faces_fwd_piter<D, G> v(ima.domain(), 0);
296 mln_invariant(v.to_site().size() == 1);
297 ostr << v.to_site().front()[0] <<
' '
298 << v.to_site().front()[1] <<
' '
299 << v.to_site().front()[2] << std::endl;
312 p_n_faces_fwd_piter<D, G> f(ima.domain(), 2);
314 typedef complex_m_face_neighborhood<D, G> nbh_t;
318 mln_fwd_niter(nbh_t) u(nbh, f);
328 unsigned nvertices = 0;
329 std::ostringstream vertices;
333 vertices <<
' ' << u.unproxy_().face().face_id();
336 ostr << nvertices << vertices.str();
338 exact(
this)->write_face_data(ostr, ima(f));
390 bin_off_saver::write_face_data(std::ostream& ,
398 int_u8_off_saver::write_face_data(std::ostream& ostr,
399 const value& v)
const
409 ostr <<
' ' << v <<
' ' << v <<
' ' << v
410 <<
' ' << 1.0f << std::endl;
417 float_off_saver::write_face_data(std::ostream& ostr,
418 const value& v)
const
429 mln_assertion(0.0f <= v);
430 mln_assertion(v <= 1.0f);
431 ostr <<
' ' << v <<
' ' << v <<
' ' << v
437 rgb8_off_saver::write_face_data(std::ostream& ostr,
438 const value& v)
const
445 ostr <<
' ' << v.red() <<
' ' << v.green() <<
' ' << v.blue()
453 # endif // ! MLN_INCLUDE_ONLY
462 #endif // ! MLN_IO_OFF_SAVE_HH