1 #include "bbPackRecalageTransparency.h"
2 #include "bbPackRecalagePackage.h"
5 #include "vtkImageActor.h"
7 #include <vtkImageMapToColors.h>
8 #include <vtkLookupTable.h>
9 #include <vtkCommand.h>
11 namespace bbPackRecalage
14 class MyTransparencyImage
17 MyTransparencyImage(Transparency* box);
18 ~MyTransparencyImage();
27 //Upper image (we apply the lookup table with transparency to this actor)
28 vtkImageActor *upperImageActor;
30 //Base image (not to be modifyed)
31 vtkImageActor *baseImageActor;
40 MyTransparencyImage::MyTransparencyImage(Transparency* box)
50 MyTransparencyImage::~MyTransparencyImage()
52 //if(newImage != NULL)
59 * Set image actors and apply lookup table
61 void MyTransparencyImage::UpdateView()
63 if( ( mBox->bbGetInputImage1() == NULL ) )
67 else if( (mBox->bbGetInputImage1() != NULL) && ( (mBox->bbGetInputStatus("Image1") != bbtk::UPTODATE) ) )
74 vtkLookupTable *lookup = vtkLookupTable::New();
75 lookup->SetAlphaRange(0, 1);
76 lookup->SetRange(0, 255);
77 lookup->SetValueRange(0.0, 255);
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++)
82 if( i >= 0 && i <= 50 )
84 lookup->SetTableValue(i, 1.0, 0.0, 1.0, 1);
86 else if( i > 50 && i <= 100 )
88 lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
90 else if( i > 100 && i <= 150 )
92 lookup->SetTableValue(i, 0.0, 1.0, 0.0, 1);
94 else if( i > 150 && i <= 200 )
96 lookup->SetTableValue(i, 0.0, 0.0, 1.0, 1);
98 else if( i > 200 && i <= 250 )
100 lookup->SetTableValue(i, 0.0, 1.0, 1.0, 1);
102 else if( i > 250 && i <= 254)
104 lookup->SetTableValue(i, 1.0, 1.0, 0.0, 1);
107 lookup->SetTableValue(255, 1.0, 1.0, 1.0, 0);
109 lookup->SetSaturationRange(0.0, 0.0);
110 lookup->SetRampToLinear( );
113 vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
114 mapperImage->SetLookupTable( lookup );
115 mapperImage->SetInput( mBox->bbGetInputImage2() );
116 mapperImage->SetOutputFormatToRGBA( );
118 upperImageActor = vtkImageActor::New( );
119 upperImageActor->SetInput( mapperImage->GetOutput() );
120 upperImageActor->SetOpacity( 1 );
122 baseImageActor = vtkImageActor::New( );
123 baseImageActor->SetInput( mBox->bbGetInputImage1() );
125 mBox->bbSetOutputActor1( (vtkProp3D*) baseImageActor );
126 mBox->bbSetOutputActor2( (vtkProp3D*) upperImageActor );
131 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,Transparency)
132 BBTK_BLACK_BOX_IMPLEMENTATION(Transparency,bbtk::AtomicBlackBox);
133 void Transparency::Process()
135 MyTransparencyImage* trs = new MyTransparencyImage( this );
137 void Transparency::bbUserSetDefaultValues()
139 bbSetInputImage1(NULL);
140 bbSetInputImage2(NULL);
141 bbSetOutputActor1(NULL);
142 bbSetOutputActor2(NULL);
145 void Transparency::bbUserInitializeProcessing()
148 // THE INITIALIZATION METHOD BODY :
150 // but this is where you should allocate the internal/output pointers
155 void Transparency::bbUserFinalizeProcessing()
158 // THE FINALIZATION METHOD BODY :
160 // but this is where you should desallocate the internal/output pointers
165 // EO namespace bbPackRecalage