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