]> Creatis software - creaRigidRegistration.git/commitdiff
Added Switch and Convolution Visualizations
authortrillos <trillos>
Tue, 13 Oct 2009 13:46:20 +0000 (13:46 +0000)
committertrillos <trillos>
Tue, 13 Oct 2009 13:46:20 +0000 (13:46 +0000)
PackRecalage/src/bbPackRecalageImageConvolution.cxx [new file with mode: 0644]
PackRecalage/src/bbPackRecalageImageConvolution.h [new file with mode: 0644]
PackRecalage/src/bbPackRecalageImageSubstraction.cxx
PackRecalage/src/bbPackRecalageImageSubstraction.h
PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx

diff --git a/PackRecalage/src/bbPackRecalageImageConvolution.cxx b/PackRecalage/src/bbPackRecalageImageConvolution.cxx
new file mode 100644 (file)
index 0000000..e57aedc
--- /dev/null
@@ -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 (file)
index 0000000..8ead42a
--- /dev/null
@@ -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__
+
index 23ef9264ac36f8baa887d3caadd3c8f070dfe0ec..46864cc1435802063b803ac11592a7729509575c 100644 (file)
 #include "bbPackRecalagePackage.h"
 namespace bbPackRecalage
 {
-
-       MyImageSubstraction::MyImageSubstraction(vtkImageData* imageData1,vtkImageData* imageData2, int uZLevel,int lZLevel, std::vector<double> uColor, std::vector<double> lColor, std::vector<double> 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;i<sx;i++)
-       {
-               for(j=0;j<sy;j++)
-               {
-                       for(k=0;k<sz;k++)
-                       {
-                               
-                               // this is for getting just the grey level in that position
-                               //originalValue=(short)imageData->GetScalarComponentAsFloat(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
   
 }
 }
index f2a18e9a2d918b16c59adefc36178536bffc664c..00822e2e58e3309f0fd1e208a11ce4d95ab864f7 100644 (file)
@@ -8,86 +8,11 @@
 #include <string>
 #include <vector>
 
+#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<double> uColor, std::vector<double> lColor, std::vector<double> 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);
index c5eee38fd2f570b769e6fc72512dd6737a57d11b..919e32cbf505fb7d5248e5402c92ef77bdad00bb 100644 (file)
@@ -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()
 {