vtkTestHull将多个平面围成一个凸面体
1、vtkHull
produce an n-sided convex hull
vtkHull is a filter which will produce an n-sided convex hull given a set of n planes. (The convex hull bounds the input polygonal data.) The hull is generated by squeezing the planes towards the input vtkPolyData, until the planes just touch the vtkPolyData. Then, the resulting planes are used to generate a polyhedron (i.e., hull) that is represented by triangles.
The n planes can be defined in a number of ways including 1) manually specifying each plane; 2) choosing the six face planes of the input's bounding box; 3) choosing the eight vertex planes of the input's bounding box; 4) choosing the twelve edge planes of the input's bounding box; and/or 5) using a recursively subdivided octahedron. Note that when specifying planes, the plane normals should point outside of the convex region.
The output of this filter can be used in combination with vtkLODActor to represent a levels-of-detail in the LOD hierarchy. Another use of this class is to manually specify the planes, and then generate the polyhedron from the planes (without squeezing the planes towards the input). The method GenerateHull() is used to do this.
- Tests:
- vtkHull (Tests)
下面分别是有50个和150个随机面围裹成的两个凸多面体

示例代码:
#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include <iostream>
using namespace std;
#include <vtkVersion.h>
#include <vtkActor.h>
#include <vtkLine.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkFloatArray.h> #include <vtkMath.h>
#include <vtkPlanes.h>
#include <vtkHull.h> int main()
{
vtkSmartPointer<vtkMath> mathObj=vtkSmartPointer<vtkMath>::New();
vtkSmartPointer<vtkPoints> points=vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkFloatArray> normals=vtkSmartPointer<vtkFloatArray>::New();
normals->SetNumberOfComponents();
float radius,theta,phi,x,y,z;
int numberOfPlanes=;
///创建numberOfPlanes个随机平面,每个平面中心点坐标为(x,y,z),其法向量为(x,y,z),
///无论怎样随机,这些平面都是与半径为radius的球面相切,并包裹着该球面
for(int i=;i<numberOfPlanes;i++)
{
radius=;
theta=mathObj->Random(,mathObj->Pi()*);
phi=mathObj->Random(,mathObj->Pi());
x=radius*sin(phi)*cos(theta);
y=radius*sin(phi)*sin(theta);
z=radius*cos(phi);
points->InsertPoint(i,x,y,z);
normals->InsertTuple3(i,x,y,z);
}
vtkSmartPointer<vtkPlanes>planes=vtkSmartPointer<vtkPlanes>::New();
planes->SetPoints(points);
planes->SetNormals(normals);
std::cout<<planes->GetNumberOfPlanes()<<std::endl;
vtkSmartPointer<vtkHull>hull=vtkSmartPointer<vtkHull>::New();
hull->SetPlanes(planes);
vtkSmartPointer<vtkPolyData> pd=vtkSmartPointer<vtkPolyData>::New();
hull->GenerateHull(pd,-,,-,,-,); vtkSmartPointer<vtkPolyDataMapper>hullMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
hullMapper->SetInputData(pd); vtkSmartPointer<vtkActor>hullActor=vtkSmartPointer<vtkActor>::New();
hullActor->SetMapper(hullMapper);
//创建图形对象
//创建显示窗口
vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
ren1->AddActor(hullActor);
renWin->AddRenderer(ren1);
iren->SetRenderWindow(renWin); ren1->ResetCamera();
iren->Initialize();
iren->Start(); return ;
}
vtkTestHull将多个平面围成一个凸面体的更多相关文章
- C语言——N个人围成一圈报数淘汰问题
<一>问题描述: 有17个人围成一圈(编号为0-16),从第 0号的人开始从 1报数, 凡报到 3的倍数的人离开圈子,然后再数下去,直到最后只剩下一个人为止. 问此人原来的位置是多少号? ...
- C++经典题目:有n个人围成一圈,顺序排号,然后数数进行淘汰的解法和一些思考
问题描述: 有n个人围成一圈,顺序排号.从第一个人开始报数(1~3报数),凡报到3的人退出圈子,问最后留下的人原来排在第几号. 分析: 首先由用户输入人数n,然后对这n个人进行编号[因为如果不编号的话 ...
- n人围成一圈报数
题目:有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来的第几号的那位 思路:用一个数组存这n个人,里面的初始状态全设为1,表示都还在圈子里面. ...
- java解答:有17个人围成一圈(编号0~16),从第0号的人开始从1报数,凡报到3的倍数的人离开圈子,然后再数下去,直到最后只剩下一个人为止,问此人原来的位置是多少号?
package ttt; import java.util.HashMap; import java.util.Map.Entry; /** * 有17个人围成一圈(编号0~16),从第0号的人开始从 ...
- hdu 3951 硬币围成一圈(博弈)
n个硬币围成一个环 每次只能取1-K个硬币 最后取完者胜 假如5个硬币 每次取1-2个情况1 先手取1个 后手取剩下4个中间2个 破坏了连续 虽然最后剩2个,但先手只能取一个 然后后再取一个 后手胜 ...
- 37 有n个人围成一圈,顺序排号,从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号那位.
题目:有n个人围成一圈,顺序排号,从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号那位. public class _037NumberOff { public st ...
- 20190121-n个人围成一圈,凡报到3的人退出圈子,最后留下的是原来第几号的那位
1. 报数问题:有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位 思路:此题主要问题在于但凡报到3的人退出圈子,而报数的号码与圈子的 ...
- 约瑟夫环问题:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
首先,我最大的学习来源不是百度而是我群友~~在这里表白一波我热爱学习的群友们!然后今天群里突然有人提出了题目的这个问题:有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出 ...
- 代码实现:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
import java.util.ArrayList; import java.util.List; import java.util.Scanner; //有n个人围成一圈,顺序排号.从第一个人开始 ...
随机推荐
- Django学习系列10:保存用户输入——编写表单,发送POST请求
要获取用户输入的待办事项,发送给服务器,这样才能使用某种方式保存待办事项,然后在显示给用户查看. 上次运行测试指出无法保存用户的输入.现在,要使用HTML post请求. 若想让浏览器发送POST请求 ...
- C++最快获取像素值
HDC hdc, hdcTemp; RECT rect; BYTE* bitPointer; int x, y; int red, green, blue, alpha; while(true) { ...
- linux的逻辑运算符
1:expression :用于计算括号中的组合表达式,如果整个表达式的计算按结果为真,则测试结果也为真. 2:!exp:客队表达式进行逻辑非运算,即对测试结果求反 3:符合 -a 或者 && ...
- [CF1105E] Helping Hiaset
问题描述 你在某社交网站上面注册了一个新账号,这个账号有\(n(n\leq 10^5)\)次记录.要么就是你更改过一次ID,要么就是一个ID为\(s(|s|\leq 40)\)的朋友访问过你的空间. ...
- C# SqlDataReader
var reader = MSSQLHelper.ExecuteReader(sb.ToString(), out erro, ConnectionString); //SqlDataReader / ...
- 删除文件中的 ^M 字符
删除文件中的 ^M 字符 有时候,我们在 Linux 中打开曾在 Win 中编辑过的文件时,会在行尾看到 ^M 字符.虽然,这并不影响什么,但心里面还是有点不痛快.如果想要删除这些 ^M 字符,可以使 ...
- [Flask]celery异步任务队列的使用
Celery异步任务队列 目录结构树: 配置文件config.py: # 设置中间人地址 broker_url = 'redis://127.0.0.1:6379/1' 主main.py: impor ...
- c语言 - 关键字const的作用
const修饰的数据类型是指常类型,常类型的变量或对象的值是不能被更新的. 1.const char * p1; //表示p1指向了的字符串不可更改 2.char const ...
- JS实现深拷贝的几种方法
引 如何区分深拷贝与浅拷贝,简单点来说,就是假设B复制了A,当修改A时,看B是否会发生变化,如果B也跟着变了,说明这是浅拷贝,拿人手短,如果B没变,那就是深拷贝,自食其力. 此篇文章中也会简单阐述到栈 ...
- xwiki使用中的问题
xwiki 内存限制 问题重现: xwiki启动后内存.cpu一直上涨,不回落,启动后服务访问速度越来越慢,最后无法访问 分析: xwiki在启动时会消耗大量内存和cpu,增加tomcat最大内存限制 ...