00001
00002 #ifndef vil3d_image_view_h_
00003 #define vil3d_image_view_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012 #include <vcl_iosfwd.h>
00013 #include <vcl_string.h>
00014 #include <vcl_cassert.h>
00015 #include <vcl_cstddef.h>
00016 #include <vil3d/vil3d_image_view_base.h>
00017 #include <vil/vil_memory_chunk.h>
00018 #include <vil/vil_pixel_format.h>
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 template <class T>
00035 class vil3d_image_view : public vil3d_image_view_base
00036 {
00037 private:
00038 VCL_SAFE_BOOL_DEFINE;
00039 protected:
00040
00041 T * top_left_;
00042
00043 vcl_ptrdiff_t istep_;
00044
00045 vcl_ptrdiff_t jstep_;
00046
00047 vcl_ptrdiff_t kstep_;
00048
00049 vcl_ptrdiff_t planestep_;
00050
00051
00052 vil_memory_chunk_sptr ptr_;
00053
00054
00055 void release_memory() { ptr_ = 0; }
00056
00057 public:
00058
00059
00060
00061 vil3d_image_view();
00062
00063
00064 vil3d_image_view(unsigned ni, unsigned nj, unsigned nk, unsigned n_planes=1);
00065
00066
00067
00068
00069 vil3d_image_view(const T* top_left,
00070 unsigned ni, unsigned nj, unsigned nk, unsigned nplanes,
00071 vcl_ptrdiff_t i_step, vcl_ptrdiff_t j_step,
00072 vcl_ptrdiff_t k_step, vcl_ptrdiff_t plane_step);
00073
00074
00075
00076
00077
00078 vil3d_image_view(const vil_memory_chunk_sptr& mem_chunk,
00079 const T* top_left,
00080 unsigned ni, unsigned nj, unsigned nk, unsigned nplanes,
00081 vcl_ptrdiff_t i_step, vcl_ptrdiff_t j_step,
00082 vcl_ptrdiff_t k_step, vcl_ptrdiff_t plane_step);
00083
00084
00085
00086 vil3d_image_view(const vil3d_image_view<T>& rhs);
00087
00088
00089
00090 vil3d_image_view(const vil3d_image_view_base& base_ref);
00091
00092
00093
00094 vil3d_image_view(const vil3d_image_view_base_sptr& base_sptr);
00095
00096
00097 const vil3d_image_view<T>& operator=(const vil3d_image_view<T>& rhs);
00098
00099
00100
00101
00102 const vil3d_image_view& operator=(const vil3d_image_view_base& base_ref);
00103
00104
00105
00106
00107 inline const vil3d_image_view<T>& operator=(const vil3d_image_view_base_sptr& rhs)
00108 {
00109 if (!rhs) clear();
00110 else *this = *rhs;
00111 return *this;
00112 }
00113
00114
00115 virtual ~vil3d_image_view();
00116
00117
00118
00119
00120
00121
00122 typedef T pixel_type;
00123
00124
00125 bool is_contiguous() const;
00126
00127
00128 typedef T *iterator;
00129 inline iterator begin() { assert(is_contiguous()); return top_left_; }
00130 inline iterator end () { assert(is_contiguous()); return top_left_ + size(); }
00131
00132 typedef T const *const_iterator;
00133 inline const_iterator begin() const { assert(is_contiguous()); return top_left_; }
00134 inline const_iterator end () const { assert(is_contiguous()); return top_left_ + size(); }
00135
00136
00137
00138
00139
00140 inline T * origin_ptr() { return top_left_; }
00141
00142
00143 inline const T * origin_ptr() const { return top_left_; }
00144
00145
00146
00147 inline vcl_ptrdiff_t istep() const { return istep_; }
00148
00149
00150 inline vcl_ptrdiff_t jstep() const { return jstep_; }
00151
00152
00153 inline vcl_ptrdiff_t kstep() const { return kstep_; }
00154
00155
00156 inline vcl_ptrdiff_t planestep() const { return planestep_; }
00157
00158
00159 operator safe_bool () const
00160 { return (top_left_ != (T*)0)? VCL_SAFE_BOOL_TRUE : 0; }
00161
00162
00163 bool operator!() const
00164 { return (top_left_ != (T*)0)? false : true; }
00165
00166
00167 inline vcl_size_t size_bytes() const { return size() * sizeof(T); }
00168
00169
00170
00171
00172
00173
00174 inline const vil_memory_chunk_sptr& memory_chunk() const { return ptr_; }
00175
00176
00177
00178
00179
00180
00181 inline vil_memory_chunk_sptr& memory_chunk() { return ptr_; }
00182
00183
00184
00185
00186 inline const T& operator()(unsigned i, unsigned j, unsigned k) const {
00187 assert(i<ni_); assert(j<nj_); assert(k<nk_);
00188 return top_left_[kstep_*k+jstep_*j+i*istep_]; }
00189
00190
00191 inline T& operator()(unsigned i, unsigned j, unsigned k) {
00192 assert(i<ni_); assert(j<nj_); assert(k<nk_);
00193 return top_left_[istep_*i+j*jstep_+kstep_*k]; }
00194
00195
00196 inline const T& operator()(unsigned i, unsigned j, unsigned k, unsigned p) const {
00197 assert(i<ni_); assert(j<nj_); assert(k<nk_); assert(p<nplanes_);
00198 return top_left_[p*planestep_ + kstep_*k + j*jstep_ + i*istep_]; }
00199
00200
00201 inline T& operator()(unsigned i, unsigned j, unsigned k, unsigned p) {
00202 assert(i<ni_); assert(j<nj_); assert(k<nk_); assert(p<nplanes_);
00203 return top_left_[p*planestep_ + kstep_*k + j*jstep_ + i*istep_]; }
00204
00205
00206
00207
00208
00209 virtual void set_size(unsigned ni, unsigned nj, unsigned nk);
00210
00211
00212
00213 virtual void set_size(unsigned ni, unsigned nj, unsigned nk, unsigned nplanes);
00214
00215
00216 void deep_copy(const vil3d_image_view<T>& src);
00217
00218
00219
00220 inline void clear() { release_memory(); ni_=nj_=nk_=nplanes_=0; top_left_=0; }
00221
00222
00223
00224
00225
00226
00227
00228 void set_to_memory(const T* top_left,
00229 unsigned ni, unsigned nj, unsigned nk, unsigned nplanes,
00230 vcl_ptrdiff_t i_step, vcl_ptrdiff_t j_step,
00231 vcl_ptrdiff_t k_step, vcl_ptrdiff_t plane_step);
00232
00233
00234 void fill(T value);
00235
00236
00237 virtual void print(vcl_ostream&) const;
00238
00239
00240 virtual vcl_string is_a() const;
00241
00242
00243 virtual bool is_class(vcl_string const& s) const;
00244
00245
00246
00247 inline vil_pixel_format pixel_format() const { return vil_pixel_format_of(T()); }
00248
00249
00250
00251
00252
00253 bool operator==(const vil3d_image_view<T>& other) const;
00254
00255
00256
00257
00258
00259 inline bool operator!=(const vil3d_image_view<T>& rhs) const { return !operator==(rhs); }
00260
00261
00262
00263
00264
00265 bool operator<(const vil3d_image_view<T>& other) const;
00266
00267
00268 inline bool operator>=(const vil3d_image_view<T>& other) const { return !operator<(other); }
00269
00270
00271 inline bool operator>(const vil3d_image_view<T>& other) const { return other<(*this); }
00272
00273
00274 inline bool operator<=(const vil3d_image_view<T>& other) const { return !operator>(other); }
00275 };
00276
00277
00278 template <class T>
00279 inline
00280 vcl_ostream& operator<<(vcl_ostream& s, vil3d_image_view<T> const& im)
00281 {
00282 im.print(s); return s;
00283 }
00284
00285
00286
00287
00288
00289
00290 template<class T>
00291 bool vil3d_image_view_deep_equality(const vil3d_image_view<T> &lhs,
00292 const vil3d_image_view<T> &rhs);
00293
00294 #endif // vil3d_image_view_h_