00001 // This is mul/vil3d/vil3d_image_resource.h 00002 #ifndef vil3d_image_resource_h_ 00003 #define vil3d_image_resource_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Representation of a generic image source or destination. 00010 // 00011 // \author Ian Scott 00012 // \date 2 Mar 2003 00013 00014 #include <vil3d/vil3d_image_view_base.h> 00015 #include <vcl_cassert.h> 00016 #include <vil/vil_smart_ptr.h> 00017 #include <vil/vil_pixel_format.h> 00018 00019 //: 00020 // Abstract representation of an image source or image destination. 00021 // Most references to vil3d_image_resource objects should usually be done 00022 // through smart pointers - vil3d_image_resource_sptr; 00023 // 00024 // All image data is presumed to be in planes, not components. This 00025 // does not say whether the data is stored on disk or in memory 00026 // as RGBRGBRGB.. or RRR..GGG..BBB.., just that the interface will 00027 // always tell you that it has a multi-plane single-component view. 00028 class vil3d_image_resource 00029 { 00030 public: 00031 vil3d_image_resource(): reference_count_(0) {} 00032 virtual ~vil3d_image_resource() {} 00033 00034 //: Dimensions: Planes x ni x nj. 00035 // This concept is treated as a synonym to components. 00036 virtual unsigned nplanes() const = 0; 00037 //: Dimensions: Planes x ni x nj x nk. 00038 // The number of pixels in each row. 00039 virtual unsigned ni() const = 0; 00040 //: Dimensions: Planes x ni x nj x nk. 00041 // The number of pixels in each column. 00042 virtual unsigned nj() const = 0; 00043 //: Dimensions: Planes x ni x nj x nk. 00044 // The number of pixels in each column. 00045 virtual unsigned nk() const = 0; 00046 00047 //: Pixel Format. 00048 // pixel_format() == VIL_PIXEL_FORMAT_BYTE 00049 virtual enum vil_pixel_format pixel_format() const = 0; 00050 00051 //: Create a read/write view of the data. 00052 // Modifying this view might modify the actual data. 00053 // If you want to modify this data in place, call put_view after you done, and 00054 // it should work efficiently. This function will always return a 00055 // multi-plane scalar-pixel view of the data. 00056 // \return 0 if unable to get view of correct size, or if resource is write-only. 00057 // 00058 // If you want to fill an existing view (e.g. a window onto some other image), 00059 // then use 00060 // \code 00061 // vil3d_reformat(data->get_view(..), window); 00062 //\endcode 00063 virtual vil3d_image_view_base_sptr get_view(unsigned i0, unsigned ni, 00064 unsigned j0, unsigned nj, 00065 unsigned k0, unsigned nk) const 00066 { return get_copy_view (i0, ni, j0, nj, k0, nk); } 00067 00068 //: Create a read/write view of all the data. 00069 vil3d_image_view_base_sptr get_view() const 00070 { return get_view (0, ni(), 0, nj(), 0, nk()); } 00071 00072 00073 //: Set the size of the each voxel in the i,j,k directions. 00074 // You can get the voxel sizes via get_properties(). 00075 // \return false if underlying image doesn't store pixel sizes. 00076 virtual bool set_voxel_size(float/*i*/,float/*j*/,float/*k*/) {return false;} 00077 00078 //: Create a read/write view of a copy of this data. 00079 // This function will always return a 00080 // multi-plane scalar-pixel view of the data. 00081 // \return 0 if unable to get view of correct size, or if resource is write-only. 00082 virtual vil3d_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni, 00083 unsigned j0, unsigned nj, 00084 unsigned k0, unsigned nk) const = 0; 00085 00086 //: Put the data in this view back into the image source. 00087 // The view must be of scalar components. Assign your 00088 // view to a scalar-component view if this is not the case. 00089 // \return false if failed, because e.g. resource is read-only, 00090 // format of view is not correct (if it is a compound pixel type, try 00091 // assigning it to a multi-plane scalar pixel view.) 00092 virtual bool put_view(const vil3d_image_view_base& im, 00093 unsigned i0=0, unsigned j0=0, unsigned k0=0) = 0; 00094 00095 //: Check that a view will fit into the data at the given offset. 00096 // This includes checking that the pixel type is scalar. 00097 virtual bool view_fits(const vil3d_image_view_base& im, 00098 unsigned i0, unsigned j0, unsigned k0) 00099 { 00100 return (i0 + im.ni() <= ni() && j0 + im.nj() <= nj() && 00101 k0 + im.nk() <= nk() && im.nplanes() == nplanes() && 00102 vil_pixel_format_num_components(im.pixel_format()) == 1); 00103 } 00104 00105 //: Return a string describing the file format. 00106 // Only file images have a format, others return 0 00107 virtual char const* file_format() const { return 0; } 00108 00109 //: Extra property information 00110 virtual bool get_property(char const* label, void* property_value = 0) const =0; 00111 00112 private: 00113 // You probably should not use a vil3d_image_resource in a vbl_smart_ptr, so the 00114 // ref functions are private 00115 friend class vil_smart_ptr<vil3d_image_resource>; 00116 void ref() { ++reference_count_; } 00117 void unref() { 00118 assert(reference_count_>0); 00119 if (--reference_count_<=0) delete this;} 00120 int reference_count_; 00121 }; 00122 00123 //: Use this type to refer to and store a vil3d_image_resource 00124 // This object is used to provide safe manipulation of 00125 // vil3d_image_resource derivatives. If you want to 00126 // store an image resource (e.g. an image on disk, type-agnostic 00127 // memory image), then use this type. 00128 typedef vil_smart_ptr<vil3d_image_resource> vil3d_image_resource_sptr; 00129 00130 #endif // vil3d_image_resource_h_