[vtkusers] Help - Drawing multiple lines.

prakash vtk prakash2vtk at gmail.com
Tue Jun 17 09:04:44 EDT 2008


Hi all,

How do we draw multiple lines in vtk?

I want to draw a two lines intersecting perpendicularly at the center in my
MPR project- like
             x2,y2
                |
x0,y0--------|--------x1,y1
                |
             x3,y4                                       Here , y0 and y1;
x2 and x3 are equal;

I am using vtklinesource in my program.

code snippet:

     vtkLineSource *linea=vtkLineSource::New();
    vtkPolyDataMapper2D *mapper=vtkPolyDataMapper2D::New();
    vtkActor2D *actor=vtkActor2D::New();
    vtkRenderer *render=vtkRenderer::New();
    vtkRenderWindow *ventana=vtkRenderWindow::New();
    vtkRenderWindowInteractor *interac=vtkRenderWindowInteractor::New();

    vtkInteractorStyleImage *imageStyle = vtkInteractorStyleImage::New();
     linea->SetResolution(4);
    linea->Update();
    linea->GetOutput()->GetPoints()->SetNumberOfPoints(4);
   // Try.
    linea->GetOutput()->GetPoints()->SetPoint(0,150,0,0);
    linea->GetOutput()->GetPoints()->SetPoint(1,150,300,0);
    linea->GetOutput()->GetPoints()->SetPoint(2,0,150,0);
    linea->GetOutput()->GetPoints()->SetPoint(3,300,150,0);
    /*                                        _p
    Dirty fix out put:                 q|_|_
    int x=1024,y=740;                  |
    //Line p & q are outside the rendering window.
    linea->GetOutput()->GetPoints()->SetPoint(0,x/2,0,0);
    linea->GetOutput()->GetPoints()->SetPoint(1,x/2,y,0);
    linea->GetOutput()->GetPoints()->SetPoint(2,0,y,0);
    linea->GetOutput()->GetPoints()->SetPoint(3,0,y/2,0);
    linea->GetOutput()->GetPoints()->SetPoint(4,x,y/2,0);*/

    mapper->SetInput(linea->GetOutput());
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(1.0,0.0,0.0);

    render->AddActor2D(actor);
    render->SetBackground(0.1,0.2,0.4);

    ventana->AddRenderer(render);
    interac->SetInteractorStyle(imageStyle);
    interac->SetRenderWindow(ventana);

    ventana->Render();

   interac->Render();
  //cleanup codes..

  //Code ends here...

But, using vtklinesource, I am getting continuous line as attached snapshot.
I have fixed it. but its a dirty fix which I dont want to integrate in my
project. ( you can see the code for dirty fix and its output in attachment).

Is there any way using vtklinesource to get what I expected?

vtklinesource draws a continuous line, I guess. I might be wrong here...

Or Are there any other classes which help me to do this?
Or how can I get this done in vtk?

Please help me ...

Regards
Prakash,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080617/166c5cea/attachment.htm>


More information about the vtkusers mailing list