contrib/rpl/rsdl/rsdl_borgefors.h

Go to the documentation of this file.
00001 #ifndef rsdl_borgefors_h_
00002 #define rsdl_borgefors_h_
00003 
00004 //:
00005 // \file
00006 // \brief templated borgefors distance map using 3-4 chamfer distance transform
00007 // \author Charlene Tsai
00008 // \date 5 May 2001
00009 //
00010 // Defines functions associated with a templated borgefors
00011 // distance map. The data based on which the map is built is a vector
00012 // (should be changed to any stl container type later) of any
00013 // datatype with x() and y() functions defined.
00014 
00015 #include <vcl_vector.h>
00016 #include <vbl/vbl_array_2d.h>
00017 
00018 //: Defines functions associated with a templated borgefors distance map.
00019 //  The data based on which the map is built is a vector
00020 //  (should be changed to any stl container type later) of any
00021 //  datatype with x() and y() functions defined.
00022 //
00023 //  The computation of the distance map is done using 3-4 chamfer distance
00024 //  transform.
00025 //
00026 //  CAVEAT:
00027 //  To avoid data duplication, objects are stored as pointers in the map.
00028 //  Classes having rsdl_borgefors as the internal data should recompute
00029 //  the borgefors map when define the copy constructor and operator=
00030 //  To enforce this, the copy constructor and the operator= of rsdl_borgefors
00031 //  are not implemented and are private member functions to avoid default ones
00032 //  being generated by the compiler.
00033 //
00034 template <class T>
00035 class rsdl_borgefors
00036 {
00037   typedef typename vcl_vector<T>::iterator iterator_type;
00038   typedef typename vcl_vector<T>::const_iterator const_iterator_type;
00039 
00040  public:
00041   //: default constructor
00042   rsdl_borgefors();
00043   //: constructor: constructs a distance map, with dimensions set by size_x and size_y
00044   rsdl_borgefors(int org_x, int org_y, int size_x, int size_y,
00045                  iterator_type begin, iterator_type end, bool release_dist_map = false);
00046   //: sets distance and index maps, with dimensions set by size_x and size_y
00047   //  \param org_x  x-coord of the top left corner
00048   //  \param org_y  y-coord of the top left corner
00049   //  \param size_x x dimension
00050   //  \param size_y y dimension
00051   //  \param begin  begin ptr of the data vector
00052   //  \param end    end ptr of the data vector
00053   //  \param release_dist_map should the distance map be released?
00054   void set(int org_x, int org_y, int size_x, int size_y,
00055            iterator_type begin, iterator_type end, bool release_dist_map = false);
00056 
00057   //: sets all data members from the caller
00058   //  \param org_x  x-coord of the top left corner
00059   //  \param org_y  y-coord of the top left corner
00060   //  \param size_x x dimension
00061   //  \param size_y y dimension
00062   //  \param begin  begin ptr of the data vector
00063   //  \param end    end ptr of the data vector
00064   //  \param index_map    index map
00065   //  \param distance_map distance map
00066   void set(int org_x, int org_y, int size_x, int size_y,
00067            iterator_type begin, iterator_type end,
00068            vbl_array_2d<int> index_map,
00069            vbl_array_2d<int>* distance_map = 0 );
00070 
00071   //: resets the data members
00072   void reset();
00073   //: returns true if the map contains valid data
00074   bool is_valid() const {return is_valid_;}
00075 
00076   //: returns approximated distance to between (x,y) and closest object in the map
00077   double distance(int x, int y) const;
00078   //: verifies if (x,y) position is valid in the map
00079   bool in_map(int x, int y) const;
00080   //: returns a pointer to the closest object to (x,y) in the map
00081   //  It aborts if (x,y) not in map. Should always check in_map(x,y) first.
00082   const_iterator_type nearest(int x, int y) const;
00083 
00084   //: returns width of the map
00085   int width() const {return size_x_; }
00086   //: returns height of the map
00087   int height()const {return  size_y_; }
00088 
00089   //: returns origin of the map
00090   void origin(int& start_x, int& start_y) const;
00091 
00092   const vbl_array_2d<int>& distance_map() const {return distance_map_; }
00093   const vbl_array_2d<int>& index_map() const {return index_map_; }
00094 
00095   //: equality (comparison) operator
00096   bool operator== (const rsdl_borgefors<T> & rhs) const;
00097 
00098  private:
00099   //: copy constructor, not implemented
00100   rsdl_borgefors(const rsdl_borgefors<T>& old);
00101   //: assignment operator, not implemented
00102   rsdl_borgefors<T>& operator=(const rsdl_borgefors<T>& rhs);
00103 
00104   void initialize(iterator_type  begin, iterator_type end);
00105   void chamfer34();
00106   void forward_chamfer();
00107   void backward_chamfer();
00108   int minimum4(int,int,int,int) const;
00109   int minimum5(int,int,int,int,int) const;
00110 
00111  private:
00112   bool is_valid_;
00113   int org_x_, org_y_, size_x_, size_y_;
00114   vbl_array_2d<int> distance_map_;
00115   vbl_array_2d<int> index_map_;
00116   vcl_vector<iterator_type> data_;
00117 };
00118 
00119 #endif // rsdl_borgefors_h_

Generated on Mon Mar 8 05:26:57 2010 for contrib/rpl/rsdl by  doxygen 1.5.1