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