[vtkusers] Disappearing image

Roger Mason rmason at mun.ca
Sat May 29 08:39:13 EDT 2010


Hello,

I have created the following by translation to C++ from a file
PerlinTerrain.py found on the web.  The Python version produces and
displays a surface.

// #includes snipped
int main(int argc, char** argv)
{
 
  vtkPlane* plane = vtkPlane::New();

  vtkPerlinNoise* p1 = vtkPerlinNoise::New();
  p1->SetFrequency(1, 1, 0);

  vtkPerlinNoise* p2 = vtkPerlinNoise::New();
  p2->SetFrequency(3, 5, 0);
  p2->SetPhase(0.5, 0.5, 0);

  vtkPerlinNoise* p3 = vtkPerlinNoise::New();
  p3->SetFrequency(16, 16, 0);

  vtkImplicitSum* sum = vtkImplicitSum::New();
  sum->SetNormalizeByWeight(1);
  sum->AddFunction(plane);
  sum->AddFunction(p1, 0.2);
  sum->AddFunction(p2, 0.1);
  sum->AddFunction(p3, 0.02);

  vtkSampleFunction* sample = vtkSampleFunction::New();
  sample->SetImplicitFunction(sum);
  sample->SetSampleDimensions(65, 65, 20);
  sample->SetModelBounds(-1, 1, -1, 1, -0.5, 0.5);
  sample->ComputeNormalsOff();

  vtkContourFilter* surface = vtkContourFilter::New();
  surface->SetInputConnection(sample->GetOutputPort());
  surface->SetValue(0, 0.0);

  vtkPolyDataNormals* smooth = vtkPolyDataNormals::New();
  smooth->SetInputConnection(surface->GetOutputPort());
  smooth->SetFeatureAngle(90);

  vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
  mapper->SetInputConnection(smooth->GetOutputPort());
  mapper->ScalarVisibilityOff();

  vtkActor* actor = vtkActor::New();
  actor->SetMapper(mapper);
  actor->GetProperty()->SetColor(0.4, 0.2, 0.1);

  // Create the renderer etc.
  vtkRenderer* ren = vtkRenderer::New();
  vtkRenderWindow* renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren);
  vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

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

// Clean-up snipped
  return 0;
}

The version above compiles without errors or warnings.  The window
appears and remains visible.  The image seems to be drawn but then
disappears, leaving an empty window.

This is my first try at using VTK.  If anyone can spot my mistake,
please help.

Thanks,
Roger



More information about the vtkusers mailing list