X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=PackRecalage%2Fsrc%2FbbPackRecalageTransparency.cxx;fp=PackRecalage%2Fsrc%2FbbPackRecalageTransparency.cxx;h=3a074a02b650cc84ef69fb0b6a3b11f51adf0529;hb=aa1b23f7a0b103bc3fd8989c0e60b97697adbbc3;hp=0000000000000000000000000000000000000000;hpb=bd79966de4ad9bd5e2991c37c281ab8d1e49161f;p=creaRigidRegistration.git diff --git a/PackRecalage/src/bbPackRecalageTransparency.cxx b/PackRecalage/src/bbPackRecalageTransparency.cxx new file mode 100644 index 0000000..3a074a0 --- /dev/null +++ b/PackRecalage/src/bbPackRecalageTransparency.cxx @@ -0,0 +1,167 @@ +#include "bbPackRecalageTransparency.h" +#include "bbPackRecalagePackage.h" + +#include "vtkCamera.h" +#include "vtkImageActor.h" + +#include +#include +#include + +namespace bbPackRecalage +{ + + class MyTransparencyImage + { + public: + MyTransparencyImage(Transparency* box); + ~MyTransparencyImage(); + + void UpdateView(); + + private: + + //The box to use + Transparency *mBox; + + //Upper image (we apply the lookup table with transparency to this actor) + vtkImageActor *upperImageActor; + + //Base image (not to be modifyed) + vtkImageActor *baseImageActor; + + bool mUpdateCamera; + + }; + + /* + * Constructor + */ + MyTransparencyImage::MyTransparencyImage(Transparency* box) + : + mBox(box) + { + UpdateView(); + } + + /* + * Destructor + */ + MyTransparencyImage::~MyTransparencyImage() + { + //if(newImage != NULL) + { + //newImage->Delete(); + } + } + + /* + * Set image actors and apply lookup table + */ + void MyTransparencyImage::UpdateView() + { + if( ( mBox->bbGetInputImage1() == NULL ) ) + { + mUpdateCamera = true; + } + else if( (mBox->bbGetInputImage1() != NULL) && ( (mBox->bbGetInputStatus("Image1") != bbtk::UPTODATE) ) ) + { + mUpdateCamera = true; + } + if(mUpdateCamera) + { + //Lookup Table + vtkLookupTable *lookup = vtkLookupTable::New(); + lookup->SetAlphaRange(0, 1); + lookup->SetRange(0, 255); + lookup->SetValueRange(0.0, 255); + + //We assign a table of colors for the upper image, and set the white as transparent + for(int i = 0; i < 256; i++) + { + if( i >= 0 && i <= 50 ) + { + lookup->SetTableValue(i, 1.0, 0.0, 1.0, 1); + } + else if( i > 50 && i <= 100 ) + { + lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1); + } + else if( i > 100 && i <= 150 ) + { + lookup->SetTableValue(i, 0.0, 1.0, 0.0, 1); + } + else if( i > 150 && i <= 200 ) + { + lookup->SetTableValue(i, 0.0, 0.0, 1.0, 1); + } + else if( i > 200 && i <= 250 ) + { + lookup->SetTableValue(i, 0.0, 1.0, 1.0, 1); + } + else if( i > 250 && i <= 254) + { + lookup->SetTableValue(i, 1.0, 1.0, 0.0, 1); + } + } + lookup->SetTableValue(255, 1.0, 1.0, 1.0, 0); + + lookup->SetSaturationRange(0.0, 0.0); + lookup->SetRampToLinear( ); + lookup->Build( ); + + vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( ); + mapperImage->SetLookupTable( lookup ); + mapperImage->SetInput( mBox->bbGetInputImage2() ); + mapperImage->SetOutputFormatToRGBA( ); + + upperImageActor = vtkImageActor::New( ); + upperImageActor->SetInput( mapperImage->GetOutput() ); + upperImageActor->SetOpacity( 1 ); + + baseImageActor = vtkImageActor::New( ); + baseImageActor->SetInput( mBox->bbGetInputImage1() ); + + mBox->bbSetOutputActor1( (vtkProp3D*) baseImageActor ); + mBox->bbSetOutputActor2( (vtkProp3D*) upperImageActor ); + + } + } + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,Transparency) +BBTK_BLACK_BOX_IMPLEMENTATION(Transparency,bbtk::AtomicBlackBox); +void Transparency::Process() +{ + MyTransparencyImage* trs = new MyTransparencyImage( this ); +} +void Transparency::bbUserSetDefaultValues() +{ + bbSetInputImage1(NULL); + bbSetInputImage2(NULL); + bbSetOutputActor1(NULL); + bbSetOutputActor2(NULL); + +} +void Transparency::bbUserInitializeProcessing() +{ + +// THE INITIALIZATION METHOD BODY : +// Here does nothing +// but this is where you should allocate the internal/output pointers +// if any + + +} +void Transparency::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbPackRecalage + +