27 #ifndef MLN_IO_FLD_SAVE_HH
28 # define MLN_IO_FLD_SAVE_HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/core/concept/gpoint.hh>
39 # include <mln/io/fld/header.hh>
40 # include <mln/io/fld/write_header.hh>
41 # include <mln/io/fld/max_components.hh>
43 # include <mln/algebra/vec.hh>
45 # include <mln/geom/bbox.hh>
64 # ifndef MLN_INCLUDE_ONLY
70 void save_data_contiguous(std::ofstream& file,
const I& ima)
72 typedef mln_site(I) P;
73 typedef mln_value(I) V;
74 enum { dim = P::dim };
76 P pmin = ima.domain().pmin();
77 P pmax = ima.domain().pmax();
79 std::size_t len = pmax[dim - 1] - pmin[dim - 1] + 1;
80 std::size_t n = len *
sizeof(V);
84 file.write((
char*)(&ima(p)), n);
90 file.write((
char*)(&ima(p)), n);
93 for (
int i = dim - 2; p[i] > pmax[i]; --i)
103 template <
typename I>
105 fld::fld_header make_header(
const I& ima)
108 typedef mln_site(I) P;
109 typedef mln_value(I) V;
110 enum { dim = P::dim };
114 hdr.veclen = mln_dim(V);
115 hdr.dim =
new int[dim];
116 hdr.min_ext =
new float[dim];
117 hdr.max_ext =
new float[dim];
120 P pmin = bbox.pmin();
121 P pmax = bbox.pmax();
123 for (
unsigned i = 0; i < dim; i++)
125 hdr.dim[i] = pmax[i] - pmin[i] + 1;
126 hdr.min_ext[i] = pmin[i];
127 hdr.max_ext[i] = pmax[i];
151 template <
typename I>
154 mln_trace(
"mln::io::fld::save");
156 mlc_is(mln_trait_image_speed(I), trait::image::speed::fastest)::check();
158 const I& ima =
exact(ima_);
159 mln_precondition(ima.is_valid());
161 std::ofstream file(filename);
162 fld_header hdr = internal::make_header(ima);
165 internal::save_data_contiguous(file, ima);
171 # endif // ! MLN_INCLUDE_ONLY
178 #endif // !MLN_IO_FLD_SAVE_HH