[vtkusers] Manual polylines

John Biddiscombe jbiddiscombe at skippingmouse.co.uk
Mon Feb 4 08:26:59 EST 2002


If you haven't solved your problem... Try something like this instead
(vtkIdType is for vtk4 upwards, use int if using vtk3.x). It may not be the
quite most effficient method, but works fine...

// n = number of points in this polyline
vtkIdType *references = new vtkIdType[n];
// if n is always less than say 256, skip a dynamic allocate and use a
static array
for (int i=0; i<n; i++) {
  references[i] = points->InsertNextPoint(&pts[i*3]);
  // pts is my list of floats (3 per point)
}
polylines->InsertNextCell(VTK_POLY_LINE, n, &references[0]);
// use vtk_polygon or line quuad etc etc depending on stuff
delete []references;

JB


----- Original Message -----
From: "Chris Scharver" <scharver at evl.uic.edu>
To: <vtkusers at public.kitware.com>
Sent: Friday, February 01, 2002 5:07 PM
Subject: [vtkusers] Manual polylines


> Hello,
>
> I am trying a relatively simple action of creating polylines from sampled
positions with VTK 3.2 on IRIX.  Points are samples from 3D space before
being passed along to VTK.  However, it appears that I am not constructing
the vtkPolyData correctly, as the vtkTubeFilter doesn't seem to create
anything.  I can verify that I have all the points into the structures, but
am I missing something in the assembly of the cell array?
>
> (lineStruct is a simple structure with the length of the line and the
vertices within it.)
>
> ...
>   vtkPoints* points = vtkPoints::New();
>   vtkCellArray* lines = vtkCellArray::New();
>   lines->InsertNextCell(lineStruct->length[0]);
>   float xyz[3];
>   for (int i = 0; i < lineStruct->length[0]; ++i) {
>     xyz[0] = lineStruct->verts[i][0];
>     xyz[1] = lineStruct->verts[i][1];
>     xyz[2] = lineStruct->verts[i][2];
>     points->InsertPoint(i, xyz);
>     lines->InsertCellPoint(i);
>   }
>
>   vtkPolyData* dataSet = vtkPolyData::New();
>   dataSet->SetPoints(points);
>   dataSet->SetLines(lines);
>
>   vtkTubeFilter* tubes = vtkTubeFilter::New();
>     tubes->SetRadius(0.5f);
>     tubes->SetNumberOfSides(6);
>     tubes->SetInput(dataSet);
>   // Use a geometry filter for vtkActor to Performer translation
>   vtkGeometryFilter* gf = vtkGeometryFilter::New();
>     gf->SetInput(tubes->GetOutput());
>   vtkPolyDataMapper* pntMapper = vtkPolyDataMapper::New();
>     pntMapper->SetInput(gf->GetOutput());
>     pntMapper->ScalarVisibilityOff();
>   vtkActor* pntActor = vtkActor::New();
>     pntActor->SetMapper(pntMapper);
>     pntActor->GetProperty()->SetOpacity(1.0f);
>     pntActor->GetProperty()->SetColor(0.9f,0.9f,0.0f);
> ...
>
> Thanks,
> Chris
> --
> Chris Scharver
> Electronic Visualization Laboratory
> The University of Illinois at Chicago
> Ph: 312-996-3002   FAX: 312-413-7585
> <http://www.evl.uic.edu/scharver/>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers




More information about the vtkusers mailing list