1 // This is tbl/vipl/section/vipl_section_descriptor.h 2 #ifndef vipl_section_descriptor_h_ 3 #define vipl_section_descriptor_h_ 4 //: 5 // \file 6 7 #include <iostream> 8 #include <vector> 9 #ifdef _MSC_VER 10 # include <vcl_msvc_warnings.h> 11 #endif 12 13 template < class DataType > class vipl_section_container; //template forward reference 14 template < class DataType > class vipl_section_iterator; //template forward reference 15 16 template < class DataType > 17 class vipl_section_descriptor 18 { 19 friend class vipl_section_container< DataType > ; //declare a friend class 20 friend class vipl_section_iterator< DataType > ; //declare a friend class 21 22 vipl_section_descriptor< DataType >* hsreal_descriptor; 23 vipl_section_container< DataType >* hsreal_container; 24 DataType* hsi_data_ptr; 25 std::vector< int > hsi_data_offsets; 26 std::vector< int > hsi_curr_sec_start; 27 std::vector< int > hsi_curr_sec_end; 28 std::vector< int > hsi_curr_sec_size; 29 30 protected: 31 //: Assigns the pointers directly. Does not attempt to deep copy them. 32 vipl_section_descriptor( vipl_section_descriptor< DataType >* desc , 33 vipl_section_container< DataType >* container) ; 34 35 //: Deep-copies the pointers 36 vipl_section_descriptor( 37 const vipl_section_descriptor< DataType >* desc , 38 const vipl_section_container< DataType >* container , int t) ; 39 40 public: 41 //: 42 // A simple section_descriptor useful for filter 43 // Regions_of_Application. it is not associated with any 44 // container or ``real'' descriptor. It cannot verify that the 45 // start/end points are meaningful for a particular image (there 46 // is none associated with it), but if used for the ROA of a 47 // filter this can be used to limit its operation to only a small 48 // window within the image. 49 vipl_section_descriptor( std::vector< int >& startpts , std::vector< int >& endpts); 50 51 virtual ~vipl_section_descriptor();//low_level destructor 52 vipl_section_descriptor();//low_level c++ constructor 53 //user accessed low_level c++ copy constructor 54 vipl_section_descriptor(const vipl_section_descriptor< DataType > &); 55 56 //: 57 // This method takes in an integer argument called axis (i.e. 0 58 // means the ``x'' axis, 1 means ``y'' axis etc...) and returns 59 // an integer which describes the start coordinate value for ``x'' 60 // (or ``y'' etc..) with respect to the ``image'' coordinate system. curr_sec_start(int axis)61 virtual int curr_sec_start( int axis) const { return hsi_curr_sec_start[axis]; } 62 63 //: 64 // This method takes in an integer argument called axis (i.e. 0 65 // means the ``x'' axis, 1 means ``y'' axis etc...) and returns 66 // an integer which describes the end coordinate value for ``x'' 67 // (or ``y'' etc..) with respect to the ``image'' coordinate system. curr_sec_end(int axis)68 virtual int curr_sec_end( int axis) const { return hsi_curr_sec_end[axis]; } 69 70 //: 71 // This method takes in an integer argument called axis (i.e. 0 72 // means the ``x'' axis, 1 means ``y'' axis etc...) and returns 73 // an integer which describes the size of the axis (end minus 74 // start) for ``x'' (or ``y'' etc..) with respect to the 75 // ``image'' coordinate system. curr_sec_size(int axis)76 virtual int curr_sec_size( int axis) const { return hsi_curr_sec_size[axis]; } 77 78 //: 79 // This method takes in an integer argument called axis (i.e. 0 80 // means the ``x'' axis, 1 means ``y'' axis etc...) and returns 81 // an integer which describes the offset of the next 82 // (i.e. associated with the higher coordinate value) data item 83 // along the axis. 84 virtual int data_offsets( int axis) const ; 85 86 //: Returns a referable pointer to the first data item in the current section. 87 // If the value returned is null, then the 88 // address is not available to the filter. 89 virtual DataType* data_ptr() ; 90 91 //: 92 // Returns a const pointer to the first data item in the current 93 // section. If the value returned is null, then the address is 94 // not available to the filter. 95 virtual const DataType* data_ptr() const ; 96 97 //: Returns a writable pointer to the ``real'' section descriptor. 98 // If this method is called on a concrete instance, 99 // it should return 0. inner_descriptor()100 virtual vipl_section_descriptor< DataType >* inner_descriptor(){return hsreal_descriptor;} 101 102 //: Returns a const pointer to the ``real'' section descriptor. 103 // If this method is called on a concrete instance, 104 // it should return 0. inner_descriptor()105 virtual const vipl_section_descriptor< DataType >* inner_descriptor()const{return hsreal_descriptor;} 106 107 //: 108 // This method takes in a section_descriptor (which can be thought 109 // of as a filter's ROA) and updates this section to be the 110 // intersection of the ROA and the original section. It returns 0 111 // if the region is empty, 1 if nothing changed and 2 if there 112 // was really a change in the section. 113 int restrict( const vipl_section_descriptor< DataType >& ROA) ; 114 115 //: 116 // Makes a new correct copy. It's just a bit more tricky because 117 // descriptors have pointers to its ``real instance.'' 118 virtual vipl_section_descriptor< DataType >* virtual_copy() const ; 119 120 public: real_descriptor()121 vipl_section_descriptor< DataType >* real_descriptor() const{ return hsreal_descriptor;} ref_real_descriptor()122 vipl_section_descriptor< DataType >* & ref_real_descriptor(){ return hsreal_descriptor;} put_real_descriptor(vipl_section_descriptor<DataType> * v)123 void put_real_descriptor( vipl_section_descriptor< DataType >* v){ hsreal_descriptor = v;} real_container()124 vipl_section_container< DataType >* real_container() const{ return hsreal_container;} ref_real_container()125 vipl_section_container< DataType >* & ref_real_container(){ return hsreal_container;} put_real_container(vipl_section_container<DataType> * v)126 void put_real_container( vipl_section_container< DataType >* v){ hsreal_container = v;} i_data_ptr()127 DataType* i_data_ptr() const{ return hsi_data_ptr;} ref_i_data_ptr()128 DataType* & ref_i_data_ptr(){ return hsi_data_ptr;} put_i_data_ptr(DataType * v)129 void put_i_data_ptr( DataType* v){ hsi_data_ptr = v;} i_data_offsets()130 std::vector< int > const & i_data_offsets() const{ return hsi_data_offsets;} ref_i_data_offsets()131 std::vector< int > & ref_i_data_offsets(){ return hsi_data_offsets;} put_i_data_offsets(std::vector<int> const & v)132 void put_i_data_offsets( std::vector< int > const & v){ hsi_data_offsets = v;} i_curr_sec_start()133 std::vector< int > const & i_curr_sec_start() const{ return hsi_curr_sec_start;} ref_i_curr_sec_start()134 std::vector< int > & ref_i_curr_sec_start(){ return hsi_curr_sec_start;} put_i_curr_sec_start(std::vector<int> const & v)135 void put_i_curr_sec_start( std::vector< int > const & v){ hsi_curr_sec_start = v;} 136 //: 137 // This method takes in an integer argument called axis (i.e. 0 138 // means the ``x'' axis, 1 means ``y'' axis etc...) and returns 139 // an integer which describes the end coordinate value for ``x'' 140 // (or ``y'' etc..) with respect to the ``image'' coordinate system. i_curr_sec_end()141 std::vector< int > const & i_curr_sec_end() const{ return hsi_curr_sec_end;} ref_i_curr_sec_end()142 std::vector< int > & ref_i_curr_sec_end(){ return hsi_curr_sec_end;} put_i_curr_sec_end(std::vector<int> const & v)143 void put_i_curr_sec_end( std::vector< int > const & v){ hsi_curr_sec_end = v;} i_curr_sec_size()144 std::vector< int > const & i_curr_sec_size() const{ return hsi_curr_sec_size;} ref_i_curr_sec_size()145 std::vector< int > & ref_i_curr_sec_size(){ return hsi_curr_sec_size;} put_i_curr_sec_size(std::vector<int> const & v)146 void put_i_curr_sec_size( std::vector< int > const & v){ hsi_curr_sec_size = v;} 147 148 // refcounting: 149 private: 150 int refcount_{1}; 151 refcount()152 public: int refcount() const { return refcount_; } inc_refcount()153 public: int inc_refcount() { return ++refcount_; } dec_refcount()154 public: int dec_refcount() { if (refcount_<=1) { delete this; return 0; } return --refcount_; } 155 156 }; // end of class definition 157 158 #ifdef INSTANTIATE_TEMPLATES 159 #include "vipl_section_descriptor.hxx" 160 #endif 161 162 #endif // vipl_section_descriptor_h_ 163