Michele,<div><br></div><div>Matrix inversion is very sensitive, and the successive inversion operations can easily result in the accumulation of round-off error. You matrix does not seem to be badly ill-conditioned, which would worsen the issue -- admittedly I just eyeballed it instead of calculating it -- and yet after 2 million matrix inversions, I find it believable that you have lost all of your significant digits. Why would you do this? If you need to use both the inverse and forward transforms, make a copy and invert it once. You could also use the GetInverse() function to get the 4x4 matrix that implements the inverse of the current transform. It will always be calculated from the original matrix and will not exhibit this problem. Constantly going back and forth between the forward and inverse transforms is a bad idea from both a mathematical standpoint and from a processing standpoint.</div>
<div><br></div><div>- Wes</div><div><br><div class="gmail_quote">On Mon, Feb 8, 2010 at 10:45 AM, Michele Conconi <span dir="ltr"><<a href="mailto:michele.conconi@unibo.it">michele.conconi@unibo.it</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi again.<br>
I'm sorry, I probably did not explain my problem in the best way.<br>
I do not think that it is a round off error. Indeed, what I'm doing is not reading the output after a bing number of inversion. Instead, I set the transformation matrix to some values, invert it many times, than I reset the matrix into my check configuration and see if the output still corresponds with what I impose. So the problem seems to be that by inverting the vktTransofrm enough times, it "obeys" no more, i.e. it goes no more where it should.<br>
<br>
As both David and Murat suggested, I also thought at the beginning that the problem was caused by some roundoff error. So, to compensateit, I reset the matrix of my transformation to the identity before any change. I also performed my checks introducing some tolerance as you may see in the new code below. Unfortunately, with epsilon up to 1.5 I obtain the same problem. The filter change its behavior always after the same number of cycle (214 for your knowledge). Also, the error I obtain is not of the dimension of a roundoff error. Indeed, at the failure the center of the polydata is<br>
<br>
x = -0.0438237 , y =0.0876474 , z = -4.98359 instead of x = 9.95618, y = -23.462, z = 26.4141<br>
<br>
and the matrix is the identity instead of<br>
<br>
1 0 0 10<br>
0 0.707107 0.707107 -20<br>
0 -0.707107 0.707107 30<br>
0 0 0 1<br>
<br>
Where could be the problem?<br>
Michele<br>
<br>
#include "vtkTransformPolyDataFilter.h"<br>
#include "vtkSTLReader.h"<br>
#include "vtkTransform.h"<br>
#include <iostream><br>
<br>
<br>
using namespace std;<br>
<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
double center[]={0,0,0};<br>
double c[]={0,0,0};<br>
<br>
vtkSTLReader *volumeReader = vtkSTLReader::New();<br>
vtkTransformPolyDataFilter *TF = vtkTransformPolyDataFilter::New();<br>
vtkTransform *ActualPosition = vtkTransform::New();<br>
vtkPolyData *poly = vtkPolyData::New();<br>
<br>
volumeReader->SetFileName("cube.stl");<br>
TF->SetInput(volumeReader->GetOutput());<br>
volumeReader->Delete();<br>
<br>
TF->SetTransform(ActualPosition);<br>
poly=TF->GetOutput();<br>
<br>
poly->GetCenter(center);<br>
cout<<center[0]<<" "<<center[1]<<" "<<center[2]<<endl;//the center of the cube containing the polydata in its ZERO configuration, i.e. no rotation or translation<br>
<br>
ActualPosition->Identity();<br>
ActualPosition->PostMultiply();<br>
ActualPosition->RotateX(-45);<br>
ActualPosition->Translate(10,-20,30);<br>
poly->Update();<br>
<br>
poly->GetCenter(center);<br>
cout<<center[0]<<" "<<center[1]<<" "<<center[2]<<endl;//the center of the cube containing the polydata in the control configuration configuration<br>
ActualPosition->Print(cout);<br>
int i=0;<br>
while(i<200000)<br>
{<br>
//modify the vtkTransform<br>
ActualPosition->Identity();<br>
ActualPosition->PostMultiply();<br>
ActualPosition->RotateX(0);<br>
ActualPosition->Translate(0,0,0);<br>
poly->Update();<br>
<br>
for (int j=0; j<1e7; j++)<br>
{<br>
ActualPosition->Inverse();<br>
//my operations...<br>
ActualPosition->Inverse();<br>
}<br>
<br>
<br>
if(i%10000==0)<br>
cout<<i<<endl;<br>
<br>
//bring it back to the control configuration<br>
ActualPosition->Identity();<br>
ActualPosition->PostMultiply();<br>
ActualPosition->RotateX(-45);<br>
ActualPosition->Translate(10,-20,30);<br>
poly->Update();<br>
<br>
<br>
poly->GetCenter(c);<br>
//check if the center of the cube containing the polydata is still in the right position<br>
double epsilon=1.5;<br>
if(abs(c[0]-center[0])<epsilon && abs(c[1]-center[1])<epsilon && abs(c[2]-center[2])<epsilon)<br>
i++;<br>
else<br>
{<br>
cout<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;<br>
cout<<i<<endl;<br>
ActualPosition->Print(cout);<br>
i=2000000;<br>
}<br>
}<br>
<br>
ActualPosition->Delete();<br>
TF->Delete();<br>
}<br>
-- <br>
* Eng. Michele Conconi*<br>
Ph.D. student<br>
DIEM - Dept. of Mechanical Engineering<br>
Alma Mater Studiorum - University of Bologna<br>
Viale Risorgimento 2, 40136, Bologna, Italy<br>
Email: <a href="mailto:michele.conconi@unibo.it" target="_blank">michele.conconi@unibo.it</a><br>
Website: <a href="http://www.diem.ing.unibo.it/grab" target="_blank">http://www.diem.ing.unibo.it/grab</a><br>
Office: (+39) 051 20 93451<br>
Mobile: (+39) 329 0287996<br>
<br>
<br>
<br>
* INFORMAZIONE RISERVATA E CONFIDENZIALE *<br>
Questo messaggio contiene informazioni riservate e confidenziali.<br>
Se il lettore non fosse il destinatario del messaggio, inoltrato e ricevuto per errore,<br>
il testo dovrà essere immediatamente cancellato dal computer del ricevente.<br>
E' assolutamente proibita qualunque circolazione, disseminazione o<br>
copia del messaggio spedito e/o ricevuto per errore.<br>
<br>
* CONFIDENTIALITY and WARNING NOTICE *<br>
This message may contain legally privileged or confidential information.<br>
If the reader is not the intended recipient, you received this message in error<br>
and it should therefore be deleted from your computer at once.<br>
Any dissemination, distribution and copying of a message<br>
mistakenly sent or received is strictly forbidden.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Wesley D. Turner, Ph.D.<br>Kitware, Inc.<br>Technical Leader<br>28 Corporate Drive<br>Clifton Park, NY 12065-8662<br>Phone: 518-881-4920<br>
</div>