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
00028 #ifndef OLENA_IO_SE_WINDOW_HH
00029 # define OLENA_IO_SE_WINDOW_HH
00030
00031 # include <mlc/type.hh>
00032
00033 # include <oln/core/image1d.hh>
00034 # include <oln/core/image2d.hh>
00035 # include <oln/core/image3d.hh>
00036 # include <oln/core/window1d.hh>
00037 # include <oln/core/window2d.hh>
00038 # include <oln/core/window3d.hh>
00039 # include <oln/core/macros.hh>
00040
00041 # include <oln/io/image.hh>
00042
00043 namespace oln {
00044
00045 namespace io {
00046
00047 namespace internal {
00048
00050
00057 inline bool
00058 read(window1d& output, const std::string& name)
00059 {
00060 image1d<ntg::bin> im;
00061 if (!read(im, name))
00062 return false;
00063 if (!(im.ncols() % 2))
00064 return false;
00065 image1d<ntg::bin>::iter_type it(im);
00066 window1d w;
00067 for_all (it)
00068 if (!im[it])
00069 w.add(dpoint1d(it) - dpoint1d(im.ncols()/2));
00070 output = w;
00071 return true;
00072 }
00073
00080 inline bool
00081 read(window2d& output, const std::string& name)
00082 {
00083 image2d<ntg::bin> im;
00084 if (!read(im, name))
00085 return false;
00086 if (!(im.ncols() % 2) || !(im.nrows() % 2))
00087 {
00088
00089
00090
00091 return false;
00092 }
00093 image2d<ntg::bin>::fwd_iter_type it(im);
00094 window2d w;
00095 for_all (it)
00096 if (!im[it])
00097 w.add(dpoint2d(it) - dpoint2d(im.nrows()/2, im.ncols()/2));
00098 output = w;
00099 return true;
00100 }
00101
00108 inline bool
00109 read(window3d& output, const std::string& name)
00110 {
00111 image3d<ntg::bin> im;
00112 if (!read(im, name))
00113 return false;
00114 if (!(im.ncols() % 2) || !(im.nrows() % 2) || !(im.nslices() % 2))
00115 return false;
00116 image3d<ntg::bin>::iter_type it(im);
00117 window3d w;
00118 for_all (it)
00119 if (!im[it])
00120 w.add(dpoint3d(it) - dpoint3d(im.nrows()/2,
00121 im.ncols()/2,
00122 im.nslices()/2));
00123 output = w;
00124 return true;
00125 }
00126
00133 inline bool
00134 write(const window1d& input, const std::string& name)
00135 {
00136 image1d<ntg::bin> im(input.delta()*2+1);
00137 image1d<ntg::bin>::iter_type it(im);
00138 for_all (it) im[it] = true;
00139 for (unsigned i = 0; i < input.card(); ++i)
00140 im[point1d(input.delta()) + input.dp(i)] = false;
00141 if (!write(im, name))
00142 return false;
00143 return true;
00144 }
00145
00152 inline bool
00153 write(const window2d& input, const std::string& name)
00154 {
00155 image2d<ntg::bin> im(input.delta()*2+1, input.delta()*2+1);
00156 image2d<ntg::bin>::fwd_iter_type it(im);
00157 for_all (it) im[it] = true;
00158 for (unsigned i = 0; i < input.card(); ++i)
00159 im[point2d(input.delta(), input.delta()) + input.dp(i)] = false;
00160 if (!write(im, name))
00161 return false;
00162 return true;
00163 }
00164
00171 inline bool
00172 write(const window3d& input, const std::string& name)
00173 {
00174 image3d<ntg::bin> im(input.delta()*2+1,
00175 input.delta()*2+1,
00176 input.delta()*2+1);
00177 image3d<ntg::bin>::iter_type it(im);
00178 for_all (it) im[it] = true;
00179 for (unsigned i = 0; i < input.card(); ++i)
00180 im[point3d(input.delta(), input.delta(), input.delta())
00181 + input.dp(i)] = false;
00182 if (!write(im, name))
00183 return false;
00184 return true;
00185 }
00186
00187 }
00188
00189 }
00190
00191 }
00192
00193 #endif // ! OLENA_IO_SE_WINDOW_HH