00001
00002 #ifndef vil3d_slice_h_
00003 #define vil3d_slice_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011 #include <vil/vil_image_view.h>
00012 #include <vil3d/vil3d_image_view.h>
00013 #include <vcl_cassert.h>
00014
00015
00016
00017
00018
00019 template <class T>
00020 inline vil_image_view<T> vil3d_slice_ji(const vil3d_image_view<T> &im, unsigned k)
00021 {
00022 assert(k<im.nk());
00023
00024 vcl_ptrdiff_t pstep = im.planestep();
00025 if (im.nplanes()==1) pstep=im.ni()*im.nj();
00026 return vil_image_view<T>(im.memory_chunk(),
00027 im.origin_ptr()+k*im.kstep(),
00028 im.nj(), im.ni(), im.nplanes(),
00029 im.jstep(), im.istep(), pstep);
00030 }
00031
00032
00033
00034
00035
00036 template <class T>
00037 inline vil_image_view<T> vil3d_slice_ij(const vil3d_image_view<T> &im, unsigned k)
00038 {
00039 assert(k<im.nk());
00040
00041 vcl_ptrdiff_t pstep = im.planestep();
00042 if (im.nplanes()==1) pstep=im.ni()*im.nj();
00043 return vil_image_view<T>(im.memory_chunk(),
00044 im.origin_ptr()+k*im.kstep(),
00045 im.ni(), im.nj(), im.nplanes(),
00046 im.istep(), im.jstep(), pstep);
00047 }
00048
00049
00050
00051
00052
00053 template <class T>
00054 inline vil_image_view<T> vil3d_slice_jk(const vil3d_image_view<T> &im, unsigned i)
00055 {
00056 assert(i<im.ni());
00057
00058 vcl_ptrdiff_t pstep = im.planestep();
00059 if (im.nplanes()==1) pstep=im.nj()*im.nk();
00060 return vil_image_view<T>(im.memory_chunk(),
00061 im.origin_ptr()+i*im.istep(),
00062 im.nj(), im.nk(), im.nplanes(),
00063 im.jstep(), im.kstep(), pstep);
00064 }
00065
00066
00067
00068
00069
00070 template <class T>
00071 inline vil_image_view<T> vil3d_slice_kj(const vil3d_image_view<T> &im, unsigned i)
00072 {
00073 assert(i<im.ni());
00074
00075 vcl_ptrdiff_t pstep = im.planestep();
00076 if (im.nplanes()==1) pstep=im.nj()*im.nk();
00077 return vil_image_view<T>(im.memory_chunk(),
00078 im.origin_ptr()+i*im.istep(),
00079 im.nk(), im.nj(), im.nplanes(),
00080 im.kstep(), im.jstep(), pstep);
00081 }
00082
00083
00084
00085
00086
00087 template <class T>
00088 inline vil_image_view<T> vil3d_slice_ki(const vil3d_image_view<T> &im, unsigned j)
00089 {
00090 assert(j<im.nj());
00091
00092 vcl_ptrdiff_t pstep = im.planestep();
00093 if (im.nplanes()==1) pstep=im.ni()*im.nk();
00094 return vil_image_view<T>(im.memory_chunk(),
00095 im.origin_ptr()+j*im.jstep(),
00096 im.nk(), im.ni(), im.nplanes(),
00097 im.kstep(), im.istep(), pstep);
00098 }
00099
00100
00101
00102
00103
00104 template <class T>
00105 inline vil_image_view<T> vil3d_slice_ik(const vil3d_image_view<T> &im, unsigned j)
00106 {
00107 assert(j<im.nj());
00108
00109 vcl_ptrdiff_t pstep = im.planestep();
00110 if (im.nplanes()==1) pstep=im.ni()*im.nk();
00111 return vil_image_view<T>(im.memory_chunk(),
00112 im.origin_ptr()+j*im.jstep(),
00113 im.ni(), im.nk(), im.nplanes(),
00114 im.istep(), im.kstep(), pstep);
00115 }
00116
00117
00118 enum vil3d_slice_format
00119 {
00120 VIL3D_SLICE_FORMAT_IJ=0,
00121 VIL3D_SLICE_FORMAT_JI=1,
00122 VIL3D_SLICE_FORMAT_IK=2,
00123 VIL3D_SLICE_FORMAT_KI=3,
00124 VIL3D_SLICE_FORMAT_JK=4,
00125 VIL3D_SLICE_FORMAT_KJ=5
00126 };
00127
00128
00129
00130
00131
00132 template <class T>
00133 inline vil_image_view<T> vil3d_slice(const vil3d_image_view<T> &im, unsigned slice_index,
00134 vil3d_slice_format slice_format)
00135 {
00136 switch (slice_format)
00137 {
00138 case VIL3D_SLICE_FORMAT_IJ: return vil3d_slice_ij(im,slice_index);
00139 case VIL3D_SLICE_FORMAT_JI: return vil3d_slice_ji(im,slice_index);
00140 case VIL3D_SLICE_FORMAT_IK: return vil3d_slice_ik(im,slice_index);
00141 case VIL3D_SLICE_FORMAT_KI: return vil3d_slice_kj(im,slice_index);
00142 case VIL3D_SLICE_FORMAT_JK: return vil3d_slice_jk(im,slice_index);
00143 case VIL3D_SLICE_FORMAT_KJ: return vil3d_slice_kj(im,slice_index);
00144 default: assert(!"invalid slice_format");
00145 }
00146 return vil_image_view<T>();
00147 }
00148
00149
00150
00151 inline unsigned vil3d_n_slices(const vil3d_image_view_base& image,
00152 vil3d_slice_format slice_format)
00153 {
00154 switch (slice_format)
00155 {
00156 case VIL3D_SLICE_FORMAT_IJ: return image.nk();
00157 case VIL3D_SLICE_FORMAT_JI: return image.nk();
00158 case VIL3D_SLICE_FORMAT_IK: return image.nj();
00159 case VIL3D_SLICE_FORMAT_KI: return image.nj();
00160 case VIL3D_SLICE_FORMAT_JK: return image.ni();
00161 case VIL3D_SLICE_FORMAT_KJ: return image.ni();
00162 default: assert(!"invalid slice_format");
00163 }
00164 return 0;
00165 }
00166
00167
00168
00169 inline double vil3d_slice_pixel_width_i(double src_i_width, double src_j_width, double src_k_width,
00170 vil3d_slice_format slice_format)
00171 {
00172 switch (slice_format)
00173 {
00174 case VIL3D_SLICE_FORMAT_IJ: return src_i_width;
00175 case VIL3D_SLICE_FORMAT_JI: return src_j_width;
00176 case VIL3D_SLICE_FORMAT_IK: return src_i_width;
00177 case VIL3D_SLICE_FORMAT_KI: return src_k_width;
00178 case VIL3D_SLICE_FORMAT_JK: return src_j_width;
00179 case VIL3D_SLICE_FORMAT_KJ: return src_k_width;
00180 default: assert(!"invalid slice_format");
00181 }
00182 return 0.0;
00183 }
00184
00185
00186
00187 inline double vil3d_slice_pixel_width_j(double src_i_width, double src_j_width, double src_k_width,
00188 vil3d_slice_format slice_format)
00189 {
00190 switch (slice_format)
00191 {
00192 case VIL3D_SLICE_FORMAT_IJ: return src_j_width;
00193 case VIL3D_SLICE_FORMAT_JI: return src_i_width;
00194 case VIL3D_SLICE_FORMAT_IK: return src_k_width;
00195 case VIL3D_SLICE_FORMAT_KI: return src_i_width;
00196 case VIL3D_SLICE_FORMAT_JK: return src_k_width;
00197 case VIL3D_SLICE_FORMAT_KJ: return src_j_width;
00198 default: assert(!"invalid slice_format");
00199 }
00200 return 0.0;
00201 }
00202
00203
00204
00205 inline double vil3d_slice_separation(double src_i_width, double src_j_width, double src_k_width,
00206 vil3d_slice_format slice_format)
00207 {
00208 switch (slice_format)
00209 {
00210 case VIL3D_SLICE_FORMAT_IJ: return src_k_width;
00211 case VIL3D_SLICE_FORMAT_JI: return src_k_width;
00212 case VIL3D_SLICE_FORMAT_IK: return src_j_width;
00213 case VIL3D_SLICE_FORMAT_KI: return src_j_width;
00214 case VIL3D_SLICE_FORMAT_JK: return src_i_width;
00215 case VIL3D_SLICE_FORMAT_KJ: return src_i_width;
00216 default: assert(!"invalid slice_format");
00217 }
00218 return 0.0;
00219 }
00220
00221
00222 #endif // vil3d_slice_h_