[vtk-developers] Problem with Unstructure Grid Points Binary VTK

Fanis Kalatzis me00260 at cc.uoi.gr
Fri May 12 03:33:11 EDT 2006


Dear developers-list
I am new to the list and i have the following problem:

I want to display a binary vtk file colored accroding to scalar p.
The following C++ code works with the blow.vtk example file
but it does not work with my binary vtk file.
My vkt which seems to be ok displaying it with
paraview. My vtk file is output from OpenFOAM fluid dynamics.

int main(int argc, char *argv[])
{
  if (argc != 2) {
    fprintf(stderr, "input need a datafile!\n");
    exit(1);
  }

  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);
  ren1->SetBackground(0.0, 0.0, 0.0);
  renWin->SetSize(800,600);

  vtkDataSetReader *reader = vtkDataSetReader::New();
  reader->SetFileName(argv[1]);
  reader->SetScalarsName("p");
  reader->SetVectorsName("U");
  reader->Update();
  //cout<<reader->GetScalarsName()<<endl;

  vtkPointDataToCellData *p2c=vtkPointDataToCellData::New();
  p2c->SetInputConnection(reader->GetOutputPort());
  p2c->PassPointDataOn();

  vtkWarpVector *warp=vtkWarpVector::New();
  warp->SetInput(p2c->GetUnstructuredGridOutput());


  vtkThreshold *thresh=vtkThreshold::New();
  thresh->SetInputConnection(warp->GetOutputPort());
  thresh->ThresholdBetween(0.25,0.75);

thresh->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS,"p");


  vtkConnectivityFilter *connect2=vtkConnectivityFilter::New();
  connect2->SetInputConnection(thresh->GetOutputPort());

  vtkGeometryFilter *parison=vtkGeometryFilter::New();
  parison->SetInputConnection(connect2->GetOutputPort());

  vtkLookupTable *lut=vtkLookupTable::New();
  lut->SetHueRange(0.0,0.66667);

  vtkPolyDataMapper *parisonMapper=vtkPolyDataMapper::New();
  parisonMapper->SetInputConnection(parison->GetOutputPort());
  parisonMapper->SetLookupTable(lut);
  parisonMapper->SetScalarRange(-0.2,1.0);

  vtkActor *parisonActor=vtkActor::New();
  parisonActor->SetMapper(parisonMapper);
  ren1->AddActor(parisonActor);

  // Set up the lighting.
  vtkLight *light1 = vtkLight::New();
  light1->SetPosition(-1,1,1);
  ren1->AddLight(light1);

  vtkLight *light2 = vtkLight::New();
  light2->SetPosition(1,-1,-3);
  ren1->AddLight(light2);

  ren1->GetActiveCamera()->SetFocalPoint(0,0,0);
  ren1->GetActiveCamera()->SetPosition(0,0,1);
  ren1->GetActiveCamera()->SetViewUp(0,1,0);
  ren1->GetActiveCamera()->ParallelProjectionOn();
  ren1->ResetCamera();
  ren1->GetActiveCamera()->SetParallelScale(2.8);

  // This starts the event loop and invokes an initial render.
  iren->Initialize();
  iren->Start();

  reader->Delete();
  light1->Delete();
  light2->Delete();
  lut->Delete();
  ren1->Delete();
  renWin->Delete();
  iren->Delete();

  return 0;
}


Thanks,
Fanis Kalatzis



More information about the vtk-developers mailing list