[vtkusers] Apparent VTK bug?

Sidney Cadot sidney at v2e.nl
Wed Mar 6 18:05:39 EST 2002


Hi everybody,

Below, a rather small piece of VTK code is given that should render a
point cloud, and it does if the number of points is >= 8191, on my Linux
machine. However, if the number of points is 8190 or less, it seg-faults
within the VTK libs.

Could anybody give this code a go and see if it works? I'm flabbergasted!

Best regards,

  Sidney Cadot

=============== to compile and link (on my Linux machine):

g++ -W -Wall -Werror -O2 -ansi -pedantic -I/usr/local/include/vtk  -c \
   -o tri-sphere.o tri-sphere.cpp
g++ -L/usr/local/lib/vtk -L/usr/X11R6/lib  tri-sphere.o  -lGL -lXt \
  -lvtkRendering -lvtkGraphics -lvtkFiltering -lvtkCommon  -o tri-sphere

=============== the code (tri-sphere.cpp)

#include <stdio.h>

#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>

double rnd(const double min, const double max)
{
  return min+rand()*(max-min)/RAND_MAX;
}

int main(int argc, char *argv[])
{
  int N = 10000;

  if (argc==2)
    sscanf(argv[1],"%d", &N);

  // create actor

  vtkPoints    * points   = vtkPoints::New();
  vtkCellArray * vertices = vtkCellArray::New();

  for(int i=0;i<N;i++)
    {
      double x = rnd(-1,1);
      double y = rnd(-1,1);
      double z = rnd(-1,1);

      vtkIdType newpointID = points->InsertNextPoint(x,y,z);
      vertices->InsertCellPoint(newpointID);
    }

  vtkPolyData *poly = vtkPolyData::New();
  poly->SetPoints(points);
  poly->SetVerts(vertices);

  vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
  mapper->SetInput(poly); poly->Delete();

  vtkActor *actor = vtkActor::New();
  actor->SetMapper(mapper); mapper->Delete();

  // create renderer

  vtkRenderer *renderer = vtkRenderer::New();
  renderer->AddActor(actor); actor->Delete();

  vtkRenderWindow *rwindow = vtkRenderWindow::New();
  rwindow->AddRenderer(renderer); renderer->Delete();

  vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
  interactor->SetRenderWindow(rwindow); rwindow->Delete();

  // render & interact!
  
  interactor->Render();
  interactor->Start();

  // clean up

  interactor->Delete();
  points->Delete();

  return 0;
}




More information about the vtkusers mailing list