CMS 3D CMS Logo

IgQtRangeMValue.h

Go to the documentation of this file.
00001 #ifndef IGUANA_GL_BROWSERS_IG_QT_RANGE_MVALUE_H
00002 # define IGUANA_GL_BROWSERS_IG_QT_RANGE_MVALUE_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "Iguana/GLBrowsers/interface/config.h"
00007 # include <climits>
00008 # include <vector>
00009 # include <classlib/utils/DebugAids.h>
00010 
00011 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00012 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00013 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00014 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00015 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00016 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00017 
00018 template<class T>
00019 class IGUANA_GL_BROWSERS_API IgQtRangeMValue
00020 {
00021 public:
00022     typedef IgQtRangeMValue<T> inherited;
00023     
00024     enum BoundaryHandling {
00025         ACCUMULATE,
00026         MODULATE
00027     };
00028 
00029     typedef std::vector<T> rangeMValues;
00030     
00031     IgQtRangeMValue (T value = 0,
00032                      T min = 0,
00033                      T max = SHRT_MAX);
00034     
00035     IgQtRangeMValue (unsigned int size,
00036                      const T* values,
00037                      T min = 0,
00038                      T max = SHRT_MAX);
00039     
00040     IgQtRangeMValue (const rangeMValues& values,
00041                      T min = 0,
00042                      T max = SHRT_MAX);
00043     // implicit copy constructor
00044     // implicit assignment operator
00045     virtual ~IgQtRangeMValue (void) {}
00046    
00047     unsigned int        size (void) const
00048     { return m_value.size(); }
00049     
00050     virtual void        resize (unsigned int size, T appendedValues = 0)
00051     {
00052       ASSERT (size);
00053       if (size == m_value.size ()) return;
00054       m_value.resize(size, appendedValues);
00055       m_change.resize(size, 0);
00056     }
00057     
00058     virtual void        setValue (unsigned int index, T value)
00059     {
00060       ASSERT ( index < m_value.size() );
00061       value = adjustValue (value);
00062       m_change[index] += value - m_value [index];
00063       m_value[index]  = value;
00064       m_valueChangeFlag = isValueChanged (index);
00065     }
00066     
00067     virtual void        setValue (unsigned int size, const T* values)
00068     {
00069       m_valueChangeFlag = false;
00070       resize (size);
00071       for(unsigned int i = 0; i < size; i++)
00072         setValue (i, values [i]);
00073     }
00074     
00075     virtual void        setValue (const rangeMValues& values)
00076     { setValue (values.size (), &values [0]); }
00077     
00078     virtual T           value (unsigned int index) const
00079     {
00080       ASSERT ( index < m_value.size() );
00081       return m_value [index];
00082     }
00083     
00084     virtual const rangeMValues& value (void) const
00085     { return m_value; }
00086     
00087     virtual T           valueChange (unsigned int index) const
00088     {
00089       ASSERT ( index < m_value.size() );
00090       return m_change[index];
00091     }
00092     
00093     virtual const rangeMValues& valueChange (void) const
00094     { return m_change; }
00095     
00096     virtual bool        isValueChanged (void) const
00097     { return m_valueChangeFlag; }
00098     
00099     virtual bool        isValueChanged (unsigned int index) const
00100     { return valueChange (index) != 0 ? true : false; }
00101 
00102     virtual void        setRange (T min, T max)
00103     {
00104       if (min == m_min && max == m_max)
00105         return;
00106       else if (min > max)
00107         std::swap (min, max);
00108       m_max = max;
00109       m_min = min;
00110       setValue (m_value);
00111     }
00112     
00113     virtual T   minValue (void) const
00114     { return m_min; }
00115     
00116     virtual void        setMinValue (T min)
00117     { setRange (min, maxValue ()); }
00118     
00119     virtual T   maxValue (void) const
00120     { return m_max; }
00121     
00122     virtual void        setMaxValue (T max)
00123     { setRange (max, maxValue ()); }
00124 
00125     virtual BoundaryHandling boundaryHandling (void) const
00126     { return m_boundary; }
00127 
00128     virtual void        setBoundaryHandling (BoundaryHandling mode)
00129     { 
00130       if (m_boundary != mode)
00131       { m_boundary = mode; setValue (m_value); }
00132     }
00133 
00134 protected:
00135     T           modulate (T value) const
00136     {
00137       T width = m_max - m_min;
00138       value -= int ((value - m_min) / width) * width;
00139       value += int ((m_max - value) / width) * width;
00140       return value;
00141     }
00142     
00143     T           accumulate (T value) const
00144     {
00145       if (value > m_max)
00146         return m_max;
00147       else if (value < m_min)
00148         return m_min;
00149       return value;
00150     }
00151 
00152     T  adjustValue (T value)
00153     {
00154       switch (boundaryHandling ())
00155       {
00156       case ACCUMULATE:
00157         value = accumulate (value);
00158         break;
00159 
00160       case MODULATE:
00161         value = modulate (value);
00162         break;
00163       }
00164       return value;
00165     }
00166 
00167     virtual void        forceValue (T value)
00168     {
00169       unsigned int size = m_value.size ();
00170       for (unsigned int i = 0; i < size; i++)
00171         m_value [i] = value;
00172     }
00173     
00174     virtual void        forceValue (unsigned int index, T value)
00175     {
00176       ASSERT ( index < m_value.size() );
00177       m_value [index] = value;
00178     }
00179     
00180     virtual void        forceValue (unsigned int size, const T* values)
00181     {
00182       for (unsigned int i = 0; i < size; i++)
00183         forceValue (i, values[i]);
00184     }
00185     
00186     virtual void        forceValue (const rangeMValues& values)
00187     {
00188       unsigned int size = values.size ();
00189       for (unsigned int i = 0; i < size; i++)
00190         forceValue (i, values[i]);
00191     }
00192     
00193     virtual void        forceValueChanged (T delta)
00194     {
00195       unsigned int size = m_change.size ();
00196       for (unsigned int i = 0; i < size; i++)
00197         m_change [i] = delta;
00198       m_valueChangeFlag = delta ? true : false;
00199     }
00200     
00201     virtual void        forceValueChanged (unsigned int index, T delta)
00202     {
00203       ASSERT ( index < m_change.size() );
00204       m_change [index] = delta;
00205       if(delta != 0)
00206         m_valueChangeFlag = true;
00207     }
00208     
00209     virtual void        forceValueChanged (unsigned int size, const T* delta)
00210     {
00211       m_valueChangeFlag = false;
00212       for (unsigned int i = 0; i < size; i++)
00213         forceValueChanged (i, delta[i]);
00214     }
00215     
00216     virtual void        forceValueChanged (const rangeMValues& delta)
00217     {
00218       unsigned int size = delta.size ();
00219       m_valueChangeFlag = false;
00220       for (unsigned int i = 0; i < size; i++)
00221         forceValueChanged (i, delta[i]);
00222     }
00223 
00224 protected:
00225 
00226     rangeMValues        m_value;
00227     rangeMValues        m_change;
00228     T                   m_min;
00229     T                   m_max;
00230     BoundaryHandling    m_boundary;
00231     bool                m_valueChangeFlag;
00232 };
00233 
00234 template<class T>
00235 IgQtRangeMValue<T>::IgQtRangeMValue (T value,
00236                                      T min /* = 0 */,
00237                                      T max /* = SHRT_MAX */)
00238     : m_value (1, value),
00239       m_change (1, value),
00240       m_min (min),
00241       m_max (max),
00242       m_boundary (ACCUMULATE),
00243       m_valueChangeFlag (false)
00244 { setValue (m_value); }
00245 
00246 template<class T>
00247 IgQtRangeMValue<T>::IgQtRangeMValue (unsigned int size,
00248                                      const T* values,
00249                                      T min /* = 0 */,
00250                                      T max /* = SHRT_MAX */)
00251     : m_value (size, 0),
00252       m_change (size, 0),
00253       m_min (min),
00254       m_max (max),
00255       m_boundary (ACCUMULATE),
00256       m_valueChangeFlag (false)
00257 { 
00258     ASSERT (size);
00259     setValue (size, values);
00260 }
00261 
00262 template<class T>
00263 IgQtRangeMValue<T>::IgQtRangeMValue (const rangeMValues& values,
00264                                      T min /* = 0 */,
00265                                      T max /* = SHRT_MAX */)
00266     : m_value (values.size (), 0),
00267       m_change (values.size (), 0),
00268       m_min (min),
00269       m_max (max),
00270       m_boundary (ACCUMULATE),
00271       m_valueChangeFlag (false)
00272 {
00273     ASSERT (values.size());
00274     setValue (values);
00275 }
00276 
00277 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00278 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00279 
00280 #endif // IGUANA_GL_BROWSERS_IG_QT_RANGE_MVALUE_H

Generated on Tue Jun 9 17:38:34 2009 for CMSSW by  doxygen 1.5.4