vtkPolyData 生成轮廓线

news2024/10/4 6:47:25

 PolyData 的轮廓用法实战

#include <vtkActor.h>
#include <vtkCutter.h>
#include <vtkMath.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPlane.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkXMLPolyDataReader.h>

int main(int argc, char* argv[])
{
    vtkNew<vtkNamedColors> colors;

    vtkSmartPointer<vtkPolyData> inputPolyData;
    if (argc > 1)
    {
        vtkNew<vtkXMLPolyDataReader> reader;
        reader->SetFileName(argv[1]);
        reader->Update();
        inputPolyData = reader->GetOutput();
    }
    else
    {
        vtkNew<vtkSphereSource> sphereSource;
        sphereSource->SetThetaResolution(30);
        sphereSource->SetPhiResolution(15);
        sphereSource->Update();
        inputPolyData = sphereSource->GetOutput();
    }

    vtkNew<vtkPolyDataMapper> inputMapper;
    inputMapper->SetInputData(inputPolyData);

    // Create a plane to cut
    vtkNew<vtkPlane> plane;
    plane->SetOrigin(inputPolyData->GetCenter());
    plane->SetNormal(1, 1, 1);

    double minBound[3];
    minBound[0] = inputPolyData->GetBounds()[0];
    minBound[1] = inputPolyData->GetBounds()[2];
    minBound[2] = inputPolyData->GetBounds()[4];

    double maxBound[3];
    maxBound[0] = inputPolyData->GetBounds()[1];
    maxBound[1] = inputPolyData->GetBounds()[3];
    maxBound[2] = inputPolyData->GetBounds()[5];

    double center[3];
    center[0] = inputPolyData->GetCenter()[0];
    center[1] = inputPolyData->GetCenter()[1];
    center[2] = inputPolyData->GetCenter()[2];

    double distanceMin = sqrt(vtkMath::Distance2BetweenPoints(minBound, center));
    double distanceMax = sqrt(vtkMath::Distance2BetweenPoints(maxBound, center));

    // Create cutter.
    vtkNew<vtkCutter> cutter;
    cutter->SetCutFunction(plane);
    cutter->SetInputData(inputPolyData);

    cutter->GenerateValues(20, -distanceMin, distanceMax);
    vtkNew<vtkPolyDataMapper> cutterMapper;
    cutterMapper->SetInputConnection(cutter->GetOutputPort());
    cutterMapper->ScalarVisibilityOff();

    // Create plane actor.
    vtkNew<vtkActor> planeActor;
    planeActor->GetProperty()->SetColor(
        colors->GetColor3d("Deep_pink").GetData());
    planeActor->GetProperty()->SetLineWidth(5);
    planeActor->SetMapper(cutterMapper);

    // Create input actor.
    vtkNew<vtkActor> inputActor;
    inputActor->GetProperty()->SetColor(colors->GetColor3d("Bisque").GetData());
    inputActor->SetMapper(inputMapper);

    // Create renderers and add actors of plane and cube.
    vtkNew<vtkRenderer> renderer;
    renderer->AddActor(planeActor); // Display the rectangle resulting from the
                                    // cut.
    renderer->AddActor(inputActor); // Display the cube.

    // Add renderer to renderwindow and render
    vtkNew<vtkRenderWindow> renderWindow;
    renderWindow->AddRenderer(renderer);
    renderWindow->SetWindowName("ContoursFromPolyData");
    renderWindow->SetSize(600, 600);

    vtkNew<vtkRenderWindowInteractor> interactor;
    interactor->SetRenderWindow(renderWindow);
    renderer->SetBackground(colors->GetColor3d("Slate_grey").GetData());
    renderWindow->Render();

    interactor->Start();

    return EXIT_SUCCESS;
}

 

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

探索设计模式的魅力:迭代器模式让你轻松驾驭复杂数据集合

​&#x1f308; 个人主页&#xff1a;danci_ &#x1f525; 系列专栏&#xff1a;《设计模式》 &#x1f4aa;&#x1f3fb; 制定明确可量化的目标&#xff0c;并且坚持默默的做事。 文章目录 一、&#x1f4a1; 引言二、原理与结构 &#x1f4da;&#x1f465; 迭代器模式的关…

Matlab|基于支持向量机的电力短期负荷预测【最小二乘、标准粒子群、改进粒子群】

目录 主要内容 部分代码 结果一览 下载链接 主要内容 该程序主要是对电力短期负荷进行预测&#xff0c;采用三种方法&#xff0c;分别是最小二乘支持向量机&#xff08;LSSVM&#xff09;、标准粒子群算法支持向量机和改进粒子群算法支持向量机三种方法对负荷进行…

Eclipse - Colors and Fonts

Eclipse - Colors and Fonts References 编码最好使用等宽字体&#xff0c;Ubuntu 下自带的 Ubuntu Mono 可以使用。更换字体时看到名字里面带有 Mono 的基本都是等宽字体。 Window -> Preferences -> General -> Appearance -> Colors and Fonts -> C/C ->…

Java——IO流

目录 一、IO流的概述 1、IO流的分类 1.1、纯文本文件 2、小结 二、IO流的体系结构 三、字节流 1、FileOutputStream&#xff08;字节输出流&#xff09; 2、FileOutputStream写出数据的细节 3、FileOutputStream写数据的3种方式 3.1、一次写一个字节数据 3.2、一次写…

【网络安全 | 网络协议】一文讲清HTTP协议

HTTP概念简述 HTTP&#xff08;Hypertext Transfer Protocol&#xff09;协议&#xff0c;又称超文本传输协议&#xff0c;用于传输文本、图像、音频、视频以及其他多媒体文件。它是Web应用程序通信的基础&#xff0c;通过HTTP协议&#xff0c;Web浏览器可以向Web服务器发起请…

通俗易懂的L0范数和L1范数及其Python实现

定义 L0 范数&#xff08;L0-Norm&#xff09; L0 范数并不是真正意义上的一个范数&#xff0c;因为它不满足范数的三角不等式性质&#xff0c;但它在数学优化和信号处理等领域有着实际的应用。L0 范数指的是向量中非零元素的个数。它通常用来度量向量的稀疏性。数学上表示为…

合理利用pandas来简化大量请求数据组装工作

工作场景 本次我们开发了一个新功能&#xff0c;为了验证它是否合理&#xff0c;我们需要从线上导出一批真实的用户数据来进行模拟请求&#xff0c;以此来验证功能的完整性。 例如一个很简单的功能&#xff0c;我们是一个对学生成绩进行数据分析的系统&#xff0c;各学校会将…

prometheus+mysql_exporter监控mysql

prometheus+mysql_exporter监控mysql 一.安装mysql 1.下载:wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 2.安装客户端:yum -y install mysql57-community-release-el7-10.noarch.rpm 3.安装服务端:yum -y install mysql-community-se…

mysql 2-1

添加数据 方式二 更新数据 删除数据 小结 计算列 数据类型 可选属性 适用场景 如何选择 浮点类型 存在精度问题 定点数介绍 BIT类型 日期与时间类型 YEAR类型 DATA类型 TIME类型 DATATIME TIMESTAMP 文本字符串类型 适用场景 TEXT类型

JavaWeb-JDBC-练习

一、环境准备 1、数据库表 tb_brand 2、实体类 Brand 最后注意使用get、set方法和toString 二、实现功能 1、查询所有数据 2、添加数据 3、根据id修改 4、根据id删除

【类与对象 -2】学习类的6个默认成员函数中的构造函数与析构函数

目录 1.类的6个默认成员函数 2.构造函数 2.1概念 2.2特性 3.析构函数 3.1析构函数的概念 3.2特性 1.类的6个默认成员函数 如果一个类中什么成员都没有&#xff0c;简称为空类。 空类中真的什么都没有吗&#xff1f;并不是&#xff0c;任何类在什么都不写时&#xff0c;…

红队学习笔记Day6 --->干货分享

今天看到这样的一个东西&#xff0c;好好好&#xff0c;有点恐怖&#x1f613;&#x1f613;&#x1f631;&#x1f631;&#x1f631;&#x1f631; 我就想网安是不是也有这种东西&#xff1f; 我来试试 icmp&#xff0c;RDP&#xff0c;arp&#xff0c;dhcp&#xff0c;nat&a…

C语言系列-带有副作用的宏参数#和##命名约定宏替换的规则

&#x1f308;个人主页: 会编辑的果子君 &#x1f4ab;个人格言:“成为自己未来的主人~” 目录 带有副作用的宏参数 宏替换的规则 宏函数的对比 #和## #运算符 ##运算符 命名约定 #undef 带有副作用的宏参数 当宏参数在宏的定义中出现超过一次的时候&#xff0c;如果…

2024/2/19

作业1&#xff1a;使用fread和fwrite完成两个图片文件的拷贝 代码&#xff1a; #include <myhead.h>int main(int argc, const char *argv[]) {FILE *fpNULL;//以只读的形式打开文件if(( fpfopen("./dashuai.bmp","r")) NULL){perror("fopen…

【lesson62】网络通信UdpSocket版

文章目录 UdpSocketUdpServer.hppUdpServer类成员变量解释成员函数解释 UdpServer的实现ServerIinit的实现socketbindhtonsinet_addr具体实现 ServerStart的实现recvfromsendtontohsinet_ntoa具体实现 ~UdpServer函数实现UdpServer.hpp整体完整代码 UdpServer.ccUdpClient.ccTh…

Java学习--黑马SpringBoot3课程个人总结-2024-02-12

1.环境准备 出现报错 Vue 引入路径正确的&#xff0c;但一直报错&#xff1a; Already included file name ‘‘ differs from file name ‘‘ only in casing. 解决方案来自此链接 2.注册界面的搭建 代码如下 <script setup> import { User, Lock } from element-plus/…

【C语言】通讯录(静态版本+动态版本)思路解析+完整源代码

通讯录 由于代码比较长&#xff0c;为了增加可读性&#xff0c;分成了contact.h&#xff0c;contact.c&#xff0c;test.c&#xff0c;分别用来声明函数或者类型&#xff0c;实现函数功能&#xff0c;测试代码 contact.h 我们希望通讯录具有增加联系人&#xff0c;删除联系人…

防火墙之firewalld基础

一、firewalld的简介 firewalld防火墙是Centos7系统默认的防火墙管理工具&#xff0c;取代了之前的iptables防火墙&#xff0c;也是工作在网络层&#xff0c;属于包过滤防火墙。 firewalld和iptables都是用来管理防火墙的工具&#xff08;属于用户态&#xff09;来定义防火墙的…

css pointer-events 多层鼠标点击事件

threejs 无法滑动视角&#xff0c;菜单界面覆盖threejs操作事件。 pointer-events /* Keyword values */ pointer-events: auto; pointer-events: none; pointer-events: visiblePainted; /* SVG only */ pointer-events: visibleFill; /* SVG only */ pointer-events: visib…

web基础及http协议 (二) apache

一、httpd 安装组成 http 服务基于 C/S 结构 1 .常见http 服务器程序 httpd apache&#xff0c;存在C10K&#xff08;10K connections&#xff09;问题 nginx 解决C10K问题lighttpd IIS .asp 应用程序服务器 tomcat .jsp 应用程序服务器 jetty 开源的servlet容器&#xf…