]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.cxx
3195 creaVtk Feature New Normal - new Boxes ImageCutByAxis LightKit MeshCutByAxis
[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=200;
66                         for (i=0;i<iMax;i++)
67                         {
68                                 _colorLookupTable->GetTableValue(500+100+i, rgba);
69                                 rgba[3]=(double)i/(double)iMax;
70                                 _colorLookupTable->SetTableValue(500+100+i,rgba);
71                                 _colorLookupTable->GetTableValue(500-100-i, rgba);
72                                 rgba[3]=(double)i/(double)iMax;
73                                 _colorLookupTable->SetTableValue(500-100-i,rgba);
74                         } // for
75
76                         iMax=100;
77                         for (i=0;i<iMax;i++)
78                         {
79                                 _colorLookupTable->GetTableValue(500+i, rgba);
80                                 rgba[3]=0;
81                                 _colorLookupTable->SetTableValue(500+i,rgba);
82                                 _colorLookupTable->GetTableValue(500-i, rgba);
83                                 rgba[3]=0;
84                                 _colorLookupTable->SetTableValue(500-i,rgba);
85                         } // for
86
87                 } // if Type 0
88
89 //EED 2018-06-8 ***********************ARDS Projet***********************************************
90                 if (bbGetInputType()==1)
91                 {
92                         _colorLookupTable = vtkLookupTable::New();
93                         if (bbGetInputRange().size()==2)
94                         {
95                                 _colorLookupTable->SetRange( bbGetInputRange()[0],bbGetInputRange()[1]);
96 //                              _colorLookupTable->SetTableRange( bbGetInputRange()[0],bbGetInputRange()[1]);
97                         } else {
98                                 _colorLookupTable->SetRange(0,255);
99                         }
100                         _colorLookupTable->SetValueRange(0.0, 1.0); // from black to white
101                         _colorLookupTable->SetSaturationRange(0.0, 0.0); // no color saturation
102                         _colorLookupTable->SetRampToLinear();
103                         _colorLookupTable->Build();
104                         double rgba[4];
105                         _colorLookupTable->GetTableValue(0,rgba);
106                         rgba[3]=0;
107                         _colorLookupTable->SetTableValue(0,rgba);
108                 } // IF 
109
110
111
112
113         } // firsttime
114
115         double rgb[3];
116         std::vector<double>colorRGB;
117          _colorLookupTable->GetColor( bbGetInputScalarValue() , rgb );
118         colorRGB.push_back( rgb[0] );
119         colorRGB.push_back( rgb[1] );
120         colorRGB.push_back( rgb[2] );
121         bbSetOutputColor( colorRGB );
122         bbSetOutputLookupTable(_colorLookupTable);
123
124 printf("EED ScalarsToColors::Process End\n");
125
126 }
127 //===== 
128 // 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)
129 //===== 
130 void ScalarsToColors::bbUserSetDefaultValues()
131 {
132
133 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
134 //    Here we initialize the input 'In' to 0
135    bbSetInputType(0);
136    std::vector<double>range;
137    range.push_back( 0 );
138    range.push_back( 1 );
139         bbSetInputRange(range);
140    bbSetInputScalarValue(0);
141    firsttime=true;
142   
143    _colorLookupTable=NULL;
144 }
145 //===== 
146 // 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)
147 //===== 
148 void ScalarsToColors::bbUserInitializeProcessing()
149 {
150
151 //  THE INITIALIZATION METHOD BODY :
152 //    Here does nothing 
153 //    but this is where you should allocate the internal/output pointers 
154 //    if any 
155
156   
157 }
158 //===== 
159 // 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)
160 //===== 
161 void ScalarsToColors::bbUserFinalizeProcessing()
162 {
163
164 //  THE FINALIZATION METHOD BODY :
165 //    Here does nothing 
166 //    but this is where you should desallocate the internal/output pointers 
167 //    if any
168   
169 }
170 }
171 // EO namespace bbcreaVtk
172
173