[vtkusers] Two Simple Drawing Questions

Dean Inglis dean.inglis at sympatico.ca
Mon Jun 23 17:46:46 EDT 2008


 
>First, I'm drawing shapes using vtkPoints() and vtkCellArray() then adding
>them as points and lines to a vtkPolyData(). This works fine for drawing
the
>frame of the shape but what if I want the shape to be filled in? I'm
>assuming it is just a simple filter I need to do this but I haven't had any
>luck getting it working 
 
You need to convert a closed contour into a polygon:

Here you might have a sequence of points making a closed loop:

 

  int npts = pts->GetNumberOfPoints();

 

  if ( npts < 3 )

  {

    pts->Delete();

    return false;

  }

 

  vtkCellArray *cells = vtkCellArray::New();

  cells->Allocate( cells->EstimateSize( npts + 1, 2 ) ); 

  cells->InsertNextCell( npts + 1 );

 

  for ( int i = 0; i < npts; ++i )

  {

    cells->InsertCellPoint( i );

  }

 

// close the loop back on the first point

 

  cells->InsertCellPoint( 0 );

 

  vtkPolyData* temp = vtkPolyData::New();

 

  temp->SetPoints( pts );

  pts->Delete();

  temp->SetPolys( cells );

  cells->Delete();

 

// use the triangle filter to make a triangulated polygon

 

  vtkTriangleFilter* tri = vtkTriangleFilter::New();

  tri->SetInputConnection( temp->GetProducerPort() );

  tri->Update();

  outPoly->DeepCopy( tri->GetOutput() );

  tri->Delete();

  temp->Delete();

 

>Second, a vtkCellArray allows me to draw straight lines with ease but I
also
>need to draw some curved lines. I can always add a few points along the
line
>to give the illusion of a curved line using straight lines but is there an
>easy way to draw a curved line between two points? Again is there a way to

>do this. Thanks

 

 

For curved lines, you could do this interactively with either
vtkSplineWidget or vtkContourWidget,

see 

VTK/Examples/GUI/Tcl/ProbeWithSplineWidget.tcl

VTK/Examples/GUI/Tcl/ImageTracerWidget.tcl

VTK/Widgets/Testing/Cxx/TestContourWidget2.cxx

 

Dean

 

 

 

 

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


More information about the vtkusers mailing list