]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSurfaceTexture.cxx
0016c6eeb502c29ce1a2985119e8a679e8087418
[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
44 //EED 2017-01-01 Migration VTK7
45 #if VTK_MAJOR_VERSION <= 5
46         bbGetInputImage()->GetWholeExtent(ext);
47 #else
48         bbGetInputImage()->GetExtent(ext);
49 #endif
50
51         int maxX = ext[1]-ext[0]+1;
52         int maxY = ext[3]-ext[2]+1;
53         int maxZ = ext[5]-ext[4]+1;
54         
55         if (firsttime==true)
56         {
57                 firsttime=false;
58                 // Generate the colors for each point based on the color map
59                 colors = vtkUnsignedCharArray::New(); 
60                 colors->SetNumberOfComponents(3);
61                 colors->SetName("Colors");
62                 
63                 // Create the color map
64                 if (bbGetInputColorType()==1)
65                 {
66                         colorLookupTableWL      = vtkWindowLevelLookupTable::New();
67                         colorLookupTableWL->InverseVideoOn();
68                         colorLookupTable        = colorLookupTableWL;
69                 } else {
70                         colorLookupTable = vtkLookupTable::New();
71                 }
72                 colorLookupTable->SetTableRange(range[0],range[1]);
73                 colorLookupTable->Build();
74                 double rgba1[4];
75                 double rgba2[4];
76                 for (int iLookTable = 0; iLookTable<128; iLookTable++)
77                 {
78                   colorLookupTable->GetTableValue(      iLookTable, rgba1);
79                   colorLookupTable->GetTableValue(256-1-iLookTable, rgba2);
80
81                   colorLookupTable->SetTableValue(256-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
82                   colorLookupTable->SetTableValue(      iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
83                 } // for iLookTable
84
85 //EED 2018-06-8 ***********************ARDS Projet***********************************************
86                 if (bbGetInputColorType()==2)
87                 {
88                         int tableSize=256;
89                         colorLookupTable = vtkLookupTable::New();
90 //                      colorLookupTable->SetNumberOfTableValues(tableSize); 
91                         colorLookupTable->SetTableRange(range[0],range[1]);
92 //                      colorLookupTable->SetTableRange(0,11);
93                         colorLookupTable->Build();
94
95 /*
96   for (unsigned int i = 0; i < tableSize; ++i)
97     {
98     colorLookupTable->SetTableValue(i,
99                        vtkMath::Random(.25, 1.0),
100                        vtkMath::Random(.25, 1.0),
101                        vtkMath::Random(.25, 1.0),
102                        1.0);
103     }
104 */
105
106                         double rgba1[4];
107                         double rgba2[4];
108                         int i,j;
109                         for (int iLookTable = 0; iLookTable<tableSize*3; iLookTable++)
110                         {
111                                 i=rand() % tableSize;
112                                 j=rand() % tableSize;
113                                 colorLookupTable->GetTableValue(i, rgba1);
114                                 colorLookupTable->GetTableValue(j, rgba2);
115
116                           colorLookupTable->SetTableValue(j, rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
117                           colorLookupTable->SetTableValue(i, rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
118                         } // for iLookTable
119
120                 } // type 2
121
122
123                 if (bbGetInputColorType()==3)
124                 {
125                         int tableSize=13;
126                         colorLookupTable = vtkLookupTable::New();
127                         colorLookupTable->SetNumberOfTableValues(tableSize); 
128                         colorLookupTable->SetTableRange(6,range[1]);
129                         colorLookupTable->Build();
130
131                   colorLookupTable->SetTableValue(0, 1  ,1      ,1      ,1);
132                   colorLookupTable->SetTableValue(1, 1  ,0      ,0      ,1);
133                   colorLookupTable->SetTableValue(2, 0  ,1      ,0      ,1);
134                   colorLookupTable->SetTableValue(3, 0  ,0      ,1      ,1);
135                   colorLookupTable->SetTableValue(4, 0  ,1      ,1      ,1);
136                   colorLookupTable->SetTableValue(5, 1  ,1      ,0      ,1);
137                   colorLookupTable->SetTableValue(6, 1  ,0      ,1      ,1);
138
139                   colorLookupTable->SetTableValue(7, 0.5,1      ,1      ,1);
140                   colorLookupTable->SetTableValue(8, 1  ,0.5,1  ,1);
141                   colorLookupTable->SetTableValue(9, 1  ,1      ,0.5,1);
142
143                   colorLookupTable->SetTableValue(10,1  ,0.5,0.5,1);
144                   colorLookupTable->SetTableValue(11,0.5,0.5,1  ,1);
145
146                 } // type 3
147
148
149                 
150
151         }  // firsttime
152
153
154         bbGetInputMesh()->GetPointData()->SetScalars(colors);
155
156         if (bbGetInputColorType()==1)
157         {
158                 colorLookupTableWL->SetLevel( bbGetInputColorLevel() );
159                 colorLookupTableWL->SetWindow( bbGetInputColorWindow() );
160         }       
161
162
163         if (bbGetInputExternalLookupTable()!=NULL) 
164         {
165                 generalLookupTable = bbGetInputExternalLookupTable();
166         } else {
167                 generalLookupTable = colorLookupTable;
168         }
169                 
170     int missingpoints = bbGetInputMesh()->GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents();
171         for(i = 0; i < missingpoints; i++)
172     {
173                 colors->InsertNextTuple3(0,0,0);
174         }       
175
176         if (bbGetInputTransform()!=NULL)
177         {
178                 bbGetInputTransform()->Update();
179         }
180         
181         double gl; 
182         double p1[3];
183         double p2[3];
184         double dcolor[3];
185         for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++)
186     {
187                 if (bbGetInputTransform()!=NULL)
188                 {
189                         bbGetInputMesh()->GetPoint(i,p1);
190                         bbGetInputTransform()->TransformPoint(p1,p2);
191                 } else {
192                         bbGetInputMesh()->GetPoint(i,p2);
193                 }
194                 p2[0] = p2[0]/spc[0];
195                 p2[1] = p2[1]/spc[1];
196                 p2[2] = p2[2]/spc[2];   
197                 
198                 if ( (p2[0]>=0) && (p2[0]<maxX) && (p2[1]>=0) && (p2[1]<maxY) &&(p2[2]>=0) && (p2[2]<maxZ)  )
199                 {
200                    gl =  bbGetInputImage()->GetScalarComponentAsDouble(p2[0], p2[1], p2[2],0);
201                 } else {
202                         gl=0;
203                 }
204                 generalLookupTable->GetColor(gl, dcolor);
205                 colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]);         
206         } // for i
207         bbGetInputMesh()->Modified();   
208
209 }
210 //===== 
211 // 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)
212 //===== 
213 void SurfaceTexture::bbUserSetDefaultValues()
214 {
215
216 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
217 //    Here we initialize the input 'In' to 0
218         bbSetInputMesh(NULL);
219         bbSetInputImage(NULL);
220         bbSetInputColorType(0);
221         bbSetInputColorLevel(500);
222         bbSetInputColorWindow(500);
223         bbSetInputTransform(NULL);
224   
225         firsttime                               = true;
226         colors                                  = NULL;
227         colorLookupTable                = NULL;
228         colorLookupTableWL              = NULL;
229 }
230 //===== 
231 // 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)
232 //===== 
233 void SurfaceTexture::bbUserInitializeProcessing()
234 {
235
236 //  THE INITIALIZATION METHOD BODY :
237 //    Here does nothing 
238 //    but this is where you should allocate the internal/output pointers 
239 //    if any 
240
241   
242 }
243 //===== 
244 // 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)
245 //===== 
246 void SurfaceTexture::bbUserFinalizeProcessing()
247 {
248
249 //  THE FINALIZATION METHOD BODY :
250 //    Here does nothing 
251 //    but this is where you should desallocate the internal/output pointers 
252 //    if any
253   
254 }
255 }
256 // EO namespace bbvtk
257
258