]> Creatis software - bbtk.git/blobdiff - packages/vtk/src/bbvtkInversCrop.cxx
#3212 BBTK Feature New Normal - vtk8itk4wx3-mingw64
[bbtk.git] / packages / vtk / src / bbvtkInversCrop.cxx
index 8581943820eb2e983ad2861975efcda79f2223cb..29be94cabe1ed7bd18a5b9e3f2b6b89130773987 100644 (file)
@@ -26,13 +26,15 @@ void InversCrop::Process()
 //    * TYPE is the C++ type of the input/output
 //      (the one provided in the attribute 'type' of the tag 'input')
 
-    if ((bbGetInputImageFix()!=NULL) && (bbGetInputImageMove()!=NULL) )
-    {
-     if ( bbGetInputImageFix()->GetScalarType()==bbGetInputImageMove()->GetScalarType() ) 
-     {
-        // Creating Image
-       int dim[3];
-       int ext[6];
+       if (bbGetInputActive()==true)
+       {
+           if ( (bbGetInputImageFix()!=NULL) && (bbGetInputImageMove()!=NULL) )
+           {
+            if ( bbGetInputImageFix()->GetScalarType()==bbGetInputImageMove()->GetScalarType() ) 
+            {
+               // Creating Image
+               int dim[3];
+               int ext[6];
        
 //EED 2017-01-01 Migration VTK7
 #if (VTK_MAJOR_VERSION <= 5) 
@@ -111,21 +113,75 @@ void InversCrop::Process()
                     (py>=0)    && (pz>=0)      &&
                     (sizeXM>0) ) 
                {
-                       memcpy( _imageoutput->GetScalarPointer(px,py,pz) , bbGetInputImageMove()->GetScalarPointer(spxM,j,k) , sizeXM );
+                       _imageoutput = vtkImageData::New();
+                       _imageoutput->Initialize();
+                       _imageoutput->SetScalarType( bbGetInputImageFix()->GetScalarType() );
+                       _imageoutput->SetSpacing( bbGetInputImageFix()->GetSpacing() );
+                       _imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
+                       _imageoutput->AllocateScalars();
+                       // Duplicating Fix Image
+                       long sizeimage = dim[0]*dim[1]*dim[2]*bbGetInputImageFix()->GetScalarSize();    
+                       memcpy( _imageoutput->GetScalarPointer() , bbGetInputImageFix()->GetScalarPointer() , sizeimage);
+               }
+               if (bbGetInputType()==1)
+               {
+                       _imageoutput=bbGetInputImageFix();
                }
 
-          } // for j
-       } // for k
-        _imageoutput->Modified();
-      } // If Image Fixe Move the same GetScalarType
-        else {
-           printf ("ERROR: InversCrop  both ImageFixe and ImageMove need the same format.\n");
-      }  
-    } // If Image Fixe Move != NULL
-     else {
-        printf ("ERROR: InversCrop  need ImageFixe and ImageMove to run.\n");
-    } 
-    bbSetOutputOut(_imageoutput);
+
+
+               // Copy the Move Image
+               int j,k; 
+               int px,py,pz;
+
+               bbGetInputImageMove()->GetWholeExtent(ext);
+               int dimMoveX    = ext[1]-ext[0]+1;
+               int dimMoveY    = ext[3]-ext[2]+1;
+               int dimMoveZ    = ext[5]-ext[4]+1;
+
+               int spxM                = 0;  // start px MoveImage
+               int sizeXM              = 0;  // sizeX MoveImage
+
+               px                              = bbGetInputOrigin()[0];
+               spxM                    = 0;
+               if (px<0)
+               { 
+                  spxM=px*(-1);
+                  px=0;
+               }
+               sizeXM = dimMoveX-spxM;
+               if (px+sizeXM>=dim[0]) sizeXM=dim[0]-px;
+               sizeXM=sizeXM*bbGetInputImageFix()->GetScalarSize();
+               for (k=0; k<dimMoveZ; k++)
+               {
+                  for (j=0; j<dimMoveY; j++)
+                  {
+                       py=j+bbGetInputOrigin()[1];
+                               pz=k+bbGetInputOrigin()[2];
+                               if ( (py<dim[1]) && (pz<dim[2]) &&
+                                (py>=0)    && (pz>=0)  &&
+                                        (sizeXM>0) ) 
+                               {
+                                       memcpy( _imageoutput->GetScalarPointer(px,py,pz) , bbGetInputImageMove()->GetScalarPointer(spxM,j,k) , sizeXM );
+                               }
+
+                  } // for j
+               } // for k
+               _imageoutput->Modified();
+             } // If Image Fixe Move the same GetScalarType
+               else {
+                  printf ("ERROR: InversCrop  both ImageFixe and ImageMove need the same format.\n");
+                  printf ("       type ImageFix:%d   type ImageMove:%d\n", bbGetInputImageFix()->GetScalarType(), bbGetInputImageMove()->GetScalarType() );
+
+             }  
+           } // If Image Fixe Move != NULL   
+            else {
+               printf ("ERROR: InversCrop  need ImageFixe and ImageMove to run.\n");
+           } 
+           bbSetOutputOut(_imageoutput);
+
+       } // if Active
+
 }
 
 //===== 
@@ -133,19 +189,17 @@ void InversCrop::Process()
 //===== 
 void InversCrop::bbUserSetDefaultValues()
 {
-
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
+   bbSetInputActive(true);
    bbSetInputType(0);
    bbSetInputImageFix(NULL);
    bbSetInputImageMove(NULL);
-
    std::vector<int> origin;
    origin.push_back(0);
    origin.push_back(0);
    origin.push_back(0);
    bbSetInputOrigin(origin);
-   
    _imageoutput=NULL;
 }
 //=====