Plot lines using pairs of points

Will Schroeder will.schroeder at kitware.com
Mon Oct 18 18:45:50 EDT 1999


Hi Li-

I think you'd be much better off just creating a vtkPolyData directly, with appropriate cell data. Something like:

vtkPolyData *pd = vtkPolyData::New();
vtkPoints *pts = vtkPoints::New();
vtkCellArray *ca = vtkCellArray::New();
ca->Allocate(ca->EstimateSize(numLines,2));
vtkScalars *cellScalars = vtkCellScalars::New();
cellScalars->SetNumberOfScalars(numLines);

cellScalars->SetNumber
  //for each line
for (i=0; i<numLines; i++)
   {
   ptIds[0] = pts->InsertNextPoint(endPoint1);
   ptIds[1] = pts->InsertNextPoint(endPoint2);

   cellId = ca->InsertNextCell(s,ptIds);
   cellScalars->SetScalar(cellId, ve);
   }

pd->SetPoints(pts);
pd->SetLines(ca);
pd->GetCellData()->SetScalars(cellScalars);
pts->Delete();
ca->Delete();
cellScalars->Delete();

and then hook the polydata to a vtkPolyDataMapper and display.

Will

At 02:03 PM 10/18/99 -0700, you wrote:
>Hello,
>
>I have a number of pairs of points, representing the two end points of
>lines, in the format of
>(xs1, ys1, zs1, vs1), (xe1, ye1, ze1, ve1)
>(xs2, ys2, zs2, vs2), (xe2, ye2, ze2, ve2)
>...
>(xsN, ysN, zsN, vsN), (xeN, yeN, zeN, veN),
>where vs and ve are the color value of the start and the end points of a
>line.
>
>I am going to use the following to display these lines but not sure it is
>the best way to do it.
>
>vtkLineSource* line_source = vtkLineSource::New();
>vtkScalars* lineScalar = vtkFloatScalars::New();
>lineScalar->SetNumberOfScalars(1);
>vtkAppendPolyData* line_group = vtkAppendPolyData::New();
>
>for (int i=0; i<numLines; i++)
>{
>         float v = (points[2*i][_V] + points[2*i+1][_V]) / 2.;   // _V=3
>         lineScalar->SetScalar(0, v);
>         line_source->SetPoint1(points[2*i][_X], points[2*i][_Y], points[2*i][_Z]);
>// _X=0,_Y=1,_Z=2
>         line_source->SetPoint2(points[2*i+1][_X], points[2*i+1][_Y],
>points[2*i+1][_Z]);
>         line_source->SetResolution(1);
>         line_source->GetOutput()->GetCellData()->SetScalars( lineScalar );
>         line_source->Update();
>
>         line_group->AddInput( line_source->GetOutput() );
>         line_group->Update();
>}
>
>Is it the right way to display a set of colored lines? Please help.
>
>Li
>
>
>
>-----------------------------------------------------------------------------
>This is the private VTK discussion list.  Please keep messages on-topic.
>Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
>To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
><majordomo at gsao.med.ge.com>.  For help, send message body containing
>"info vtkusers" to the same address.     Live long and prosper.
>-----------------------------------------------------------------------------



-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list