00001 #ifndef vimt3d_image_3d_h_ 00002 #define vimt3d_image_3d_h_ 00003 //: 00004 // \file 00005 // \brief A base class for arbitrary 3D images+transform 00006 // \author Tim Cootes 00007 00008 #include <vgl/vgl_box_3d.h> 00009 #include <vimt/vimt_image.h> 00010 #include <vimt3d/vimt3d_transform_3d.h> 00011 #include <vil3d/vil3d_image_view_base.h> 00012 00013 //: A base class for arbitrary 3D images 00014 // world2im() gives transformation from world to image co-ordinates 00015 class vimt3d_image_3d : public vimt_image 00016 { 00017 protected: 00018 vimt3d_transform_3d world2im_; 00019 00020 vimt3d_image_3d(const vimt3d_transform_3d& w2i) : world2im_(w2i) {} 00021 00022 public: 00023 //: Dflt ctor 00024 vimt3d_image_3d() {} 00025 00026 //: Destructor 00027 virtual ~vimt3d_image_3d() {} 00028 00029 //: Return dimensionality of image 00030 virtual unsigned n_dims() const { return 3; } 00031 00032 //: Return 3 element vector indicating size of image in pixels 00033 // 3D image is v[0] x v[1] x v[2] 00034 // Somewhat inefficient: Only use when you absolutely have to. 00035 // Usually one only needs to know the size once one knows the exact type. 00036 virtual vcl_vector<unsigned> image_size() const; 00037 00038 //: Return 3D vectors defining bounding box containing image in world co-ords 00039 // Somewhat inefficient: Only use when you absolutely have to. 00040 // Usually one only needs to know the size once one knows the exact type. 00041 virtual void world_bounds(vcl_vector<double>& b_lo, 00042 vcl_vector<double>& b_hi) const; 00043 00044 //: Return 3 element vector indicating the size of a pixel 00045 // Somewhat inefficient: Only use when you absolutely have to. 00046 // Usually one only needs to know the size once one knows the exact type. 00047 virtual vcl_vector<double> pixel_size() const; 00048 00049 //: Current world-to-image transformation 00050 const vimt3d_transform_3d& world2im() const { return world2im_; } 00051 00052 //: Current world-to-image transformation 00053 vimt3d_transform_3d& world2im() { return world2im_; } 00054 00055 //: Set world-to-image transformation 00056 // \deprecated in favour of non-const world2im() 00057 void set_world2im(const vimt3d_transform_3d& w2i) { world2im_ = w2i ;} 00058 00059 //: Baseclass view of image 00060 virtual const vil3d_image_view_base& image_base() const = 0; 00061 00062 //: Name of the class 00063 virtual vcl_string is_a() const { return "vimt3d_image_3d"; } 00064 00065 //: Does the name of the class match the argument? 00066 virtual bool is_class(vcl_string const& s) const 00067 { return s=="vimt3d_image_3d" || vimt_image::is_class(s); } 00068 }; 00069 00070 // Related Functions 00071 00072 //: Return bounding box containing input image in world co-ords, but more conveniently as a box 00073 // This may be more convenient than the similar class method in generic vector form, 00074 // as the latter is for a general number of dimensions 00075 vgl_box_3d<double> world_bounding_box(const vimt3d_image_3d& img); 00076 00077 00078 //: Translate the image transform so that the image centre is at the world origin. 00079 void vimt3d_centre_image_at_origin(vimt3d_image_3d& image); 00080 00081 00082 //: Calculate the voxel dimensions from the image transform 00083 vgl_vector_3d<double> vimt3d_voxel_size_from_transform(const vimt3d_image_3d& image); 00084 00085 00086 #endif // vimt3d_image_3d_h_