contrib/tbl/vipl/section/vipl_section_container.h
Go to the documentation of this file.
00001 // This is tbl/vipl/section/vipl_section_container.h
00002 #ifndef vipl_section_container_h_
00003 #define vipl_section_container_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 
00008 #include <vcl_vector.h>
00009 #include <vcl_cstddef.h>
00010 
00011 template <  class DataType > class vipl_section_descriptor; //template forward reference
00012 template <  class DataType > class vipl_section_iterator; //template forward reference
00013 
00014 template < class DataType >
00015 class vipl_section_container
00016 {
00017   friend class vipl_section_descriptor< DataType > ; //declare a friend class
00018   friend class vipl_section_iterator< DataType > ; //declare a friend class
00019    // STL container typedefs
00020  public:
00021   typedef vipl_section_descriptor< DataType > value_type;
00022   typedef vipl_section_descriptor< DataType >& reference;
00023   typedef const vipl_section_descriptor< DataType >& const_reference;
00024   typedef vipl_section_descriptor< DataType >* pointer;
00025   typedef vipl_section_iterator< DataType > iterator;
00026   typedef const vipl_section_iterator< DataType > const_iterator;
00027   typedef vcl_ptrdiff_t difference_type;
00028   typedef vcl_size_t size_type;
00029  protected:
00030   // declare data, accessors from codegen
00031   vipl_section_container< DataType >* hsthe;
00032   // allow for subclasses with pass-by-value
00033   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > hsimgsz;
00034   // the dimensions of image
00035   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > hsimgstart;
00036   // the starting index of image
00037   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > hssecsz;
00038   // the size of a "normal" section
00039   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > hsoverlap;
00040   // the amount to overlap sections
00041   DataType* hsrawdata;
00042   // pointer to raw block of data for section (may ==0)
00043   const void* hsimgptr;
00044   // (void) pointer to users "image", we just carry it
00045 
00046  public:
00047   // The pointer ``the'' is just assigned
00048   vipl_section_container(vipl_section_container< DataType >* pt);
00049   // The pointer is deep copied
00050   vipl_section_container(const vipl_section_container< DataType >* pt , int t);
00051   virtual ~vipl_section_container(); //low_level destructor
00052   vipl_section_container(); //low_level c++ constructor
00053   //user accessed low_level c++ copy constructor
00054   vipl_section_container(const vipl_section_container< DataType > &);
00055   virtual vipl_section_iterator< DataType > begin();
00056   virtual vipl_section_iterator< DataType > end();
00057   virtual const vipl_section_iterator< DataType > begin() const;
00058   virtual const vipl_section_iterator< DataType > end() const;
00059 
00060   // True only if the internal filterable image associated with
00061   // b is the same as for this.
00062   virtual bool operator==( const vipl_section_container< DataType >& b) const;
00063 
00064   // STL demands a few methods
00065   virtual bool operator!=( const vipl_section_container< DataType >& b) const;
00066 
00067   // STL demands this
00068   virtual vipl_section_container<DataType>& operator=( const vipl_section_container< DataType >& b);
00069 
00070   virtual int size() const ;
00071   virtual int max_size() const ;
00072   virtual bool empty() ;
00073   // None of the comparison operators are implemented yet. FIXME
00074   virtual bool operator<( const vipl_section_container< DataType >& b) const ;
00075   virtual bool operator>( const vipl_section_container< DataType >& b) const ;
00076   virtual bool operator<=( const vipl_section_container< DataType >& b) const ;
00077   virtual bool operator>=( const vipl_section_container< DataType >& b) const ;
00078 
00079   // not implemented
00080   virtual void swap( const vipl_section_container< DataType >& b) const ;
00081 
00082   // Modifies the passed in descriptor to point to the next section.
00083   // This is used by the default iterators for the operator++ method.
00084   // Returns TRUE if successfully incremented the variable.
00085   // Used so we don't have to copy descriptors a zillion times.
00086   // Unfortunately STL usage implies we do copy more often than we'd like.
00087  protected:
00088   virtual bool next_section( vipl_section_descriptor< DataType >& in_out) const ;
00089 
00090   // Given the axis, returns the starting coordinate of the related
00091   // image in the specified axis. The values of \usearg {axis}
00092   // increase from 0. Rationale for this is the span of the image
00093   // in pixels in the first (i.e. 0) axis, the second (i.e. 1) axis
00094   // etc... The Axes have const values in the class filter,
00095   // e.g. vipl_filter::X_Axis
00096  public:
00097   virtual int image_start( int axis) const ;
00098 
00099   // Given the axis, returns the size of the related image in the
00100   // specified axis. The values of \usearg {axis} increase from
00101   // 0. Rationale for this is the span of the image in pixels in
00102   // the first (i.e. 0) axis, the second (i.e. 1) axis etc...
00103   virtual int image_size( int axis) const ;
00104 
00105   // Given the axis, returns the end coordinate of the related
00106   // image in the specified axis. The values of \usearg {axis}
00107   // increase from 0. Rationale for this is the span of the image
00108   // in pixels in the first (i.e. 0) axis, the second (i.e. 1) axis
00109   // etc...
00110   virtual int image_end( int axis) const ;
00111 
00112   // Given the axis, returns the size of the related section size
00113   // in the specified axis. The values of \usearg {axis} increase
00114   // from 0. Rationale for this is the span of the image in pixels
00115   // in the first (i.e. 0) axis, the second (i.e. 1) axis etc... If
00116   // the section container does not use fixed sized sections then
00117   // this should return -1
00118   virtual int section_size( int axis) const ;
00119 
00120   // Returns true if the \useclass {section_descriptor}s will have
00121   // valid pointer values. By default they are if and only if the
00122   // raw_data_pointer is set.
00123   virtual bool is_pointer_safe() const ;
00124 
00125   // Does the correct copy. It's a bit tricky due to the fact that
00126   // an instance has a pointer to its ``real instance''.
00127  protected:
00128   virtual vipl_section_container< DataType >* virtual_copy() const ;
00129  public:
00130   vipl_section_container< DataType >* the() const{ return hsthe;}
00131   vipl_section_container< DataType >* & ref_the(){ return hsthe;}
00132   void put_the( vipl_section_container< DataType >* v){ hsthe = v;}
00133   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > const & imgsz() const{ return hsimgsz;}
00134   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > & ref_imgsz(){ return hsimgsz;}
00135   void put_imgsz( vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > const & v){ hsimgsz = v;}
00136   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > const & imgstart() const{ return hsimgstart;}
00137   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > & ref_imgstart(){ return hsimgstart;}
00138   void put_imgstart( vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > const & v){ hsimgstart = v;}
00139   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > const & secsz() const{ return hssecsz;}
00140   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > & ref_secsz(){ return hssecsz;}
00141   void put_secsz( vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > const & v){ hssecsz = v;}
00142   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > const & overlap() const{ return hsoverlap;}
00143   vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > & ref_overlap(){ return hsoverlap;}
00144   void put_overlap( vcl_vector< VCL_SUNPRO_ALLOCATOR_HACK(int) > const & v){ hsoverlap = v;}
00145   DataType* rawdata() const{ return hsrawdata;}
00146   DataType* & ref_rawdata(){ return hsrawdata;}
00147   void put_rawdata( DataType* v){ hsrawdata = v;}
00148   const void* imgptr() const{ return hsimgptr;}
00149   const void* & ref_imgptr(){ return hsimgptr;}
00150   void put_imgptr( const void* v){ hsimgptr = v;}
00151 
00152   // refcounting:
00153  private: int refcount_;
00154  public:  int refcount() const { return refcount_; }
00155  public:  int inc_refcount() { return ++refcount_; }
00156  public:  int dec_refcount() { if (refcount_<=1) { delete this; return 0; } return --refcount_; }
00157 
00158 }; // end of class definition
00159 
00160 #ifdef INSTANTIATE_TEMPLATES
00161 #include "vipl_section_container.txx"
00162 #endif
00163 
00164 #endif // vipl_section_container_h_