contrib/mul/vimt/vimt_image_2d_of.h
Go to the documentation of this file.
00001 // This is mul/vimt/vimt_image_2d_of.h
00002 #ifndef vimt_image_2d_of_h_
00003 #define vimt_image_2d_of_h_
00004 //:
00005 // \file
00006 // \brief Container for vil_image_view<T> + transform
00007 // \author Tim Cootes
00008 
00009 #include <vimt/vimt_image_2d.h>
00010 #include <vil/vil_image_view.h>
00011 #include <vcl_iosfwd.h>
00012 
00013 //: Represent 2D image of type T together with a transform.
00014 //  Each plane is ni() x nj() Ts, with the (x,y) element
00015 //  of the i'th plane accessible using im.plane(i)[x*im.istep() + y*im.jstep()]
00016 template<class T>
00017 class vimt_image_2d_of : public vimt_image_2d
00018 {
00019   vil_image_view<T> image_;
00020 
00021   //: Shallow equality tester.
00022   //  The parameter must be identical type to this.
00023   bool equals(const vimt_image &) const;
00024 
00025 public:
00026 
00027   //: Default constructor
00028   //  Creates an empty one-plane image.
00029   vimt_image_2d_of() {}
00030 
00031 
00032   //: Construct an image of size (ni, nj, np) with optional world_to_image transform.
00033   vimt_image_2d_of(unsigned ni, unsigned nj, unsigned np=1,
00034                    const vimt_transform_2d& w2i=vimt_transform_2d())
00035     : vimt_image_2d(w2i), image_(ni, nj, np) {}
00036 
00037 
00038   //: Construct from a view and optional world-to-image transform (takes copies of both).
00039   explicit vimt_image_2d_of(const vil_image_view<T>& view, 
00040                    const vimt_transform_2d& w2i=vimt_transform_2d())
00041     : vimt_image_2d(w2i), image_(view) {}
00042 
00043   
00044   //: Destructor
00045   virtual ~vimt_image_2d_of() {}
00046 
00047   //: Baseclass view of image
00048   virtual const vil_image_view_base& image_base() const { return image_; }
00049 
00050   //: Image view
00051   vil_image_view<T>& image() { return image_; }
00052 
00053   //: Image view
00054   const vil_image_view<T>& image() const { return image_; }
00055 
00056   //: True if transforms are equal, and they share same image data.
00057   //  This does not do a deep equality on image data. If the images point
00058   //  to different image data objects that contain identical images, then
00059   //  the result will still be false.
00060   bool operator==(const vimt_image_2d_of<T> &) const;
00061 
00062   //: Define valid data region (including transform).
00063   //  Resizes and sets the transformation so that
00064   //  world2im(x,y) is valid for all points in range
00065   //  Specifically, set_valid_region(x0,nx,y0,ny);
00066   //  world2im() translates by (-x0,-y0)
00067   void set_valid_region(int x0, unsigned nx, int y0, unsigned ny);
00068 
00069   //: Get the number of planes in the image.
00070   unsigned n_planes() const {return image_.nplanes();}
00071 
00072   //: Take a deep copy of image (copy data, not just pointers)
00073   void deep_copy(const vimt_image_2d_of& image);
00074 
00075   //: Version number for I/O
00076   short version_no() const;
00077 
00078   //: Name of the class
00079   virtual vcl_string is_a() const;
00080 
00081   //: Does the name of the class match the argument?
00082   virtual bool is_class(vcl_string const& s) const;
00083 
00084     //: Create a copy on the heap and return base class pointer
00085     //  Note that this will make a shallow copy of any contained images
00086   virtual vimt_image* clone() const { return new vimt_image_2d_of(*this); }
00087 
00088     //: Create a deep copy on the heap and return base class pointer
00089     //  This will make a deep copy of any contained images
00090   virtual vimt_image* deep_clone() const;
00091 
00092   //: Print class to os
00093   virtual void print_summary(vcl_ostream& os) const;
00094 
00095   //: print all data to os (rounds output to int)
00096   virtual void print_all(vcl_ostream& os) const;
00097 
00098   //: Save class to binary file stream
00099   virtual void b_write(vsl_b_ostream& bfs) const;
00100 
00101   //: Load class from binary file stream
00102   virtual void b_read(vsl_b_istream& bfs);
00103 };
00104 
00105 #endif // vimt_image_2d_of_h_