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月前
|
消息中间件 缓存 安全
电商API数据接口深度分析
电商 API 是连接平台、商家与用户的核心枢纽,其设计直接影响数据流通效率与系统稳定性。本文从技术架构、性能优化、安全防护、合规治理等维度深度解析,结合淘宝、京东等头部平台实践,提供高并发场景下的多级缓存、异步处理、智能限流等落地解决方案,助力企业构建高效、安全、合规的 API 体系,推动电商系统智能化演进。
|
存储 运维
CIO擦亮眼,2024 Gartner企业存储报告这么看
CIO擦亮眼,2024 Gartner企业存储报告这么看
CIO擦亮眼,2024 Gartner企业存储报告这么看
|
域名解析 缓存 网络协议
如何解决域名解析不生效问题?
文中对域名解析不生效的原因进行了分析,并针对最常见的本地递归域名服务器缓存不生效的问题提出了解决方案,尤其移动域名解析HTTPDNS对无线场景下的应用特别有效。
32662 0
|
运维 监控 安全
云时代下的运维转型之路:从反应式到主动智能
【8月更文挑战第23天】在数字化转型的浪潮中,传统的运维模式正面临前所未有的挑战。本文将探讨如何从被动应对故障的反应式运维,转变为通过数据驱动和智能化工具实现的主动智能运维。我们将深入分析现代运维的核心要素,包括自动化、监控、数据分析和团队文化的转变,以及这些变化如何帮助企业提升运维效率,降低风险,并最终实现业务价值的最大化。文章旨在为运维专业人士提供一条清晰的转型路径,帮助他们在云时代保持竞争力。
|
10月前
|
JSON API 开发者
淘宝拍立淘图片搜索API接口指南(淘宝API系列)
淘宝拍立淘图片搜索API为电商应用提供强大的技术支持,允许用户通过上传图片查找相似商品。开发者需在淘宝开放平台注册并获取权限,使用HTTP POST请求上传图片数据,返回商品列表信息如标题、价格等。该接口有助于提高购物效率和市场分析。示例代码展示了如何用Python调用此API,包括参数设置、签名生成和请求发送。
|
存储 人工智能 自然语言处理
Elasticsearch Inference API增加对阿里云AI的支持
本文将介绍如何在 Elasticsearch 中设置和使用阿里云的文本生成、重排序、稀疏向量和稠密向量服务,提升搜索相关性。
469 14
Elasticsearch Inference API增加对阿里云AI的支持
|
12月前
|
存储 运维 前端开发
同城圈子搭子交友论坛系统/搭建圈子系统的常见问题
需求分析不明确 在系统设计初期,如果未能充分理解目标用户的需求,可能导致系统功能与实际需求脱节,进而影响用户体验。 解决方案:通过市场调研、用户访谈、问卷调查等方式深入了解用户需求,确保系统设计符合用户期望。 技术选型困难 选择合适的技术栈对于系统的稳定性和可扩展性至关重要。技术选型不当可能导致系统性能低下或开发周期延长。 解决方案:根据系统需求、开发团队的技术栈以及未来扩展性等因素综合考虑,选择适合的技术栈。例如,前端可以使用uinapp 等框架,后端可以选择PHP框架,数据库可以选择MySQL等。
397 0
|
存储 机器学习/深度学习 安全
小微企业的如何使用云计算帮助企业节约成本?
小微企业的如何使用云计算帮助企业节约成本?
|
安全 网络安全
代理服务器拒绝连接怎么办
代理服务器拒绝连接怎么办
2349 0

热门文章

最新文章