]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSurfaceTexture.cxx
#3194 BBTK Feature New Normal - Update surfaceTexture box with new lookuptables
[bbtk.git] / packages / vtk / src / bbvtkSurfaceTexture.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 "bbvtkSurfaceTexture.h"
5 #include "bbvtkPackage.h"
6
7 #include <vtkPointData.h>
8 #include <vtkMath.h>
9
10 namespace bbvtk
11 {
12
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SurfaceTexture)
14 BBTK_BLACK_BOX_IMPLEMENTATION(SurfaceTexture,bbtk::AtomicBlackBox);
15 //===== 
16 // 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)
17 //===== 
18 void SurfaceTexture::Process()
19 {
20
21 // THE MAIN PROCESSING METHOD BODY
22 //   Here we simply set the input 'In' value to the output 'Out'
23 //   And print out the output value
24 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
25 //    void bbSet{Input|Output}NAME(const TYPE&)
26 //    const TYPE& bbGet{Input|Output}NAME() const 
27 //    Where :
28 //    * NAME is the name of the input/output
29 //      (the one provided in the attribute 'name' of the tag 'input')
30 //    * TYPE is the C++ type of the input/output
31 //      (the one provided in the attribute 'type' of the tag 'input')
32
33 //    bbSetOutputOut( bbGetInputIn() );
34 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
35   
36
37         int i;
38         double spc[3];
39         double range[2];
40         int ext[6];
41         bbGetInputImage()->GetSpacing(spc);
42         bbGetInputImage()->GetScalarRange(range);
43         bbGetInputImage()->GetWholeExtent(ext);
44         int maxX = ext[1]-ext[0]+1;
45         int maxY = ext[3]-ext[2]+1;
46         int maxZ = ext[5]-ext[4]+1;
47         
48         if (firsttime==true)
49         {
50                 firsttime=false;
51                 // Generate the colors for each point based on the color map
52                 colors = vtkUnsignedCharArray::New(); 
53                 colors->SetNumberOfComponents(3);
54                 colors->SetName("Colors");
55                 
56                 // Create the color map
57                 if (bbGetInputColorType()==1)
58                 {
59                         colorLookupTableWL      = vtkWindowLevelLookupTable::New();
60                         colorLookupTableWL->InverseVideoOn();
61                         colorLookupTable        = colorLookupTableWL;
62                 } else {
63                         colorLookupTable = vtkLookupTable::New();
64                 }
65                 colorLookupTable->SetTableRange(range[0],range[1]);
66                 colorLookupTable->Build();
67                 double rgba1[4];
68                 double rgba2[4];
69                 for (int iLookTable = 0; iLookTable<128; iLookTable++)
70                 {
71                   colorLookupTable->GetTableValue(      iLookTable, rgba1);
72                   colorLookupTable->GetTableValue(256-1-iLookTable, rgba2);
73
74                   colorLookupTable->SetTableValue(256-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
75                   colorLookupTable->SetTableValue(      iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
76                 } // for iLookTable
77
78 //EED 2018-06-8 ***********************ARDS Projet***********************************************
79                 if (bbGetInputColorType()==2)
80                 {
81                         int tableSize=256;
82                         colorLookupTable = vtkLookupTable::New();
83 //                      colorLookupTable->SetNumberOfTableValues(tableSize); 
84                         colorLookupTable->SetTableRange(range[0],range[1]);
85 //                      colorLookupTable->SetTableRange(0,11);
86                         colorLookupTable->Build();
87
88 /*
89   for (unsigned int i = 0; i < tableSize; ++i)
90     {
91     colorLookupTable->SetTableValue(i,
92                        vtkMath::Random(.25, 1.0),
93                        vtkMath::Random(.25, 1.0),
94                        vtkMath::Random(.25, 1.0),
95                        1.0);
96     }
97 */
98
99                         double rgba1[4];
100                         double rgba2[4];
101                         int i,j;
102                         for (int iLookTable = 0; iLookTable<tableSize*3; iLookTable++)
103                         {
104                                 i=rand() % tableSize;
105                                 j=rand() % tableSize;
106                                 colorLookupTable->GetTableValue(i, rgba1);
107                                 colorLookupTable->GetTableValue(j, rgba2);
108
109                           colorLookupTable->SetTableValue(j, rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
110                           colorLookupTable->SetTableValue(i, rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
111                         } // for iLookTable
112
113                 } // type 2
114
115
116                 if (bbGetInputColorType()==3)
117                 {
118                         int tableSize=13;
119                         colorLookupTable = vtkLookupTable::New();
120                         colorLookupTable->SetNumberOfTableValues(tableSize); 
121                         colorLookupTable->SetTableRange(6,range[1]);
122                         colorLookupTable->Build();
123
124                   colorLookupTable->SetTableValue(0, 1  ,1      ,1      ,1);
125                   colorLookupTable->SetTableValue(1, 1  ,0      ,0      ,1);
126                   colorLookupTable->SetTableValue(2, 0  ,1      ,0      ,1);
127                   colorLookupTable->SetTableValue(3, 0  ,0      ,1      ,1);
128                   colorLookupTable->SetTableValue(4, 0  ,1      ,1      ,1);
129                   colorLookupTable->SetTableValue(5, 1  ,1      ,0      ,1);
130                   colorLookupTable->SetTableValue(6, 1  ,0      ,1      ,1);
131
132                   colorLookupTable->SetTableValue(7, 0.5,1      ,1      ,1);
133                   colorLookupTable->SetTableValue(8, 1  ,0.5,1  ,1);
134                   colorLookupTable->SetTableValue(9, 1  ,1      ,0.5,1);
135
136                   colorLookupTable->SetTableValue(10,1  ,0.5,0.5,1);
137                   colorLookupTable->SetTableValue(11,0.5,0.5,1  ,1);
138
139                 } // type 2
140
141
142
143
144         }
145
146         bbGetInputMesh()->GetPointData()->SetScalars(colors);
147
148         if (bbGetInputColorType()==1)
149         {
150                 colorLookupTableWL->SetLevel( bbGetInputColorLevel() );
151                 colorLookupTableWL->SetWindow( bbGetInputColorWindow() );
152         }       
153                 
154     int missingpoints = bbGetInputMesh()->GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents();
155         for(i = 0; i < missingpoints; i++)
156     {
157                 colors->InsertNextTuple3(0,0,0);
158         }       
159
160         if (bbGetInputTransform()!=NULL)
161         {
162                 bbGetInputTransform()->Update();
163         }
164         
165         double gl; 
166         double p1[3];
167         double p2[3];
168         double dcolor[3];
169         for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++)
170     {
171                 if (bbGetInputTransform()!=NULL)
172                 {
173                         bbGetInputMesh()->GetPoint(i,p1);
174                         bbGetInputTransform()->TransformPoint(p1,p2);
175                 } else {
176                         bbGetInputMesh()->GetPoint(i,p2);
177                 }
178                 p2[0] = p2[0]/spc[0];
179                 p2[1] = p2[1]/spc[1];
180                 p2[2] = p2[2]/spc[2];   
181                 
182                 if ( (p2[0]>=0) && (p2[0]<maxX) && (p2[1]>=0) && (p2[1]<maxY) &&(p2[2]>=0) && (p2[2]<maxZ)  )
183                 {
184                    gl =  bbGetInputImage()->GetScalarComponentAsDouble(p2[0], p2[1], p2[2],0);
185                 } else {
186                         gl=0;
187                 }
188                 colorLookupTable->GetColor(gl, dcolor);
189                 colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]);         
190         } // for i
191         bbGetInputMesh()->Modified();   
192
193 }
194 //===== 
195 // 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)
196 //===== 
197 void SurfaceTexture::bbUserSetDefaultValues()
198 {
199
200 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
201 //    Here we initialize the input 'In' to 0
202         bbSetInputMesh(NULL);
203         bbSetInputImage(NULL);
204         bbSetInputColorType(0);
205         bbSetInputColorLevel(500);
206         bbSetInputColorWindow(500);
207         bbSetInputTransform(NULL);
208   
209         firsttime                               = true;
210         colors                                  = NULL;
211         colorLookupTable                = NULL;
212         colorLookupTableWL      = NULL;
213 }
214 //===== 
215 // 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)
216 //===== 
217 void SurfaceTexture::bbUserInitializeProcessing()
218 {
219
220 //  THE INITIALIZATION METHOD BODY :
221 //    Here does nothing 
222 //    but this is where you should allocate the internal/output pointers 
223 //    if any 
224
225   
226 }
227 //===== 
228 // 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)
229 //===== 
230 void SurfaceTexture::bbUserFinalizeProcessing()
231 {
232
233 //  THE FINALIZATION METHOD BODY :
234 //    Here does nothing 
235 //    but this is where you should desallocate the internal/output pointers 
236 //    if any
237   
238 }
239 }
240 // EO namespace bbvtk
241
242