tags:

views:

303

answers:

1

Can somebody point me in the right direction of how to draw a multiple lines that seem connected? I found vtkLine and its SetPoint1 and SetPoint2 functions. Then I found vtkPolyLine, but there doesn't seem to be any add, insert or set function for this. Same for vtkPolyVertex.

Is there a basic function that allows me to just push some point at the end of its internal data and the simply render it? Or if there's no such function/object, what is the way to go here?

On a related topic: I don't like vtk too much. Is there a visualization toolkit, maybe with limited functionality, that is easier to use?

Thanks in advance

+1  A: 

For drawing multiple lines, you should first create a vtkPoints class that contains all the points, and then add in connectivity info for the points you would like connected into lines through either vtkPolyData or vtkUnstructuredGrid (which is your vtkDataSet class; a vtkDataSet class contains vtkPoints as well as the connectivity information for these points). Once your vtkDataSet is constructued, you can take the normal route to render it (mapper->actor->renderer...)

For example:

vtkPoints *pts = vtkPoints::New();
pts->InsertNextPoint(1,1,1);
...
pts->InsertNextPoint(5,5,5);

vtkPolyData *polydata = vtkPolyData::New();
polydata->Allocate();
vtkIdType connectivity[2];
connectivity[0] = 0;
connectivity[1] = 3;
polydata->InsertNextCell(VTK_LINE,2,connectivity); //Connects the first and fourth point we inserted into a line

vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInput(polydata);

// And so on, need actor and renderer now

There are plenty of examples on the documentation site for all the classes Here is vtkPoints : http://www.vtk.org/doc/release/5.4/html/a01250.html

If you click on the vtkPoints (Tests) link, you can see the tests associated with the class. It provides a bunch of different sample code.

Also, the vtk mailing list is probably going to be much more useful than stack overflow.

Will