//===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== #include "bbvtkInversCrop.h" #include "bbvtkPackage.h" namespace bbvtk { BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,InversCrop) BBTK_BLACK_BOX_IMPLEMENTATION(InversCrop,bbtk::AtomicBlackBox); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void InversCrop::Process() { // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value // INPUT/OUTPUT ACCESSORS ARE OF THE FORM : // void bbSet{Input|Output}NAME(const TYPE&) // const TYPE& bbGet{Input|Output}NAME() const // Where : // * NAME is the name of the input/output // (the one provided in the attribute 'name' of the tag 'input') // * TYPE is the C++ type of the input/output // (the one provided in the attribute 'type' of the tag 'input') 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) bbGetInputImageFix()->GetWholeExtent(ext); #endif #if (VTK_MAJOR_VERSION >= 6) bbGetInputImageFix()->GetExtent(ext); #endif dim[0]= ext[1]-ext[0]+1; dim[1]= ext[3]-ext[2]+1; dim[2] = 1; if (bbGetInputImageFix()->GetDataDimension()==3) { dim[2] = ext[5]-ext[4]+1; } if (bbGetInputType()==0) { _imageoutput = vtkImageData::New(); _imageoutput->Initialize(); _imageoutput->SetSpacing( bbGetInputImageFix()->GetSpacing() ); _imageoutput->SetDimensions( dim[0], dim[1], dim[2] ); //EED 2017-01-01 Migration VTK7 #if (VTK_MAJOR_VERSION <= 5) _imageoutput->SetScalarType( bbGetInputImageFix()->GetScalarType() ); _imageoutput->AllocateScalars(); #endif #if (VTK_MAJOR_VERSION >= 6) _imageoutput->AllocateScalars(bbGetInputImageFix()->GetScalarType() , 1); #endif // Duplicating Fix Image long sizeimage = dim[0]*dim[1]*dim[2]*bbGetInputImageFix()->GetScalarSize(); memcpy( _imageoutput->GetScalarPointer() , bbGetInputImageFix()->GetScalarPointer() , sizeimage); } if (bbGetInputType()==1) { _imageoutput=bbGetInputImageFix(); } // Copy the Move Image int j,k; int px,py,pz; //EED 2017-01-01 Migration VTK7 #if (VTK_MAJOR_VERSION <= 5) bbGetInputImageMove()->GetWholeExtent(ext); #endif #if (VTK_MAJOR_VERSION >= 6) bbGetInputImageMove()->GetExtent(ext); #endif int dimMoveX = ext[1]-ext[0]+1; int dimMoveY = ext[3]-ext[2]+1; int dimMoveZ = 1; if (bbGetInputImageMove()->GetDataDimension()==3) { dimMoveZ = ext[5]-ext[4]+1; } double org[3]; org[0]=0; org[1]=0; org[2]=0; if (bbGetInputOrigin().size()==3) { org[0]=bbGetInputOrigin()[0]; org[1]=bbGetInputOrigin()[1]; org[2]=bbGetInputOrigin()[2]; } if (bbGetInputOrigin().size()==2) { org[0]=bbGetInputOrigin()[0]; org[1]=bbGetInputOrigin()[1]; } if (bbGetInputOrigin().size()==1) { org[0]=bbGetInputOrigin()[0]; } int spxM = 0; // start px MoveImage int sizeXM = 0; // sizeX MoveImage px = org[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; kGetDataDimension()==3) { pz = k+org[2]; } else { pz = k; }// Dimension 3 if ( (py=0) && (pz>=0) && (sizeXM>0) ) { memcpy( _imageoutput->GetScalarPointer(px,py,pz) , bbGetInputImageMove()->GetScalarPointer(spxM,j,k) , sizeXM ); } } // for j } // for k _imageoutput->Modified(); } else { // If Image Fixe Move the same GetScalarType printf ("ERROR: InversCrop both ImageFixe and ImageMove need the same format.\n"); printf (" type ImageFix:%d type ImageMove:%d\n", bbGetInputImageFix()->GetScalarType(), bbGetInputImageMove()->GetScalarType() ); } } else { // If Image Fixe Move != NULL printf ("ERROR: InversCrop need ImageFixe and ImageMove to run.\n"); } bbSetOutputOut(_imageoutput); } // if Active } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== 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 origin; origin.push_back(0); origin.push_back(0); origin.push_back(0); bbSetInputOrigin(origin); _imageoutput=NULL; } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void InversCrop::bbUserInitializeProcessing() { // THE INITIALIZATION METHOD BODY : // Here does nothing // but this is where you should allocate the internal/output pointers // if any } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void InversCrop::bbUserFinalizeProcessing() { // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers // if any } } // EO namespace bbvtk