[vtkusers] Strange Problem with vtkImageReslice for 2D rotation

Thomas Zhang tzhang at xradia.com
Thu Jun 11 15:15:55 EDT 2009


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090611/ed672f5b/attachment.htm>


More information about the vtkusers mailing list