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 // 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
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')
32 // bbSetOutputOut( bbGetInputIn() );
33 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
39 if ((bbGetInputImage()!=NULL) && (bbGetInputMesh()!=NULL) && ( bbGetInputColorType()>=0 ))
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);
47 bbGetInputImage()->GetExtent(ext);
49 int maxX = ext[1]-ext[0]+1;
50 int maxY = ext[3]-ext[2]+1;
51 int maxZ = ext[5]-ext[4]+1;
53 if (backColorType!=bbGetInputColorType() )
55 backColorType = bbGetInputColorType();
56 if (colors!=NULL) { colors->Delete(); }
57 // if (colorLookupTable!=NULL) { colorLookupTable->Delete(); }
58 // if (colorLookupTableWL!=NULL) { colorLookupTableWL->Delete(); }
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)
69 colorLookupTableWL = vtkWindowLevelLookupTable::New();
70 colorLookupTableWL->InverseVideoOn();
71 colorLookupTable = colorLookupTableWL;
73 colorLookupTable = vtkLookupTable::New();
75 colorLookupTable->SetTableRange(range[0],range[1]);
76 colorLookupTable->Build();
79 for (int iLookTable = 0; iLookTable<128; iLookTable++)
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]);
87 //EED 2018-06-8 ***********************ARDS Projet***********************************************
88 if (bbGetInputColorType()==2)
91 colorLookupTable = vtkLookupTable::New();
92 // colorLookupTable->SetNumberOfTableValues(tableSize);
93 colorLookupTable->SetTableRange(range[0],range[1]);
94 // colorLookupTable->SetTableRange(0,11);
95 colorLookupTable->Build();
98 for (unsigned int i = 0; i < tableSize; ++i)
100 colorLookupTable->SetTableValue(i,
101 vtkMath::Random(.25, 1.0),
102 vtkMath::Random(.25, 1.0),
103 vtkMath::Random(.25, 1.0),
110 for (int iLookTable = 0; iLookTable<tableSize*3; iLookTable++)
112 i=rand() % tableSize;
113 j=rand() % tableSize;
114 colorLookupTable->GetTableValue(i, rgba1);
115 colorLookupTable->GetTableValue(j, rgba2);
117 colorLookupTable->SetTableValue(j, rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
118 colorLookupTable->SetTableValue(i, rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
121 if (bbGetInputColorType()==3)
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);
145 bbGetInputMesh()->GetPointData()->SetScalars(colors);
146 if (bbGetInputColorType()==1)
148 colorLookupTableWL->SetLevel( bbGetInputColorLevel() );
149 colorLookupTableWL->SetWindow( bbGetInputColorWindow() );
151 if (bbGetInputExternalLookupTable()!=NULL)
153 generalLookupTable = bbGetInputExternalLookupTable();
155 generalLookupTable = colorLookupTable;
157 int missingpoints = bbGetInputMesh()->GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents();
158 for(i = 0; i < missingpoints; i++)
160 colors->InsertNextTuple3(0,0,0);
162 if (bbGetInputTransform()!=NULL)
164 bbGetInputTransform()->Update();
170 for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++)
172 if (bbGetInputTransform()!=NULL)
174 bbGetInputMesh()->GetPoint(i,p1);
175 bbGetInputTransform()->TransformPoint(p1,p2);
177 bbGetInputMesh()->GetPoint(i,p2);
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) )
184 gl = bbGetInputImage()->GetScalarComponentAsDouble(round(p2[0]), round(p2[1]), round(p2[2]),0);
188 generalLookupTable->GetColor(gl, dcolor);
189 colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]);
191 bbGetInputMesh()->Modified();
192 } // if Image && Mesh
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)
198 void SurfaceTexture::bbUserSetDefaultValues()
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);
211 backColorType = -999;
213 colorLookupTable = NULL;
214 colorLookupTableWL = NULL;
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)
219 void SurfaceTexture::bbUserInitializeProcessing()
222 // THE INITIALIZATION METHOD BODY :
224 // but this is where you should allocate the internal/output pointers
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)
232 void SurfaceTexture::bbUserFinalizeProcessing()
235 // THE FINALIZATION METHOD BODY :
237 // but this is where you should desallocate the internal/output pointers
242 // EO namespace bbvtk