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)
4 #include "bbvtkSurfaceTexture.h"
5 #include "bbvtkPackage.h"
7 #include <vtkPointData.h>
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SurfaceTexture)
14 BBTK_BLACK_BOX_IMPLEMENTATION(SurfaceTexture,bbtk::AtomicBlackBox);
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)
18 void SurfaceTexture::Process()
20 printf("EED SurfaceTexture:Process() Start\n");
22 // THE MAIN PROCESSING METHOD BODY
23 // Here we simply set the input 'In' value to the output 'Out'
24 // And print out the output value
25 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
26 // void bbSet{Input|Output}NAME(const TYPE&)
27 // const TYPE& bbGet{Input|Output}NAME() const
29 // * NAME is the name of the input/output
30 // (the one provided in the attribute 'name' of the tag 'input')
31 // * TYPE is the C++ type of the input/output
32 // (the one provided in the attribute 'type' of the tag 'input')
34 // bbSetOutputOut( bbGetInputIn() );
35 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
44 if ((bbGetInputImage()!=NULL) && (bbGetInputMesh()!=NULL))
48 bbGetInputImage()->GetSpacing(spc);
49 bbGetInputImage()->GetScalarRange(range);
51 //EED 2017-01-01 Migration VTK7
52 #if VTK_MAJOR_VERSION <= 5
53 bbGetInputImage()->GetWholeExtent(ext);
55 bbGetInputImage()->GetExtent(ext);
58 int maxX = ext[1]-ext[0]+1;
59 int maxY = ext[3]-ext[2]+1;
60 int maxZ = ext[5]-ext[4]+1;
65 // Generate the colors for each point based on the color map
66 colors = vtkUnsignedCharArray::New();
67 colors->SetNumberOfComponents(3);
68 colors->SetName("Colors");
70 // Create the color map
71 if (bbGetInputColorType()==1)
73 colorLookupTableWL = vtkWindowLevelLookupTable::New();
74 colorLookupTableWL->InverseVideoOn();
75 colorLookupTable = colorLookupTableWL;
77 colorLookupTable = vtkLookupTable::New();
79 colorLookupTable->SetTableRange(range[0],range[1]);
80 colorLookupTable->Build();
83 for (int iLookTable = 0; iLookTable<128; iLookTable++)
85 colorLookupTable->GetTableValue( iLookTable, rgba1);
86 colorLookupTable->GetTableValue(256-1-iLookTable, rgba2);
88 colorLookupTable->SetTableValue(256-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
89 colorLookupTable->SetTableValue( iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
92 //EED 2018-06-8 ***********************ARDS Projet***********************************************
93 if (bbGetInputColorType()==2)
96 colorLookupTable = vtkLookupTable::New();
97 // colorLookupTable->SetNumberOfTableValues(tableSize);
98 colorLookupTable->SetTableRange(range[0],range[1]);
99 // colorLookupTable->SetTableRange(0,11);
100 colorLookupTable->Build();
103 for (unsigned int i = 0; i < tableSize; ++i)
105 colorLookupTable->SetTableValue(i,
106 vtkMath::Random(.25, 1.0),
107 vtkMath::Random(.25, 1.0),
108 vtkMath::Random(.25, 1.0),
116 for (int iLookTable = 0; iLookTable<tableSize*3; iLookTable++)
118 i=rand() % tableSize;
119 j=rand() % tableSize;
120 colorLookupTable->GetTableValue(i, rgba1);
121 colorLookupTable->GetTableValue(j, rgba2);
123 colorLookupTable->SetTableValue(j, rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
124 colorLookupTable->SetTableValue(i, rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
130 if (bbGetInputColorType()==3)
133 colorLookupTable = vtkLookupTable::New();
134 colorLookupTable->SetNumberOfTableValues(tableSize);
135 colorLookupTable->SetTableRange(6,range[1]);
136 colorLookupTable->Build();
138 colorLookupTable->SetTableValue(0, 1 ,1 ,1 ,1);
139 colorLookupTable->SetTableValue(1, 1 ,0 ,0 ,1);
140 colorLookupTable->SetTableValue(2, 0 ,1 ,0 ,1);
141 colorLookupTable->SetTableValue(3, 0 ,0 ,1 ,1);
142 colorLookupTable->SetTableValue(4, 0 ,1 ,1 ,1);
143 colorLookupTable->SetTableValue(5, 1 ,1 ,0 ,1);
144 colorLookupTable->SetTableValue(6, 1 ,0 ,1 ,1);
146 colorLookupTable->SetTableValue(7, 0.5,1 ,1 ,1);
147 colorLookupTable->SetTableValue(8, 1 ,0.5,1 ,1);
148 colorLookupTable->SetTableValue(9, 1 ,1 ,0.5,1);
150 colorLookupTable->SetTableValue(10,1 ,0.5,0.5,1);
151 colorLookupTable->SetTableValue(11,0.5,0.5,1 ,1);
161 bbGetInputMesh()->GetPointData()->SetScalars(colors);
163 if (bbGetInputColorType()==1)
165 colorLookupTableWL->SetLevel( bbGetInputColorLevel() );
166 colorLookupTableWL->SetWindow( bbGetInputColorWindow() );
170 if (bbGetInputExternalLookupTable()!=NULL)
172 generalLookupTable = bbGetInputExternalLookupTable();
174 generalLookupTable = colorLookupTable;
177 int missingpoints = bbGetInputMesh()->GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents();
178 for(i = 0; i < missingpoints; i++)
180 colors->InsertNextTuple3(0,0,0);
183 if (bbGetInputTransform()!=NULL)
185 bbGetInputTransform()->Update();
192 for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++)
194 if (bbGetInputTransform()!=NULL)
196 bbGetInputMesh()->GetPoint(i,p1);
197 bbGetInputTransform()->TransformPoint(p1,p2);
199 bbGetInputMesh()->GetPoint(i,p2);
201 p2[0] = p2[0]/spc[0];
202 p2[1] = p2[1]/spc[1];
203 p2[2] = p2[2]/spc[2];
205 if ( (p2[0]>=0) && (p2[0]<maxX) && (p2[1]>=0) && (p2[1]<maxY) &&(p2[2]>=0) && (p2[2]<maxZ) )
207 gl = bbGetInputImage()->GetScalarComponentAsDouble(round(p2[0]), round(p2[1]), round(p2[2]),0);
211 generalLookupTable->GetColor(gl, dcolor);
212 colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]);
214 bbGetInputMesh()->Modified();
216 } // if Image && Mesh
217 printf("EED SurfaceTexture:Process() End\n");
222 // 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 void SurfaceTexture::bbUserSetDefaultValues()
227 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
228 // Here we initialize the input 'In' to 0
229 bbSetInputMesh(NULL);
230 bbSetInputImage(NULL);
231 bbSetInputColorType(0);
232 bbSetInputColorLevel(500);
233 bbSetInputColorWindow(500);
234 bbSetInputTransform(NULL);
235 bbSetInputExternalLookupTable(NULL);
239 colorLookupTable = NULL;
240 colorLookupTableWL = NULL;
243 // 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 void SurfaceTexture::bbUserInitializeProcessing()
248 // THE INITIALIZATION METHOD BODY :
250 // but this is where you should allocate the internal/output pointers
256 // 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)
258 void SurfaceTexture::bbUserFinalizeProcessing()
261 // THE FINALIZATION METHOD BODY :
263 // but this is where you should desallocate the internal/output pointers
268 // EO namespace bbvtk