[vtkusers] How to draw a line (in display)

David Doria daviddoria+vtk at gmail.com
Wed Apr 14 22:05:05 EDT 2010


On Wed, Apr 14, 2010 at 9:37 PM, Erkang Cheng <ekyaya at gmail.com> wrote:

> Hi all:
>
> I have a question about drawing a line.
> Actually, I want to draw a line in display window. But when I change these
> two points, the line doesn't looks correct.
> I follow the example :
>
> //create two points, P0 and P1
>   double p0[3] = {1.0, 0.0, 0.0};
>
>   double p1[3] = {0.0, 1.0, 0.0};
>
>
>   vtkSmartPointer<vtkLineSource> lineSource =
>       vtkSmartPointer<vtkLineSource>::New();
>
>   lineSource->SetPoint1(p0);
>   lineSource->SetPoint2(p1);
>
>   lineSource->Update();
>
>   //Create a mapper and actor
>   vtkSmartPointer<vtkPolyDataMapper> mapper =
>
>       vtkSmartPointer<vtkPolyDataMapper>::New();
>
>   mapper->SetInputConnection(lineSource->GetOutputPort());
>
>   vtkSmartPointer<vtkActor> actor =
>       vtkSmartPointer<vtkActor>::New();
>
>   actor->SetMapper(mapper);
>
>   //Create a renderer, render window, and interactor
>
>   vtkSmartPointer<vtkRenderer> renderer =
>       vtkSmartPointer<vtkRenderer>::New();
>
>   vtkSmartPointer<vtkRenderWindow> renderWindow =
>       vtkSmartPointer<vtkRenderWindow>::New();
>
>   renderWindow->AddRenderer(renderer);
>   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>
>       vtkSmartPointer<vtkRenderWindowInteractor>::New();
>
>   renderWindowInteractor->SetRenderWindow(renderWindow);
>
>   //Add the actor to the scene
>
>   renderer->AddActor(actor);
>
>   //Render and interact
>   renderWindow->Render();
>
>   renderWindowInteractor->Start();
>
> *But, when I change these two points as*
>
> double p0[3] = {10.0, 0.0, 0.0};
>
>   double p1[3] = {0.0, 10.0, 0.0};
>
> The line doesn't change.
>
> Could Anyone tell me what's the problem?
> I want to draw a line in display coordinate.
>
> Thanks
> Best
> Erkang
>
>
> Erkang,

The camera is automatically reset to "fit" the scene in the render window.
If you want those two lines to appear different, you'll have to control the
camera yourself:

<http://www.vtk.org/Wiki/VTK/Examples/vtkCamera>
http://www.vtk.org/Wiki/VTK/Examples/vtkCamera

Add another object (say a sphere with radius 1) to the scene to convince
yourself of what is happening. (You will see that the sphere is the same
size as the line in your first example, but much smaller than the line in
your second example)
<http://www.vtk.org/Wiki/VTK/Examples/vtkCamera>
Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100414/a14798bb/attachment.htm>


More information about the vtkusers mailing list