27 #ifndef MLN_IO_OFF_SAVE_HH
28 # define MLN_IO_OFF_SAVE_HH
44 # include <mln/version.hh>
45 # include <mln/core/alias/complex_image.hh>
46 # include <mln/core/image/complex_neighborhoods.hh>
47 # include <mln/core/image/complex_neighborhood_piter.hh>
69 void save(
const bin_2complex_image3df& ima,
82 void save(
const int_u8_2complex_image3df& ima,
96 void save(
const float_2complex_image3df& ima,
109 void save(
const rgb8_2complex_image3df& ima,
116 template <
typename I,
typename E>
117 struct off_saver :
public Object<E>
120 typedef mln_value(I)
value;
123 static const
unsigned D = 2;
129 void operator()(const I& ima, const std::
string&
filename) const;
134 : public off_saver< bin_2complex_image3df, bin_off_saver >
139 void write_face_data(std::ostream& ostr,
const value& v)
const;
142 struct int_u8_off_saver
143 :
public off_saver< int_u8_2complex_image3df, int_u8_off_saver >
146 void write_face_data(std::ostream& ostr,
const value& v)
const;
153 struct float_off_saver
154 :
public off_saver< float_2complex_image3df, float_off_saver >
157 void write_face_data(std::ostream& ostr,
const value& v)
const;
161 struct rgb8_off_saver
162 :
public off_saver< rgb8_2complex_image3df, rgb8_off_saver >
165 void write_face_data(std::ostream& ostr,
const value& v)
const;
172 # ifndef MLN_INCLUDE_ONLY
180 save(
const bin_2complex_image3df& ima,
const std::string&
filename)
182 mln_trace(
"mln::io::off::save");
183 internal::bin_off_saver()(ima,
filename);
188 save(
const int_u8_2complex_image3df& ima,
const std::string&
filename)
190 mln_trace(
"mln::io::off::save");
191 internal::int_u8_off_saver()(ima,
filename);
196 save(
const float_2complex_image3df& ima,
const std::string&
filename)
198 mln_trace(
"mln::io::off::save");
199 internal::float_off_saver()(ima,
filename);
204 save(
const rgb8_2complex_image3df& ima,
const std::string&
filename)
206 mln_trace(
"mln::io::off::save");
207 internal::rgb8_off_saver()(ima,
filename);
222 template <
typename I,
typename E>
223 off_saver<I, E>::off_saver()
226 void (E::*m1)(std::ostream&,
const value&)
const =
232 template <
typename I,
typename E>
234 off_saver<I, E>::operator()(
const I& ima,
237 const std::string me =
"mln::io::off::save";
239 std::ofstream ostr(filename.c_str());
242 std::cerr << me <<
": `" << filename <<
"' invalid file."
261 ostr <<
"OFF" << std::endl;
264 ostr <<
"# Generated by " OLN_PACKAGE_STRING
" (" OLN_PACKAGE_URL
")"
266 <<
"# " OLN_PACKAGE_AUTHORS
280 ostr << ima.domain().cplx().template nfaces_of_static_dim<0>() <<
' '
281 << ima.domain().cplx().template nfaces_of_static_dim<2>() <<
' '
282 << ima.domain().cplx().template nfaces_of_static_dim<1>()
293 typedef mln_geom(I) G;
303 p_n_faces_fwd_piter<D, G> v(ima.domain(), 0);
306 mln_invariant(v.to_site().size() == 1);
307 ostr << v.to_site().front()[0] <<
' '
308 << v.to_site().front()[1] <<
' '
309 << v.to_site().front()[2] << std::endl;
322 p_n_faces_fwd_piter<D, G> f(ima.domain(), 2);
324 typedef complex_m_face_neighborhood<D, G> nbh_t;
328 mln_fwd_niter(nbh_t) u(nbh, f);
338 unsigned nvertices = 0;
339 std::ostringstream vertices;
343 vertices <<
' ' << u.unproxy_().face().face_id();
346 ostr << nvertices << vertices.str();
348 exact(
this)->write_face_data(ostr, ima(f));
400 bin_off_saver::write_face_data(std::ostream& ,
408 int_u8_off_saver::write_face_data(std::ostream& ostr,
409 const value& v)
const
419 ostr <<
' ' << v <<
' ' << v <<
' ' << v
420 <<
' ' << 1.0f << std::endl;
427 float_off_saver::write_face_data(std::ostream& ostr,
428 const value& v)
const
439 mln_assertion(0.0f <= v);
440 mln_assertion(v <= 1.0f);
441 ostr <<
' ' << v <<
' ' << v <<
' ' << v
447 rgb8_off_saver::write_face_data(std::ostream& ostr,
448 const value& v)
const
455 ostr <<
' ' << v.red() <<
' ' << v.green() <<
' ' << v.blue()
463 # endif // ! MLN_INCLUDE_ONLY
472 #endif // ! MLN_IO_OFF_SAVE_HH