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