Qt&Vtk-028-SGrid

简介: Qt&Vtk-028-SGrid

image.png 摘要

文章目录


1 官方示例展示


代码搬运工作就要接近尾声了,和面也不想在抄了,编程了直接拷贝了。看下官方实例image.png

#ifndef SGRID_H
#define SGRID_H
#include <QWidget>
#include "QVTKOpenGLWidget.h"               //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkFloatArray.h"
#include "vtkHedgeHog.h"
#include "vtkMath.h"
#include "vtkNamedColors.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkStructuredGrid.h"
#include "array"
namespace Ui {
class SGrid;
}
class SGrid : public QWidget
{
    Q_OBJECT
public:
    explicit SGrid(QWidget *parent = 0);
    ~SGrid();
private:
    Ui::SGrid *ui;
    vtkNew<vtkNamedColors> colors;
    float rMin = 0.5, rMax = 1.0, deltaRad, deltaZ;
    std::array<int, 3> dims = {{13, 11, 11}};
    vtkNew<vtkStructuredGrid> sgrid;
    vtkNew<vtkFloatArray> vectors;
    vtkNew<vtkPoints> points;
    vtkNew<vtkHedgeHog> hedgehog;
    vtkNew<vtkPolyDataMapper> sgridMapper;
    vtkNew<vtkActor> sgridActor;
    vtkNew<vtkRenderer> renderer;
};
#endif // SGRID_H

2.2 sgrid.cpp


#include "sgrid.h"
#include "ui_sgrid.h"
SGrid::SGrid(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SGrid)
{
    ui->setupUi(this);
    sgrid->SetDimensions(dims.data());
    vectors->SetNumberOfComponents(3);
    vectors->SetNumberOfTuples(dims[0] * dims[1] * dims[2]);
    points->Allocate(dims[0] * dims[1] * dims[2]);
    deltaZ = 2.0 / (dims[2] - 1);
    deltaRad = (rMax - rMin) / (dims[1] - 1);
    float x[3], v[3];
    v[2] = 0.0;
    for (auto k = 0; k < dims[2]; k++)
    {
        x[2] = -1.0 + k * deltaZ;
        int kOffset = k * dims[0] * dims[1];
        for (auto j = 0; j < dims[1]; j++)
        {
            float radius = rMin + j * deltaRad;
            int jOffset = j * dims[0];
            for (auto i = 0; i < dims[0]; i++)
            {
                float theta = i * vtkMath::RadiansFromDegrees(15.0);
                x[0] = radius * cos(theta);
                x[1] = radius * sin(theta);
                v[0] = -x[1];
                v[1] = x[0];
                int offset = i + jOffset + kOffset;
                points->InsertPoint(offset, x);
                vectors->InsertTuple(offset, v);
            }
        }
    }
    sgrid->SetPoints(points);
    sgrid->GetPointData()->SetVectors(vectors);
    hedgehog->SetInputData(sgrid);
    hedgehog->SetScaleFactor(0.1);
    sgridMapper->SetInputConnection(hedgehog->GetOutputPort());
    sgridActor->SetMapper(sgridMapper);
    sgridActor->GetProperty()->SetColor(colors->GetColor3d("Indigo").GetData());
    renderer->AddActor(sgridActor);
    renderer->SetBackground(colors->GetColor3d("Cornsilk").GetData());
    renderer->ResetCamera();
    renderer->GetActiveCamera()->Elevation(60.0);
    renderer->GetActiveCamera()->Azimuth(30.0);
    renderer->GetActiveCamera()->Zoom(1.0);
    ui->widget->GetRenderWindow()->AddRenderer(renderer);
}
SGrid::~SGrid()
{
    delete ui;
}

image.pngimage.png

目录
相关文章
Temporary email邮箱API发送邮件的步骤
使用Temporary email API发送邮件可保护隐私。步骤包括:了解API原理,注册获取API密钥,调用API并传入密钥,生成临时邮箱地址,编写邮件内容,然后发送。此方法确保真实邮箱不被泄露,适用于避免垃圾邮件。记得遵守使用规定和法规。
|
弹性计算 关系型数据库 Apache
基于ECS搭建云上博客
本场景将基于一台配置了CentOS 7.7操作系统的ECS实例(云服务器)。通过本教程的操作,您可以在一台CentOS 7.7操作系统的ECS实例上安装和部署LAMP环境,然后安装 WordPress,帮助您快速搭建自己的博客。
基于ECS搭建云上博客
|
机器学习/深度学习 算法 安全
内容过滤算法:构建数字世界的守护者
内容过滤算法:构建数字世界的守护者
|
Cloud Native Devops 持续交付
云原生与 DevOps
云原生与 DevOps
723 0
|
机器学习/深度学习 并行计算 API
【GPU】CUDA是什么?以及学习路线图!
【GPU】CUDA是什么?以及学习路线图!
3889 0
|
C++ Python
VS+VTK+Dicom(dcm)+CT影像切片窗体界面显示源码
VS+VTK+Dicom(dcm)+CT影像切片窗体界面显示源码
592 0
|
数据可视化 vr&ar 图形学
技术好文:VTK初识VTK
技术好文:VTK初识VTK
208 0
|
存储 机器学习/深度学习 数据可视化
开发人员必知的医疗影像基础概念
DICOM(Digital Imaging and Communication in Medical) 是医学影像领域最常见的标准之一,主要用于存储、交换和检索医学图像。如 X光片、CT扫描、MRI等。
250 1
|
缓存 小程序 前端开发
如何解决小程序异步请求问题
如何解决小程序异步请求问题
315 0
|
C++ Python
C++ VTK鼠标网格表面绘制曲线
C++ VTK鼠标网格表面绘制曲线
741 0
C++ VTK鼠标网格表面绘制曲线