[vtkusers] Strange Problem with vtkImageReslice for 2D rotation

Thomas Zhang tzhang at xradia.com
Fri Jun 12 12:25:51 EDT 2009


Sorry, in the code I posted, the 3rd and 4th lines to force all the input hard-coded have mistakes.  They should be:

            memset(pInImageData, 0, sizeof (float)*nOriginalWidth*nOriginalHeight);     //make it a blank image.
            float fAngle = 0.2;       //hard code the input, angle = 0.2 instead of 0.02

Could anyone please help?  This could potentially be a problem in VTK itself as the exact same inputs give totally different results!

I have also tried the latest version of vtk 5.4.2 and it gives me the same problem.

Thomas
________________________________
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Thomas Zhang
Sent: Thursday, June 11, 2009 12:16 PM
To: vtkusers at vtk.org
Subject: [vtkusers] Strange Problem with vtkImageReslice for 2D rotation

I have this code below to do 2D image rotation.  Strangely, even if I force all the input value as hard coded, it will give me different answers at different times.

The output at the last lines, nNewWidth is sometimes 2055, sometimes 1, which is totally wrong.  The 1st time it's always 1.  Can anyone help?

The vtk version is 5.0.4.

Thanks!
Thomas

            int nOriginalWidth = 2048, nOriginalHeight=2048; //hard code the input.
            float* pInImageData = new float[nOriginalWidth*nOriginalHeight];
            memset(pInImageData, sizeof (float)*nOriginalWidth*nOriginalHeight);
            float fAngle = 0.02; //hard code the input.

            vtkFloatArray *pFltArray1 = vtkFloatArray::New();
            pFltArray1->SetVoidArray(pInImageData,nOriginalWidth*nOriginalHeight,1);


            vtkImageData *pvtkImageData1;
            pvtkImageData1= vtkImageData::New();
            pvtkImageData1->SetDimensions(nOriginalWidth,nOriginalHeight,1);
            pvtkImageData1->SetScalarTypeToFloat();
            pvtkImageData1->SetNumberOfScalarComponents(1);
            pvtkImageData1->GetPointData()->SetScalars(pFltArray1);


            vtkTransform *pTransForm = vtkTransform::New();
            pTransForm->RotateZ(fAngle);
            double points1[3]={1,0,0};
            double points2[3]={0,1,0};
            double points3[3]={0,0,1};

            pTransForm->TransformPoint(points1,points1);
            pTransForm->TransformPoint(points2,points2);
            pTransForm->TransformPoint(points3,points3);

            vtkImageReslice  *pImageReslice = vtkImageReslice::New();
            pImageReslice->SetResliceAxesDirectionCosines(points1,points2,points3);
            pImageReslice->SetInput(pvtkImageData1);

            int nExtent[6];
            pvtkImageData1->GetExtent(nExtent);

            pImageReslice->SetResliceAxesOrigin((nExtent[1]-nExtent[0])/2.0,(nExtent[3]-nExtent[2])/2.0,0);
            pImageReslice->SetOutputExtentToDefault();
            pImageReslice->SetOutputOriginToDefault();
            pImageReslice->GetOutput()->SetUpdateExtentToWholeExtent();
            pImageReslice->MirrorOn ();
            pImageReslice->AutoCropOutputOn();
            pImageReslice->InterpolateOn();
            pImageReslice->Update();

            vtkImageData *pvtkOutImageData = pImageReslice->GetOutput();

            float *pOutData = (float*)pvtkOutImageData->GetScalarPointer();
            int nDim[3];
            pvtkOutImageData->GetDimensions(nDim);

            nNewWidth = nDim[0];
            assert(nNewWidth> nOriginalWidth);

            //ERROR: sometimes nNewWidth is 1; sometimes it's 2055.

________________________________
The information in this email, including any attachments, is confidential and intended only for the recipient(s) listed. Any use of this email for any other purpose is prohibited. If you have received this email in error, please notify me immediately by reply email, delete this email, and do not disclose its contents to anyone.

________________________________
The information in this email, including any attachments, is confidential and intended only for the recipient(s) listed. Any use of this email for any other purpose is prohibited. If you have received this email in error, please notify me immediately by reply email, delete this email, and do not disclose its contents to anyone.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090612/7b8460d1/attachment.htm>


More information about the vtkusers mailing list