用vtk读取cgns文件,用opengl显示。vtk有多种显示接口,还有qt,该怎么选择?
添加include目录以后,添加库文件,列表如下(有一些可能没有用):
vtkCommonCore-9.2d.lib
vtkRenderingCore-9.2d.lib
vtkInteractionWidgets-9.2d.lib
vtkInteractionStyle-9.2d.lib
vtkcgns-9.2d.lib
vtkRenderingOpenGL2-9.2d.lib
vtksys-9.2d.lib
vtkIOCGNSReader-9.2d.lib
vtkIOCore-9.2d.lib
vtkCommonDataModel-9.2d.lib
vtkCommonComputationalGeometry-9.2d.lib
vtkCommonMath-9.2d.lib
vtkCommonExecutionModel-9.2d.lib
vtkCommonSystem-9.2d.lib
vtkCommonTransforms-9.2d.lib
vtkFiltersCore-9.2d.lib
vtkFiltersGeometry-9.2d.lib
#include "vtkNew.h"
#include "vtkStructuredGrid.h"
#include "vtkTestUtilities.h"
#include "vtkCompositeDataGeometryFilter.h"
#include "vtkGeometryFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkDataSetMapper.h"
#include "vtkActor.h"
#include "vtkAssembly.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkDataArraySelection.h"
#include "vtkExtractBlock.h"
#include "vtkExtractArray.h"
#include "vtkInformation.h"
#include "vtkPolyDataWriter.h"
#include "vtkDataSetWriter.h"
#include "vtkDataObjectTree.h"
#include "vtkExtractBlock.h"
#include "vtkCompositeDataWriter.h"
#include <vtkMultiProcessController.h>
#include <iostream>
#include "vtkCGNSReader.h"
#include "vtkCGNSFileSeriesReader.h"
#include "vtkCell.h"
#include "vtkMultiBlockDataSet.h"
/*=========================================================================*/
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingOpenGL2)
int main(int, char**) {
vtkNew<vtkCGNSReader> reader;
reader->SetFileName("test.cgns");
reader->Update();
vtkSmartPointer<vtkMultiBlockDataSet> multiBlockDataSet = reader->GetOutput();
auto nb = multiBlockDataSet->GetNumberOfBlocks();
std::cout << "nb=" << nb << std::endl;
auto np = multiBlockDataSet->GetNumberOfPoints();
std::cout << "np=" << np << std::endl;
auto nc = multiBlockDataSet->GetNumberOfCells();
std::cout << "nc=" << nc << std::endl;
// auto multiblock=multiBlockDataSet->GetBlock(0);
// int i = 0;
// auto info = multiBlockDataSet->GetMetaData(i);
vtkNew<vtkCompositeDataGeometryFilter> geom;
geom->SetInputConnection(reader->GetOutputPort());
geom->Update();
vtkNew<vtkDataSetMapper> modelmapper;
modelmapper->SetInputConnection(geom->GetOutputPort());
// Create Actor
vtkNew<vtkActor> modelActor;
modelActor->SetMapper(modelmapper);
//Assembly
vtkNew<vtkAssembly> assembly;
assembly->AddPart(modelActor);
vtkNew<vtkRenderer> render;
render->AddActor(assembly);
render->SetBackground(160.0 / 255.0, 163.0 / 255.0, 228.0 / 255.0);
//render->SetBackground(0.1, 0.2, 0.3);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(render);
renderWindow->SetMultiSamples(0);
renderWindow->Render();
vtkNew<vtkRenderWindowInteractor> rwInteractor;
vtkNew<vtkInteractorStyleTrackballCamera> style;
rwInteractor->SetRenderWindow(renderWindow);
rwInteractor->SetInteractorStyle(style);
rwInteractor->Initialize();
rwInteractor->Start();
std::cout << "Success!\n";
}