]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.cxx
e4524c6514a703f050415dbd438abc87b7e151f4
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkScalarsToColors.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaVtkScalarsToColors.h"
5 #include "bbcreaVtkPackage.h"
6
7 namespace bbcreaVtk
8 {
9
10 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ScalarsToColors)
11 BBTK_BLACK_BOX_IMPLEMENTATION(ScalarsToColors,bbtk::AtomicBlackBox);
12 //===== 
13 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
14 //===== 
15 void ScalarsToColors::Process()
16 {
17
18 // THE MAIN PROCESSING METHOD BODY
19 //   Here we simply set the input 'In' value to the output 'Out'
20 //   And print out the output value
21 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
22 //    void bbSet{Input|Output}NAME(const TYPE&)
23 //    const TYPE& bbGet{Input|Output}NAME() const 
24 //    Where :
25 //    * NAME is the name of the input/output
26 //      (the one provided in the attribute 'name' of the tag 'input')
27 //    * TYPE is the C++ type of the input/output
28 //      (the one provided in the attribute 'type' of the tag 'input')
29
30 //    bbSetOutputOut( bbGetInputIn() );
31 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
32   
33    if (firsttime==true)
34         {
35                 firsttime=false;
36
37                 // Create the color map
38                 if (bbGetInputType()==0)
39                 {
40                         _colorLookupTable = vtkLookupTable::New();
41                 _colorLookupTable->Build();
42                    double rgba1[4];
43                    double rgba2[4];
44                    for (int iLookTable = 0; iLookTable<128; iLookTable++)
45                    {
46                                 _colorLookupTable->GetTableValue(      iLookTable, rgba1);
47                                 _colorLookupTable->GetTableValue(256-1-iLookTable, rgba2);
48
49                                 _colorLookupTable->SetTableValue(256-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
50                                 _colorLookupTable->SetTableValue(      iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
51                         } // for iLookTable     
52                 } // if
53   } // firsttime
54
55   if (bbGetInputRange().size()==2)
56   {
57     _colorLookupTable->SetTableRange( bbGetInputRange()[0],bbGetInputRange()[1]);
58   } else {
59     _colorLookupTable->SetTableRange( 0,1 );
60   }
61   
62   double rgb[3];
63   _colorLookupTable->GetColor( bbGetInputScalarValue() , rgb );
64   std::vector<double>colorRGB;
65   colorRGB.push_back( rgb[0] );
66   colorRGB.push_back( rgb[1] );
67   colorRGB.push_back( rgb[2] );
68
69   bbSetOutputColor( colorRGB );
70   bbSetOutputLookupTable(_colorLookupTable);
71   
72 }
73 //===== 
74 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
75 //===== 
76 void ScalarsToColors::bbUserSetDefaultValues()
77 {
78
79 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
80 //    Here we initialize the input 'In' to 0
81    bbSetInputType(0);
82    std::vector<double>range;
83    range.push_back( 0 );
84    range.push_back( 1 );
85         bbSetInputRange(range);
86    bbSetInputScalarValue(0);
87    firsttime=true;
88   
89    _colorLookupTable=NULL;
90 }
91 //===== 
92 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
93 //===== 
94 void ScalarsToColors::bbUserInitializeProcessing()
95 {
96
97 //  THE INITIALIZATION METHOD BODY :
98 //    Here does nothing 
99 //    but this is where you should allocate the internal/output pointers 
100 //    if any 
101
102   
103 }
104 //===== 
105 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
106 //===== 
107 void ScalarsToColors::bbUserFinalizeProcessing()
108 {
109
110 //  THE FINALIZATION METHOD BODY :
111 //    Here does nothing 
112 //    but this is where you should desallocate the internal/output pointers 
113 //    if any
114   
115 }
116 }
117 // EO namespace bbcreaVtk
118
119