[vtkusers] Re: how to get the world coordinates of a point?

lin zhang zhanglinsjtu at gmail.com
Thu Jul 12 03:23:42 EDT 2007


Hi Michael

Thanks for you kind help! Your solution is so cool!
Before I get your solution, I have tried another way to retrieve the world
coordinate of the points and it seems that it can also work well.
The example code:


 vtkDataSet dataSetCone1 = coneActor1.GetMapper().GetInputAsDataSet();

    vtkTransform transform = new vtkTransform();

    transform.SetMatrix(coneActor1.GetMatrix());



     double[] localcoor = new double[3];

     localcoor = dataSetCone1.GetPoint(id);

  double[] worldPos = transform.TransformDoublePoint(localcoor);

Then the worldPos is the world coordinate of the point.

Thanks a lot,
Best Regards,
Lin Zhang



Message: 8
Date: Tue, 10 Jul 2007 09:57:23 +0200
From: "Michael Knopke" <Michael.Knopke at gmx.de>
Subject: [vtkusers] how to get the world coordinates of a point?
To: <vtkusers at vtk.org>
Message-ID: <000001c7c2c7$f35edf70$4378a8c0 at imagesystems.local>
Content-Type: text/plain; charset="us-ascii"

Hi Lin Zhang,



I had the same "problem" as you before. The reason is, that when applying
any transformation/rotation matrix to a dataset (e.g. with vtkTransform) it
will not change the position of the original points. (It changes only the
position of actors but you can't querry their WorldCoordinates)

You will have to use vtkTransformPolyDataFilter on the dataset to really
transform it.



Here is an example (translating one point only):



   vtkPoints *inputPoints2 = vtkPoints::New();

                   inputPoints2->SetDataTypeToDouble();

                   inputPoints2->SetNumberOfPoints(1);

                   inputPoints2->SetPoint(0,corPos);





  vtkPolyData *poly2 = vtkPolyData::New();

                     poly2->SetPoints(inputPoints1);



  vtkTransformPolyDataFilter *transPolyData2 =
vtkTransformPolyDataFilter::New();

                     transPolyData2->SetInput(poly2);

                     transPolyData2->SetTransform(sag_mprTransform);

                     transPolyData2->Update();



                     vtkPoints *outputPoints2
=transPolyData2->GetOutput()->GetPoints();

                     double TranslatedPoint2[3];

                     TranslatedPoint2 = outputPoints2->GetPoint(0);



  transPolyData->Delete();

  poly2->Delete();

  inputPoints2->Delete();

  outputPoints2->Delete();



Better to look for vtkTransformPolyDataFilter to get better examples.



Regards



Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070712/c42b8378/attachment.htm>


More information about the vtkusers mailing list