2 #ifndef vil_image_view_hxx_ 3 #define vil_image_view_hxx_ 30 # include <vcl_msvc_warnings.h> 40 unsigned n_interleaved_planes)
41 : top_left_(nullptr), istep_(n_interleaved_planes)
43 assert(n_planes==1 || n_interleaved_planes==1);
45 n_planes * n_interleaved_planes == 1 ||
47 set_size(n_i,n_j,n_planes*n_interleaved_planes);
53 std::ptrdiff_t i_step, std::ptrdiff_t j_step, std::ptrdiff_t plane_step)
55 set_to_memory(top_left,n_i,n_j,n_planes,i_step,j_step,plane_step);
62 const T* top_left,
unsigned n_i,
unsigned n_j,
unsigned n_planes,
63 std::ptrdiff_t i_step, std::ptrdiff_t j_step, std::ptrdiff_t plane_step)
65 , top_left_(const_cast<T*>(top_left))
66 , istep_(i_step), jstep_(j_step)
67 , planestep_(plane_step)
74 if ( mem_chunk->size() < n_planes*n_i*n_j*
sizeof(T) )
75 std::cerr <<
"mem_chunk->size()=" << mem_chunk->size() <<
'\n' 76 <<
"nplanes=" << n_planes <<
'\n' 77 <<
"n_i=" << n_i <<
'\n' 78 <<
"n_j=" << n_j <<
'\n' 79 <<
"sizeof(T)=" <<
sizeof(T) <<
'\n' 80 <<
"n_planes*n_i*n_j*sizeof(T)=" << n_planes*n_i*n_j*
sizeof(T) <<
'\n';
81 assert(mem_chunk->size() >= n_planes*n_i*n_j*
sizeof(T));
82 if (top_left < reinterpret_cast<const T*>(mem_chunk->data()) ||
83 top_left >= reinterpret_cast<const T*>(reinterpret_cast<const char*>(mem_chunk->data()) + mem_chunk->size()))
84 std::cerr <<
"top_left at " << static_cast<const void*>(top_left) <<
", memory_chunk at " 85 << reinterpret_cast<const void*>(mem_chunk->data()) <<
", size " << mem_chunk->size()
86 <<
", size of data type " <<
sizeof(T) <<
'\n';
87 assert(top_left >= reinterpret_cast<const T*>(mem_chunk->data()) &&
88 (mem_chunk->size()==0 || top_left < reinterpret_cast<const T*>(reinterpret_cast<const char*>(mem_chunk->data()) + mem_chunk->size())) );
99 top_left_(nullptr), istep_(0), jstep_(0), planestep_(0), ptr_(nullptr)
101 operator=( static_cast<vil_image_view_base const&>(that) );
109 top_left_(nullptr), istep_(0), jstep_(0), planestep_(0), ptr_(nullptr)
119 top_left_(nullptr), istep_(0), jstep_(0), planestep_(0), ptr_(nullptr)
141 while (s_it!=end_it) {*d_it = *s_it; ++s_it; ++d_it; }
145 const std::ptrdiff_t s_planestep = src.
planestep();
146 const std::ptrdiff_t s_istep = src.
istep();
147 const std::ptrdiff_t s_jstep = src.
jstep();
153 for (
unsigned int p=0;p<nplanes_;++p,src_data += s_planestep,data += planestep_)
156 const T* src_row = src_data;
157 for (
unsigned int j=0;j<nj_;++j,row += jstep_,src_row += s_jstep)
160 const T* sp = src_row;
161 for (
unsigned int i=0;i<ni_;++i,p+=istep_,sp+=s_istep) *p = *sp;
183 typedef typename T::value_type comp_type;
192 ncomp == (int)rhs_base.
nplanes() )
196 if (rhs.
planestep() != 1 || std::abs((
int)rhs.
istep())<ncomp || std::abs((
int)rhs.
jstep())<ncomp )
return false;
281 unsigned ni = rhs.
ni(), nj = rhs.
nj();
284 for (
unsigned j = 0; j<nj; ++j)
285 for (
unsigned i = 0; i<ni; ++i){
286 lhs(i,j).r = rhsv(i,j,0); lhs(i, j).g = rhsv(i,j,1); lhs(i, j).b = rhsv(i,j,2);
299 unsigned ni = rhs.
ni(), nj = rhs.
nj();
302 for (
unsigned j = 0; j<nj; ++j)
303 for (
unsigned i = 0; i<ni; ++i){
304 lhs(i, j).r = rhsv(i,j,0); lhs(i, j).g = rhsv(i,j,1); lhs(i, j).b = rhsv(i,j,2);
305 lhs(i, j).a = rhsv(i,j,3);
314 const unsigned ncomp =
326 rhs.
ni(),rhs.
nj(),ncomp,
338 const unsigned ncomp =
350 rhs.
ni(),rhs.
nj(),ncomp,
362 const unsigned ncomp =
374 rhs.
ni(),rhs.
nj(),ncomp,
386 const unsigned ncomp =
398 rhs.
ni(),rhs.
nj(),ncomp,
410 const unsigned ncomp =
422 rhs.
ni(),rhs.
nj(),ncomp,
434 const unsigned ncomp =
446 rhs.
ni(),rhs.
nj(),ncomp,
460 const unsigned ncomp =
472 rhs.
ni(),rhs.
nj(),ncomp,
484 const unsigned ncomp =
496 rhs.
ni(),rhs.
nj(),ncomp,
504 #endif // VXL_HAS_INT_64 510 const unsigned ncomp =
522 rhs.
ni(),rhs.
nj(),ncomp,
534 const unsigned ncomp =
546 rhs.
ni(),rhs.
nj(),ncomp,
558 return operator=( static_cast<vil_image_view_base const&>(rhs) );
565 if (static_cast<const vil_image_view_base*>(
this) == &rhs)
589 rhs.
pixel_format(), this->pixel_format(),
"vil_image_view::operator =") );
590 set_to_memory(
nullptr, 0, 0, 0, 0, 0, 0);
602 set_size(n_i, n_j, nplanes_);
604 set_size(n_i, n_j, 1);
619 std::ptrdiff_t s1, s2, s3;
621 if ( istep_ < jstep_ )
622 if ( jstep_ < planestep_ )
624 s1 = istep_; s2 = jstep_; s3 = planestep_;
628 if ( istep_ < planestep_ )
630 s1 = istep_; s2 = planestep_; s3 = jstep_;
631 n1 = ni_; n2 = nplanes_;
635 s1 = planestep_; s2 = istep_; s3 = jstep_;
636 n1 = nplanes_; n2 = ni_;
639 if ( jstep_ < planestep_ )
640 if ( istep_ < planestep_ )
642 s1 = jstep_; s2 = istep_; s3 = planestep_;
647 s1 = jstep_; s2 = planestep_; s3 = istep_;
648 n1 = nj_; n2 = nplanes_;
652 s1 = planestep_; s2 = jstep_; s3 = istep_;
653 n1 = nplanes_; n2 = nj_;
657 s2 > 0 && unsigned(s2) == n1 &&
658 s3 > 0 && unsigned(s3) == n1*n2;
666 if (n_i==ni_ && n_j==nj_ && n_planes==nplanes_)
return;
681 if (istep_==0 ||
int(istep_) !=
int(n_planes)) istep_ = 1;
683 planestep_ = istep_==1 ? n_i*n_j : 1;
685 top_left_ = reinterpret_cast<T*>(ptr_->data());
686 assert( (istep_==1 && (
int)planestep_==
int(n_i*n_j)) || (planestep_==1 && (
int)istep_==(
int)n_planes) );
693 unsigned n_i,
unsigned n_j,
unsigned n_planes,
694 std::ptrdiff_t i_step, std::ptrdiff_t j_step, std::ptrdiff_t plane_step)
697 top_left_ = const_cast<T*>(top_left);
704 planestep_ = plane_step;
713 T* plane = top_left_;
717 std::fill(begin(), end(), value);
723 for (
unsigned int p=0;p<nplanes_;++p,plane += planestep_)
726 for (
unsigned int j=0;j<nj_;++j,row += jstep_)
729 while (i!=0) { row[--i]=value; }
737 for (
unsigned int p=0;p<nplanes_;++p,plane += planestep_)
740 for (
unsigned int i=0;i<ni_;++i,col += istep_)
743 while (j!=0) { col[--j]=value; }
749 for (
unsigned int p=0;p<nplanes_;++p,plane += planestep_)
752 for (
unsigned int j=0;j<nj_;++j,row += jstep_)
755 for (
unsigned int i=0;i<ni_;++i,p+=istep_) *p = value;
773 os<<nplanes_<<
" planes, each "<<ni_<<
" x "<<nj_;
788 if (
this == &other)
return true;
790 if (!(
bool) *
this && !(bool)other)
return true;
791 return ptr_ == other.
ptr_ &&
792 top_left_ == other.top_left_ &&
793 nplanes_ == other.nplanes_ &&
796 (nplanes_ <= 1 || planestep_ == other.planestep_) &&
797 istep_ == other.istep_ &&
798 jstep_ == other.jstep_;
812 if (ptr_ != other.
ptr_)
return ptr_<other.
ptr_;
813 if (!(
bool) *
this && !(bool)other)
return false;
814 if (nplanes_ != other.nplanes_)
return nplanes_ < other.nplanes_;
815 if (ni_ != other.ni_)
return ni_ < other.ni_;
816 if (nj_ != other.nj_)
return nj_ < other.nj_;
817 if (planestep_ != other.planestep_)
return planestep_ < other.planestep_;
818 if (istep_ != other.istep_)
return istep_ < other.istep_;
819 return jstep_ < other.jstep_;
835 if (
this == &other)
return false;
837 if (ptr_ != other.
ptr_)
return ptr_>other.
ptr_;
838 if (!(
bool) *
this && !(bool)other)
return false;
839 if (nplanes_ != other.nplanes_)
return nplanes_ > other.nplanes_;
840 if (ni_ != other.ni_)
return ni_ > other.ni_;
841 if (nj_ != other.nj_)
return nj_ > other.nj_;
842 if (planestep_ != other.planestep_)
return planestep_ > other.planestep_;
843 if (istep_ != other.istep_)
return istep_ > other.istep_;
844 return jstep_ > other.jstep_;
859 lhs.
nj() != rhs.
nj() ||
860 lhs.
ni() != rhs.
ni())
863 for (
unsigned p = 0; p < rhs.
nplanes(); ++p)
864 for (
unsigned j = 0; j < rhs.
nj(); ++j)
865 for (
unsigned i = 0; i < rhs.
ni(); ++i)
866 if (!(rhs(i,j,p) == lhs(i,j,p)))
886 #define VIL_IMAGE_VIEW_INSTANTIATE(T) \ 887 template <> std::string vil_image_view_type_name(T*) \ 888 { return std::string("vil_image_view<" #T ">"); } \ 889 template class vil_image_view<T >; \ 890 template bool vil_image_view_deep_equality(const vil_image_view<T >&, \ 891 const vil_image_view<T >&) 893 #endif // vil_image_view_hxx_ unsigned ni_
Number of columns.
An abstract base class of smart pointers to actual image data in memory.
virtual bool is_class(std::string const &s) const
True if this is (or is derived from) class s.
std::ptrdiff_t istep_
Add this to a pixel pointer to move one column left.
bool convert_planes_from_components(vil_image_view< T > &, const vil_image_view_base &)
Convert components to planes from planes, or do nothing if types are wrong.
Concrete view of image data of type T held in memory.
void fill(T value)
Fill view with given value.
bool is_contiguous() const
True if data all in one unbroken block and top_left_ptr() is lowest data address.
bool convert_components_from_planes(vil_image_view< T > &lhs, const vil_image_view_base &rhs_base)
Convert planes to components from planes, or do nothing if types are wrong.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
Exceptions thrown by vil, and a mechanism for turning them off.
std::ptrdiff_t planestep_
Add this to a pixel pointer to move one plane back.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
bool vil_image_view_deep_equality(const vil_image_view< T > &lhs, const vil_image_view< T > &rhs)
True if the actual images are identical.
bool operator<(const vil_image_view_base &rhs) const
Provides an ordering.
vil_memory_chunk_sptr ptr_
Reference to actual image data.
unsigned ni() const
Width.
unsigned nj() const
Height.
virtual enum vil_pixel_format pixel_format() const =0
Return a description of the concrete data pixel type.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
bool operator>(const vil_image_view_base &rhs) const
Provides an ordering.
void deep_copy(const vil_image_view< T > &src)
Make a copy of the data in src and set this to view it.
void print(std::ostream &) const override
Print a 1-line summary of contents.
unsigned nplanes_
Number of planes.
A base class reference-counting view of some image data.
bool const * const_iterator
unsigned long size() const
The number of pixels.
std::string is_a() const override
Return class name.
Ref. counted block of data on the heap.
std::ptrdiff_t jstep_
Add this to a pixel pointer to move one row down.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
This is the appropriate pixel type for RGBA colour images.
unsigned nplanes() const
Number of planes.
void set_to_memory(const T *top_left, unsigned ni, unsigned nj, unsigned nplanes, std::ptrdiff_t i_step, std::ptrdiff_t j_step, std::ptrdiff_t plane_step)
Set this view to look at someone else's memory data.
std::string vil_image_view_type_name(T *)
const vil_memory_chunk_sptr & memory_chunk() const
Smart pointer to the object holding the data for this view.
void vil_exception_warning(T exception)
Throw an exception indicating a potential problem.
unsigned nj_
Number of rasters.
vil_image_view()
Dflt ctor.
bool is_class(std::string const &s) const override
True if this is (or is derived from) class s.
T * top_left_
Pointer to pixel at origin.
const vil_image_view< T > & operator=(const vil_image_view< T > &rhs)
Copy a view. The rhs and lhs will point to the same image data.
bool operator==(const vil_image_view_base &other) const
True if they share same view of same image data.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
This is the appropriate pixel type for 24-bit colour images.