VTK中的隐形色图图

时间:2016-06-19 05:03:33

标签: vtk

我尝试将Colormap方法应用于从3D数据中获取的Scalar字段切片的可视化。我看到了颜色条,但是我无法将颜色映射图本身添加到渲染窗口。请帮我。

马克西姆。

==

int main(int argc, char **argv) 
{ 


 int i; 
  static float x[47]={ ...}; 
  static float y[33]={...}; 
  static float z[44]={...}; 

  vtkFloatArray *xCoords = vtkFloatArray::New(); 
  for (i=0; i<47; i++) xCoords->InsertNextValue(x[i]); 

  vtkFloatArray *yCoords = vtkFloatArray::New(); 
  for (i=0; i<33; i++) yCoords->InsertNextValue(y[i]); 

  vtkFloatArray *zCoords = vtkFloatArray::New(); 
  for (i=0; i<44; i++) zCoords->InsertNextValue(z[i]); 

  vtkFloatArray *field_data = vtkFloatArray::New(); 

  for (int i=0; i<47; i++) 
     for (int j=0; j<33; j++) 
        for (int l=0; l<44; l++) 
            field_data->InsertNextValue(x[i]*x[i]+y[j]*y[j]+z[l]*z[l]); 

  vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New(); 
  rgrid->SetDimensions(47,33,44); 
  rgrid->SetXCoordinates(xCoords); 
  rgrid->SetYCoordinates(yCoords); 
  rgrid->SetZCoordinates(zCoords); 

  rgrid->GetPointData()->SetScalars(field_data); 

  double ra[2]; 
  rgrid->GetPointData()->GetScalars()->GetRange(ra); 

  vtkRectilinearGridGeometryFilter *plane= vtkRectilinearGridGeometryFilter::New(); 
  plane->SetInputData(rgrid); 
  plane->SetExtent(0,47, 0,33, 10,10); // make section at z[10] 

  vtkLookupTable *lut = vtkLookupTable::New(); 
  lut->SetNumberOfColors(256); 

  lut->SetRange(ra); 
  lut->SetHueRange(0.66667, 0.0); 
  lut->Build(); 

  vtkDataSetMapper *filledMapper = vtkDataSetMapper::New(); 
  filledMapper->SetInputData(plane->GetOutput()); 
  filledMapper->SetLookupTable(lut); 
  filledMapper->ScalarVisibilityOn(); 
  filledMapper->SetScalarRange(ra); 

  vtkActor *filledActor = vtkActor::New(); 
  filledActor->SetMapper(filledMapper); 

  vtkRenderer *renderer = vtkRenderer::New(); 
  vtkRenderWindow *renWin = vtkRenderWindow::New(); 
  renWin->AddRenderer(renderer); 
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); 
  iren->SetRenderWindow(renWin); 

  vtkScalarBarActor *barActor = vtkScalarBarActor::New(); 
  barActor->SetLookupTable(lut); 
  barActor->SetTitle("Bumps"); 
  renderer->AddActor(barActor); 
  renderer->AddActor(filledActor); 


  renderer->SetBackground(1,1,1); 
  renderer->ResetCamera(); 
//  renderer->GetActiveCamera()->Elevation(60.0); 
//  renderer->GetActiveCamera()->Azimuth(30.0); 
//  renderer->GetActiveCamera()->Zoom(1.0); 

  renWin->SetSize(300,300); 

  // interact with data 
  renWin->Render(); 
  iren->Start(); 

}

0 个答案:

没有答案