contrib/tbl/vipl/section/vipl_section_descriptor.h
Go to the documentation of this file.
00001 // This is tbl/vipl/section/vipl_section_descriptor.h
00002 #ifndef vipl_section_descriptor_h_
00003 #define vipl_section_descriptor_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 //  \file
00009 
00010 #include <vcl_vector.h>
00011 
00012 template < class DataType > class vipl_section_container; //template forward reference
00013 template < class DataType > class vipl_section_iterator; //template forward reference
00014 
00015 template < class DataType >
00016 class vipl_section_descriptor
00017 {
00018   friend class vipl_section_container< DataType > ; //declare a friend class
00019   friend class vipl_section_iterator< DataType > ; //declare a friend class
00020 
00021   vipl_section_descriptor< DataType >* hsreal_descriptor;
00022   vipl_section_container< DataType >* hsreal_container;
00023   DataType* hsi_data_ptr;
00024   vcl_vector< int > hsi_data_offsets;
00025   vcl_vector< int > hsi_curr_sec_start;
00026   vcl_vector< int > hsi_curr_sec_end;
00027   vcl_vector< int > hsi_curr_sec_size;
00028 
00029  protected:
00030   //: Assigns the pointers directly. Does not attempt to deep copy them.
00031   vipl_section_descriptor( vipl_section_descriptor< DataType >* desc ,
00032                            vipl_section_container< DataType >* container) ;
00033 
00034   //: Deep-copies the pointers
00035   vipl_section_descriptor(
00036       const vipl_section_descriptor< DataType >* desc ,
00037       const vipl_section_container< DataType >* container , int t) ;
00038 
00039  public:
00040   //:
00041   // A simple section_descriptor useful for filter
00042   // Regions_of_Application. it is not associated with any
00043   // container or ``real'' descriptor. It cannot verify that the
00044   // start/end points are meaningful for a particular image (there
00045   // is none associated with it), but if used for the ROA of a
00046   // filter this can be used to limit its operation to only a small
00047   // window within the image.
00048   vipl_section_descriptor( vcl_vector< int >& startpts , vcl_vector< int >& endpts);
00049 
00050   virtual ~vipl_section_descriptor();//low_level destructor
00051   vipl_section_descriptor();//low_level c++ constructor
00052   //user accessed low_level c++ copy constructor
00053   vipl_section_descriptor(const vipl_section_descriptor< DataType > &);
00054 
00055   //:
00056   // This method takes in an integer argument called axis (i.e. 0
00057   // means the ``x'' axis, 1 means ``y'' axis etc...) and returns
00058   // an integer which describes the start coordinate value for ``x''
00059   // (or ``y'' etc..) with respect to the ``image'' coordinate system.
00060   virtual int curr_sec_start( int axis) const { return hsi_curr_sec_start[axis]; }
00061 
00062   //:
00063   // This method takes in an integer argument called axis (i.e. 0
00064   // means the ``x'' axis, 1 means ``y'' axis etc...) and returns
00065   // an integer which describes the end coordinate value for ``x''
00066   // (or ``y'' etc..) with respect to the ``image'' coordinate system.
00067   virtual int curr_sec_end( int axis) const { return hsi_curr_sec_end[axis]; }
00068 
00069   //:
00070   // This method takes in an integer argument called axis (i.e. 0
00071   // means the ``x'' axis, 1 means ``y'' axis etc...) and returns
00072   // an integer which describes the size of the axis (end minus
00073   // start) for ``x'' (or ``y'' etc..) with respect to the
00074   // ``image'' coordinate system.
00075   virtual int curr_sec_size( int axis) const { return hsi_curr_sec_size[axis]; }
00076 
00077   //:
00078   // This method takes in an integer argument called axis (i.e. 0
00079   // means the ``x'' axis, 1 means ``y'' axis etc...) and returns
00080   // an integer which describes the offset of the next
00081   // (i.e. associated with the higher coordinate value) data item
00082   // along the axis.
00083   virtual int data_offsets( int axis) const ;
00084 
00085   //: Returns a referable pointer to the first data item in the current section.
00086   // If the value returned is null, then the
00087   // address is not available to the filter.
00088   virtual DataType* data_ptr() ;
00089 
00090   //:
00091   // Returns a const pointer to the first data item in the current
00092   // section. If the value returned is null, then the address is
00093   // not available to the filter.
00094   virtual const DataType* data_ptr() const ;
00095 
00096   //: Returns a writable pointer to the ``real'' section descriptor.
00097   // If this method is called on a concrete instance,
00098   // it should return 0.
00099   virtual vipl_section_descriptor< DataType >* inner_descriptor(){return hsreal_descriptor;}
00100 
00101   //: Returns a const pointer to the ``real'' section descriptor.
00102   // If this method is called on a concrete instance,
00103   // it should return 0.
00104   virtual const vipl_section_descriptor< DataType >* inner_descriptor()const{return hsreal_descriptor;}
00105 
00106   //:
00107   // This method takes in a section_descriptor (which can be thought
00108   // of as a filter's ROA) and updates this section to be the
00109   // intersection of the ROA and the original section. It returns 0
00110   // if the region is empty, 1 if nothing changed and 2 if there
00111   // was really a change in the section.
00112   int restrict( const vipl_section_descriptor< DataType >& ROA) ;
00113 
00114   //:
00115   // Makes a new correct copy. It's just a bit more tricky because
00116   // descriptors have pointers to its ``real instance.''
00117   virtual vipl_section_descriptor< DataType >* virtual_copy() const ;
00118 
00119  public:
00120   vipl_section_descriptor< DataType >* real_descriptor() const{ return hsreal_descriptor;}
00121   vipl_section_descriptor< DataType >* & ref_real_descriptor(){ return hsreal_descriptor;}
00122   void put_real_descriptor( vipl_section_descriptor< DataType >* v){ hsreal_descriptor = v;}
00123   vipl_section_container< DataType >* real_container() const{ return hsreal_container;}
00124   vipl_section_container< DataType >* & ref_real_container(){ return hsreal_container;}
00125   void put_real_container( vipl_section_container< DataType >* v){ hsreal_container = v;}
00126   DataType* i_data_ptr() const{ return hsi_data_ptr;}
00127   DataType* & ref_i_data_ptr(){ return hsi_data_ptr;}
00128   void put_i_data_ptr( DataType* v){ hsi_data_ptr = v;}
00129   vcl_vector< int > const & i_data_offsets() const{ return hsi_data_offsets;}
00130   vcl_vector< int > & ref_i_data_offsets(){ return hsi_data_offsets;}
00131   void put_i_data_offsets( vcl_vector< int > const & v){ hsi_data_offsets = v;}
00132   vcl_vector< int > const & i_curr_sec_start() const{ return hsi_curr_sec_start;}
00133   vcl_vector< int > & ref_i_curr_sec_start(){ return hsi_curr_sec_start;}
00134   void put_i_curr_sec_start( vcl_vector< int > const & v){ hsi_curr_sec_start = v;}
00135   //:
00136   // This method takes in an integer argument called axis (i.e. 0
00137   // means the ``x'' axis, 1 means ``y'' axis etc...) and returns
00138   // an integer which describes the end coordinate value for ``x''
00139   // (or ``y'' etc..) with respect to the ``image'' coordinate system.
00140   vcl_vector< int > const & i_curr_sec_end() const{ return hsi_curr_sec_end;}
00141   vcl_vector< int > & ref_i_curr_sec_end(){ return hsi_curr_sec_end;}
00142   void put_i_curr_sec_end( vcl_vector< int > const & v){ hsi_curr_sec_end = v;}
00143   vcl_vector< int > const & i_curr_sec_size() const{ return hsi_curr_sec_size;}
00144   vcl_vector< int > & ref_i_curr_sec_size(){ return hsi_curr_sec_size;}
00145   void put_i_curr_sec_size( vcl_vector< int > const & v){ hsi_curr_sec_size = v;}
00146 
00147   // refcounting:
00148  private: int refcount_;
00149  public:  int refcount() const { return refcount_; }
00150  public:  int inc_refcount() { return ++refcount_; }
00151  public:  int dec_refcount() { if (refcount_<=1) { delete this; return 0; } return --refcount_; }
00152 
00153 }; // end of class definition
00154 
00155 #ifdef INSTANTIATE_TEMPLATES
00156 #include "vipl_section_descriptor.txx"
00157 #endif
00158 
00159 #endif // vipl_section_descriptor_h_