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()
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
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')
33 // bbSetOutputOut( bbGetInputIn() );
34 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
41 bbGetInputImage()->GetSpacing(spc);
42 bbGetInputImage()->GetScalarRange(range);
45 //EED 2017-01-01 Migration VTK7
46 #if VTK_MAJOR_VERSION <= 5
47 bbGetInputImage()->GetWholeExtent(ext);
49 bbGetInputImage()->GetExtent(ext);
52 int maxX = ext[1]-ext[0]+1;
53 int maxY = ext[3]-ext[2]+1;
54 int maxZ = ext[5]-ext[4]+1;
59 // Generate the colors for each point based on the color map
60 colors = vtkUnsignedCharArray::New();
61 colors->SetNumberOfComponents(3);
62 colors->SetName("Colors");
64 // Create the color map
65 if (bbGetInputColorType()==1)
67 colorLookupTableWL = vtkWindowLevelLookupTable::New();
68 colorLookupTableWL->InverseVideoOn();
69 colorLookupTable = colorLookupTableWL;
71 colorLookupTable = vtkLookupTable::New();
73 colorLookupTable->SetTableRange(range[0],range[1]);
74 colorLookupTable->Build();
77 for (int iLookTable = 0; iLookTable<128; iLookTable++)
79 colorLookupTable->GetTableValue( iLookTable, rgba1);
80 colorLookupTable->GetTableValue(256-1-iLookTable, rgba2);
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]);
88 bbGetInputMesh()->GetPointData()->SetScalars(colors);
90 if (bbGetInputColorType()==1)
92 colorLookupTableWL->SetLevel( bbGetInputColorLevel() );
93 colorLookupTableWL->SetWindow( bbGetInputColorWindow() );
96 int missingpoints = bbGetInputMesh()->GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents();
97 for(i = 0; i < missingpoints; i++)
99 colors->InsertNextTuple3(0,0,0);
102 if (bbGetInputTransform()!=NULL)
104 bbGetInputTransform()->Update();
111 for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++)
113 if (bbGetInputTransform()!=NULL)
115 bbGetInputMesh()->GetPoint(i,p1);
116 bbGetInputTransform()->TransformPoint(p1,p2);
118 bbGetInputMesh()->GetPoint(i,p2);
120 p2[0] = p2[0]/spc[0];
121 p2[1] = p2[1]/spc[1];
122 p2[2] = p2[2]/spc[2];
124 if ( (p2[0]>=0) && (p2[0]<maxX) && (p2[1]>=0) && (p2[1]<maxY) &&(p2[2]>=0) && (p2[2]<maxZ) )
126 gl = bbGetInputImage()->GetScalarComponentAsDouble(p2[0], p2[1], p2[2],0);
130 colorLookupTable->GetColor(gl, dcolor);
131 colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]);
133 bbGetInputMesh()->Modified();
137 // 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)
139 void SurfaceTexture::bbUserSetDefaultValues()
142 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
143 // Here we initialize the input 'In' to 0
144 bbSetInputMesh(NULL);
145 bbSetInputImage(NULL);
146 bbSetInputColorType(0);
147 bbSetInputColorLevel(500);
148 bbSetInputColorWindow(500);
149 bbSetInputTransform(NULL);
153 colorLookupTable = NULL;
154 colorLookupTableWL = NULL;
157 // 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)
159 void SurfaceTexture::bbUserInitializeProcessing()
162 // THE INITIALIZATION METHOD BODY :
164 // but this is where you should allocate the internal/output pointers
170 // 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)
172 void SurfaceTexture::bbUserFinalizeProcessing()
175 // THE FINALIZATION METHOD BODY :
177 // but this is where you should desallocate the internal/output pointers
182 // EO namespace bbvtk