00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _MbLinearColorMapping_H
00024 #define _MbLinearColorMapping_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
00044 template < typename _TValue, typename _TColor, typename _TColorType>
00045 class MbLinearColorMapping : public MiColorMapping<_TValue,_TColor>
00046 {
00047 public:
00048 MbLinearColorMapping();
00049 virtual ~MbLinearColorMapping();
00050
00054 virtual _TColor getColor(_TValue value) const ;
00055
00059 virtual void getRange(_TValue& min, _TValue& max) const;
00060
00066 virtual size_t getTimeStamp() const ;
00067
00073 void setColormap(std::vector< std::pair<_TValue,_TColor> >& colorMap);
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
00087 size_t getNumValues() const {return m_colorMap.size(); };
00088
00089 void getValue(size_t level, _TValue& value, _TColor& color) const
00090 {
00091 value = m_colorMap[level].first;
00092 color = m_colorMap[level].second;
00093 };
00094
00095 private:
00096
00097 size_t m_timeStamp;
00098
00099 std::vector< std::pair<_TValue,_TColor> > m_colorMap;
00100
00101 bool m_minThresholdEnable;
00102 _TValue m_minThresholdValue;
00103 _TColor m_minThresholdColor;
00104
00105 bool m_maxThresholdEnable;
00106 _TValue m_maxThresholdValue;
00107 _TColor m_maxThresholdColor;
00108
00109 };
00110
00111
00112 template < typename _TValue, typename _TColor, typename _TColorType>
00113 MbLinearColorMapping<_TValue,_TColor,_TColorType>::MbLinearColorMapping()
00114 {
00115 m_minThresholdEnable = false;
00116 m_minThresholdValue = _TValue(0.);
00117 m_maxThresholdEnable = false;
00118 m_maxThresholdValue = _TValue(1.);
00119
00120 m_timeStamp = MxTimeStamp::getTimeStamp();
00121 }
00122
00123 template < typename _TValue, typename _TColor, typename _TColorType>
00124 MbLinearColorMapping<_TValue,_TColor,_TColorType>::~MbLinearColorMapping()
00125 {
00126 }
00127
00128 template < typename _TValue, typename _TColor, typename _TColorType>
00129 void
00130 MbLinearColorMapping<_TValue,_TColor,_TColorType>::setColormap(std::vector< std::pair<_TValue,_TColor> >& colorMap)
00131 {
00132
00133 if ((colorMap.size() != m_colorMap.size()) ||
00134 std::equal(colorMap.begin(),colorMap.end(),m_colorMap.begin()) == false)
00135 {
00136 typename std::vector< std::pair<_TValue,_TColor> >::iterator it;
00137
00138 m_colorMap.clear();
00139 m_colorMap.reserve(colorMap.size());
00140
00141 for (it = colorMap.begin(); it != colorMap.end(); ++it)
00142 {
00143 m_colorMap.push_back(*it);
00144 }
00145
00146 m_timeStamp = MxTimeStamp::getTimeStamp();
00147 }
00148 }
00149 template < typename _TValue, typename _TColor, typename _TColorType>
00150 size_t
00151 MbLinearColorMapping<_TValue,_TColor,_TColorType>::getTimeStamp() const
00152 {
00153 return m_timeStamp;
00154 }
00155
00156 template < typename _TValue, typename _TColor, typename _TColorType>
00157 _TColor
00158 MbLinearColorMapping<_TValue,_TColor,_TColorType>::getColor(_TValue value) const
00159 {
00160
00161 if (m_minThresholdEnable == true && value < m_minThresholdValue)
00162 return m_minThresholdColor;
00163
00164 if (m_maxThresholdEnable == true && m_maxThresholdValue < value)
00165 return m_maxThresholdColor;
00166
00167 _TColor retVal;
00168
00169 _TValue vmin,vmax;
00170 _TColor cmin,cmax;
00171
00172
00173 typename std::vector< std::pair<_TValue,_TColor> >::const_iterator it;
00174 typename std::vector< std::pair<_TValue,_TColor> >::const_iterator itPrev;
00175 for (it=m_colorMap.begin(); it != m_colorMap.end(); ++it)
00176 {
00177 vmax = (*it).first;
00178 if (value < vmax) break;
00179 itPrev = it;
00180 }
00181
00182 if (it == m_colorMap.begin())
00183 {
00184
00185 return (*it).second;
00186 }
00187 if (it == m_colorMap.end())
00188 {
00189
00190 return (*itPrev).second;
00191 }
00192
00193 vmin = (*itPrev).first;
00194 cmin = (*itPrev).second;
00195 cmax = (*it).second;
00196
00197 _TValue v = (value-vmin)/(vmax-vmin);
00198
00199 retVal = _TColorType(v)*(cmax-cmin)+cmin;
00200
00201 return retVal ;
00202 }
00203
00204 template < typename _TValue, typename _TColor, typename _TColorType>
00205 void
00206 MbLinearColorMapping<_TValue,_TColor,_TColorType>::setMinThreshold(bool enable, _TValue minValue, _TColor minColor)
00207 {
00208 if (m_minThresholdEnable != enable || m_minThresholdValue != minValue || m_minThresholdColor != minColor)
00209 m_timeStamp = MxTimeStamp::getTimeStamp();
00210 m_minThresholdEnable = enable;
00211 m_minThresholdValue = minValue;
00212 m_minThresholdColor = minColor;
00213 }
00214
00215 template < typename _TValue, typename _TColor, typename _TColorType>
00216 bool
00217 MbLinearColorMapping<_TValue,_TColor,_TColorType>::getMinThreshold(_TValue& minValue, _TColor& minColor) const
00218 {
00219 minValue = m_minThresholdValue;
00220 minColor = m_minThresholdColor;
00221 return m_minThresholdEnable;
00222 }
00223
00224 template < typename _TValue, typename _TColor, typename _TColorType>
00225 void
00226 MbLinearColorMapping<_TValue,_TColor,_TColorType>::setMaxThreshold(bool enable, _TValue maxValue, _TColor maxColor)
00227 {
00228 if (m_maxThresholdEnable != enable || m_maxThresholdValue != maxValue || m_maxThresholdColor != maxColor)
00229 m_timeStamp = MxTimeStamp::getTimeStamp();
00230 m_maxThresholdEnable = enable;
00231 m_maxThresholdValue = maxValue;
00232 m_maxThresholdColor = maxColor;
00233 }
00234
00235 template < typename _TValue, typename _TColor, typename _TColorType>
00236 bool
00237 MbLinearColorMapping<_TValue,_TColor,_TColorType>::getMaxThreshold(_TValue& maxValue, _TColor& maxColor) const
00238 {
00239 maxValue = m_maxThresholdValue;
00240 maxColor = m_maxThresholdColor;
00241 return m_maxThresholdEnable;
00242 }
00243
00244 template < typename _TValue, typename _TColor, typename _TColorType>
00245 void
00246 MbLinearColorMapping<_TValue,_TColor,_TColorType>::getRange(_TValue& min, _TValue& max) const
00247 {
00248 min = m_colorMap[0].first;
00249 max = m_colorMap[m_colorMap.size()-1].first;
00250 }
00251
00252 #endif
00253
00254
00255
00256
00257
00258
00259
00260