【VTKExamples::Visualization】第三期 Background设置

很高兴在雪易的CSDN遇见你 

VTK技术爱好者 QQ:870202403


前言

本文分享几种背景设置的方式,希望对各位小伙伴有所帮助!

感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!

你的点赞就是我的动力(^U^)ノ~YO


目录

前言

1. 纯色背景

2. 渐变背景

3. 纹理背景

3.1 创建点集PolyData对象

3.2 通过顶点插值轮廓

完整示例代码

结论:


1. 纯色背景

  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();renderer->AddActor(actor);renderer->SetBackground(1,.5,1); // Background color

2. 渐变背景

  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();// Add the actor to the scenerenderer->AddActor(actor);vtkSmartPointer<vtkNamedColors> colors =vtkSmartPointer<vtkNamedColors>::New();// Setup the background gradientrenderer->GradientBackgroundOn();renderer->SetBackground(colors->GetColor3d("Banana").GetData());renderer->SetBackground2(colors->GetColor3d("Tomato").GetData());

3. 纹理背景

  

3.1 创建点集PolyData对象

    // Create a set of vertices (polydata)vtkSmartPointer<vtkPoints> points =vtkSmartPointer<vtkPoints>::New();points->InsertNextPoint(100.0, 0.0, 0.0);points->InsertNextPoint(300.0, 0.0, 0.0);// Setup colorsunsigned char white[3] = { 255, 255, 255 };unsigned char black[3] = { 0, 0, 0 };vtkSmartPointer<vtkUnsignedCharArray> vertexColors =vtkSmartPointer<vtkUnsignedCharArray>::New();vertexColors->SetNumberOfComponents(3);vertexColors->SetName("Colors");vertexColors->InsertNextTuple3(black[0], black[1], black[2]);vertexColors->InsertNextTuple3(white[0], white[1], white[2]);// We must make two objects, because the ShepardMethod uses the ActiveScalars, as does the renderer!vtkSmartPointer<vtkPolyData> polydataToVisualize =vtkSmartPointer<vtkPolyData>::New();polydataToVisualize->SetPoints(points);polydataToVisualize->GetPointData()->SetScalars(vertexColors);vtkSmartPointer<vtkVertexGlyphFilter> vertexGlyphFilter =vtkSmartPointer<vtkVertexGlyphFilter>::New();vertexGlyphFilter->AddInputData(polydataToVisualize);vertexGlyphFilter->Update();//Create a mapper and actorvtkSmartPointer<vtkPolyDataMapper> vertsMapper =vtkSmartPointer<vtkPolyDataMapper>::New();vertsMapper->ScalarVisibilityOff();vertsMapper->SetInputConnection(vertexGlyphFilter->GetOutputPort());vtkSmartPointer<vtkActor> vertsActor =vtkSmartPointer<vtkActor>::New();vertsActor->SetMapper(vertsMapper);vertsActor->GetProperty()->SetColor(1, 0, 0);vertsActor->GetProperty()->SetPointSize(3);//此时点的颜色为(1,0,0);
//vertsMapper->ScalarVisibilityOff();注释后,颜色为黑白。

3.2 通过顶点插值轮廓

// Create a shepard filter to interpolate the vertices over a regularized image gridvtkSmartPointer<vtkShepardMethod> shepard = vtkSmartPointer<vtkShepardMethod>::New();shepard->SetInputData(polydataToProcess);shepard->SetSampleDimensions(2, 2, 2);shepard->SetModelBounds(100, 300, -10, 10, -10, 10);shepard->SetMaximumDistance(1);// Contour the shepard generated image at 3 isovalues// The accuracy of the results are highly dependent on how the shepard filter is set upvtkSmartPointer<vtkContourFilter> contourFilter = vtkSmartPointer<vtkContourFilter>::New();/*contourFilter->SetNumberOfContours(3);contourFilter->SetValue(0, 0.25);contourFilter->SetValue(1, 0.50);contourFilter->SetValue(2, 0.75);*/contourFilter->SetNumberOfContours(4);contourFilter->SetValue(0, 0.2);contourFilter->SetValue(1, 0.4);contourFilter->SetValue(2, 0.6);contourFilter->SetValue(3, 0.8);contourFilter->SetInputConnection(shepard->GetOutputPort());contourFilter->Update();

完整示例代码

    // Create a set of vertices (polydata)vtkSmartPointer<vtkPoints> points =vtkSmartPointer<vtkPoints>::New();points->InsertNextPoint(100.0, 0.0, 0.0);points->InsertNextPoint(300.0, 0.0, 0.0);// Setup colorsunsigned char white[3] = { 255, 255, 255 };unsigned char black[3] = { 0, 0, 0 };vtkSmartPointer<vtkUnsignedCharArray> vertexColors =vtkSmartPointer<vtkUnsignedCharArray>::New();vertexColors->SetNumberOfComponents(3);vertexColors->SetName("Colors");vertexColors->InsertNextTuple3(black[0], black[1], black[2]);vertexColors->InsertNextTuple3(white[0], white[1], white[2]);// Create a scalar array for the pointdata, each value represents the distance// of the vertices from the first vertexvtkSmartPointer<vtkFloatArray> values =vtkSmartPointer<vtkFloatArray>::New();values->SetNumberOfComponents(1);values->SetName("Values");values->InsertNextValue(0.0);values->InsertNextValue(1.0);// We must make two objects, because the ShepardMethod uses the ActiveScalars, as does the renderer!vtkSmartPointer<vtkPolyData> polydataToProcess =vtkSmartPointer<vtkPolyData>::New();polydataToProcess->SetPoints(points);polydataToProcess->GetPointData()->SetScalars(values);vtkSmartPointer<vtkPolyData> polydataToVisualize =vtkSmartPointer<vtkPolyData>::New();polydataToVisualize->SetPoints(points);polydataToVisualize->GetPointData()->SetScalars(vertexColors);vtkSmartPointer<vtkVertexGlyphFilter> vertexGlyphFilter =vtkSmartPointer<vtkVertexGlyphFilter>::New();vertexGlyphFilter->AddInputData(polydataToVisualize);vertexGlyphFilter->Update();//Create a mapper and actorvtkSmartPointer<vtkPolyDataMapper> vertsMapper =vtkSmartPointer<vtkPolyDataMapper>::New();vertsMapper->ScalarVisibilityOff();vertsMapper->SetInputConnection(vertexGlyphFilter->GetOutputPort());vtkSmartPointer<vtkActor> vertsActor =vtkSmartPointer<vtkActor>::New();vertsActor->SetMapper(vertsMapper);vertsActor->GetProperty()->SetColor(1, 0, 0);vertsActor->GetProperty()->SetPointSize(3);// Create a shepard filter to interpolate the vertices over a regularized image gridvtkSmartPointer<vtkShepardMethod> shepard = vtkSmartPointer<vtkShepardMethod>::New();shepard->SetInputData(polydataToProcess);shepard->SetSampleDimensions(2, 2, 2);shepard->SetModelBounds(100, 300, -10, 10, -10, 10);shepard->SetMaximumDistance(1);// Contour the shepard generated image at 3 isovalues// The accuracy of the results are highly dependent on how the shepard filter is set upvtkSmartPointer<vtkContourFilter> contourFilter = vtkSmartPointer<vtkContourFilter>::New();/*contourFilter->SetNumberOfContours(3);contourFilter->SetValue(0, 0.25);contourFilter->SetValue(1, 0.50);contourFilter->SetValue(2, 0.75);*/contourFilter->SetNumberOfContours(4);contourFilter->SetValue(0, 0.2);contourFilter->SetValue(1, 0.4);contourFilter->SetValue(2, 0.6);contourFilter->SetValue(3, 0.8);contourFilter->SetInputConnection(shepard->GetOutputPort());contourFilter->Update();//Create a mapper and actor for the resulting isosurfacesvtkSmartPointer<vtkPolyDataMapper> contourMapper =vtkSmartPointer<vtkPolyDataMapper>::New();contourMapper->SetInputConnection(contourFilter->GetOutputPort());contourMapper->ScalarVisibilityOn();contourMapper->SetColorModeToMapScalars();vtkSmartPointer<vtkActor> contourActor =vtkSmartPointer<vtkActor>::New();contourActor->SetMapper(contourMapper);contourActor->GetProperty()->SetAmbient(1);contourActor->GetProperty()->SetSpecular(0);contourActor->GetProperty()->SetDiffuse(0);// Report the results of the interpolationdouble* range = contourFilter->GetOutput()->GetScalarRange();std::cout << "Shepard interpolation:" << std::endl;std::cout << "contour output scalar range: " << range[0] << ", " << range[1] << std::endl;vtkIdType nCells = contourFilter->GetOutput()->GetNumberOfCells();double bounds[6];for (vtkIdType i = 0; i < nCells; ++i){if (i % 2) // each isosurface value only has 2 cells to report on the odd ones{contourFilter->GetOutput()->GetCellBounds(i, bounds);std::cout << "cell " << i << ", x position: " << bounds[0] << std::endl;}}// Create a transfer function to color the isosurfacesvtkSmartPointer<vtkColorTransferFunction> lut =vtkSmartPointer<vtkColorTransferFunction>::New();lut->SetColorSpaceToRGB();lut->AddRGBPoint(range[0], 0, 0, 0);//blacklut->AddRGBPoint(range[1], 1, 1, 1);//whitelut->SetScaleToLinear();contourMapper->SetLookupTable(lut);// Create a renderer, render window and interactorvtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();renderer->GradientBackgroundOn();renderer->SetBackground(0, 0, 1);renderer->SetBackground2(1, 0, 1);vtkSmartPointer<vtkRenderWindow> renderWindow =vtkSmartPointer<vtkRenderWindow>::New();renderWindow->AddRenderer(renderer);renderer->AddActor(contourActor);renderer->AddActor(vertsActor);vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =vtkSmartPointer<vtkRenderWindowInteractor>::New();renderWindowInteractor->SetRenderWindow(renderWindow);// Position the camera so that the image produced is viewablevtkCamera* camera = renderer->GetActiveCamera();camera->SetPosition(450, 100, 100);camera->SetFocalPoint(200, 0, 0);camera->SetViewUp(0, 0, 1);renderWindow->Render();renderWindowInteractor->Start();

结论:

        主要介绍背景创建的几种方法

感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!

你的赞赏是我的最最最最大的动力(^U^)ノ~YO

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/333928.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

池化层解析:简单易懂理解 PyTorch 中的核心组件

目录 torch.nn详解 nn.MaxPool1d nn.MaxPool2d nn.MaxPool3d nn.MaxUnpool1d nn.MaxUnpool2d nn.MaxUnpool3d nn.AvgPool1d nn.AvgPool2d nn.AvgPool3d nn.FractionalMaxPool2d nn.FractionalMaxPool3d nn.LPPool1d nn.LPPool2d nn.AdaptiveMaxPool1d nn.Adapt…

Lumerical Monitors------Mode expansion monitors

Lumerical Monitors------Mode expansion monitors 引言正文引言 本文,作者将重点介绍 Lumerical 中的 Mode expansion monitors 的用法 正文 Mode expansion monitors 允许我们去分析传递进入光纤或者波导中的任何感兴趣模式的功率百分比。能做到这一点是因为 Mode expans…

光缆通信有什么特点?

光缆由一个或多个光纤组成&#xff0c;每个光纤由一个非常纤细的玻璃或塑料纤维组成&#xff0c;可以传输光信号的高速数据。光缆通信具有以下特点&#xff1a; 1. 高带宽&#xff1a;光缆通信可以提供非常高的带宽&#xff0c;远远超过传统的铜缆通信。光纤的宽带特性使其能够…

kubernetes NetworkPolicy(防火墙)

开头语 写在前面&#xff1a;如有问题&#xff0c;以你为准&#xff0c; 目前24年应届生&#xff0c;各位大佬轻喷&#xff0c;部分资料与图片来自网络 内容较长&#xff0c;页面右上角目录方便跳转 概述 网络策略指的是 Pod 间的网络隔离策略&#xff0c;默认情况下是互通…

Google Breakpad使用方法

源码下载地址&#xff1a;https://chromium.googlesource.com/breakpad/breakpad 依赖头文件下载地址&#xff1a; https://chromium.googlesource.com/linux-syscall-support Breakpad由三个主要组件&#xff1a; client 是一个库, 以library的形式内置在应用中&#xff0c…

Flask修改Response Headers中的Server值

Headers中的Server会暴露出Python版本&#xff0c;导致的结果就是方便被渗透快速定位Python版本后找到对应版本的漏洞&#xff0c;因此导致网络安全问题 伪方法&#xff1a; 像这个马上就暴露出Python版本&#xff0c;如何解决这个网络上有说直接用response.headers.remove(Ser…

Postgres 中文周报:PostgreSQL 2023 热门回顾

2024 新年好&#xff01;原英文 Postgres Weekly 最新一期回顾了 2023 周刊中的热门点击文章、视频与工具等事项。当然&#xff0c;PostgreSQL 在 2023 年值得回顾的瞬间还有很多&#xff0c;远不止周刊中提到的。因此&#xff0c;在编译原周刊内容的基础上&#xff0c;我们增加…

HarmonyOS 应用开发学习笔记 stateStyles:多态样式

1、 HarmoryOS Ability页面的生命周期 2、 Component自定义组件 3、HarmonyOS 应用开发学习笔记 ets组件生命周期 4、HarmonyOS 应用开发学习笔记 ets组件样式定义 Styles装饰器&#xff1a;定义组件重用样式 Extend装饰器&#xff1a;定义扩展组件样式 前面记录了ets组件样式…

1-04C语言执行过程

一、概述 本小节主要讲解一个C程序从源代码到最终执行的过程&#xff0c;这个过程又可以细分为两部分&#xff1a; 源代码到可执行文件的过程可执行文件在内存中执行 本小节是C语言基础当中&#xff0c;比较容易被初学者忽视的知识点。而实际上&#xff1a; 熟悉C程序从源文…

使用curl命令在Linux中进行HTTP请求

在Linux中&#xff0c;curl是一个非常强大的命令行工具&#xff0c;用于发送HTTP请求。它允许用户发送各种类型的HTTP请求&#xff0c;如GET、POST、PUT、DELETE等&#xff0c;并能够处理响应数据。 首先&#xff0c;确保您的Linux系统已经安装了curl。如果未安装&#xff0c;…

OpenVoice实时语音克隆功能实现

前言 在【OpenVoice本地部署教程与踩坑记录】一文中介绍了OpenVoice的基本概念与&#xff0c;并且完成了项目的安装与运行。官方给的示例和用法中仅包含了文本转TTS再克隆音色的功能&#xff0c;仅能用于TTS场景下的文字朗读。 本文基于官方示例改造&#xff0c;实现了实时采集…

亿尚网:撤柜上线电商+直播将成为美妆行业发展的绝佳组合

亿尚网&#xff1a;撤柜上线电商直播将成为美妆行业发展的绝佳组合 来源&#xff1a; 编辑&#xff1a;亿尚风范 时间&#xff1a;2024-01-09 随着社交媒体的兴起&#xff0c;网红经济逐渐成为市场中的一股不可忽视的力量。而在这其中&#xff0c;直播电商的模式更是为网红们…