2

視覚化のためにVTKを使用する C++ アプリケーションを開発しています。.vtr ファイル (RectilinearGrid) を読み取り、VTK ボリューム レンダリング機能を使用してレンダリングする必要があります。
私はParaviewでそれをやろうとしましたが、それは非常に簡単でした。「IsoVolume」フィルターを適用するだけで、結果はまさに私が必要としていたものです:

Paraview でレンダリングされた vtkRectilinearGrid ボリューム

問題は...どうすればC ++でそれを行うことができますか? IsoVolume Filter は、ParaView の連中によって作成された VTKの拡張に属しているため、私のライブラリにはなく、リンク エラーなしでこれらのクラスをインポートする方法が見つかりませんでした。
もっと簡単な方法はありますか?直線的なグリッド データで動作する VTK 内の IsoVolume Filter に代わるものはありますか?

4

1 に答える 1

5

私は自分でそれを理解しました:

#define vtkp vtkSmartPointer

// Read the file.
vtkp<vtkXMLRectilinearGridReader> vtrReader = vtkp<vtkXMLRectilinearGridReader>::New();
    vtrReader->SetFileName("../models/my_grid_model.vtr");
    vtrReader->Update();
vtkp<vtkRectilinearGrid> grid = vtrReader->GetOutput();
vtkp<vtkDataArray> scalars = grid->GetPointData()->GetArray("temperatures");

// Convert the vtkRectilinearGrid to vtkUnstructuredGrid.
vtkp<vtkUnstructuredGrid> ugrid = vtkp<vtkUnstructuredGrid>::New();
    vtkp<vtkPoints> points = vtkp<vtkPoints>::New();
        grid->GetPoints(points);
    ugrid->SetPoints(points);
    ugrid->GetPointData()->SetScalars(scalars);

for (unsigned int i = 0; i < grid->GetNumberOfCells(); i++){
    vtkCell* cell = grid->GetCell(i);
    ugrid->InsertNextCell(cell->GetCellType(), cell->GetPointIds());
}

// Make sure we have only tetrahedra. (may be slow for big data. tip: save the result to a file)
vtkp<vtkDataSetTriangleFilter> trifilter = vtkp<vtkDataSetTriangleFilter>::New();
    trifilter->SetInputData(ugrid);

// The mapper that renders the volume data.
vtkp<vtkOpenGLProjectedTetrahedraMapper> volumeMapper = vtkp<vtkOpenGLProjectedTetrahedraMapper>::New();
    volumeMapper->SetInputConnection(trifilter->GetOutputPort());

// Create transfer mapping scalar value to opacity.
vtkp<vtkPiecewiseFunction> opacityTransferFunction = vtkp<vtkPiecewiseFunction>::New();
    opacityTransferFunction->AddPoint(range[0], 0.05);
    opacityTransferFunction->AddPoint(range[1], 0.5);

// Create transfer mapping scalar value to color.
vtkp<vtkColorTransferFunction> colorTransferFunction = vtkp<vtkColorTransferFunction>::New();
    colorTransferFunction->AddRGBPoint(range[0], 0.0, 0.0, 1.0);
    colorTransferFunction->AddRGBPoint(range[1], 1.0, 0.0, 0.0);

// The property describes how the data will look.
vtkp<vtkVolumeProperty> volumeProperty = vtkp<vtkVolumeProperty>::New();
    volumeProperty->SetColor(colorTransferFunction);
    volumeProperty->SetScalarOpacity(opacityTransferFunction);
    volumeProperty->SetScalarOpacityUnitDistance(300);
    volumeProperty->ShadeOff();

// Creation of the volume.
vtkp<vtkVolume> volume = vtkp<vtkVolume>::New();
    volume->SetMapper(volumeMapper);
    volume->SetProperty(volumeProperty);

// Usual visualization.
vtkp<vtkRenderer> renderer = vtkp<vtkRenderer>::New();
    renderer->AddVolume(volume);
vtkp<vtkRenderWindow> window = vtkp<vtkRenderWindow>::New();
    window->Render();
vtkp<vtkInteractorStyleTrackballCamera> style = vtkp<vtkInteractorStyleTrackballCamera>::New();
vtkp<vtkRenderWindowInteractor> interactor = vtkRenderWindowInteractor::New();
    interactor->SetRenderWindow(window);
    interactor->SetInteractorStyle(style);
    interactor->Initialize();
    interactor->Start();
于 2015-12-02T10:58:45.453 に答える