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 $
=========================================================================*/
/* ---------------------------------------------------------------------
void Flip::bbUserInitializeProcessing()
{
//std::cout << "-------- entree ds Flip::bbUserInitalizeProcessing()\n" << std::endl;
- //bbUserFinalizeProcessing();
- mImageOut = vtkImageData::New(); // Alloc depends on bbGetInputIn().size()
}
//---------------------------------------------------------------------
// WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR
if (mImageOut!=NULL)
{
- // mImageOut->Delete();
- // mImageOut=NULL;
+ mImageOut->Delete();
+ mImageOut=NULL;
}
bbSetOutputOut(mImageOut);
}
///
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_