fw4spl
SrcLib/io/fwVtkIO/src/fwVtkIO/helper/TransferFunction.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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 #include "fwVtkIO/helper/TransferFunction.hpp"
8 
9 #include <vtkLookupTable.h>
10 
11 namespace fwVtkIO
12 {
13 namespace helper
14 {
15 
16 //------------------------------------------------------------------------------
17 
19  ::fwData::TransferFunction::csptr tf,
20  vtkSmartPointer<vtkLookupTable> lt,
21  bool allowTransparency,
22  unsigned int size )
23 {
24  // Configures basic parameters
25  lt->SetNumberOfTableValues( size );
26  lt->SetScaleToLinear();
27 
28  ::fwData::TransferFunction::TFValuePairType minMax = tf->getMinMaxTFValues();
29 
30  lt->SetTableRange( minMax.first, minMax.second );
31 
32  double delta = ( minMax.second - minMax.first ) / (double) (size - 1);
33  ::fwData::TransferFunction::TFColor interpolatedColor;
34 
35  if ( allowTransparency )
36  {
37  for( unsigned int k = 0; k < size; ++k )
38  {
39  interpolatedColor = tf->getInterpolatedColor( k*delta + minMax.first );
40  lt->SetTableValue(k, interpolatedColor.r, interpolatedColor.g, interpolatedColor.b, interpolatedColor.a);
41  }
42  }
43  else
44  {
45  for( unsigned int k = 0; k < size; ++k )
46  {
47  interpolatedColor = tf->getInterpolatedColor( k*delta + minMax.first );
48  lt->SetTableValue(k, interpolatedColor.r, interpolatedColor.g, interpolatedColor.b, 1.0);
49  }
50  }
51 
52  lt->Modified();
53 }
54 
55 //------------------------------------------------------------------------------
56 
58  double rangeMin,
59  double rangeMax,
60  vtkSmartPointer<vtkLookupTable> lt,
61  unsigned int size )
62 {
64 
65  // Configures basic parameters
66  lt->Allocate( size, size );
67  lt->SetScaleToLinear();
68 
69  lt->SetRampToLinear();
70  lt->SetTableRange( rangeMin, rangeMax );
71  lt->SetAlphaRange( 1.0, 1.0 );
72  lt->SetHueRange( 0.0, 0.0 );
73  lt->SetSaturationRange( 0.0, 0.0 );
74  lt->SetValueRange( 0.0, 1.0 );
75 
76  lt->Build();
77 
78  lt->Modified();
79 }
80 
81 //------------------------------------------------------------------------------
82 
83 } // namespace helper
84 } // namespace fwVtkIO
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
static FWVTKIO_API void toVtkLookupTable(fwData::TransferFunction::csptr tf, vtkSmartPointer< vtkLookupTable > lt, bool allowTransparency=false, unsigned int size=256)
Convert a fwData::TransferFunction to a vtkLookupTable.
static FWVTKIO_API void toBWVtkLookupTable(double rangeMin, double rangeMax, vtkSmartPointer< vtkLookupTable > lt, unsigned int size=256)
Convert the range of an Image or a TransferFunction to a black and white vtkLookupTable.