Qt&Vtk-029-SpecularSpheres

简介: Qt&Vtk-029-SpecularSpheres

image.png摘要

文章目录


1 官方示例展示


代码搬运接着干,下面看示例代码,GoGoGoimage.png

#ifndef SPECULARSPHERES_H
#define SPECULARSPHERES_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 SpecularSpheres;
}
class SpecularSpheres : public QWidget
{
    Q_OBJECT
public:
    explicit SpecularSpheres(QWidget *parent = 0);
    ~SpecularSpheres();
private:
    Ui::SpecularSpheres *ui;
    vtkSmartPointer<vtkSphereSource> sphere = nullptr;
    vtkSmartPointer<vtkPolyDataMapper> sphereMapper =nullptr;
    vtkSmartPointer<vtkActor> sphere1 =nullptr,sphere2 =nullptr,sphere3 =nullptr,sphere4 =nullptr,sphere5 =nullptr,sphere6 =nullptr,sphere7 =nullptr,sphere8 =nullptr;
    vtkSmartPointer<vtkRenderer> render = nullptr;
    vtkSmartPointer<vtkLight> light = nullptr;
};
#endif // SPECULARSPHERES_H

2.2 specularspheres.cpp


#include "specularspheres.h"
#include "ui_specularspheres.h"
SpecularSpheres::SpecularSpheres(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SpecularSpheres)
{
    ui->setupUi(this);
    sphere = vtkSmartPointer<vtkSphereSource>::New();
    sphere->SetThetaResolution(100);
    sphere->SetPhiResolution(50);
    sphereMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    sphereMapper->SetInputConnection(sphere->GetOutputPort());
    sphere1 = vtkSmartPointer<vtkActor>::New();
    sphere2 = vtkSmartPointer<vtkActor>::New();
    sphere3 = vtkSmartPointer<vtkActor>::New();
    sphere4 = vtkSmartPointer<vtkActor>::New();
    sphere5 = vtkSmartPointer<vtkActor>::New();
    sphere6 = vtkSmartPointer<vtkActor>::New();
    sphere7 = vtkSmartPointer<vtkActor>::New();
    sphere8 = vtkSmartPointer<vtkActor>::New();
    sphere1->SetMapper(sphereMapper);
    sphere1->GetProperty()->SetColor(1,0,0);
    sphere1->GetProperty()->SetAmbient(0.3);
    sphere1->GetProperty()->SetDiffuse(0.0);
    sphere1->GetProperty()->SetSpecular(1.0);
    sphere1->GetProperty()->SetSpecularPower(5.0);
    sphere2->SetMapper(sphereMapper);
    sphere2->GetProperty()->SetColor(1,0,0);
    sphere2->GetProperty()->SetAmbient(0.3);
    sphere2->GetProperty()->SetDiffuse(0.0);
    sphere2->GetProperty()->SetSpecular(1.0);
    sphere2->GetProperty()->SetSpecularPower(10.0);
    sphere2->AddPosition(1.25,0,0);
    sphere3->SetMapper(sphereMapper);
    sphere3->GetProperty()->SetColor(1,0,0);
    sphere3->GetProperty()->SetAmbient(0.3);
    sphere3->GetProperty()->SetDiffuse(0.0);
    sphere3->GetProperty()->SetSpecular(1.0);
    sphere3->GetProperty()->SetSpecularPower(20.0);
    sphere3->AddPosition(2.5,0,0);
    sphere4->SetMapper(sphereMapper);
    sphere4->GetProperty()->SetColor(1,0,0);
    sphere4->GetProperty()->SetAmbient(0.3);
    sphere4->GetProperty()->SetDiffuse(0.0);
    sphere4->GetProperty()->SetSpecular(1.0);
    sphere4->GetProperty()->SetSpecularPower(40.0);
    sphere4->AddPosition(3.75,0,0);
    sphere5->SetMapper(sphereMapper);
    sphere5->GetProperty()->SetColor(1,0,0);
    sphere5->GetProperty()->SetAmbient(0.3);
    sphere5->GetProperty()->SetDiffuse(0.0);
    sphere5->GetProperty()->SetSpecular(0.5);
    sphere5->GetProperty()->SetSpecularPower(5.0);
    sphere5->AddPosition(0.0,1.25,0);
    sphere6->SetMapper(sphereMapper);
    sphere6->GetProperty()->SetColor(1,0,0);
    sphere6->GetProperty()->SetAmbient(0.3);
    sphere6->GetProperty()->SetDiffuse(0.0);
    sphere6->GetProperty()->SetSpecular(0.5);
    sphere6->GetProperty()->SetSpecularPower(10.0);
    sphere6->AddPosition(1.25,1.25,0);
    sphere7->SetMapper(sphereMapper);
    sphere7->GetProperty()->SetColor(1,0,0);
    sphere7->GetProperty()->SetAmbient(0.3);
    sphere7->GetProperty()->SetDiffuse(0.0);
    sphere7->GetProperty()->SetSpecular(0.5);
    sphere7->GetProperty()->SetSpecularPower(20.0);
    sphere7->AddPosition(2.5,1.25,0);
    sphere8->SetMapper(sphereMapper);
    sphere8->GetProperty()->SetColor(1,0,0);
    sphere8->GetProperty()->SetAmbient(0.3);
    sphere8->GetProperty()->SetDiffuse(0.0);
    sphere8->GetProperty()->SetSpecular(0.5);
    sphere8->GetProperty()->SetSpecularPower(40.0);
    sphere8->AddPosition(3.75,1.25,0);
    render = vtkSmartPointer<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);
    render->SetBackground(0.1, 0.2, 0.4);
    light = vtkSmartPointer<vtkLight>::New();
    light->SetFocalPoint(1.875,0.6125,0);
    light->SetPosition(0.875,1.6125,1);
    render->AddLight(light);
    render->GetActiveCamera()->SetFocalPoint(0,0,0);
    render->GetActiveCamera()->SetPosition(0,0,1);
    render->GetActiveCamera()->SetViewUp(0,1,0);
    render->GetActiveCamera()->ParallelProjectionOn();
    render->ResetCamera();
    render->GetActiveCamera()->SetParallelScale(3.0);
    ui->widget->GetRenderWindow()->AddRenderer(render);
}
SpecularSpheres::~SpecularSpheres()
{
    delete ui;
}

image.pngimage.png

目录
相关文章
|
4月前
|
存储 人工智能 监控
Mahilo:多智能体实时协作框架开源!人类与AI无缝交互,复杂任务一键协同
Mahilo 是一个灵活的多智能体框架,支持创建与人类互动的多智能体系统,适用于从客户服务到紧急响应等多种场景。
253 2
Mahilo:多智能体实时协作框架开源!人类与AI无缝交互,复杂任务一键协同
ly~
|
9月前
|
存储 SQL NoSQL
数据库介绍
数据库是组织、存储和管理数据的仓库,分为关系型(RDBMS)和非关系型(NoSQL)。RDBMS 如 MySQL、Oracle 和 SQL Server 通过表间关系存储结构化数据;NoSQL 包括 MongoDB、Redis 和 Neo4j,处理非结构化数据。数据库功能组件有数据定义语言(DDL)、数据操作语言(DML)和数据库管理系统(DBMS)。应用场景涵盖企业资源规划(ERP)、电子商务和大数据分析,支持自动化管理、数据分析及决策支持。
ly~
171 3
|
10月前
|
网络协议
TCP协议中TIME_WAIT状态的分析
`TIME_WAIT`状态是TCP协议设计中的一个重要组成部分,它通过确保数据传输的可靠性和连接的正确关闭来提升网络通信的稳定性。尽管 `TIME_WAIT`可能导致资源占用,适当的系统配置和网络编程实践可以最小化其潜在的负面影响。理解 `TIME_WAIT`状态及其背后的逻辑是每一位网络开发人员和系统管理员必须掌握的知识点。
381 1
|
机器学习/深度学习 存储 自然语言处理
深入理解LSTM:案例和代码详解
深入理解LSTM:案例和代码详解
878 2
|
Web App开发 JSON 小程序
技术心得:基于室友发签到码的对分易自动签到
技术心得:基于室友发签到码的对分易自动签到
474 0
|
JSON API 数据安全/隐私保护
闲鱼商品详情API:深入解析与应用指南
闲鱼商品详情API助力提升交易体验,提供商品全貌,包括价格、描述、图片等实时信息,增强买卖双方信任。开发者可通过接口获取商品基本信息、描述、图片、分类等,用于构建推荐、比价系统。接口调用示例展示了如何获取商品数据,如价格、位置、卖家信息等,以JSON格式返回,便于集成到应用中,促进高效交易。
|
安全 网络安全
代理服务器拒绝连接怎么办
代理服务器拒绝连接怎么办
1233 0
|
缓存 监控 关系型数据库
关于NAS你必须知道的坑
小小的备份为何老是将数据库主机打挂
1134 0
|
小程序
Uni-App - 事件处理、事件绑定、事件传参
Uni-App - 事件处理、事件绑定、事件传参
606 0
|
编解码 算法 计算机视觉
Python opencv图像处理基础总结(六) 直线检测 圆检测 轮廓发现
我还有改变的可能性 一想起这一点 我就心潮澎湃
1117 0
Python opencv图像处理基础总结(六) 直线检测 圆检测 轮廓发现
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等