contrib/mul/vimt3d/vimt3d_slice.h
Go to the documentation of this file.
00001 // This is mul/vimt3d/vimt3d_slice.h
00002 #ifndef vimt3d_slice_h_
00003 #define vimt3d_slice_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Chris Wolstenholme
00010 
00011 #include <vil/vil_image_view.h>
00012 #include <vil3d/vil3d_slice.h>
00013 #include <vimt/vimt_image_2d_of.h>
00014 #include <vimt3d/vimt3d_image_3d_of.h>
00015 #include <vimt3d/vimt3d_transform_3d.h>
00016 #include <vimt/vimt_transform_2d.h>
00017 #include <vcl_cassert.h>
00018 
00019 //: Return a 2D view of slice k of 3D image aligned as (j,i).
00020 //  result(x,y,p)=im(y,x,k,p)
00021 // \relatesalso vil3d_image_view
00022 // \relatesalso vil_image_view
00023 template<class T>
00024 inline vimt_image_2d_of<T> vimt3d_slice_ji(const vimt3d_image_3d_of<T> &im, unsigned k)
00025 {
00026   // Check the slice is in range
00027   assert(k<im.image().nk());
00028 
00029   // Get the 2d view
00030   vil_image_view<T> imview = vil3d_slice_ji(im.image(),k);
00031 
00032   // Check the transform
00033   vimt3d_transform_3d trans3 = im.world2im();
00034   assert(trans3.is_identity() || 
00035          trans3.form()==vimt3d_transform_3d::Translation || 
00036          trans3.form()==vimt3d_transform_3d::ZoomOnly);
00037 
00038   // Get the appropriate transform details
00039   vimt_transform_2d trans2;
00040   trans2.set_zoom_only(trans3.matrix()(1,1),trans3.matrix()(0,0),trans3.matrix()(1,3),trans3.matrix()(0,3));
00041 
00042   return vimt_image_2d_of<T>(imview,trans2);
00043 }
00044 
00045 //: Return a 2D view of slice k of 3D image aligned as (i,j)
00046 //  result(x,y,p)=im(x,y,k,p)
00047 // \relatesalso vil3d_image_view
00048 // \relatesalso vil_image_view
00049 template<class T>
00050 inline vimt_image_2d_of<T> vimt3d_slice_ij(const vimt3d_image_3d_of<T> &im, unsigned k)
00051 {
00052   // Check the slice is in range
00053   assert(k<im.image().nk());
00054 
00055   // Get the 2d view
00056   vil_image_view<T> imview = vil3d_slice_ij(im.image(),k);
00057 
00058   // Check the transform
00059   vimt3d_transform_3d trans3 = im.world2im();
00060   assert(trans3.is_identity() || 
00061          trans3.form()==vimt3d_transform_3d::Translation || 
00062          trans3.form()==vimt3d_transform_3d::ZoomOnly);
00063 
00064   // Get the appropriate transform details
00065   vimt_transform_2d trans2;
00066   trans2.set_zoom_only(trans3.matrix()(0,0),trans3.matrix()(1,1),trans3.matrix()(0,3),trans3.matrix()(1,3));
00067 
00068   return vimt_image_2d_of<T>(imview,trans2);
00069 }
00070 
00071 //: Return a 2D view of slice i of 3D image aligned as (j,k)
00072 //  result(x,y,p)=im(i,x,y,p)
00073 // \relatesalso vil3d_image_view
00074 // \relatesalso vil_image_view
00075 template<class T>
00076 inline vimt_image_2d_of<T> vimt3d_slice_jk(const vimt3d_image_3d_of<T> &im, unsigned i)
00077 {
00078   // Check the slice is in range
00079   assert(i<im.image().ni());
00080 
00081   // Get the 2d view
00082   vil_image_view<T> imview = vil3d_slice_jk(im.image(),i);
00083 
00084   // Check the transform
00085   vimt3d_transform_3d trans3 = im.world2im();
00086   assert(trans3.is_identity() || 
00087          trans3.form()==vimt3d_transform_3d::Translation || 
00088          trans3.form()==vimt3d_transform_3d::ZoomOnly);
00089 
00090   // Get the appropriate transform details
00091   vimt_transform_2d trans2;
00092   trans2.set_zoom_only(trans3.matrix()(1,1),trans3.matrix()(2,2),trans3.matrix()(1,3),trans3.matrix()(2,3));
00093 
00094   return vimt_image_2d_of<T>(imview,trans2);
00095 }
00096 
00097 //: Return a 2D view of slice i of 3D image aligned as (k,j)
00098 //  result(x,y,p)=im(i,y,x,p)
00099 // \relatesalso vil3d_image_view
00100 // \relatesalso vil_image_view
00101 template<class T>
00102 inline vimt_image_2d_of<T> vimt3d_slice_kj(const vimt3d_image_3d_of<T> &im, unsigned i)
00103 {
00104   // Check the slice is in range
00105   assert(i<im.image().ni());
00106 
00107   // Get the 2d view
00108   vil_image_view<T> imview = vil3d_slice_kj(im.image(),i);
00109  
00110   // Check the transform
00111   vimt3d_transform_3d trans3 = im.world2im();
00112   assert(trans3.is_identity() || 
00113          trans3.form()==vimt3d_transform_3d::Translation || 
00114          trans3.form()==vimt3d_transform_3d::ZoomOnly);
00115 
00116   // Get the appropriate transform details
00117   vimt_transform_2d trans2;
00118   trans2.set_zoom_only(trans3.matrix()(2,2),trans3.matrix()(1,1),trans3.matrix()(2,3),trans3.matrix()(1,3));
00119 
00120   return vimt_image_2d_of<T>(imview,trans2);
00121 }
00122 
00123 //: Return a 2D view of slice j of 3D image aligned as (k,i)
00124 //  result(x,y,p)=im(y,i,x,p)
00125 // \relatesalso vil3d_image_view
00126 // \relatesalso vil_image_view
00127 template<class T>
00128 inline vimt_image_2d_of<T> vimt3d_slice_ki(const vimt3d_image_3d_of<T> &im, unsigned j)
00129 {
00130   // Check the slice is in range
00131   assert(j<im.image().nj());
00132 
00133   // Get the 2d view
00134   vil_image_view<T> imview = vil3d_slice_ki(im.image(),j);
00135 
00136   // Check the transform
00137   vimt3d_transform_3d trans3 = im.world2im();
00138   assert(trans3.is_identity() || 
00139          trans3.form()==vimt3d_transform_3d::Translation || 
00140          trans3.form()==vimt3d_transform_3d::ZoomOnly);
00141 
00142   // Get the appropriate transform details
00143   vimt_transform_2d trans2;
00144   trans2.set_zoom_only(trans3.matrix()(2,2),trans3.matrix()(0,0),trans3.matrix()(2,3),trans3.matrix()(0,3));
00145 
00146   return vimt_image_2d_of<T>(imview,trans2);
00147 }
00148 
00149 //: Return a 2D view of slice j of 3D image aligned as (i,k)
00150 //  result(x,y,p)=im(x,i,y,p)
00151 // \relatesalso vil3d_image_view
00152 // \relatesalso vil_image_view
00153 template<class T>
00154 inline vimt_image_2d_of<T> vimt3d_slice_ik(const vimt3d_image_3d_of<T> &im, unsigned j)
00155 { 
00156   // Check the slice is in range
00157   assert(j<im.image().nj());
00158 
00159   // Get the 2d view
00160   vil_image_view<T> imview = vil3d_slice_ik(im.image(),j);
00161 
00162   // Check the transform
00163   vimt3d_transform_3d trans3 = im.world2im();
00164   assert(trans3.is_identity() || 
00165          trans3.form()==vimt3d_transform_3d::Translation || 
00166          trans3.form()==vimt3d_transform_3d::ZoomOnly);
00167 
00168   // Get the appropriate transform details
00169   vimt_transform_2d trans2;
00170   trans2.set_zoom_only(trans3.matrix()(0,0),trans3.matrix()(2,2),trans3.matrix()(0,3),trans3.matrix()(2,3));
00171 
00172   return vimt_image_2d_of<T>(imview,trans2);
00173 }
00174 
00175 #endif // vimt3d_slice_h_