1 // This is mul/vimt3d/vimt3d_image_3d_of.h 2 3 #ifndef vimt3d_image_3d_of_h_ 4 #define vimt3d_image_3d_of_h_ 5 6 //: 7 // \file 8 // \brief Container for vil3d_image_view<T> + transform 9 // \author Tim Cootes 10 11 12 #include <iostream> 13 #include <iosfwd> 14 #include <vimt3d/vimt3d_image_3d.h> 15 #include <vil3d/vil3d_image_view.h> 16 #ifdef _MSC_VER 17 # include <vcl_msvc_warnings.h> 18 #endif 19 20 21 //: Represent 3D image of type T together with a transform. 22 // Each plane is ni() x nj() Ts, with the (x,y) element 23 // of the i'th plane accessible using im.plane(i)[x*im.istep() + y*im.jstep()] 24 template<class T> 25 class vimt3d_image_3d_of : public vimt3d_image_3d 26 { 27 private: 28 29 vil3d_image_view<T> image_; 30 31 //: Shallow equality tester. 32 // The parameter must be identical type to this. 33 bool equals(const vimt_image &) const override; 34 35 36 public: 37 38 //: Construct an empty one-plane image. 39 vimt3d_image_3d_of() = default; 40 41 42 //: Construct an image of size (ni, nj, nk, np) with optional world_to_image transform w2i. 43 vimt3d_image_3d_of(unsigned ni, unsigned nj, unsigned nk, unsigned np=1, 44 const vimt3d_transform_3d& w2i=vimt3d_transform_3d()) vimt3d_image_3d(w2i)45 : vimt3d_image_3d(w2i), image_(ni, nj, nk, np) {} 46 47 48 //: Construct from a view and a world-to-image transform. 49 // The underlying pixel data is not duplicated. vimt3d_image_3d_of(const vil3d_image_view<T> & view,const vimt3d_transform_3d & w2i)50 vimt3d_image_3d_of(const vil3d_image_view<T>& view, 51 const vimt3d_transform_3d& w2i) 52 : vimt3d_image_3d(w2i), image_(view) {} 53 54 55 //: Destructor 56 ~vimt3d_image_3d_of() override = default; 57 58 //: Base class view of image image_base()59 const vil3d_image_view_base& image_base() const override { return image_; } 60 61 //: Image view image()62 vil3d_image_view<T>& image() { return image_; } 63 64 //: Image view image()65 const vil3d_image_view<T>& image() const { return image_; } 66 67 //: Get the number of planes in the image. n_planes()68 unsigned n_planes() const override {return image_.nplanes();} 69 70 71 //: True if transforms are equal, and they share same image data. 72 // This does not do a deep equality on image data. If the images point 73 // to different image data objects that contain identical images, then 74 // the result will still be false. 75 bool operator==(const vimt3d_image_3d_of<T> &) const; 76 77 //: Define valid data region (including transform). 78 // Resizes and sets the transformation so that 79 // world2im(x,y) is valid for all points in range 80 // Specifically, set_valid_region(i0,ni,j0,nj,k0,nk); 81 // world2im() translates by (-i0,-j0,-k0) 82 void set_valid_region(int i0, unsigned ni, int j0, unsigned nj, 83 int k0, unsigned nk); 84 85 //: Take a deep copy of image (copy data, not just pointers) 86 void deep_copy(const vimt3d_image_3d_of& image); 87 88 //: Version number for I/O 89 short version_no() const; 90 91 //: Name of the class 92 std::string is_a() const override; 93 94 //: Does the name of the class match the argument? 95 bool is_class(std::string const& s) const override; 96 97 //: Create a copy on the heap and return base class pointer 98 // Note that this will make a shallow copy of any contained images clone()99 vimt_image* clone() const override { return new vimt3d_image_3d_of(*this); } 100 101 //: Create a deep copy on the heap and return base class pointer 102 // This will make a deep copy of any contained images 103 vimt_image* deep_clone() const override; 104 105 //: Print class to os 106 void print_summary(std::ostream& os) const override; 107 108 //: print all data to os (rounds output to int) 109 void print_all(std::ostream& os) const override; 110 111 //: Save class to binary file stream 112 void b_write(vsl_b_ostream& bfs) const override; 113 114 //: Load class from binary file stream 115 void b_read(vsl_b_istream& bfs) override; 116 }; 117 118 119 //======================================================================= 120 //: True if the transforms and the actual image data are identical. 121 // The image pointers need not be identical, 122 // provided that the underlying image data are the same. 123 // \relatesalso vimt3d_image_3d_of<T> 124 // \relatesalso vil3d_image_view 125 template<class T> 126 bool vimt3d_image_3d_deep_equality(const vimt3d_image_3d_of<T>& lhs, 127 const vimt3d_image_3d_of<T>& rhs); 128 129 130 #endif // vimt3d_image_3d_of_h_ 131