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