Qt&Vtk-016-DiffuseSpheres

简介: Qt&Vtk-016-DiffuseSpheres

image.png 今天搞光照,漫反射。


文章目录


1 官方示例展示

2 代码搬运

2.1 diffuseSphere.h

2.2 diffuseSpheres.cpp

3 运行效果

★ 源码 ★

1 官方示例展示

今天搬运的代码有点和第一天搬运的有点像是,只不过第一天是高光,今天这个是漫反射,先撸代码再说。

image.png

2 代码搬运


2.1 diffuseSphere.h


#ifndef DIFFUSESPHERES_H
#define DIFFUSESPHERES_H
#include <QWidget>
#include "QVTKOpenGLWidget.h"               //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkSmartPointer.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkLight.h"
namespace Ui {
class DiffuseSpheres;
}
class DiffuseSpheres : public QWidget
{
    Q_OBJECT
public:
    explicit DiffuseSpheres(QWidget *parent = 0);
    ~DiffuseSpheres();
private:
    Ui::DiffuseSpheres *ui;
    vtkSphereSource *sphere = nullptr;
    vtkPolyDataMapper *mapper = nullptr;
    vtkActor *sphere1 = nullptr,
            *sphere2 = nullptr,
            *sphere3 = nullptr,
            *sphere4 = nullptr,
            *sphere5 = nullptr,
            *sphere6 = nullptr,
            *sphere7 = nullptr,
            *sphere8 = nullptr;
    vtkRenderer *render = nullptr;
};
#endif // DIFFUSESPHERES_H

2.2 diffuseSpheres.cpp


#include "diffusespheres.h"
#include "ui_diffusespheres.h"
DiffuseSpheres::DiffuseSpheres(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DiffuseSpheres)
{
    ui->setupUi(this);
    sphere = vtkSphereSource::New();
    sphere->SetThetaResolution(100);
    sphere->SetPhiResolution(50);
    mapper = vtkPolyDataMapper::New();
    mapper->SetInputConnection(sphere->GetOutputPort());
    sphere1 = vtkActor::New();
    sphere2 = vtkActor::New();
    sphere3 = vtkActor::New();
    sphere4 = vtkActor::New();
    sphere5 = vtkActor::New();
    sphere6 = vtkActor::New();
    sphere7 = vtkActor::New();
    sphere8 = vtkActor::New();
    sphere1->SetMapper(mapper);
    sphere2->SetMapper(mapper);
    sphere3->SetMapper(mapper);
    sphere4->SetMapper(mapper);
    sphere5->SetMapper(mapper);
    sphere6->SetMapper(mapper);
    sphere7->SetMapper(mapper);
    sphere8->SetMapper(mapper);
    sphere1->GetProperty()->SetColor(1,0,0);
    sphere1->GetProperty()->SetAmbient(0.3);
    sphere1->GetProperty()->SetDiffuse(0.0);
    sphere1->GetProperty()->SetSpecular(0.0);
    sphere1->GetProperty()->SetSpecularPower(5.0);
    sphere2->GetProperty()->SetColor(1,0,0);
    sphere2->GetProperty()->SetAmbient(0.3);
    sphere2->GetProperty()->SetDiffuse(0.125);
    sphere2->GetProperty()->SetSpecular(0.0);
    sphere2->GetProperty()->SetSpecularPower(10.0);
    sphere2->AddPosition(1.25,0,0);
    sphere3->GetProperty()->SetColor(1,0,0);
    sphere3->GetProperty()->SetAmbient(0.3);
    sphere3->GetProperty()->SetDiffuse(0.25);
    sphere3->GetProperty()->SetSpecular(0.0);
    sphere3->AddPosition(2.5,0,0);
    sphere4->GetProperty()->SetColor(1,0,0);
    sphere4->GetProperty()->SetAmbient(0.3);
    sphere4->GetProperty()->SetDiffuse(0.375);
    sphere4->GetProperty()->SetSpecular(0.0);
    sphere4->AddPosition(3.75,0,0);
    sphere5->GetProperty()->SetColor(1,0,0);
    sphere5->GetProperty()->SetAmbient(0.3);
    sphere5->GetProperty()->SetDiffuse(0.5);
    sphere5->GetProperty()->SetSpecular(0.0);
    sphere5->AddPosition(0.0,1.25,0);
    sphere6->GetProperty()->SetColor(1,0,0);
    sphere6->GetProperty()->SetAmbient(0.3);
    sphere6->GetProperty()->SetDiffuse(0.625);
    sphere6->GetProperty()->SetSpecular(0.0);
    sphere6->AddPosition(1.25,1.25,0);
    sphere7->GetProperty()->SetColor(1,0,0);
    sphere7->GetProperty()->SetAmbient(0.3);
    sphere7->GetProperty()->SetDiffuse(0.75);
    sphere7->GetProperty()->SetSpecular(0.0);
    sphere7->AddPosition(2.5,1.25,0);
    sphere8->GetProperty()->SetColor(1,0,0);
    sphere8->GetProperty()->SetAmbient(0.3);
    sphere8->GetProperty()->SetDiffuse(0.875);
    sphere8->GetProperty()->SetSpecular(0.0);
    sphere8->AddPosition(3.75,1.25,0);
    render = vtkRenderer::New();
    render->AddActor(sphere1);
    render->AddActor(sphere2);
    render->AddActor(sphere3);
    render->AddActor(sphere4);
    render->AddActor(sphere5);
    render->AddActor(sphere6);
    render->AddActor(sphere7);
    render->AddActor(sphere8);
    ui->widget->GetRenderWindow()->AddRenderer(render);
}
DiffuseSpheres::~DiffuseSpheres()
{
    delete ui;
}

image.pngimage.png

目录
相关文章
|
移动开发 缓存 监控
面试官:本机号码一键登录,是怎么实现的?
面试官:本机号码一键登录,是怎么实现的?
2543 0
面试官:本机号码一键登录,是怎么实现的?
|
存储 机器学习/深度学习 人工智能
AI推理场景使用文件存储NAS的优势
AI推理场景使用文件存储NAS的优势
682 0
|
机器学习/深度学习 人工智能 数据可视化
斯坦福博士图解AlphaFold 3:超多细节+可视化还原ML工程师眼中的AF3
【8月更文挑战第8天】AlphaFold 3作为AI领域的重大突破,革新了蛋白质结构预测。斯坦福博士通过图解详析了其内部机制,展示了多尺度建模与图神经网络技术如何提升预测精度。尽管存在数据依赖性和计算成本等挑战,AlphaFold 3仍极大地加速了生物学研究与药物开发进程。论文详情参见:https://www.nature.com/articles/s41586-024-07487-w
612 4
|
数据可视化 JavaScript Serverless
天猫精灵【电影推荐】
创建一个电影推荐的小技能
3152 1
天猫精灵【电影推荐】
|
小程序 机器人 关系型数据库
【HiFlow】腾讯云HiFlow场景连接器实现校园信息管理智能化
【HiFlow】腾讯云HiFlow场景连接器实现校园信息管理智能化
545 0
【HiFlow】腾讯云HiFlow场景连接器实现校园信息管理智能化
|
机器学习/深度学习 自然语言处理 TensorFlow
【NLP】NLTK工具集使用
关于nltk的下载还是很多坑的,如果直接import nltk和nltk.download()下载失败,可参考: (1)nltk安装失败:由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 (2)直接下载github的nltk:https://github.com/nltk/nltk_data。我一开始就是一直报错For more information see:
510 0
【NLP】NLTK工具集使用
|
XML JSON 前端开发
一键智能Mock,你值得拥有
大家好呀,我是一名苦逼的前端开发工程师,为啥苦逼呢,这不,项目下周就要上线了,但是后端还没给我接口,没有接口我就无法调试,工作停滞不前,我也只能坐着干着急。 我报告给了我的老板山哥: 老板,这后端不靠谱啊,都快上线了,接口还没出来。 山哥回道,别着急呀,这不有 Mock 吗?
 一键智能Mock,你值得拥有
|
数据可视化 前端开发 算法
大淘宝中后台页面无代码生产新模式探索
电商发展至今,流量红利见顶,供给侧升级降本提能、精细化运营是未来的关键,由此B端中后台需求井喷并呈增长态势。随着运营工作台SOP体系通过跨系统能力整合打造运营标准操作链路,解决运营操作体验及站点交付效率问题时,运营能力的产品&体验一致需要页面研发保障,提供保障体验的高效页面研发能力尤为重要。
802 0
大淘宝中后台页面无代码生产新模式探索
|
IDE JavaScript Java
硬核调试实操 | 手把手带你实现 Serverless 断点调试
本文借助 Serverless Devs 工具,对函数计算 (FC) 应用的断点调试步骤进行详细指导,手把手带你实现 Serverless 的断点调试。
硬核调试实操 | 手把手带你实现 Serverless 断点调试
|
编解码 算法 安全
瑞云科技副总经理黄金进:实时云渲染是实现现实世界和虚拟世界写实视觉效果的关键
2021年12月10日,由广东省游戏产业协会、广东省虚拟现实产业技术创新联盟、深圳市科学技术协会、深圳市互联网文化市场协会指导,陀螺科技主办,深圳市科技开发交流中心、恒悦创客魔方协办,行业头部媒体游戏陀螺、VR陀螺、陀螺电竞、陀螺财经、陀螺传媒联合主办的2021未来商业生态链接大会暨第六届金陀螺奖颁奖典礼(简称“FBEC2021”)在深圳大中华喜来登酒店6楼宴会厅盛大开幕!
瑞云科技副总经理黄金进:实时云渲染是实现现实世界和虚拟世界写实视觉效果的关键

热门文章

最新文章