1 #ifndef vimt3d_image_3d_h_ 2 #define vimt3d_image_3d_h_ 3 //: 4 // \file 5 // \brief A base class for arbitrary 3D images+transform 6 // \author Tim Cootes 7 8 #include <vgl/vgl_box_3d.h> 9 #include <vimt/vimt_image.h> 10 #include <vimt3d/vimt3d_transform_3d.h> 11 #include <vil3d/vil3d_image_view_base.h> 12 13 //: A base class for arbitrary 3D images 14 // world2im() gives transformation from world to image co-ordinates 15 class vimt3d_image_3d : public vimt_image 16 { 17 protected: 18 vimt3d_transform_3d world2im_; 19 vimt3d_image_3d(const vimt3d_transform_3d & w2i)20 vimt3d_image_3d(const vimt3d_transform_3d& w2i) : world2im_(w2i) {} 21 22 public: 23 //: Dflt ctor 24 vimt3d_image_3d() = default; 25 26 //: Destructor 27 ~vimt3d_image_3d() override = default; 28 29 //: Return dimensionality of image n_dims()30 unsigned n_dims() const override { return 3; } 31 32 //: Return 3 element vector indicating size of image in pixels 33 // 3D image is v[0] x v[1] x v[2] 34 // Somewhat inefficient: Only use when you absolutely have to. 35 // Usually one only needs to know the size once one knows the exact type. 36 std::vector<unsigned> image_size() const override; 37 38 //: Return 3D vectors defining bounding box containing image in world co-ords 39 // Somewhat inefficient: Only use when you absolutely have to. 40 // Usually one only needs to know the size once one knows the exact type. 41 void world_bounds(std::vector<double>& b_lo, 42 std::vector<double>& b_hi) const override; 43 44 //: Return 3 element vector indicating the size of a pixel 45 // Somewhat inefficient: Only use when you absolutely have to. 46 // Usually one only needs to know the size once one knows the exact type. 47 std::vector<double> pixel_size() const override; 48 49 //: Current world-to-image transformation world2im()50 const vimt3d_transform_3d& world2im() const { return world2im_; } 51 52 //: Current world-to-image transformation world2im()53 vimt3d_transform_3d& world2im() { return world2im_; } 54 55 //: Set world-to-image transformation 56 // \deprecated in favour of non-const world2im() set_world2im(const vimt3d_transform_3d & w2i)57 void set_world2im(const vimt3d_transform_3d& w2i) { world2im_ = w2i ;} 58 59 //: Baseclass view of image 60 virtual const vil3d_image_view_base& image_base() const = 0; 61 62 //: Name of the class is_a()63 std::string is_a() const override { return "vimt3d_image_3d"; } 64 65 //: Does the name of the class match the argument? is_class(std::string const & s)66 bool is_class(std::string const& s) const override 67 { return s=="vimt3d_image_3d" || vimt_image::is_class(s); } 68 }; 69 70 // Related Functions 71 72 //: Return bounding box containing input image in world co-ords, but more conveniently as a box 73 // This may be more convenient than the similar class method in generic vector form, 74 // as the latter is for a general number of dimensions 75 vgl_box_3d<double> world_bounding_box(const vimt3d_image_3d& img); 76 77 78 //: Translate the image transform so that the image centre is at the world origin. 79 void vimt3d_centre_image_at_origin(vimt3d_image_3d& image); 80 81 82 //: Calculate the voxel dimensions from the image transform 83 vgl_vector_3d<double> vimt3d_voxel_size_from_transform(const vimt3d_image_3d& image); 84 85 86 #endif // vimt3d_image_3d_h_ 87