vtkCGNSreader

本文介绍了如何使用VTK库读取CGNS文件,并通过OpenGL进行数据可视化。步骤包括设置文件路径,创建vtkCGNSReader,处理MultiBlockDataSet,以及使用OpenGL渲染器和交互式窗口进行显示。
摘要由CSDN通过智能技术生成

 用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";
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值