Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Range.H

Go to the documentation of this file.
00001 /*!@file Image/Range.H Manage min/max range information */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Rob Peters <rjpeters@klab.caltech.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/Range.H $
00035 // $Id: Range.H 7198 2006-09-21 14:11:25Z rjpeters $
00036 //
00037 
00038 #ifndef IMAGE_RANGE_H_DEFINED
00039 #define IMAGE_RANGE_H_DEFINED
00040 
00041 #include <limits> // for std::numeric_limits
00042 
00043 
00044 //! A class for managing min/max range information.
00045 /*! This class is primarily intended to work with algorithms that
00046     manipulate the dynamic range of Image<T>'s. For example, it can help to
00047     specify how an image should have its current dynamic range remapped to
00048     a new range (see remapRange() in Image_MathOps.H). In addition, the
00049     Range<T> class provides an operator() that allows it to be used as a
00050     functor in generic algorithms for accumulating the min/max over a
00051     sequence of elements (as in rangeOf() in Image_MathOps.H). */
00052 template <class T>
00053 class Range
00054 {
00055 private:
00056   T mini, maxi;
00057 
00058 public:
00059   //! Default constructor.
00060   /*! We initialize the object's min element with type T's <b>max</b>
00061       value, and we initialize the object's max element with type T's
00062       <b>min</b> value. This seeming paradoxical situation is in fact "The
00063       Right Thing" if we want to accumulate the min/max over a range of
00064       elements. The starting condition of the Range object should make the
00065       weakest possible assumption about the values that will be observed;
00066       and this weakest assumption is precisely to start with the min being
00067       as large as possible, and the max being as small as possible. */
00068   inline Range();
00069 
00070   //! Construct with given min and max values.
00071   inline Range(const T& mi, const T& ma);
00072 
00073   //! Get the current min value.
00074   const T& min() const { return mini; }
00075 
00076   //! Get the current max value.
00077   const T& max() const { return maxi; }
00078 
00079   //! Get the range (i.e. the difference of max minus min).
00080   T range() const { return maxi - mini; }
00081 
00082   //! Set the range's min value.
00083   void setMin(const T& mi) { mini = mi; }
00084 
00085   //! Set the range's max value.
00086   void setMax(const T& ma) { maxi = ma; }
00087 
00088   //! Update our min value if val is less than the current max.
00089   void mergeMin(const T& v);
00090 
00091   //! Update our max value if val is greater than the current max.
00092   void mergeMax(const T& val);
00093 
00094   //! Update our min or max value if val falls outside of the current range.
00095   void merge(const T& val);
00096 
00097   //! This operator() allows straightforward use in generic algorithms.
00098   /*! In particular, this is useful for accumulating the min/max over a
00099       range of elements. For example, rangeOf() could be implemented like
00100       this:
00101 
00102       \code
00103       Image<T> img;
00104       Range<T> rng = std::for_each(img.begin(), img.end(), Range<T>());
00105       \endcode
00106 
00107       We construct a default Range<T> object, which is copied and passed to
00108       for_each(), which in turn calls operator() on that range object for
00109       each element in the iterator sequence that is visited.
00110   */
00111   void operator()(const T& v);
00112 
00113   //! Merge other's min and max values into ours.
00114   void merge(const Range<T>& other);
00115 };
00116 
00117 
00118 // ######################################################################
00119 template <class T> inline
00120 Range<T>::Range() :
00121   mini(std::numeric_limits<T>::max()),
00122   maxi(std::numeric_limits<T>::min())
00123 {}
00124 
00125 // ######################################################################
00126 template <class T> inline
00127 Range<T>::Range(const T& mi, const T& ma) :
00128   mini(mi), maxi(ma)
00129 {}
00130 
00131 // ######################################################################
00132 template <class T> inline
00133 void Range<T>::mergeMin(const T& v) { if (v < mini) mini = v; }
00134 
00135 // ######################################################################
00136 template <class T> inline
00137 void Range<T>::mergeMax(const T& v) { if (v > maxi) maxi = v; }
00138 
00139 // ######################################################################
00140 template <class T> inline
00141 void Range<T>::merge(const T& v)
00142 {
00143   mergeMin(v);
00144   mergeMax(v);
00145 }
00146 
00147 // ######################################################################
00148 template <class T> inline
00149 void Range<T>::operator()(const T& v)
00150 {
00151   merge(v);
00152 }
00153 
00154 // ######################################################################
00155 template <class T> inline
00156 void Range<T>::merge(const Range<T>& other)
00157 {
00158   mergeMin(other.min());
00159   mergeMax(other.max());
00160 }
00161 
00162 // ######################################################################
00163 /* So things look consistent in everyone's emacs... */
00164 /* Local Variables: */
00165 /* mode: c++ */
00166 /* indent-tabs-mode: nil */
00167 /* End: */
00168 
00169 #endif // IMAGE_RANGE_H_DEFINED

Generated on Sun Nov 22 13:42:35 2009 for iLab Neuromorphic Vision Toolkit by  doxygen 1.4.4