[vtkusers] Creating a polygon from a closed polyline !

Goodwin Lawlor goodwin.lawlor at ucd.ie
Thu Feb 13 11:38:32 EST 2003


Here's an example of how to do it from /Graphics/testing/tcl/capCow.tcl

# Create polygons outlining clipped areas and triangulate them to
generate cut surface
vtkCutter cutEdges; #Generate cut lines
  cutEdges SetInput [cowNormals GetOutput]
  cutEdges SetCutFunction plane
  cutEdges GenerateCutScalarsOn
  cutEdges SetValue 0 0.5
vtkStripper cutStrips; #Forms loops (closed polylines) from cutter
  cutStrips SetInput [cutEdges GetOutput]
  cutStrips Update
vtkPolyData cutPoly; #This trick defines polygons as polyline loop
  cutPoly SetPoints [[cutStrips GetOutput] GetPoints]
  cutPoly SetPolys [[cutStrips GetOutput] GetLines]
vtkTriangleFilter cutTriangles; #Triangulates the polygons to create cut
surface
  cutTriangles SetInput cutPoly
vtkPolyDataMapper cutMapper
  cutMapper SetInput cutPoly
  cutMapper SetInput [cutTriangles GetOutput]
vtkActor cutActor
  cutActor SetMapper cutMapper
  eval [cutActor GetProperty] SetColor $peacock
-----Original Message-----
From: vtkusers-admin at public.kitware.com
[mailto:vtkusers-admin at public.kitware.com] On Behalf Of Sébastien MARAUX
Sent: 12 February 2003 10:46
To: Sebastien Auclair; vtkusers at public.kitware.com
Subject: Re: [vtkusers] Creating a polygon from a closed polyline !


Hello,

it is possible to do it via creation of new polygon cells in place of
polylines ones, and calling tesselate on it.

pseudo code :

new vtkPolydata,
new temp cell (contains polygon)
newpolydata SetPoints(yourpolydata GetPoints)
for all polyline cells{
    reset temp Cell
    for all points of this poly {
        if first, store
        add point id to cell
    }
    add first stored id (to close polygon)
    add cell to your poly
}
newpolydata Tesselate

I don't have the time to tell you more, sorry

good luck

Seb

----- Original Message -----
From: "Sebastien Auclair" <sxa at fluent.com>
To: <vtkusers at public.kitware.com>
Sent: Tuesday, February 11, 2003 10:55 PM
Subject: [vtkusers] Creating a polygon from a closed polyline !


> Greetings !
>
> We need to generate a surface out of 2D closed polylines. Like if we 
> have a circle as a polyline and all the points have z = 0 (i.e. 2D 
> polyline), we need to generate a surface for this circle to be
displayed
> as a disk !
> Of course, some of our polylines do not form easy convex polygones. 
> But
they
> are always composed with points with z = 0.
>
>
> So far we've tried this without success :
>
> (the code before the next line was trivial so not pasted...) 
> ................................................
>  int pointCount = points->GetNumberOfPoints ();  //  points is a valid

> vtkPoints  int i;
>
>  vtkPolyLine* aPolyline = vtkPolyLine::New();  
> aPolyline->GetPointIds()->SetNumberOfIds(pointCount);
>  for (i = 0; i <  pointCount; i++){
>         aPolyline->GetPointIds()->SetId( i, i);
>  }
>
>  vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();  
> aGrid->Allocate(1,1 );  aGrid->InsertNextCell 
> (aPolyline->GetCellType(),
> aPolyline->GetPointIds());
>  aGrid->SetPoints( points->m_points);
>  aGrid->Update();
>
>  vtkGeometryFilter* filter = vtkGeometryFilter::New();  
> filter->SetInput(aGrid);  filter->Update();
>
>
>  vtkTriangleFilter* tri = vtkTriangleFilter::New();  
> tri->SetInput(filter->GetOutput());
>  tri->Update();
>  vtkStripper* strip = vtkStripper::New();  
> strip->SetInput(tri->GetOutput());
>  strip->Update(); 
> ...........................................................
> The rest of the code is trivial !
>
>
> Any suggestions ?
>
> Thanks
>
> _______________________________________________
> Seb
>
> _______________________________________________
> 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
>

_______________________________________________
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