contrib/mul/vimt/vimt_image.h
Go to the documentation of this file.
00001 // This is mul/vimt/vimt_image.h
00002 #ifndef vimt_image_h_
00003 #define vimt_image_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief A base class for images of any dimension and type
00010 // \author Tim Cootes
00011 
00012 #include <vcl_string.h>
00013 #include <vcl_iosfwd.h>
00014 #include <vcl_vector.h>
00015 #include <vsl/vsl_fwd.h>
00016 
00017 //: A base class for images of any dimension and type
00018 //  Derived classes tend to have world to image transformations
00019 //  attached to them, and to be able to act as `views' of
00020 //  external data.
00021 class vimt_image
00022 {
00023   //: Shallow equality tester.
00024   //  The parameter must be identical type to this.
00025   virtual bool equals(const vimt_image &) const =0;
00026 
00027  public:
00028     //: Dflt ctor
00029   vimt_image() {}
00030 
00031     //: Destructor
00032   virtual ~vimt_image() {}
00033 
00034     //: Return dimensionality of image
00035   virtual unsigned n_dims() const = 0;
00036 
00037     //: Return number of planes in images.
00038   virtual unsigned n_planes() const = 0;
00039 
00040     //: Return vector indicating size of image in pixels
00041     //  2D image is v[0] x v[1],  3D image is v[0] x v[1] x v[2]
00042     //  Somewhat inefficient: Only use when you absolutely have to.
00043     //  Usually one only needs to know the size once one knows the exact type.
00044   virtual vcl_vector<unsigned> image_size() const = 0;
00045 
00046     //: Return vectors defining bounding box containing image in world co-ords
00047     //  Somewhat inefficient: Only use when you absolutely have to.
00048     //  Usually one only needs to know the size once one knows the exact type.
00049   virtual void world_bounds(vcl_vector<double>& b_lo,
00050                             vcl_vector<double>& b_hi) const = 0;
00051 
00052 
00053     //: Return vector indicating the size of a pixel
00054     //  2D image is v[0] x v[1],  3D image is v[0] x v[1] x v[2]
00055   virtual vcl_vector<double> pixel_size() const = 0;
00056 
00057     //: Version number for I/O
00058   short version_no() const;
00059 
00060     //: Name of the class
00061   virtual vcl_string is_a() const = 0;
00062 
00063     //: Does the name of the class match the argument?
00064   virtual bool is_class(vcl_string const&) const = 0;
00065 
00066     //: Create a copy on the heap and return base class pointer
00067     //  Note that this will make a shallow copy of any contained images
00068   virtual vimt_image* clone() const = 0;
00069 
00070     //: Create a deep copy on the heap and return base class pointer
00071     //  This will make a deep copy of any contained images
00072   virtual vimt_image* deep_clone() const = 0;
00073 
00074     //: Shallow equality.
00075     // tests if the two images are the same type, have equal transforms, and point
00076     // to the same image data with equal step sizes, etc.
00077   bool operator==(const vimt_image &) const;
00078 
00079     //: Print class to os
00080   virtual void print_summary(vcl_ostream& os) const = 0;
00081 
00082     //: Print whole image to os
00083   virtual void print_all(vcl_ostream& os) const = 0;
00084 
00085     //: Save class to binary file stream
00086   virtual void b_write(vsl_b_ostream& bfs) const = 0;
00087 
00088     //: Load class from binary file stream
00089   virtual void b_read(vsl_b_istream& bfs) = 0;
00090 };
00091 
00092 //: Allows derived class to be loaded by base-class pointer
00093 //  A loader object exists which is invoked by calls
00094 //  of the form "vsl_b_read(bfs,base_ptr);".  This loads derived class
00095 //  objects from the disk, places them on the heap and
00096 //  returns a base class pointer.
00097 //  In order to work the loader object requires
00098 //  an instance of each derived class that might be
00099 //  found.  This function gives the model class to
00100 //  the appropriate loader.
00101 void vsl_add_to_binary_loader(const vimt_image& b);
00102 
00103 //: Binary file stream output operator for class reference
00104 void vsl_b_write(vsl_b_ostream& bfs, const vimt_image& b);
00105 
00106 //: Binary file stream input operator for class reference
00107 void vsl_b_read(vsl_b_istream& bfs, vimt_image& b);
00108 
00109 //: Stream output operator for class reference
00110 vcl_ostream& operator<<(vcl_ostream& os,const vimt_image& b);
00111 
00112 //: Stream output operator for class pointer
00113 vcl_ostream& operator<<(vcl_ostream& os,const vimt_image* b);
00114 
00115 //: Print class to os
00116 void vsl_print_summary(vcl_ostream& os, const vimt_image& im);
00117 
00118 #endif // vimt_image_h_