]> Creatis software - bbtk.git/commitdiff
BUG 1576 Flip Box
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Mon, 6 Aug 2012 11:49:20 +0000 (11:49 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Mon, 6 Aug 2012 11:49:20 +0000 (11:49 +0000)
    We need to duplicate memory

packages/vtk/src/bbvtkFlip.cxx
packages/vtk/src/bbvtkFlip.h

index 33d70a709d2b2fed5c79127d9ff0f6c64103d06f..4a9bcd201f0f333457fccaecb3e86f2e547664d6 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbvtkFlip.cxx,v $
   Language:  C++
-  Date:      $Date: 2012/07/09 13:03:17 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2012/08/06 11:49:20 $
+  Version:   $Revision: 1.4 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -58,8 +58,6 @@ namespace bbvtk
    void Flip::bbUserInitializeProcessing() 
    {
        //std::cout << "-------- entree ds Flip::bbUserInitalizeProcessing()\n" << std::endl;
-      //bbUserFinalizeProcessing();
-      mImageOut = vtkImageData::New();  // Alloc depends on  bbGetInputIn().size()  
    }
   
 //---------------------------------------------------------------------
@@ -70,8 +68,8 @@ namespace bbvtk
    // WTF? we never enter here // JPR  bbUserFinalizeProcessing()  JPR 
       if (mImageOut!=NULL)
       {
-        // mImageOut->Delete();
-        // mImageOut=NULL;
+        mImageOut->Delete();
+        mImageOut=NULL;
       }
       bbSetOutputOut(mImageOut);          
    }
@@ -85,45 +83,57 @@ namespace bbvtk
  ///
 void Flip::Process()
 {
-       vtkImageData* imageIn = bbGetInputIn();
-       vtkImageData * mImageOut = flip(imageIn);
-      
-   // Devrait etre dans bbUserFinalizeProcessing() ? // JPR    
-        bbSetOutputOut(mImageOut);     
-}
-
+       
+       if (bbGetInputIn()!=NULL)
+       {
+               if (mImageOut!=NULL)
+               {
+                       mImageOut->Delete();
+                       mImageOut=NULL;
+               } // if mImageOut
+       
+               mImageOut = vtkImageData::New();  // Alloc depends on  bbGetInputIn().size()  
+               mImageOut->Initialize();
+               mImageOut->SetScalarType(  bbGetInputIn()->GetScalarType() );
+               mImageOut->SetSpacing(   bbGetInputIn()->GetSpacing()  );
+               mImageOut->SetDimensions(   bbGetInputIn()->GetDimensions()  );
+               mImageOut->SetNumberOfScalarComponents( bbGetInputIn()->GetNumberOfScalarComponents() );
+               mImageOut->AllocateScalars();
+       
+               int inputdims[3];
+               //   int outputdims[3];
+               bbGetInputIn()->GetDimensions (inputdims);
+               bbGetInputIn()->Update();
+               int nbScalComp  = bbGetInputIn()->GetNumberOfScalarComponents();
+               int scalarSize  = bbGetInputIn()->GetScalarSize();
+               int lineSize    = inputdims[0]*scalarSize*nbScalComp;      
+               int planeSize   = inputdims[1]*lineSize;
+               char *pixelsIn  = (char *)bbGetInputIn()->GetScalarPointer();
+               char *pixelsOut = (char *)mImageOut->GetScalarPointer();
+       
+               char *lineIn;
+               char *lineOut;
+               char *debPlanIn;
+               char *debPlanOut;
+               int j,k;
+               for(k=0; k<inputdims[2]; k++)  // iterate on planes
+               {  
+                       debPlanIn       = pixelsIn+k*planeSize;
+                       debPlanOut      = pixelsOut+k*planeSize;
+                       for(j=0; j<inputdims[1]; j++)  // iterates on rows
+                       { 
+                               lineIn = debPlanIn+j*lineSize;
+                               lineOut = debPlanOut+(inputdims[1]-1-j)*lineSize;
+                               memcpy(lineOut,  lineIn, lineSize);
+                       }       // for j
+               } // for k
+       
+               bbSetOutputOut( mImageOut  );           
+       } // bbGetInputIn
 
-vtkImageData * Flip::flip(vtkImageData *imageIn)
-{   
-   int inputdims[3];
-//   int outputdims[3];
-   imageIn->GetDimensions (inputdims);
-   imageIn->Update();
-   int nbScalComp = imageIn->GetNumberOfScalarComponents();
-   int scalarSize = imageIn->GetScalarSize();
-   int lineSize  = inputdims[0]*scalarSize*nbScalComp;    
-   int planeSize = inputdims[1]*lineSize;
-   char *pixelsIn = (char *)imageIn->GetScalarPointer();
-      
-   char *temp = (char *)malloc(lineSize);
-   char *line1;
-   char *line2;
-   char *debPlan;     
-   for(int k=0; k<inputdims[2]; k++) {  // iterate on planes
-        debPlan = pixelsIn+k*planeSize;
-               for(int j=0; j<inputdims[1]/2; j++) { // iterates on rows
-                       line1 = debPlan+j*lineSize;
-                       line2 = debPlan+(inputdims[1]-1-j)*lineSize;
-                       memcpy(temp,  line2, lineSize);
-                       memcpy(line2, line1, lineSize);
-                       memcpy(line1, temp,  lineSize);        
-       }
-   }
-   
-   free (temp);
-   return imageIn;        
 }
 
+
 }//namespace bbtk
 
 #endif // _USE_VTK_
index f6af304e96bda3d0be95b3787f75a28524676f22..2f369aeebfb277970474234ef026bb7f3fb1f726 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbvtkFlip.h,v $
   Language:  C++
-  Date:      $Date: 2010/10/06 16:44:04 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2012/08/06 11:49:20 $
+  Version:   $Revision: 1.2 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -64,7 +64,7 @@ namespace bbvtk
     BBTK_PROCESS(Process);
     void Process();
   private :
-  vtkImageData * flip(vtkImageData *imageIn);
+
   protected:
   
   // Attributes :