【vtkWidgetRepresentation】第七期 vtkImplicitPlaneRepresentation

news/2025/3/31 10:55:54/

很高兴在雪易的CSDN遇见你 


前言

本文分享vtkImplicitPlaneRepresentation源码剖析,及相关的实例,该接口主要用于切割交互,希望对各位小伙伴有所帮助!

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

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


目录

前言

1. vtkImplicitPlaneRepresentation介绍

2. vtkImplicitPlaneRepresentation关键参数介绍 

3. 相关的应用实例

结论:


vtkImplicitPlaneRepresentation

1. vtkImplicitPlaneRepresentation介绍

        继承自vtkWidgetRepresentation,但与vtkFinitePlaneRepresentation很相似。该类在BoundingBox中通过SetOrigin和SetNormal定义有界平面。可以通过vtkImplicitPlaneWidget2进行该平面的交互。 其子类vtkImplicitImageRepresentation在版本9.0.3中并没有,最近的版本9.3.2中存在。有兴趣的小伙伴可以自行查看。

2. vtkImplicitPlaneRepresentation关键参数介绍 

 2.1 定义平面

        SetOrigin和SetNormal进行平面的定义。

        提供了XY、YZ、XZ平面的简单创建方法:SetNormalToXAxis,SetNormalToYAxis,SetNormalToZAxis.

        也可以将平面的法向固定垂直于Camera,SetLockNormalToCamera。

2.2 平面Representation的设置

        该部分同vtkFinitePlaneRepresentation,包括:

        SetTubing,平面的边界是否采用圆形管道表示。

        SetDrawPlane,是否显示平面。

        SetDrawOutLine,是否显示平面边界。

        SetOutlineTranslation,是否允许通过左键移动轮廓。

        SetConstrainToWidgetBounds,设置为TRUE时,平面的原点不允许移动到边界之外;设置为FALSE时,则可以自由移动。

        SetScale,是否允许缩放。

2.3 GetPolyData获取切割结果

2.4 GetPlane获取平面

2.5 获取属性并设置

        包括GetNormalProperty、GetSelectedNormalProperty;

        GetPlaneProperty,GetSelectedPlaneProperty;GetOutlineProperty,GetSelectedOutlineProperty;GetEdgeProperty;

3. 相关的应用实例

#include <vtkSmartPointer.h>#include <vtkXMLPolyDataReader.h>
#include <vtkSphereSource.h>
#include <vtkClipPolyData.h>
#include <vtkPlane.h>#include <vtkCommand.h>
#include <vtkImplicitPlaneWidget2.h>
#include <vtkImplicitPlaneRepresentation.h>#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>// Callback for the interaction
// This does the actual work: updates the vtkPlane implicit function.
// This in turn causes the pipeline to update and clip the object.
class vtkIPWCallback : public vtkCommand
{
public:static vtkIPWCallback *New(){ return new vtkIPWCallback; }virtual void Execute(vtkObject *caller, unsigned long, void*){vtkImplicitPlaneWidget2 *planeWidget =reinterpret_cast<vtkImplicitPlaneWidget2*>(caller);vtkImplicitPlaneRepresentation *rep =reinterpret_cast<vtkImplicitPlaneRepresentation*>(planeWidget->GetRepresentation());rep->GetPlane(this->Plane);}vtkIPWCallback():Plane(0),Actor(0) {}vtkPlane *Plane;vtkActor *Actor;};int main(int argc, char *argv[])
{vtkSmartPointer<vtkSphereSource> sphereSource =vtkSmartPointer<vtkSphereSource>::New();sphereSource->SetRadius(10.0);vtkSmartPointer<vtkXMLPolyDataReader> reader =vtkSmartPointer<vtkXMLPolyDataReader>::New();// Setup a visualization pipelinevtkSmartPointer<vtkPlane> plane =vtkSmartPointer<vtkPlane>::New();vtkSmartPointer<vtkClipPolyData> clipper =vtkSmartPointer<vtkClipPolyData>::New();clipper->SetClipFunction(plane);clipper->InsideOutOn();if (argc < 2){clipper->SetInputConnection(sphereSource->GetOutputPort());}else{reader->SetFileName(argv[1]);clipper->SetInputConnection(reader->GetOutputPort());}// Create a mapper and actorvtkSmartPointer<vtkPolyDataMapper> mapper =vtkSmartPointer<vtkPolyDataMapper>::New();mapper->SetInputConnection(clipper->GetOutputPort());vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();actor->SetMapper(mapper);vtkSmartPointer<vtkProperty> backFaces =vtkSmartPointer<vtkProperty>::New();backFaces->SetDiffuseColor(.8, .8, .4);actor->SetBackfaceProperty(backFaces);// A renderer and render windowvtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();vtkSmartPointer<vtkRenderWindow> renderWindow =vtkSmartPointer<vtkRenderWindow>::New();renderWindow->AddRenderer(renderer);renderer->AddActor(actor);// An interactorvtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =vtkSmartPointer<vtkRenderWindowInteractor>::New();renderWindowInteractor->SetRenderWindow(renderWindow);renderWindow->Render();// The callback will do the workvtkSmartPointer<vtkIPWCallback> myCallback =vtkSmartPointer<vtkIPWCallback>::New();myCallback->Plane = plane;myCallback->Actor = actor;vtkSmartPointer<vtkImplicitPlaneRepresentation> rep =vtkSmartPointer<vtkImplicitPlaneRepresentation>::New();rep->SetPlaceFactor(1.25); // This must be set prior to placing the widgetrep->PlaceWidget(actor->GetBounds());rep->SetNormal(plane->GetNormal());vtkSmartPointer<vtkImplicitPlaneWidget2> planeWidget =vtkSmartPointer<vtkImplicitPlaneWidget2>::New();planeWidget->SetInteractor(renderWindowInteractor);planeWidget->SetRepresentation(rep);planeWidget->AddObserver(vtkCommand::InteractionEvent,myCallback);// RenderrenderWindowInteractor->Initialize();renderWindow->Render();planeWidget->On();// Begin mouse interactionrenderWindowInteractor->Start();return EXIT_SUCCESS;
}

结论:

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

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


http://www.ppmy.cn/news/1263880.html

相关文章

Django模型

一、model 文件中的类的建立&#xff1a; 对应的是数据库中的每个表&#xff0c;类中有什么字段&#xff0c;表就会对应的生成某个字段&#xff0c;主键id字段会自己生成&#xff1b; 数据库中的文件获取&#xff1a;只能通过模型类.objects来获取&#xff0c;不能通过模型类…

华为OD机试真题-执行任务赚积分-2023年OD统一考试(C卷)

题目描述: 现有N个任务需要处理,同一时间只能处理一个任务,处理每个任务所需要的时间固定为1。 每个任务都有最晚处理时间限制和积分值,在最晚处理时间点之前处理完成任务才可获得对应的积分奖励。 可用于处理任务的时间有限,请问在有限的时间内,可获得的最多积分。 输入…

mybatis的快速入门以及spring boot整合mybatis(二)

需要用到的SQL脚本&#xff1a; CREATE TABLE dept (id int unsigned PRIMARY KEY AUTO_INCREMENT COMMENT ID, 主键,name varchar(10) NOT NULL UNIQUE COMMENT 部门名称,create_time datetime DEFAULT NULL COMMENT 创建时间,update_time datetime DEFAULT NULL COMMENT 修改…

LLM之Agent(五)| AgentTuning:清华大学与智谱AI提出AgentTuning提高大语言模型Agent能力

​论文地址&#xff1a;https://arxiv.org/pdf/2310.12823.pdf Github地址&#xff1a;https://github.com/THUDM/AgentTuning 在ChatGPT带来了大模型的蓬勃发展&#xff0c;开源LLM层出不穷&#xff0c;虽然这些开源的LLM在各自任务中表现出色&#xff0c;但是在真实环境下作…

uniapp基于u-grid-item九宫格实现uCharts秋云图表展示

uniapp基于uView的UI组件u-grid-item九宫格实现uCharts秋云可视化图表展示 这里使用uView的u-grid-item九宫格组件去显示图标排列 九宫格可以做成多列&#xff0c;移动设备上可以通过左右滑动进行展示 <template><div><div style"text-align: center;font…

语言模型GPT与HuggingFace应用

受到计算机视觉领域采用ImageNet对模型进行一次预训练&#xff0c;使得模型可以通过海量图像充分学习如何提取特征&#xff0c;然后再根据任务目标进行模型微调的范式影响&#xff0c;自然语言处理领域基于预训练语言模型的方法也逐渐成为主流。以ELMo为代表的动态词向量模型开…

【漏洞复现】华脉智联指挥调度平台/xml_edit/fileread.php文件读取漏洞

Nx01 产品简介 深圳市华脉智联科技有限公司&#xff0c;融合通信系统将公网集群系统、专网宽带集群系统、不同制式、不同频段的短波/超短波对讲、模拟/数字集群系统、办公电话系统、广播系统、集群单兵视频、视频监控系统、视频会议系统等融为一体&#xff0c;集成了专业的有线…

python爬虫学习-批量爬取图片

python爬虫学习-批量爬取图片 爬虫步骤爬取前十页图片到本地根据页码获取网络源码使用xpath解析网页解析网页并下载图片主函数如下 爬取的网站为站长素材&#xff08;仅做学习使用&#xff09; 爬取的目标网站为 https://sc.chinaz.com/tupian/qinglvtupian.html如果爬取多页&…