From 9c2347c406ff902952cad52796523e6524b210cf Mon Sep 17 00:00:00 2001 From: trillos Date: Tue, 13 Oct 2009 13:46:20 +0000 Subject: [PATCH] Added Switch and Convolution Visualizations --- .../src/bbPackRecalageImageConvolution.cxx | 43 ++++ .../src/bbPackRecalageImageConvolution.h | 41 ++++ .../src/bbPackRecalageImageSubstraction.cxx | 207 +----------------- .../src/bbPackRecalageImageSubstraction.h | 82 +------ .../src/bbPackRecalageImageSwitcherBox.cxx | 9 +- 5 files changed, 98 insertions(+), 284 deletions(-) create mode 100644 PackRecalage/src/bbPackRecalageImageConvolution.cxx create mode 100644 PackRecalage/src/bbPackRecalageImageConvolution.h diff --git a/PackRecalage/src/bbPackRecalageImageConvolution.cxx b/PackRecalage/src/bbPackRecalageImageConvolution.cxx new file mode 100644 index 0000000..e57aedc --- /dev/null +++ b/PackRecalage/src/bbPackRecalageImageConvolution.cxx @@ -0,0 +1,43 @@ +#include "bbPackRecalageImageConvolution.h" +#include "bbPackRecalagePackage.h" +namespace bbPackRecalage +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ImageConvolution) +BBTK_BLACK_BOX_IMPLEMENTATION(ImageConvolution,bbtk::AtomicBlackBox); +void ImageConvolution::Process() +{ + if(convolution != NULL && bbGetInputIn() != NULL) + { + convolution->setImage(bbGetInputIn()); + convolution->setFactor(bbGetInputFactor()); + convolution->Run(); + bbSetOutputOut(convolution->getImage()); + } +} + +void ImageConvolution::bbUserSetDefaultValues() +{ + bbSetInputIn(NULL); + bbSetOutputOut(NULL); + bbSetInputFactor(5.0); +} + +void ImageConvolution::bbUserInitializeProcessing() +{ + convolution = new Convolution(); +} +void ImageConvolution::bbUserFinalizeProcessing() +{ + delete convolution; + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbPackRecalage + + diff --git a/PackRecalage/src/bbPackRecalageImageConvolution.h b/PackRecalage/src/bbPackRecalageImageConvolution.h new file mode 100644 index 0000000..8ead42a --- /dev/null +++ b/PackRecalage/src/bbPackRecalageImageConvolution.h @@ -0,0 +1,41 @@ +#ifndef __bbPackRecalageImageConvolution_h_INCLUDED__ +#define __bbPackRecalageImageConvolution_h_INCLUDED__ +#include "bbPackRecalage_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + +#include "vtkImageData.h" +#include "Convolution.h" + +namespace bbPackRecalage +{ + +class bbPackRecalage_EXPORT ImageConvolution + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(ImageConvolution,bbtk::AtomicBlackBox); + BBTK_DECLARE_INPUT(In,vtkImageData*); + BBTK_DECLARE_INPUT(Factor,double); + BBTK_DECLARE_OUTPUT(Out,vtkImageData*); + BBTK_PROCESS(Process); + void Process(); + + private: + Convolution* convolution; +}; + +BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageConvolution,bbtk::AtomicBlackBox); +BBTK_NAME("ImageConvolution"); +BBTK_AUTHOR("jn.trillos44@uniandes.edu.co"); +BBTK_DESCRIPTION("Processes an image through different convolution matrix (Edge detect)"); +BBTK_CATEGORY("filter"); +BBTK_INPUT(ImageConvolution,In,"Image to be filetered",vtkImageData*,""); +BBTK_INPUT(ImageConvolution,Factor,"Factor by how the edges will be represented",double,""); +BBTK_OUTPUT(ImageConvolution,Out,"Filtered Image",vtkImageData*,""); +BBTK_END_DESCRIBE_BLACK_BOX(ImageConvolution); +} +// EO namespace bbPackRecalage + +#endif // __bbPackRecalageImageConvolution_h_INCLUDED__ + diff --git a/PackRecalage/src/bbPackRecalageImageSubstraction.cxx b/PackRecalage/src/bbPackRecalageImageSubstraction.cxx index 23ef926..46864cc 100644 --- a/PackRecalage/src/bbPackRecalageImageSubstraction.cxx +++ b/PackRecalage/src/bbPackRecalageImageSubstraction.cxx @@ -2,213 +2,11 @@ #include "bbPackRecalagePackage.h" namespace bbPackRecalage { - - MyImageSubstraction::MyImageSubstraction(vtkImageData* imageData1,vtkImageData* imageData2, int uZLevel,int lZLevel, std::vector uColor, std::vector lColor, std::vector mColor) -{ - imageResult= vtkImageData::New(); - sizeImage=0; - uZeroLevel=uZLevel; - lZeroLevel=lZLevel; - if(uColor.size() != NULL) - { - upperColor[0] = uColor[0]; - upperColor[1] = uColor[1]; - upperColor[2] = uColor[2]; - } - else - { - upperColor[0] = 255; - upperColor[1] = 255; - upperColor[2] = 255; - } - if(mColor.size() != NULL) - { - mediumColor[0] = mColor[0]; - mediumColor[1] = mColor[1]; - mediumColor[2] = mColor[2]; - } - else - { - mediumColor[0] = 125; - mediumColor[1] = 125; - mediumColor[2] = 125; - } - if(lColor.size() != NULL) - { - lowerColor[0] = lColor[0]; - lowerColor[1] = lColor[1]; - lowerColor[2] = lColor[2]; - } - else - { - lowerColor[0] = 0; - lowerColor[1] = 0; - lowerColor[2] = 0; - } - - //Original image type this case is an unsigned char (3) - int t=imageData1->GetScalarType(); - //substracting the image - substractImage(imageData1, imageData2); -} - -MyImageSubstraction::~MyImageSubstraction() -{ - if(imageResult!=NULL)imageResult->Delete(); -} - -//---------------------------------------------------------------------------- -// Methods -//---------------------------------------------------------------------------- - - -/* -Calculate the new image and save it in the attribute imageResult -it is used if the user had given the imageData -*/ -void MyImageSubstraction::substractImage(vtkImageData* imageData1, vtkImageData* imageData2) -{ - //dimensions of the image (extent) - int ext[6]; - //setting the dimensionality (1d or 2d or 3d ) - int newDim[3]; - //image spacing - double spc[3]; - - //getting the information from the original image - imageData1->GetSpacing(spc); - imageData1->GetExtent(ext); - - //this a 2d image - newDim[0]=ext[1]-ext[0]+1; - newDim[1]=ext[3]-ext[2]+1; - newDim[2]=1;// in general it is ext[5]-ext[4]+1 - - - //initializing the image that represents the substracted image - initialize(newDim,spc); - //Time to substract - substract(imageData1, imageData2); -} - -/* - getting ready the imageResult -*/ -void MyImageSubstraction::initialize(int dimensions[], double spacing[]) -{ - //setting image data of the imageResult - imageResult->SetScalarTypeToUnsignedChar(); - imageResult->SetSpacing(spacing); - imageResult->SetDimensions(dimensions); - imageResult->AllocateScalars(); - imageResult->Update(); -} - -/* - Setting the values for the -*/ -void MyImageSubstraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) -{ - /* - images pointers - */ - //the new image type is unsigned short (5) - int t=imageData1->GetScalarType(); - - // pointers to get into the image - unsigned char* dataImagePointer1=NULL; - unsigned char* dataImagePointer2=NULL; - unsigned char* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(unsigned char*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(unsigned char*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(unsigned char*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(unsigned char*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(unsigned char*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(unsigned char*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(unsigned char) lowerColor[0]; - dataImageResultPointer[1] =(unsigned char) lowerColor[1]; - dataImageResultPointer[2] =(unsigned char) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(unsigned char) upperColor[0]; - dataImageResultPointer[1] =(unsigned char) upperColor[1]; - dataImageResultPointer[2] =(unsigned char) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(unsigned char) mediumColor[0]; - dataImageResultPointer[1] =(unsigned char) mediumColor[1]; - dataImageResultPointer[2] =(unsigned char) mediumColor[2]; - nZ++; - } - counter++; - } - } - } -} -/* -Returns the filtered image -*/ -vtkImageData* MyImageSubstraction::getSubstractedImage() -{ - return imageResult; -} - -/* - Get Image Size -*/ -int MyImageSubstraction::getImageSize() -{ - return sizeImage; -} - BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ImageSubstraction) BBTK_BLACK_BOX_IMPLEMENTATION(ImageSubstraction,bbtk::AtomicBlackBox); void ImageSubstraction::Process() { - MyImageSubstraction* subImage = new MyImageSubstraction(bbGetInputIn1(),bbGetInputIn2(),bbGetInputIn3(),bbGetInputIn4(),bbGetInputInU(),bbGetInputInL(),bbGetInputInM()); + subImage = new Substraction(bbGetInputIn1(),bbGetInputIn2(),bbGetInputIn3(),bbGetInputIn4(),bbGetInputInU(),bbGetInputInL(),bbGetInputInM()); bbSetOutputOut(subImage->getSubstractedImage()); } @@ -222,6 +20,7 @@ void ImageSubstraction::bbUserSetDefaultValues() bbSetInputInU(vector); bbSetInputInM(vector); bbSetInputInL(vector); + subImage = NULL; } void ImageSubstraction::bbUserInitializeProcessing() @@ -240,7 +39,7 @@ void ImageSubstraction::bbUserFinalizeProcessing() // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers -// if any +// if any } } diff --git a/PackRecalage/src/bbPackRecalageImageSubstraction.h b/PackRecalage/src/bbPackRecalageImageSubstraction.h index f2a18e9..00822e2 100644 --- a/PackRecalage/src/bbPackRecalageImageSubstraction.h +++ b/PackRecalage/src/bbPackRecalageImageSubstraction.h @@ -8,86 +8,11 @@ #include #include +#include "Substraction.h" -namespace bbPackRecalage -{ - class MyImageSubstraction +namespace bbPackRecalage { - - //---------------------------------------------------------------------------------------- - // Methods definition - //---------------------------------------------------------------------------------------- - public: - //-------------------------- - //Constructor & Destructor - //-------------------------- - MyImageSubstraction(vtkImageData* imageData1, vtkImageData* imageData2, int uZLevel,int lZLevel, std::vector uColor, std::vector lColor, std::vector mColor); - ~MyImageSubstraction(); - //-------------------------- - //Methods - //-------------------------- - /* - getting ready the points - */ - void initialize(int dimensions[],double spacing[]); - /* - Calculate the new image and save it in the attribute imageResult - it is used if the user had given the imageData - */ - void substractImage(vtkImageData* imageData1, vtkImageData* imageData2); - - /* - Returns the ImageResult - */ - vtkImageData* getSubstractedImage(); - - /* - Get Image Size - */ - int getImageSize(); - - /* - constructing image substract - */ - void substract(vtkImageData* imageData1, vtkImageData* imageData2); - - - - //---------------------------------------------------------------------------------------- - // Attributes declaration - //---------------------------------------------------------------------------------------- - private: - /* - Substracted Image - */ - vtkImageData* imageResult; - /* - image size dimx*dimy*dimz - */ - int sizeImage; - /* - upper zero level for doing the Substraction - */ - int uZeroLevel; - /* - lower zero level for doing the Substraction - */ - int lZeroLevel; - /* - Color for the upper threshold - */ - int upperColor[3]; - /* - Color for the lower threshold - */ - int lowerColor[3]; - /* - Color for the medium threshold - */ - int mediumColor[3]; -}; - class bbPackRecalage_EXPORT ImageSubstraction : public bbtk::AtomicBlackBox @@ -103,6 +28,9 @@ class bbPackRecalage_EXPORT ImageSubstraction BBTK_DECLARE_OUTPUT(Out,vtkImageData*); BBTK_PROCESS(Process); void Process(); + + private: + Substraction* subImage; }; BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageSubstraction,bbtk::AtomicBlackBox); diff --git a/PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx b/PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx index c5eee38..919e32c 100644 --- a/PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx +++ b/PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx @@ -14,8 +14,10 @@ namespace bbPackRecalage void MyTimer::Notify() { _box->Process(); + _box->bbSignalOutputModification(std::string("Out")); } + BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ImageSwitcherBox) @@ -30,8 +32,9 @@ void ImageSwitcherBox::Process() myTimer->Start(time); oldTime = time; } - else if(oldTime != time) + else if(oldTime != time && myTimer != NULL) { + myTimer->Stop(); myTimer->Start(time); oldTime = time; } @@ -55,8 +58,8 @@ void ImageSwitcherBox::bbUserSetDefaultValues() { myTimer = NULL; change = false; - time = -1; - oldTime = -1; + time = 500; + oldTime = 500; } void ImageSwitcherBox::bbUserInitializeProcessing() { -- 2.47.1