python VTK vtkImplicitBoolean 布尔切割

news2024/10/7 14:29:47

 

VTK中包含可以执行布尔操作的接口有vtkImplicitBoolean,vtkBooleanOperationPolyDataFilter,vtkLoopBooleanPolyDataFilter。

布尔操作包括:布尔加,布尔减和布尔交。

 

 

 

code:

#!/usr/bin/env python

"""
This example demonstrates how to use boolean combinations of implicit
 functions to create a model of an ice cream cone.

"""
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonDataModel import (
    vtkCone,
    vtkImplicitBoolean,
    vtkPlane,
    vtkSphere
)
from vtkmodules.vtkFiltersCore import vtkContourFilter
from vtkmodules.vtkImagingHybrid import vtkSampleFunction
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer
)


def main():
    colors = vtkNamedColors()

    # Create implicit function primitives. These have been carefully placed to
    # give the effect that we want. We are going to use various combinations of
    # these functions to create the shape we want for example, we use planes
    # intersected with a cone (which is infinite in extent) to get a finite
    # cone.
    #
    cone = vtkCone()
    cone.SetAngle(20)

    vertPlane = vtkPlane()
    vertPlane.SetOrigin(.1, 0, 0)
    vertPlane.SetNormal(-1, 0, 0)

    basePlane = vtkPlane()
    basePlane.SetOrigin(1.2, 0, 0)
    basePlane.SetNormal(1, 0, 0)

    iceCream = vtkSphere()
    iceCream.SetCenter(1.333, 0, 0)
    iceCream.SetRadius(0.5)

    bite = vtkSphere()
    bite.SetCenter(1.5, 0, 0.5)
    bite.SetRadius(0.25)

    # Combine primitives to build ice-cream cone. Clip the cone with planes.
    theCone = vtkImplicitBoolean()
    theCone.SetOperationTypeToIntersection()
    theCone.AddFunction(cone)
    theCone.AddFunction(vertPlane)
    theCone.AddFunction(basePlane)

    # Take a bite out of the ice cream.
    theCream = vtkImplicitBoolean()
    theCream.SetOperationTypeToDifference()
    theCream.AddFunction(iceCream)
    theCream.AddFunction(bite)

    # The sample function generates a distance function from the
    # implicit function (which in this case is the cone). This is
    # then contoured to get a polygonal surface.
    #
    theConeSample = vtkSampleFunction()
    theConeSample.SetImplicitFunction(theCone)
    theConeSample.SetModelBounds(-1, 1.5, -1.25, 1.25, -1.25, 1.25)
    theConeSample.SetSampleDimensions(128, 128, 128)
    theConeSample.ComputeNormalsOff()

    theConeSurface = vtkContourFilter()
    theConeSurface.SetInputConnection(theConeSample.GetOutputPort())
    theConeSurface.SetValue(0, 0.0)

    coneMapper = vtkPolyDataMapper()
    coneMapper.SetInputConnection(theConeSurface.GetOutputPort())
    coneMapper.ScalarVisibilityOff()

    coneActor = vtkActor()
    coneActor.SetMapper(coneMapper)
    coneActor.GetProperty().SetColor(colors.GetColor3d('Chocolate'))

    # The same here for the ice cream.
    #
    theCreamSample = vtkSampleFunction()
    theCreamSample.SetImplicitFunction(theCream)
    theCreamSample.SetModelBounds(0, 2.5, -1.25, 1.25, -1.25, 1.25)
    theCreamSample.SetSampleDimensions(128, 128, 128)
    theCreamSample.ComputeNormalsOff()

    theCreamSurface = vtkContourFilter()
    theCreamSurface.SetInputConnection(theCreamSample.GetOutputPort())
    theCreamSurface.SetValue(0, 0.0)

    creamMapper = vtkPolyDataMapper()
    creamMapper.SetInputConnection(theCreamSurface.GetOutputPort())
    creamMapper.ScalarVisibilityOff()

    creamActor = vtkActor()
    creamActor.SetMapper(creamMapper)
    creamActor.GetProperty().SetDiffuseColor(colors.GetColor3d('Mint'))
    creamActor.GetProperty().SetSpecular(.6)
    creamActor.GetProperty().SetSpecularPower(50)

    # Create the usual rendering stuff.
    #
    ren1 = vtkRenderer()

    renWin = vtkRenderWindow()
    renWin.AddRenderer(ren1)

    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Add the actors to the renderer, set the background and size.
    #
    ren1.AddActor(coneActor)
    ren1.AddActor(creamActor)
    ren1.SetBackground(colors.GetColor3d('SlateGray'))
    renWin.SetSize(640, 480)
    renWin.SetWindowName('IceCream')

    ren1.ResetCamera()
    ren1.GetActiveCamera().Roll(90)
    ren1.GetActiveCamera().Dolly(1.25)
    ren1.ResetCameraClippingRange()
    iren.Initialize()

    # render the image
    #
    renWin.Render()
    iren.Start()


if __name__ == '__main__':
    main()

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

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

相关文章

不是吧?强大的 vite 居然不支持内 SVG 转 Base64 内嵌?

大家好,我是前端西瓜哥。 诶哟喂,SVG 怎么没内嵌? 最近啊,西瓜哥我用 vite 去给一个项目构建(vite build)一个应用。打包结果是一个 html 和一些加了哈希的资源。 然后打包出来的文件一看,发…

SpringCloud学习路线(3)—— Eureka注册中心

一、导引 服务调用出现的问题 服务调用采取的请求地址是静态的,当我们使用服务集群时,很容易造成只能调用固定的微服务上的接口。多个提供者,消费者的使用对象无法确定消费者无法得知提供者的状态 二、Eureka注册中心 (一&…

加水印用什么软件你知道吗?告诉你加水印的app哪个好用吧

笑笑是一个热爱生活的女孩,她经常会随手拍下生活的瞬间,并且在社交媒体上分享自己的开心时刻。然而,最近她发现自己的照片被未经授权地使用在其他网站和博客上。这让她感到非常生气。为了保护自己的作品权益,她决定寻找一个好用的…

vue3 h函数使用图文教程

序: 1、官方文档地址》渲染函数 & JSX | Vue.js 2、博主微信公众号:“程序员野区”,关注公众号回复“加群,可以进到博主微信群 正文: 别恐惧啊,别一看官方api那边标注的 是进阶api就跳过去&#xff0c…

1ll大学学生信息管理系统系统_学院管理_查询新增或修改删除标准接口_

目录 修订版本 1. 目的 2. 阅读人员 3. 参考文档 ll大学学生信息管理系统系统_学院管理_查询新增或修改删除标准接口 4.1 接口概述 4.2 接口名称 4.3查询学院信息接口标准 4.4新增学院信息接口标准 4.5修改学院信息接口标准 学生信息管理系统系统_学院管理_查询新增或…

【unity细节】分不清楚__世界坐标,自身坐标,Vector3,transform和translate?

👨‍💻个人主页:元宇宙-秩沅 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅! 本文由 秩沅 原创 收录于专栏:unity细节和bug ⭐世界坐标系transform和自身坐标Trasform.local和Vector3⭐ 文章目录 ⭐世界坐标…

__builtin_return_address函数

文章目录 一、gcc 内置函数二、__builtin_return_address2.1 简介2.2 代码示例 三、查看函数调用参考资料 一、gcc 内置函数 GCC 内置函数是指 GCC 编译器内置的一些函数,这些函数可以用于实现一些常用的操作,如数学运算、字符串处理、内存管理、调试等…

如何创作小红书化妆品文案,技巧分析!

小红书拥有众多女性用户群。美妆自然成为里面最大的板块,所以不管是护肤品牌,还是相关达人都会进行化妆品类的文案创作。今天从两个方案来探讨下如何创作小红书化妆品文案,技巧分析! 一、对品牌输出文案的重点 1. 强调产品特点 向…

牛客周赛 Round 3

游游的7的倍数 思路分析 添加一个数让其为7的倍数。倍数&#xff0c;每7个中必有一个是7的倍数&#xff0c;在末尾添加一个数即可.遍历0-6&#xff0c;满足既可。 时间复杂度 O&#xff08;1&#xff09; 代码 #include<bits/stdc.h> using namespace std; using ll…

毫秒级的 Unix 时间戳,将其转换为日期时间格式,报错,“将 expression 转换为数据类型 int 时出现算术溢出错误”

如果您有一个时间戳值为 1689217823000&#xff0c;表示毫秒级的 Unix 时间戳&#xff0c;您可以将其转换为日期时间格式。在 SQL Server 中&#xff0c;可以使用 DATEADD 和 CONVERT 函数来进行转换。 以下是将该时间戳值转换为日期时间格式的步骤&#xff1a; DECLARE timest…

从零开始学习 Java:简单易懂的入门指南(一)

Java基础语法 1. 人机交互1.1 什么是cmd&#xff1f;1.2 如何打开CMD窗口&#xff1f;1.3 常用CMD命令1.4 CMD练习1.5 环境变量 2. Java概述1.1 Java是什么&#xff1f;1.2下载和安装1.2.1 下载1.2.2 安装1.2.3 JDK的安装目录介绍 1.3 HelloWorld小案例1.3.1 Java程序开发运行…

【矩阵的基本操作】——MatLab基础

目录索引 矩阵的基本操作&#xff1a;转置&#xff1a;矩阵的拼接&#xff1a;*横拼&#xff1a;**竖拼&#xff1a;* 矩阵的索引&#xff1a;取元素&#xff1a;*end():* 取区域&#xff1a;逻辑判断&#xff1a;逻辑取值&#xff1a;find()&#xff1a; 矩阵的基本操作&#…

基于net core2.2的redis秒杀+数据持久化+数据恢复系列(2)

第一篇我们总结了秒杀的整个流程&#xff0c;本篇我们详细介绍下redis的秒杀实现&#xff0c;基于.net core2.2开发。 首先&#xff0c;需要安装redis&#xff0c;因为我在本地测试的&#xff0c;所以安装的windows版本的redis。redis分为服务端和客户端&#xff0c;这个redis…

了解Azido TAT,使用铜催化的叠氮化物反应修饰Tat肽,以下内容查看详细信息!

资料编辑|陕西新研博美生物科技有限公司小编MISSwu​ 【产品描述】 Azido-TAT中Tat肽已被证明具有优异的细胞穿透性&#xff0c;可以增强对特异性靶向疾病的诊断和 寡核苷酸的吸收。寡核苷酸通过点击化学与Tat&#xff08;一种生物学上重要的细胞穿透肽&#xff09;的共价连接…

❤ npm install 时报Error: spawn git ENOENT

❤ npm install 时报Error: spawn git ENOENT 原因&#xff1a; 主要是因为由于 git 的环境变量未设置导致&#xff0c;所以安装一下git 的环境变量就O了&#xff0c;步骤如下&#xff1a; 设置 >> 系统 >> 高级系统设置 >> 高级 >> 环境变量 >&g…

编写软件测试用例的方法,你知道多少种

1、等价类划分法 适用场景&#xff1a; 有数据输入的地方&#xff0c;就可以使用等价类划分法。如&#xff1a;输入框 测试思想&#xff1a; 从大量数据中划分范围&#xff08;等价类&#xff09;&#xff0c;然后从每个范围中挑选代表数据&#xff0c;这些代表数据要能反应…

株洲科能冲刺上市:计划募资约6亿元,实控人为赵科峰、唐燕夫妇

7月17日&#xff0c;上海证券交易所披露的信息显示&#xff0c;已对株洲科能新材料股份有限公司&#xff08;下称“株洲科能”&#xff09;发出问询函。据贝多财经了解&#xff0c;株洲科能于2023年6月21日递交招股书&#xff0c;准备在科创板上市。 本次冲刺科创板上市&#x…

springboot+mybatis-plus实现自动建表

好长时间没输出了&#xff0c;最近工作上也是太多事&#xff0c;领导动不动就拍脑门&#xff0c;那叫一个酸爽~ 工作能力的提现不但是技术或解决问题的能力上&#xff0c;还体现在要能立刻满足领导的各种需求&#xff0c;不管是哪方面的需求&#xff0c;这样才能够拍上马屁&…

IDDR和ODDR

IDDR D&#xff1a;输入双倍速率数据&#xff08;IOB输入&#xff0c;且数据在时钟的上升沿和下降沿都会发生切换&#xff0c;即一个时钟周期发送2bit数据&#xff09; CE&#xff1a;时钟使能信号&#xff08;高有效&#xff09; C&#xff1a;时钟信号 S&#xff0c;R&#x…

STM32F4_串口 IAP

目录 前言 1. IAP简介 2. APP程序起始地址设置方法 3. 中断向量表的偏移量设置 4. 如何在MDK中生成 .BIN 文件 5. APP程序生成步骤 前言 IAP&#xff0c;即在应用编程。 1. IAP简介 IAP&#xff08;In Application Programming&#xff09;即 在应用编程&#xff0c;IAP…