contrib/tbl/vipl/section/vipl_section_descriptor.txx
Go to the documentation of this file.
00001 #ifndef vipl_section_descriptor_txx_
00002 #define vipl_section_descriptor_txx_
00003 //:
00004 // \file
00005 
00006 #include "vipl_section_descriptor.h"
00007 #include <vipl/section/vipl_section_container.h>
00008 #include <vipl/filter/vipl_filter_abs.h> // for default def of FILTER_IMPTR_INC_REFCOUNT
00009 #include <vcl_iostream.h> // for error message stuff
00010 
00011 #include <vcl_compiler.h>
00012 
00013 #ifdef VCL_VC
00014 // Disable complaints about empty controlled statements (from blank macro expansion)
00015 # pragma warning( push )
00016 # pragma warning( disable : 4390 )
00017 #endif
00018 
00019 //: Assigns the pointers directly. Does not attempt to deep copy them.
00020 template < class DataType >
00021 vipl_section_descriptor< DataType > ::vipl_section_descriptor(
00022                  vipl_section_descriptor< DataType >* desc ,
00023                  vipl_section_container< DataType >* container)
00024   : hsreal_descriptor(desc),
00025     hsreal_container(container),
00026     hsi_data_ptr(0),
00027     hsi_data_offsets(2,0),
00028     hsi_curr_sec_start(2,0),
00029     hsi_curr_sec_end(2,0),
00030     hsi_curr_sec_size(2,0),
00031     refcount_ (1)
00032 {
00033   if (desc) { FILTER_IMPTR_INC_REFCOUNT(desc); }
00034   if (container) { FILTER_IMPTR_INC_REFCOUNT(container); }
00035 #ifdef DEBUG
00036   vcl_cerr << "Warning: called unimplemented vipl_section_descriptor constructor with signature "
00037            << "vipl_section_descriptor<DataType>*, vipl_section_container<DataType>*\n";
00038 #endif
00039 }
00040 
00041 #ifdef VCL_VC
00042 # pragma warning( pop )
00043 #endif
00044 
00045 //: Deep-copies the pointers
00046 template < class DataType >
00047 vipl_section_descriptor< DataType > ::vipl_section_descriptor(
00048                 const vipl_section_descriptor< DataType >* desc ,
00049                 const vipl_section_container< DataType >* container ,
00050                 int t)
00051  : hsreal_descriptor(0),
00052    hsreal_container(0),
00053    hsi_data_ptr(0),
00054    hsi_data_offsets(2,0),
00055    hsi_curr_sec_start(2,0),
00056    hsi_curr_sec_end(2,0),
00057    hsi_curr_sec_size(2,0),
00058    refcount_ (1)
00059 {
00060   hsreal_descriptor = desc->virtual_copy();
00061   hsreal_container = container->virtual_copy();
00062 #ifdef DEBUG
00063   vcl_cerr << "Warning: called unimplemented vipl_section_descriptor constructor with signature "
00064            << "const vipl_section_descriptor<DataType>*, const vipl_section_container<DataType>*, int\n";
00065 #endif
00066 }
00067 
00068 //: A simple section_descriptor useful for filter Regions_of_Application.
00069 // It is not associated with any container or ``real'' descriptor.
00070 // It cannot verify that the start/end points are meaningful for a particular
00071 // image (there is none associated with it), but if used for the ROA of a
00072 // filter this can be used to limit its operation to only a small window
00073 // within the image.
00074 template < class DataType >
00075 vipl_section_descriptor< DataType > ::vipl_section_descriptor(
00076                  vcl_vector< int >& startpts ,
00077                  vcl_vector< int >& endpts)
00078   : hsreal_descriptor (0),
00079     hsreal_container (0),
00080     hsi_data_ptr (0),
00081     hsi_data_offsets (2,0),
00082     hsi_curr_sec_start (2,0),
00083     hsi_curr_sec_end (2,0),
00084     hsi_curr_sec_size (2,0),
00085     refcount_ (1)
00086 {
00087 #ifdef DEBUG
00088   vcl_cerr << "Warning: called unimplemented vipl_section_descriptor constructor with signature "
00089            << "vcl_vector<int>&, vcl_vector<int>&\n";
00090 #endif
00091 }
00092 
00093 template < class DataType >
00094 vipl_section_descriptor< DataType > ::~vipl_section_descriptor()
00095 {
00096   if (this != hsreal_descriptor && hsreal_descriptor && (hsreal_descriptor->refcount() > 1) )
00097     FILTER_IMPTR_DEC_REFCOUNT(hsreal_descriptor);
00098   if (hsreal_container && hsreal_container->refcount()>1)
00099     FILTER_IMPTR_DEC_REFCOUNT(hsreal_container);
00100 #ifdef DEBUG
00101   vcl_cerr << "Warning: called unfinished destructor\n";
00102 #endif
00103 }
00104 
00105 template < class DataType >
00106 vipl_section_descriptor< DataType > ::vipl_section_descriptor()
00107   : hsreal_descriptor(this),
00108     hsreal_container(0),
00109     hsi_data_ptr(0),
00110     hsi_data_offsets(2,0),
00111     hsi_curr_sec_start(2,0),
00112     hsi_curr_sec_end(2,0),
00113     hsi_curr_sec_size(2,0),
00114     refcount_ (1)
00115 // C++ auto-generated low-level constructor
00116 {
00117   hsreal_descriptor = this;
00118 }
00119 
00120 template < class DataType >
00121 vipl_section_descriptor< DataType > ::vipl_section_descriptor(const vipl_section_descriptor< DataType > &t)
00122   : hsreal_descriptor(t.hsreal_descriptor),
00123     hsreal_container(t.hsreal_container),
00124     hsi_data_ptr(t.hsi_data_ptr),
00125     hsi_data_offsets(t.hsi_data_offsets),
00126     hsi_curr_sec_start(t.hsi_curr_sec_start),
00127     hsi_curr_sec_end(t.hsi_curr_sec_end),
00128     hsi_curr_sec_size(t.hsi_curr_sec_size),
00129     refcount_ (1)
00130 // C++ auto-generated low-level copy constructor
00131 {
00132   // you can fill special ``copy constructor'' stuff here.
00133   // All dynamic/soft attributes are copied. Thus your
00134   //want to change it here is should be hard because it
00135   //is always changed!) So don't change things without
00136   //knowing their form.
00137   if (t.hsreal_descriptor)
00138     hsreal_descriptor = t.hsreal_descriptor->virtual_copy();
00139   if (t.hsreal_container)
00140     hsreal_container = t.hsreal_container->virtual_copy();
00141 }
00142 
00143 //:
00144 // This method takes in an argument called axis (i.e. 0 means the ``x'' axis,
00145 // 1 means ``y'' axis etc...) and returns an integer which describes the offset
00146 // of the next (i.e. associated with the higher coordinate value) data item
00147 // along the axis.
00148 template < class DataType >
00149 int vipl_section_descriptor< DataType > ::data_offsets( int /*axis*/ ) const
00150 {
00151   vcl_cerr << "Warning: called unimplemented method vipl_section_descriptor::data_offsets\n";
00152   return 0;
00153 }
00154 
00155 //: Returns a referable pointer to the first data item in the current section.
00156 // If the value returned is 0, then the address is not available to the filter.
00157 template < class DataType >
00158 DataType* vipl_section_descriptor< DataType > ::data_ptr()
00159 {
00160   vcl_cerr << "Warning: called unimplemented method vipl_section_descriptor::data_ptr\n";
00161   return 0;
00162 }
00163 
00164 //: Returns a const pointer to the first data item in the current section.
00165 // If the value returned is 0, then the address is not available to the filter.
00166 template < class DataType >
00167 const DataType* vipl_section_descriptor< DataType > ::data_ptr() const
00168 {
00169   vcl_cerr << "Warning: called unimplemented method vipl_section_descriptor::data_ptr\n";
00170   return 0;
00171 }
00172 
00173 //:
00174 // This method takes in a section_descriptor (which can be thought of as a
00175 // filter's ROA) and updates this section to be the intersection of the ROA
00176 // and the original section. It returns 0 if the region is empty, 1 if nothing
00177 // changed and 2 if there was really a change in the section.
00178 template < class DataType >
00179 int vipl_section_descriptor< DataType > ::restrict( const vipl_section_descriptor< DataType >& ROA)
00180 {
00181   return 0;
00182 }
00183 
00184 //: Makes a new correct copy. It's just a bit more tricky because descriptors have pointers to its ``real instance''.
00185 template < class DataType >
00186 vipl_section_descriptor< DataType >* vipl_section_descriptor< DataType > ::virtual_copy() const
00187 {
00188   vipl_section_descriptor< DataType > *rtn = new vipl_section_descriptor< DataType >;
00189   rtn->put_real_descriptor(rtn);
00190   if (real_container())
00191     rtn->put_real_container(real_container()->virtual_copy());
00192   else
00193     rtn->put_real_container(0);
00194   rtn->put_i_curr_sec_start(i_curr_sec_start());
00195   rtn->put_i_curr_sec_end(i_curr_sec_end());
00196   rtn->put_i_curr_sec_size(i_curr_sec_size());
00197   return rtn;
00198 }
00199 
00200 #endif // vipl_section_descriptor_txx_