[vtkusers] Display Coordinates Doesn't Change After Translation
Wenlong Wang
scc.wwl at gmail.com
Mon Oct 31 09:01:46 EDT 2011
Hi, David
Sorry the last mail missed somthing.
The current situdation is, I set the transform like (1, 1, 0), and a new
polydata object was created and translated to another place. I catch the
new polydata with a pointer. In this case, I think the out coming of my
code should show that the display coordinates of points on the new sphere
has the value like ( X_originnal + X_translate, Y_original+Y_Translate, 0),
since I didn't translate it in Z direction.
But the result shows the X and Y coordinates were not changed at all, only
the Z has slight difference. Why is this happened? It really strange.
Thank you so much.
Wenlong
2011/10/31 Wenlong Wang <scc.wwl at gmail.com>
> Hi, David,
>
> Thank you for your help.
>
> Here is the code shows the problem I encountered.
>
> *vtkSphereSource* s = vtkSphereSource::New();
> s->Update();
>
> vtkTransform* trans = vtkTransform::New();
> trans->Translate(1, 1, 0);
>
> vtkTransformPolyDataFilter* tf = vtkTransformPolyDataFilter::New();
> tf->SetInputConnection(s->GetOutputPort());
> tf->SetTransform(trans);
> tf->Update();
>
> vtkPolyDataMapper* originalMapper = vtkPolyDataMapper::New();
> originalMapper->SetInputConnection(s->GetOutputPort());
>
> vtkActor* originalActor = vtkActor::New();
> originalActor->SetMapper(originalMapper);
> originalActor->GetProperty()->SetColor(1, 0, 0);
>
> vtkPolyDataMapper* transformedMapper = vtkPolyDataMapper::New();
> transformedMapper->SetInputConnection(tf->GetOutputPort());
>
> vtkActor* transdformedActor = vtkActor::New();
> transdformedActor->SetMapper(transformedMapper);
> transdformedActor->GetProperty()->SetColor(0 ,1, 0);
>
> vtkCamera* camera = vtkCamera::New();
> camera->SetPosition(0, 0, 5);
> camera->SetViewUp(0, 1, 0);
>
> vtkRenderer* ren = vtkRenderer::New();
> ren->AddActor(originalActor);
> ren->AddActor(transdformedActor);
> ren->SetActiveCamera(camera);
>
> vtkRenderWindow* renWin = vtkRenderWindow::New();
> renWin->AddRenderer(ren);
>
> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(renWin);
>
> //------------------Start to convert the world coordinates to display
> coordinates--------------
> vtkPoints* points = vtkPoints::New();
> vtkPolyData* polydata = vtkPolyData::New();
>
> polydata = tf->GetOutput();
> points = polydata->GetPoints();
>
> double p[3], r[3];
> for (int i = 0; i< 50; i++)
> {
> points->GetPoint(i, p);
> ren->SetWorldPoint(p);
> ren->WorldToDisplay();
> ren->GetDisplayPoint(r);
> }**
> renWin->Render();
> iren->Start();*
>
> On the screen, the sphere did translate to another place. However, when I
> check the display coordinates store in point *r*, I found the X and Y are
> not changed, only Z has slight difference.
>
> Thank you again for your time.
>
> Wenlong
>
>
> 2011/10/30 David Doria <daviddoria at gmail.com>
>
>> On Sat, Oct 29, 2011 at 1:47 PM, Wenlong Wang <scc.wwl at gmail.com> wrote:
>>
>>> Hi David,
>>>
>>> I tried the example about vtkTransformPolyDataFilter and applied it to
>>> my actor. But seems the coordinates didn't change in the way I discribed in
>>> my earlier mail.
>>>
>>> So is that because I didn't use it right? Or I should use other methods
>>> to get access to the new dataset generated by vtkTransformPolyDataFilter?
>>>
>>> Thank you very much.
>>>
>>> Long
>>
>>
>> I suggest you send the smallest possible compilable code that you can to
>> demonstrate the problem. Something like simply display a vtkSphereSource.
>> Describe the behavior the code produces, and the behavior that you are
>> aiming for.
>>
>> David
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111031/fb3ac81c/attachment.htm>
More information about the vtkusers
mailing list