[vtkusers] Problem with drawing a concave polygonal cell

pahsieh at usgs.gov pahsieh at usgs.gov
Thu Jun 29 19:55:06 EDT 2000


I am having a problem with drawing a 5 sided, concave
polygonal cell, as illustrated by the attached picture
and sample code. The points of the polygon are:

Index        x-y-z coordinates
  0          (1, 0, 0)
  1          (1, 1, 0)
  2          (0, 1, 0)
  3          (.8, .8, 0)
  4          (0, 0, 0)

so the polygon looks like (connect 0 through 4)

    2         1

           3


    4         0

However, vtk draws a polygon with an extra black
region (see attached gif picture) that flickers on
and off when the polygon is rotated.

According to the man pages, "The polygons cannot have
any internal holes, and cannot self-intersect." These
criteria seem to be satisfied by the above example.

I am probably missing something obvious, but would
appreciate it if someone would point me in the right
direction on how to properly draw a concave polygon.

Thanks.
Paul

(See attached file: poly.gif)


// ====== sample code ======

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"

void main()
{
    // Set up the rendering stuff
    vtkRenderer *renderer = vtkRenderer::New();
    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);
    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
    renderer->SetBackground(1, 1, 1);

    // Create the poly data set
    vtkPolyData *pd = vtkPolyData::New();
    vtkPoints *pts = vtkPoints::New();
    pts->InsertNextPoint(1, 0, 0);
    pts->InsertNextPoint(1, 1, 0);
    pts->InsertNextPoint(0, 1, 0);
    pts->InsertNextPoint(0.8, 0.8, 0);
    pts->InsertNextPoint(0, 0, 0);
    pd->SetPoints(pts);
    pts->Delete();
    vtkCellArray *cellArray = vtkCellArray::New();
    int pp[5] = {0, 1, 2, 3, 4};
    cellArray->InsertNextCell(5, pp);
    pd->SetPolys(cellArray);
    cellArray->Delete();

    // Create mapper and actor
    vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
    mapper->SetInput(pd);
    vtkActor *actor = vtkActor::New();
    actor->SetMapper(mapper);
    renderer->AddActor(actor);
    actor->GetProperty()->SetColor(1, 0, 0);

    renWin->Render();
    iren->Start();

    // Clean up
    renderer->Delete();
    renWin->Delete();
    iren->Delete();
    pd->Delete();
    mapper->Delete();
    actor->Delete();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: poly.gif
Type: image/gif
Size: 3781 bytes
Desc: Compuserve GIF
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20000629/0a19d5ee/attachment-0001.gif>


More information about the vtkusers mailing list