]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.cxx
#3198 creaVtk Bug New Normal - VtkLightKit
[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 printf("EED ScalarsToColors::Process Start\n");
34         if (firsttime==true)
35         {
36                 firsttime=false;
37                 // Create the color map
38                 if (bbGetInputType()==0)
39                 {
40                         _colorLookupTable = vtkLookupTable::New();
41                         if (bbGetInputRange().size()==2)
42                         {
43                                 _colorLookupTable->SetRange( bbGetInputRange()[0],bbGetInputRange()[1]);
44 //                              _colorLookupTable->SetTableRange( bbGetInputRange()[0],bbGetInputRange()[1]);
45                         } else {
46                                 _colorLookupTable->SetRange(0,255);
47                         }
48                         _colorLookupTable->SetNumberOfTableValues(1000);
49                         _colorLookupTable->Build();
50                         double rgba1[4];
51                         double rgba2[4];
52                         int iLookTable;
53                         for (iLookTable = 0; iLookTable<500; iLookTable++)
54                         {
55                                 _colorLookupTable->GetTableValue(      iLookTable, rgba1);
56                                 _colorLookupTable->GetTableValue(1000-1-iLookTable, rgba2);
57                                 _colorLookupTable->SetTableValue(1000-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
58                                 _colorLookupTable->SetTableValue(      iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
59                         } // for iLookTable     
60                         double rgba[4];
61                         _colorLookupTable->GetTableValue(0,rgba);
62                         rgba[3]=0;
63                         _colorLookupTable->SetTableValue(0,rgba);
64
65                         int i,iMax;
66
67                         iMax=(1000/16)*4;
68                         for (i=0;i<iMax;i++)
69                         {
70
71                                 _colorLookupTable->GetTableValue(500+i, rgba);
72                                 rgba[3]=(double)i/(double)iMax;
73                                 _colorLookupTable->SetTableValue(500+i,rgba);
74                                 _colorLookupTable->GetTableValue(500-i, rgba);
75                                 rgba[3]=(double)i/(double)iMax;
76                                 _colorLookupTable->SetTableValue(500-i,rgba);
77
78                         } // for
79
80
81 /*
82                         iMax=100;
83                         for (i=0;i<iMax;i++)
84                         {
85
86                                 _colorLookupTable->GetTableValue(500+100+i, rgba);
87                                 rgba[3]=(double)i/(double)iMax;
88                                 _colorLookupTable->SetTableValue(500+100+i,rgba);
89                                 _colorLookupTable->GetTableValue(500-100-i, rgba);
90                                 rgba[3]=(double)i/(double)iMax;
91                                 _colorLookupTable->SetTableValue(500-100-i,rgba);
92
93                         } // for
94
95                         iMax=200;
96                         for (i=0;i<iMax;i++)
97                         {
98                                 _colorLookupTable->GetTableValue(500+i, rgba);
99                                 rgba[3]=0;
100                                 _colorLookupTable->SetTableValue(500+i,rgba);
101                                 _colorLookupTable->GetTableValue(500-i, rgba);
102                                 rgba[3]=0;
103                                 _colorLookupTable->SetTableValue(500-i,rgba);
104                         } // for
105 */
106
107
108
109                 } // if Type 0
110
111 //EED 2018-06-8 ***********************ARDS Projet***********************************************
112                 if (bbGetInputType()==1)
113                 {
114                         _colorLookupTable = vtkLookupTable::New();
115                         if (bbGetInputRange().size()==2)
116                         {
117                                 _colorLookupTable->SetRange( bbGetInputRange()[0],bbGetInputRange()[1]);
118 //                              _colorLookupTable->SetTableRange( bbGetInputRange()[0],bbGetInputRange()[1]);
119                         } else {
120                                 _colorLookupTable->SetRange(0,255);
121                         }
122                         _colorLookupTable->SetValueRange(0.0, 1.0); // from black to white
123                         _colorLookupTable->SetSaturationRange(0.0, 0.0); // no color saturation
124                         _colorLookupTable->SetRampToLinear();
125                         _colorLookupTable->Build();
126                         double rgba[4];
127                         _colorLookupTable->GetTableValue(0,rgba);
128                         rgba[3]=0;
129                         _colorLookupTable->SetTableValue(0,rgba);
130                 } // IF 
131
132
133
134
135         } // firsttime
136
137         double rgb[3];
138         std::vector<double>colorRGB;
139          _colorLookupTable->GetColor( bbGetInputScalarValue() , rgb );
140         colorRGB.push_back( rgb[0] );
141         colorRGB.push_back( rgb[1] );
142         colorRGB.push_back( rgb[2] );
143         bbSetOutputColor( colorRGB );
144         bbSetOutputLookupTable(_colorLookupTable);
145
146 printf("EED ScalarsToColors::Process End\n");
147
148 }
149 //===== 
150 // 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)
151 //===== 
152 void ScalarsToColors::bbUserSetDefaultValues()
153 {
154
155 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
156 //    Here we initialize the input 'In' to 0
157    bbSetInputType(0);
158    std::vector<double>range;
159    range.push_back( 0 );
160    range.push_back( 1 );
161         bbSetInputRange(range);
162    bbSetInputScalarValue(0);
163    firsttime=true;
164   
165    _colorLookupTable=NULL;
166 }
167 //===== 
168 // 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)
169 //===== 
170 void ScalarsToColors::bbUserInitializeProcessing()
171 {
172
173 //  THE INITIALIZATION METHOD BODY :
174 //    Here does nothing 
175 //    but this is where you should allocate the internal/output pointers 
176 //    if any 
177
178   
179 }
180 //===== 
181 // 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)
182 //===== 
183 void ScalarsToColors::bbUserFinalizeProcessing()
184 {
185
186 //  THE FINALIZATION METHOD BODY :
187 //    Here does nothing 
188 //    but this is where you should desallocate the internal/output pointers 
189 //    if any
190   
191 }
192 }
193 // EO namespace bbcreaVtk
194
195