fw4spl
SrcLib/core/fwData/include/fwData/TransferFunction.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWDATA_TRANSFERFUNCTION_HPP__
8 #define __FWDATA_TRANSFERFUNCTION_HPP__
9 
10 #include "fwData/config.hpp"
11 #include "fwData/Object.hpp"
12 
13 fwCampAutoDeclareDataMacro((fwData)(TransferFunction), FWDATA_API);
14 
15 namespace fwData
16 {
17 
23 class FWDATA_CLASS_API TransferFunction : public Object
24 {
25 
26 public:
27 
29  ::fwData::factory::New< TransferFunction >)
30 
31 
32 
33  fwCampMakeFriendDataMacro((fwData)(TransferFunction))
34 
36  struct TFColor
37  {
38  typedef double ColorType;
39 
41  ColorType r;
43  ColorType g;
45  ColorType b;
47  ColorType a;
48 
49  // Default constructor
50  TFColor()
51  {
52  r = 0.0;
53  g = 0.0;
54  b = 0.0;
55  a = 0.0;
56  }
57 
58  TFColor( ColorType _r, ColorType _g, ColorType _b, ColorType _a )
59  {
60  r = _r;
61  g = _g;
62  b = _b;
63  a = _a;
64  }
65 
66  //------------------------------------------------------------------------------
67 
68  inline bool operator== (const TFColor& _color) const
69  {
70  return (r == _color.r && g == _color.g && b == _color.b && a == _color.a);
71  }
72 
73  };
74 
76 
77  typedef enum
78  {
79  LINEAR,
80  NEAREST
82 
83  typedef double TFValueType;
84  typedef std::vector<TFValueType> TFValueVectorType;
85 
86  typedef std::vector<TFColor> TFColorVectorType;
87  typedef std::map< TFValueType, TFColor > TFDataType;
88 
89  typedef std::pair< TFValueType, TFValueType > TFValuePairType;
90 
95  FWDATA_API TransferFunction(::fwData::Object::Key key);
96 
98  FWDATA_API virtual ~TransferFunction();
99 
100  // Initialize a default TF.
101  FWDATA_API void initTF();
102 
103  // Create a default TF
104  FWDATA_API static TransferFunction::sptr createDefaultTF();
105 
107  FWDATA_API void shallowCopy( const Object::csptr& _source ) override;
108 
110  FWDATA_API void cachedDeepCopy(const Object::csptr& _source, DeepCopyCacheType& cache) override;
111 
113  FWDATA_API TFValueVectorType getTFValues() const;
114 
116  FWDATA_API TFValueVectorType getScaledValues() const;
117 
119  FWDATA_API TFValuePairType getMinMaxTFValues() const;
120 
122  FWDATA_API TFValuePairType getWLMinMax() const;
123 
125  FWDATA_API void setWLMinMax(const TFValuePairType& minMax);
126 
128  FWDATA_API TFValueType getNearestValue( TFValueType value ) const;
129 
131  FWDATA_API const TFDataType& getTFData() const;
132 
134  FWDATA_API void setTFData( const TFDataType& tfData );
135 
137  FWDATA_API void addTFColor( TFValueType value, const TFColor& color );
138 
140  FWDATA_API void eraseTFValue( TFValueType value);
141 
143  FWDATA_API void clear();
144 
146  FWDATA_API TFColorVectorType getTFColors() const;
147 
149  FWDATA_API TFColor getNearestColor( TFValueType value ) const;
150 
152  FWDATA_API TFColor getLinearColor( TFValueType value ) const;
153 
155  FWDATA_API TFColor getInterpolatedColor( TFValueType value ) const;
156 
157  // Get the color associated to the value.
158  FWDATA_API const TFColor& getTFColor( TFValueType value ) const;
159 
161  InterpolationMode getInterpolationMode () const;
162 
163  void setInterpolationMode (InterpolationMode val);
164 
166  double getLevel () const;
167  void setLevel (double val);
168 
170  double getWindow () const;
171  void setWindow (double val);
172 
174  const std::string& getName () const;
175  void setName (const std::string& val);
176 
178  bool getIsClamped () const;
179  void setIsClamped (bool val);
180 
182  const TFColor& getBackgroundColor () const;
183  void setBackgroundColor (const TFColor& val);
184 
186  FWDATA_API static const std::string s_DEFAULT_TF_NAME;
187 
192  typedef ::fwCom::Signal< void () > PointsModifiedSignalType;
194  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_POINTS_MODIFIED_SIG;
195 
197  typedef ::fwCom::Signal< void (double, double) > WindowingModifiedSignalType;
198  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_WINDOWING_MODIFIED_SIG;
203 private:
204 
206  double m_level;
207 
209  double m_window;
210 
212  std::string m_name;
213 
215  TFColor m_backgroundColor;
216 
218  TFDataType m_tfData;
219 
221  InterpolationMode m_interpolationMode;
222 
229  bool m_isClamped;
230 
231 };
232 
233 //-----------------------------------------------------------------------------
234 
236 {
237  TFColor color;
238 
239  if(m_interpolationMode == LINEAR)
240  {
241  color = this->getLinearColor(value);
242  }
243  else if(m_interpolationMode == NEAREST)
244  {
245  color = this->getNearestColor(value);
246  }
247  return color;
248 }
249 
250 //-----------------------------------------------------------------------------
251 
253 {
254  return m_interpolationMode;
255 }
256 
257 //-----------------------------------------------------------------------------
258 
259 inline void TransferFunction::setInterpolationMode (InterpolationMode val)
260 {
261  m_interpolationMode = val;
262 }
263 
264 //-----------------------------------------------------------------------------
265 
266 inline double TransferFunction::getLevel () const
267 {
268  return m_level;
269 }
270 
271 //-----------------------------------------------------------------------------
272 
273 inline void TransferFunction::setLevel (double val)
274 {
275  m_level = val;
276 }
277 
278 //-----------------------------------------------------------------------------
279 
280 inline double TransferFunction::getWindow () const
281 {
282  return m_window;
283 }
284 
285 //-----------------------------------------------------------------------------
286 
287 inline void TransferFunction::setWindow (double val)
288 {
289  m_window = val;
290 }
291 
292 //-----------------------------------------------------------------------------
293 
294 inline const std::string& TransferFunction::getName () const
295 {
296  return m_name;
297 }
298 
299 //-----------------------------------------------------------------------------
300 
301 inline void TransferFunction::setName (const std::string& val)
302 {
303  m_name = val;
304 }
305 
306 //-----------------------------------------------------------------------------
307 
308 inline bool TransferFunction::getIsClamped () const
309 {
310  return m_isClamped;
311 }
312 
313 //-----------------------------------------------------------------------------
314 
315 inline void TransferFunction::setIsClamped (bool val)
316 {
317  m_isClamped = val;
318 }
319 
320 //-----------------------------------------------------------------------------
321 
323 {
324  return m_backgroundColor;
325 }
326 
327 //-----------------------------------------------------------------------------
328 
329 inline void TransferFunction::setBackgroundColor (const TFColor& val)
330 {
331  m_backgroundColor = val;
332 }
333 
334 //-----------------------------------------------------------------------------
335 
336 } // namespace fwData
337 
338 #endif // __FWDATA_TRANSFERFUNCTION_HPP__
339 
static FWDATA_API const std::string s_DEFAULT_TF_NAME
Default transfer function name.
FWDATA_API TFColor getInterpolatedColor(TFValueType value) const
Get the interpolated color of the TF for a value.The result depends of the current interpolation mode...
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
const TFColor & getBackgroundColor() const
set the TF background color when tf &#39;IsClamped&#39; is true
Base class for each data object.
InterpolationMode getInterpolationMode() const
Interpolation mode.
Contains the representation of the data objects used in the framework.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_WINDOWING_MODIFIED_SIG
Type of signal when points are modified.
::fwCom::Signal< void(double, double) > WindowingModifiedSignalType
Type of signal when window-level is modified (window, level)
const std::string & getName() const
Transfert function name.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINTS_MODIFIED_SIG
Type of signal when points are modified.
InterpolationMode
Defines the available modes {LINEAR, NEAREST} to interpolate color between two TF color points...