00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _MbLevelColorMapping_H
00024 #define _MbLevelColorMapping_H
00025
00026 #include <MeshVizXLM/mapping/interfaces/MiColorMapping.h>
00027 #include <MeshVizXLM/MxTimeStamp.h>
00028
00029 #include <Inventor/STL/vector>
00030 #include <Inventor/STL/algorithm>
00031
00043 template < typename _TValue, typename _TColor >
00044 class MbLevelColorMapping : public MiColorMapping<_TValue,_TColor>
00045 {
00046 public:
00047 MbLevelColorMapping();
00048 virtual ~MbLevelColorMapping();
00049
00053 virtual _TColor getColor(_TValue value) const ;
00054
00058 virtual void getRange(_TValue& min, _TValue& max) const;
00059
00065 virtual size_t getTimeStamp() const ;
00066
00073 void setLevels(std::vector<_TValue>& values, std::vector<_TColor>& colors);
00074
00078 void setMinThreshold(bool enable, _TValue minThresholdValue, _TColor minThresholdColor);
00079 bool getMinThreshold(_TValue& minThresholdValue, _TColor& minThresholdColor) const ;
00080
00084 void setMaxThreshold(bool enable, _TValue maxThresholdValue, _TColor maxThresholdColor);
00085 bool getMaxThreshold(_TValue& maxThresholdValue, _TColor& maxThresholdColor) const;
00086
00090 size_t getLevelIndex(_TValue value) const;
00091
00092 size_t getNumValues() const {return m_values.size(); };
00093 _TValue getValue(size_t level) const { return m_values[level]; };
00094 size_t getNumColors() const {return m_colors.size(); };
00095 _TColor getColorValue(size_t index) const { return m_colors[index]; };
00096
00097
00098 private:
00099
00100 size_t m_timeStamp;
00101
00102 std::vector<_TValue> m_values;
00103 std::vector<_TColor> m_colors;
00104
00105 bool m_minThresholdEnable;
00106 _TValue m_minThresholdValue;
00107 _TColor m_minThresholdColor;
00108
00109 bool m_maxThresholdEnable;
00110 _TValue m_maxThresholdValue;
00111 _TColor m_maxThresholdColor;
00112
00113 };
00114
00115
00116 template < typename _TValue, typename _TColor>
00117 MbLevelColorMapping<_TValue,_TColor>::MbLevelColorMapping()
00118 {
00119 m_minThresholdEnable = false;
00120 m_minThresholdValue = _TValue(0.);
00121 m_maxThresholdEnable = false;
00122 m_maxThresholdValue = _TValue(1.);
00123 m_timeStamp = MxTimeStamp::getTimeStamp();
00124
00125 }
00126
00127 template < typename _TValue, typename _TColor>
00128 MbLevelColorMapping<_TValue,_TColor>::~MbLevelColorMapping()
00129 {
00130 }
00131
00132 template < typename _TValue, typename _TColor>
00133 void
00134 MbLevelColorMapping<_TValue,_TColor>::setLevels(std::vector<_TValue>& values, std::vector<_TColor>& colors)
00135 {
00136 if ((values.size() != m_values.size()) ||
00137 std::equal(values.begin(),values.end(),m_values.begin()) == false)
00138 {
00139 typename std::vector<_TValue>::iterator itVal;
00140 m_values.clear();
00141 m_values.reserve(values.size());
00142 for (itVal=values.begin(); itVal != values.end(); ++itVal)
00143 {
00144 m_values.push_back(*itVal);
00145 }
00146 m_timeStamp = MxTimeStamp::getTimeStamp();
00147 }
00148
00149 if ((colors.size() != m_colors.size()) ||
00150 std::equal(colors.begin(),colors.end(),m_colors.begin()) == false)
00151 {
00152 typename std::vector<_TColor>::iterator itCol;
00153 m_colors.clear();
00154 m_colors.reserve(colors.size());
00155 for (itCol=colors.begin(); itCol != colors.end(); ++itCol)
00156 {
00157 m_colors.push_back(*itCol);
00158 }
00159
00160 m_timeStamp = MxTimeStamp::getTimeStamp();
00161 }
00162 }
00163 template < typename _TValue, typename _TColor>
00164 size_t
00165 MbLevelColorMapping<_TValue,_TColor>::getTimeStamp() const
00166 {
00167 return m_timeStamp;
00168 }
00169
00170 template < typename _TValue, typename _TColor>
00171 _TColor
00172 MbLevelColorMapping<_TValue,_TColor>::getColor(_TValue value) const
00173 {
00174
00175 if (m_minThresholdEnable == true && value < m_minThresholdValue)
00176 return m_minThresholdColor;
00177
00178 if (m_maxThresholdEnable == true && m_maxThresholdValue < value)
00179 return m_maxThresholdColor;
00180
00181 return m_colors[getLevelIndex(value)];
00182
00183 }
00184
00185 template < typename _TValue, typename _TColor>
00186 void
00187 MbLevelColorMapping<_TValue,_TColor>::setMinThreshold(bool enable, _TValue minValue, _TColor minColor)
00188 {
00189 if (m_minThresholdEnable != enable || m_minThresholdValue != minValue || m_minThresholdColor != minColor)
00190 m_timeStamp = MxTimeStamp::getTimeStamp();
00191 m_minThresholdEnable = enable;
00192 m_minThresholdValue = minValue;
00193 m_minThresholdColor = minColor;
00194 }
00195
00196 template < typename _TValue, typename _TColor>
00197 bool
00198 MbLevelColorMapping<_TValue,_TColor>::getMinThreshold(_TValue& minValue, _TColor& minColor) const
00199 {
00200 minValue = m_minThresholdValue;
00201 minColor = m_minThresholdColor;
00202 return m_minThresholdEnable;
00203 }
00204
00205 template < typename _TValue, typename _TColor>
00206 void
00207 MbLevelColorMapping<_TValue,_TColor>::setMaxThreshold(bool enable, _TValue maxValue, _TColor maxColor)
00208 {
00209 if (m_maxThresholdEnable != enable || m_maxThresholdValue != maxValue || m_maxThresholdColor != maxColor)
00210 m_timeStamp = MxTimeStamp::getTimeStamp();
00211 m_maxThresholdEnable = enable;
00212 m_maxThresholdValue = maxValue;
00213 m_maxThresholdColor = maxColor;
00214 }
00215 template < typename _TValue, typename _TColor>
00216 bool
00217 MbLevelColorMapping<_TValue,_TColor>::getMaxThreshold(_TValue& maxValue, _TColor& maxColor) const
00218 {
00219 maxValue = m_maxThresholdValue;
00220 maxColor = m_maxThresholdColor;
00221 return m_maxThresholdEnable;
00222 }
00223
00224 template < typename _TValue, typename _TColor>
00225 size_t
00226 MbLevelColorMapping<_TValue,_TColor>::getLevelIndex(_TValue value) const
00227 {
00228 typename std::vector<_TValue>::const_iterator up;
00229 up = std::upper_bound(m_values.begin(),m_values.end(),value);
00230 if (up == m_values.end())
00231 return m_values.size()-2;
00232 else
00233 {
00234 size_t pos = size_t(up - m_values.begin());
00235 if (pos != 0)
00236 return pos-1;
00237 else
00238 return 0;
00239 }
00240 }
00241
00242 template < typename _TValue, typename _TColor>
00243 void
00244 MbLevelColorMapping<_TValue,_TColor>::getRange(_TValue& min, _TValue& max) const
00245 {
00246 min = m_values[0];
00247 max = m_values[m_values.size()-1];
00248 }
00249
00250
00251 #endif
00252
00253
00254
00255
00256
00257
00258
00259