Qt&Vtk-027-RGrid

简介: Qt&Vtk-027-RGrid

image.png摘要

文章目录


1 官方示例展示


今天还是搬运代码,争取吧能搬运的都先搬运一下,今天搬运官方RGrid代码,官方实例如下image.png

#ifndef RGRID_H
#define RGRID_H
#include <QWidget>
#include "QVTKOpenGLWidget.h"               //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkNamedColors.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRectilinearGrid.h"
#include "vtkRectilinearGridGeometryFilter.h"
#include "vtkFloatArray.h"
#include "array"
namespace Ui {
class RGrid;
}
class RGrid : public QWidget
{
    Q_OBJECT
public:
    explicit RGrid(QWidget *parent = 0);
    ~RGrid();
private:
    Ui::RGrid *ui;
    vtkNew<vtkNamedColors> colors;
    //数据直接操作不来吧
    std::array<double, 47> x = {
        {-1.22396,  -1.17188,  -1.11979,  -1.06771,  -1.01562,  -0.963542,
         -0.911458, -0.859375, -0.807292, -0.755208, -0.703125, -0.651042,
         -0.598958, -0.546875, -0.494792, -0.442708, -0.390625, -0.338542,
         -0.286458, -0.234375, -0.182292, -0.130209, -0.078125, -0.026042,
         0.0260415, 0.078125,  0.130208,  0.182291,  0.234375,  0.286458,
         0.338542,  0.390625,  0.442708,  0.494792,  0.546875,  0.598958,
         0.651042,  0.703125,  0.755208,  0.807292,  0.859375,  0.911458,
         0.963542,  1.01562,   1.06771,   1.11979,   1.17188}};
    std::array<double, 33> y = {
        {-1.25,    -1.17188,  -1.09375, -1.01562,  -0.9375,  -0.859375,
         -0.78125, -0.703125, -0.625,   -0.546875, -0.46875, -0.390625,
         -0.3125,  -0.234375, -0.15625, -0.078125, 0,        0.078125,
         0.15625,  0.234375,  0.3125,   0.390625,  0.46875,  0.546875,
         0.625,    0.703125,  0.78125,  0.859375,  0.9375,   1.01562,
         1.09375,  1.17188,   1.25}};
    std::array<double, 44> z = {{0,   0.1,  0.2, 0.3,  0.4, 0.5,  0.6, 0.7, 0.75,
                                 0.8, 0.9,  1,   1.1,  1.2, 1.3,  1.4, 1.5, 1.6,
                                 1.7, 1.75, 1.8, 1.9,  2,   2.1,  2.2, 2.3, 2.4,
                                 2.5, 2.6,  2.7, 2.75, 2.8, 2.9,  3,   3.1, 3.2,
                                 3.3, 3.4,  3.5, 3.6,  3.7, 3.75, 3.8, 3.9}};
    vtkNew<vtkFloatArray> xCoords,yCoords,zCoords;
    vtkNew<vtkRectilinearGrid> rgrid;
    vtkNew<vtkRectilinearGridGeometryFilter> plane;
    vtkNew<vtkPolyDataMapper> mapper;
    vtkNew<vtkActor> actor;
};
#endif // RGRID_H

2.2 rgrid.cpp


#include "rgrid.h"
#include "ui_rgrid.h"
RGrid::RGrid(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RGrid)
{
    ui->setupUi(this);
    for(auto&& i : x)
        xCoords->InsertNextValue(i);
    for(auto&& i : y)
        yCoords->InsertNextValue(i);
    for(auto&& i : z)
        zCoords->InsertNextValue(i);
    rgrid->SetDimensions(int(x.size()),int(y.size()),int(z.size()));
    rgrid->SetXCoordinates(xCoords);
    rgrid->SetYCoordinates(yCoords);
    rgrid->SetZCoordinates(zCoords);
    plane->SetInputData(rgrid);
    plane->SetExtent(0,46,16,16,0,43);
    mapper->SetInputConnection(plane->GetOutputPort());
    actor->SetMapper(mapper);
    actor->GetProperty()->SetRepresentationToWireframe();
    actor->GetProperty()->SetColor(colors->GetColor3d("red").GetData());
    vtkRenderer *render =  vtkRenderer::New();
    render->AddActor(actor);
    ui->widget->GetRenderWindow()->AddRenderer(render);
}
RGrid::~RGrid()
{
    delete ui;
}

image.pngimage.png

目录
相关文章
|
1天前
|
云安全 人工智能 自然语言处理
|
8天前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
648 56
Meta SAM3开源:让图像分割,听懂你的话
|
6天前
|
搜索推荐 编译器 Linux
一个可用于企业开发及通用跨平台的Makefile文件
一款适用于企业级开发的通用跨平台Makefile,支持C/C++混合编译、多目标输出(可执行文件、静态/动态库)、Release/Debug版本管理。配置简洁,仅需修改带`MF_CONFIGURE_`前缀的变量,支持脚本化配置与子Makefile管理,具备完善日志、错误提示和跨平台兼容性,附详细文档与示例,便于学习与集成。
318 116
|
5天前
|
人工智能 Java API
Java 正式进入 Agentic AI 时代:Spring AI Alibaba 1.1 发布背后的技术演进
Spring AI Alibaba 1.1 正式发布,提供极简方式构建企业级AI智能体。基于ReactAgent核心,支持多智能体协作、上下文工程与生产级管控,助力开发者快速打造可靠、可扩展的智能应用。
|
21天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
8天前
|
机器学习/深度学习 人工智能 自然语言处理
AgentEvolver:让智能体系统学会「自我进化」
AgentEvolver 是一个自进化智能体系统,通过自我任务生成、经验导航与反思归因三大机制,推动AI从“被动执行”迈向“主动学习”。它显著提升强化学习效率,在更少参数下实现更强性能,助力智能体持续自我迭代。开源地址:https://github.com/modelscope/AgentEvolver
438 32
|
4天前
|
弹性计算 人工智能 Cloud Native
阿里云无门槛和有门槛优惠券解析:学生券,满减券,补贴券等优惠券领取与使用介绍
为了回馈用户与助力更多用户节省上云成本,阿里云会经常推出各种优惠券相关的活动,包括无门槛优惠券和有门槛优惠券。本文将详细介绍阿里云无门槛优惠券的领取与使用方式,同时也会概述几种常见的有门槛优惠券,帮助用户更好地利用这些优惠,降低云服务的成本。
272 132

热门文章

最新文章