[vtkusers] couldn't plot 3D :-(

Csaba Palotai csabamdm at hotmail.com
Wed Jul 10 16:18:49 EDT 2002


Hi there,

based on examples and from the archives I've tried to plot my GFD dataset. 
It compiled well but all i got was a black screen.
i believe the problem can be with my vtkCellArray part, but without it it's 
just a mess and had  no idea what to replace it with. (The code is below).
Any ideas/suggestions/similar experience
Anything helps, thanks in advance

Csaba



  vtkFloatArray* pcoords = vtkFloatArray::New();
  pcoords->SetNumberOfComponents(3);

  // We have nj*ni tuples.
  pcoords->SetNumberOfTuples(nj*ni);

  float p[3];

  k     = 3;
  count = 0;

  for (j = 1; j <= nj; j++) {
    for (i = 1; i <= ni; i++) {
      p[1] = grid.lon[2*i+1];
      p[2] = grid.lat[2*j+1];
      p[3] = -log(P(k,j,i));
      pcoords->SetTuple(count++,p);
    }
  }

  // Create vtkPoints.
  vtkPoints* points = vtkPoints::New();
  points->SetData(pcoords);

  vtkCellArray* strips = vtkCellArray::New();
  strips->InsertNextCell(4);
  strips->InsertCellPoint(0);
  strips->InsertCellPoint(1);
  strips->InsertCellPoint(2);
  strips->InsertCellPoint(3);

  vtkFloatArray* density = vtkFloatArray::New();
  density->SetName("Density");
  k = 3;
  for (j = 1; j <= nj; j++) {
    for (i = 1; i <= ni; i++) {
      density->InsertNextValue(RHO3(k,j,i));
      dens_max = MAX(dens_max,RHO3(k,j-1,i-1));
    }
  }
  fprintf(stdout,"dens_max = %g\n",dens_max);

  vtkPolyData* polydata = vtkPolyData::New();
  polydata->SetPoints(points);
  polydata->SetStrips(strips);
  polydata->GetPointData()->SetScalars(density);

  vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
  mapper->SetInput(polydata);
  mapper->SetScalarRange(0.,dens_max*1.1);

  vtkActor* actor = vtkActor::New();
  actor->SetMapper(mapper);
  vtkRenderer* ren = vtkRenderer::New();
  ren->AddActor(actor);
  vtkRenderWindow* renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren);
  vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);
  iren->Initialize();
  iren->Start();


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com




More information about the vtkusers mailing list