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