]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSurfaceTexture.cxx
#2862 BBTK Bug New Normal - SurfaceTexture inverse W/B to B/W
[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
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
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 
27 //    Where :
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')
32
33 //    bbSetOutputOut( bbGetInputIn() );
34 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
35   
36 printf("EED SurfaceTexture::Process Start\n");
37
38         int i;
39         double spc[3];
40         double range[2];
41         int ext[6];
42         bbGetInputImage()->GetSpacing(spc);
43         bbGetInputImage()->GetScalarRange(range);
44         bbGetInputImage()->GetWholeExtent(ext);
45         int maxX = ext[1]-ext[0]+1;
46         int maxY = ext[3]-ext[2]+1;
47         int maxZ = ext[5]-ext[4]+1;
48         
49         if (firsttime==true)
50         {
51                 firsttime=false;
52                 // Generate the colors for each point based on the color map
53                 colors = vtkUnsignedCharArray::New(); 
54                 colors->SetNumberOfComponents(3);
55                 colors->SetName("Colors");
56                 
57                 // Create the color map
58                 if (bbGetInputColorType()==1)
59                 {
60                         colorLookupTableWL      = vtkWindowLevelLookupTable::New();
61                         colorLookupTableWL->InverseVideoOn();
62                         colorLookupTable        = colorLookupTableWL;
63                 } else {
64                         colorLookupTable = vtkLookupTable::New();
65                 }
66                 colorLookupTable->SetTableRange(range[0],range[1]);
67                 colorLookupTable->Build();
68                 double rgba1[4];
69                 double rgba2[4];
70                 for (int iLookTable = 0; iLookTable<128; iLookTable++)
71                 {
72                   colorLookupTable->GetTableValue(      iLookTable, rgba1);
73                   colorLookupTable->GetTableValue(256-1-iLookTable, rgba2);
74
75                   colorLookupTable->SetTableValue(256-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
76                   colorLookupTable->SetTableValue(      iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
77                 } // for iLookTable
78
79         }
80
81         bbGetInputMesh()->GetPointData()->SetScalars(colors);
82
83         if (bbGetInputColorType()==1)
84         {
85                 colorLookupTableWL->SetLevel( bbGetInputColorLevel() );
86                 colorLookupTableWL->SetWindow( bbGetInputColorWindow() );
87         }       
88                 
89     int missingpoints = bbGetInputMesh()->GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents();
90         for(i = 0; i < missingpoints; i++)
91     {
92                 colors->InsertNextTuple3(0,0,0);
93         }       
94
95         if (bbGetInputTransform()!=NULL)
96         {
97                 bbGetInputTransform()->Update();
98         }
99         
100         double gl; 
101         double p1[3];
102         double p2[3];
103         double dcolor[3];
104         for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++)
105     {
106                 if (bbGetInputTransform()!=NULL)
107                 {
108                         bbGetInputMesh()->GetPoint(i,p1);
109                         bbGetInputTransform()->TransformPoint(p1,p2);
110                 } else {
111                         bbGetInputMesh()->GetPoint(i,p2);
112                 }
113                 p2[0] = p2[0]/spc[0];
114                 p2[1] = p2[1]/spc[1];
115                 p2[2] = p2[2]/spc[2];   
116                 
117                 if ( (p2[0]>=0) && (p2[0]<maxX) && (p2[1]>=0) && (p2[1]<maxY) &&(p2[2]>=0) && (p2[2]<maxZ)  )
118                 {
119                    gl =  bbGetInputImage()->GetScalarComponentAsDouble(p2[0], p2[1], p2[2],0);
120                 } else {
121                         gl=0;
122                 }
123                 colorLookupTable->GetColor(gl, dcolor);
124                 colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]);         
125         } // for i
126         bbGetInputMesh()->Modified();   
127
128 }
129 //===== 
130 // 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)
131 //===== 
132 void SurfaceTexture::bbUserSetDefaultValues()
133 {
134
135 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
136 //    Here we initialize the input 'In' to 0
137         bbSetInputMesh(NULL);
138         bbSetInputImage(NULL);
139         bbSetInputColorType(0);
140         bbSetInputColorLevel(500);
141         bbSetInputColorWindow(500);
142         bbSetInputTransform(NULL);
143   
144         firsttime                               = true;
145         colors                                  = NULL;
146         colorLookupTable                = NULL;
147         colorLookupTableWL      = NULL;
148 }
149 //===== 
150 // 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)
151 //===== 
152 void SurfaceTexture::bbUserInitializeProcessing()
153 {
154
155 //  THE INITIALIZATION METHOD BODY :
156 //    Here does nothing 
157 //    but this is where you should allocate the internal/output pointers 
158 //    if any 
159
160   
161 }
162 //===== 
163 // 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)
164 //===== 
165 void SurfaceTexture::bbUserFinalizeProcessing()
166 {
167
168 //  THE FINALIZATION METHOD BODY :
169 //    Here does nothing 
170 //    but this is where you should desallocate the internal/output pointers 
171 //    if any
172   
173 }
174 }
175 // EO namespace bbvtk
176
177