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 (takes copies of both).
00045   vimt3d_image_3d_of(const vil3d_image_view<T>& view, 
00046                      const vimt3d_transform_3d& w2i)
00047     : vimt3d_image_3d(w2i), image_(view) {}
00048  
00049   
00050   //: Destructor
00051   virtual ~vimt3d_image_3d_of() {}
00052 
00053   //: Base class view of image
00054   virtual const vil3d_image_view_base& image_base() const { return image_; }
00055 
00056   //: Image view
00057   vil3d_image_view<T>& image() { return image_; }
00058 
00059   //: Image view
00060   const vil3d_image_view<T>& image() const { return image_; }
00061 
00062    //: Get the number of planes in the image.
00063    unsigned n_planes() const {return image_.nplanes();}
00064 
00065 
00066   //: True if transforms are equal, and they share same image data.
00067   //  This does not do a deep equality on image data. If the images point
00068   //  to different image data objects that contain identical images, then
00069   //  the result will still be false.
00070   bool operator==(const vimt3d_image_3d_of<T> &) const;
00071 
00072   //: Define valid data region (including transform).
00073   //  Resizes and sets the transformation so that
00074   //  world2im(x,y) is valid for all points in range
00075   //  Specifically, set_valid_region(i0,ni,j0,nj,k0,nk);
00076   //  world2im() translates by (-i0,-j0,-k0)
00077   void set_valid_region(int i0, unsigned ni, int j0, unsigned nj,
00078                         int k0, unsigned nk);
00079 
00080   //: Take a deep copy of image (copy data, not just pointers)
00081   void deep_copy(const vimt3d_image_3d_of& image);
00082 
00083   //: Version number for I/O
00084   short version_no() const;
00085 
00086   //: Name of the class
00087   virtual vcl_string is_a() const;
00088 
00089   //: Does the name of the class match the argument?
00090   virtual bool is_class(vcl_string const& s) const;
00091 
00092     //: Create a copy on the heap and return base class pointer
00093     //  Note that this will make a shallow copy of any contained images
00094   virtual vimt_image* clone() const { return new vimt3d_image_3d_of(*this); }
00095 
00096     //: Create a deep copy on the heap and return base class pointer
00097     //  This will make a deep copy of any contained images
00098   virtual vimt_image* deep_clone() const;
00099 
00100   //: Print class to os
00101   virtual void print_summary(vcl_ostream& os) const;
00102 
00103   //: print all data to os (rounds output to int)
00104   virtual void print_all(vcl_ostream& os) const;
00105 
00106   //: Save class to binary file stream
00107   virtual void b_write(vsl_b_ostream& bfs) const;
00108 
00109   //: Load class from binary file stream
00110   virtual void b_read(vsl_b_istream& bfs);
00111 };
00112 
00113 
00114 //=======================================================================
00115 //: True if the transforms and the actual image data are identical.
00116 // The image pointers need not be identical, 
00117 // provided that the underlying image data are the same.
00118 // \relatesalso vimt3d_image_3d_of<T>
00119 // \relatesalso vil3d_image_view
00120 template<class T>
00121 bool vimt3d_image_3d_deep_equality(const vimt3d_image_3d_of<T>& lhs,
00122                                    const vimt3d_image_3d_of<T>& rhs);
00123 
00124 
00125 #endif // vimt3d_image_3d_of_h_