<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial">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.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial">The output at the last lines, nNewWidth is sometimes 2055, sometimes 1, which is totally wrong. The 1<sup>st</sup> time it’s always 1. Can anyone help?<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial">The vtk version is 5.0.4.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial">Thanks!<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial">Thomas<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> int nOriginalWidth = 2048, nOriginalHeight=2048; //hard code the input.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> float* pInImageData = new float[nOriginalWidth*nOriginalHeight];<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> memset(pInImageData, sizeof (float)*nOriginalWidth*nOriginalHeight);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> float fAngle = 0.02; //hard code the input.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> vtkFloatArray *pFltArray1 = vtkFloatArray::New();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pFltArray1->SetVoidArray(pInImageData,nOriginalWidth*nOriginalHeight,1);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> vtkImageData *pvtkImageData1;<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pvtkImageData1= vtkImageData::New();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pvtkImageData1->SetDimensions(nOriginalWidth,nOriginalHeight,1);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pvtkImageData1->SetScalarTypeToFloat();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pvtkImageData1->SetNumberOfScalarComponents(1);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pvtkImageData1->GetPointData()->SetScalars(pFltArray1);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> vtkTransform *pTransForm = vtkTransform::New();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pTransForm->RotateZ(fAngle);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> double points1[3]={1,0,0};<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> double points2[3]={0,1,0};<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> double points3[3]={0,0,1};<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pTransForm->TransformPoint(points1,points1);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pTransForm->TransformPoint(points2,points2);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pTransForm->TransformPoint(points3,points3);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> vtkImageReslice *pImageReslice = vtkImageReslice::New();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->SetResliceAxesDirectionCosines(points1,points2,points3);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->SetInput(pvtkImageData1);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> int nExtent[6];<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pvtkImageData1->GetExtent(nExtent);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->SetResliceAxesOrigin((nExtent[1]-nExtent[0])/2.0,(nExtent[3]-nExtent[2])/2.0,0);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->SetOutputExtentToDefault();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->SetOutputOriginToDefault();
<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->GetOutput()->SetUpdateExtentToWholeExtent();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->MirrorOn ();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->AutoCropOutputOn();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->InterpolateOn();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pImageReslice->Update();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> vtkImageData *pvtkOutImageData = pImageReslice->GetOutput();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> float *pOutData = (float*)pvtkOutImageData->GetScalarPointer();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> int nDim[3];<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> pvtkOutImageData->GetDimensions(nDim);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> nNewWidth = nDim[0];<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> assert(nNewWidth> nOriginalWidth);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;
font-family:Arial"> //ERROR: sometimes nNewWidth is 1; sometimes it’s 2055.<o:p></o:p></span></font></p>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1">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.<br>
</font>
</body>
</html>