]> Creatis software - creaRigidRegistration.git/blob - PackRecalage/src/bbPackRecalageTransparency.cxx
New items
[creaRigidRegistration.git] / PackRecalage / src / bbPackRecalageTransparency.cxx
1 #include "bbPackRecalageTransparency.h"
2 #include "bbPackRecalagePackage.h"
3
4 #include "vtkCamera.h"
5 #include "vtkImageActor.h"
6
7 #include <vtkImageMapToColors.h>
8 #include <vtkLookupTable.h>
9 #include <vtkCommand.h>
10
11 namespace bbPackRecalage
12 {
13
14         class MyTransparencyImage 
15         {
16         public:
17                 MyTransparencyImage(Transparency* box);
18                 ~MyTransparencyImage();
19
20                 void UpdateView();
21
22         private: 
23
24                 //The box to use
25                 Transparency *mBox;
26
27                 //Upper image (we apply the lookup table with transparency to this actor)
28                 vtkImageActor *upperImageActor;
29
30                 //Base image (not to be modifyed)
31                 vtkImageActor *baseImageActor;
32
33                 bool mUpdateCamera;
34
35         };
36
37         /*
38         * Constructor
39         */
40         MyTransparencyImage::MyTransparencyImage(Transparency* box)
41         :
42                 mBox(box)
43         {
44                 UpdateView();
45         }
46         
47         /*
48         * Destructor
49         */
50         MyTransparencyImage::~MyTransparencyImage()
51         {
52                 //if(newImage != NULL)
53                 {
54                         //newImage->Delete();
55                 }
56         }       
57
58         /*
59         * Set image actors and apply lookup table
60         */
61         void MyTransparencyImage::UpdateView()
62         {
63                 if( ( mBox->bbGetInputImage1() == NULL ) )
64                 {
65                         mUpdateCamera = true;
66                 }
67                 else if( (mBox->bbGetInputImage1() != NULL) && ( (mBox->bbGetInputStatus("Image1") != bbtk::UPTODATE) ) )       
68                 {
69                         mUpdateCamera = true;
70                 }
71                 if(mUpdateCamera)
72                 {
73                         //Lookup Table
74                         vtkLookupTable *lookup = vtkLookupTable::New();
75                         lookup->SetAlphaRange(0, 1);
76                         lookup->SetRange(0, 255); 
77                         lookup->SetValueRange(0.0, 255); 
78
79                         //We assign a table of colors for the upper image, and set the white as transparent
80                         for(int i = 0; i < 256; i++)
81                         {
82                                 if( i >= 0 && i <= 50 )
83                                 {
84                                         lookup->SetTableValue(i, 1.0, 0.0, 1.0, 1);
85                                 }
86                                 else if( i > 50 && i <= 100 )
87                                 {
88                                         lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
89                                 }
90                                 else if( i > 100 && i <= 150 )
91                                 {
92                                         lookup->SetTableValue(i, 0.0, 1.0, 0.0, 1);
93                                 }
94                                 else if( i > 150 && i <= 200 )
95                                 {
96                                         lookup->SetTableValue(i, 0.0, 0.0, 1.0, 1);
97                                 }
98                                 else if( i > 200 && i <= 250 )
99                                 {
100                                         lookup->SetTableValue(i, 0.0, 1.0, 1.0, 1);
101                                 }
102                                 else if( i > 250 && i <= 254)
103                                 {
104                                         lookup->SetTableValue(i, 1.0, 1.0, 0.0, 1);
105                                 }       
106                         }
107                         lookup->SetTableValue(255, 1.0, 1.0, 1.0, 0);
108                         
109                         lookup->SetSaturationRange(0.0, 0.0); 
110                         lookup->SetRampToLinear( );
111                         lookup->Build( );
112
113                         vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
114                         mapperImage->SetLookupTable( lookup );
115                         mapperImage->SetInput( mBox->bbGetInputImage2() );
116                         mapperImage->SetOutputFormatToRGBA( );
117                         
118                         upperImageActor = vtkImageActor::New( );
119                         upperImageActor->SetInput( mapperImage->GetOutput() );
120                         upperImageActor->SetOpacity( 1 );
121
122                         baseImageActor = vtkImageActor::New( );
123                         baseImageActor->SetInput( mBox->bbGetInputImage1() );
124
125                         mBox->bbSetOutputActor1( (vtkProp3D*) baseImageActor );
126                         mBox->bbSetOutputActor2( (vtkProp3D*) upperImageActor );
127         
128                 } 
129         }
130
131 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,Transparency)
132 BBTK_BLACK_BOX_IMPLEMENTATION(Transparency,bbtk::AtomicBlackBox);
133 void Transparency::Process()
134 {
135         MyTransparencyImage* trs = new MyTransparencyImage( this );
136 }
137 void Transparency::bbUserSetDefaultValues()
138 {
139         bbSetInputImage1(NULL); 
140         bbSetInputImage2(NULL);
141         bbSetOutputActor1(NULL);
142         bbSetOutputActor2(NULL);
143   
144 }
145 void Transparency::bbUserInitializeProcessing()
146 {
147  
148 //  THE INITIALIZATION METHOD BODY : 
149 //    Here does nothing  
150 //    but this is where you should allocate the internal/output pointers  
151 //    if any  
152  
153   
154 }
155 void Transparency::bbUserFinalizeProcessing()
156 {
157  
158 //  THE FINALIZATION METHOD BODY : 
159 //    Here does nothing  
160 //    but this is where you should desallocate the internal/output pointers  
161 //    if any 
162   
163 }
164 }
165 // EO namespace bbPackRecalage
166
167