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将多个平面围成一个凸面体的更多相关文章

  1. C语言——N个人围成一圈报数淘汰问题

    <一>问题描述: 有17个人围成一圈(编号为0-16),从第 0号的人开始从 1报数, 凡报到 3的倍数的人离开圈子,然后再数下去,直到最后只剩下一个人为止. 问此人原来的位置是多少号? ...

  2. C++经典题目:有n个人围成一圈,顺序排号,然后数数进行淘汰的解法和一些思考

    问题描述: 有n个人围成一圈,顺序排号.从第一个人开始报数(1~3报数),凡报到3的人退出圈子,问最后留下的人原来排在第几号. 分析: 首先由用户输入人数n,然后对这n个人进行编号[因为如果不编号的话 ...

  3. n人围成一圈报数

    题目:有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来的第几号的那位 思路:用一个数组存这n个人,里面的初始状态全设为1,表示都还在圈子里面. ...

  4. java解答:有17个人围成一圈(编号0~16),从第0号的人开始从1报数,凡报到3的倍数的人离开圈子,然后再数下去,直到最后只剩下一个人为止,问此人原来的位置是多少号?

    package ttt; import java.util.HashMap; import java.util.Map.Entry; /** * 有17个人围成一圈(编号0~16),从第0号的人开始从 ...

  5. hdu 3951 硬币围成一圈(博弈)

    n个硬币围成一个环 每次只能取1-K个硬币 最后取完者胜 假如5个硬币 每次取1-2个情况1 先手取1个 后手取剩下4个中间2个 破坏了连续 虽然最后剩2个,但先手只能取一个 然后后再取一个 后手胜 ...

  6. 37 有n个人围成一圈,顺序排号,从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号那位.

    题目:有n个人围成一圈,顺序排号,从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号那位. public class _037NumberOff { public st ...

  7. 20190121-n个人围成一圈,凡报到3的人退出圈子,最后留下的是原来第几号的那位

    1. 报数问题:有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位 思路:此题主要问题在于但凡报到3的人退出圈子,而报数的号码与圈子的 ...

  8. 约瑟夫环问题:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。

    首先,我最大的学习来源不是百度而是我群友~~在这里表白一波我热爱学习的群友们!然后今天群里突然有人提出了题目的这个问题:有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出 ...

  9. 代码实现:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。

    import java.util.ArrayList; import java.util.List; import java.util.Scanner; //有n个人围成一圈,顺序排号.从第一个人开始 ...

随机推荐

  1. 微信小程序 点击事件 传递参数

    wxml: data-参数名="值" bindtap="函数名" <view class="buy-button {{cap_select == ...

  2. web性能优化-浏览器工作原理

    要彻底了解web性能优化的问题,得搞清楚浏览器的工作原理. 我们需要了解,你在浏览器地址栏中输入url到页面展示的短短几秒中,浏览器究竟做了什么,才能了解到为什么我们口中所说的优化方案能够起到优化作用 ...

  3. jar启动名称示例

    nohup java -jar -Dspring.profiles.active=20dev -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+Print ...

  4. centos7安装教程(U盘启动盘制作)

    Centos7 系统安装步骤. 1,准备一个8gU盘. 2.iso系统镜像文件. 3.下载UltraISO软件制作启动盘. 点击试用 选中u盘

  5. hiho #1469 : 福字(dp)

    #1469 : 福字 时间限制:6000ms 单点时限:1000ms 内存限制:256MB 描述 新年到了,你收到了一副画.你想找到里面最大的福字. 一副画是一个n × n的矩阵,其中每个位置都是一个 ...

  6. 15.DRF学习以及相关源码阅读

    1.http请求协议 代码很枯燥,结果和奇妙. 1.cbv django.vuews import View classs LoginView(View): def get(self,requset) ...

  7. ng-class的几种用法

    参考来自 https://www.cnblogs.com/zhoulin1234/p/9587955.html 方法1.逻辑在后面的中括号里面 ng-class="{true : 'chec ...

  8. Python天天学_03_基础三

    Python_day_03 金角大王: http://www.cnblogs.com/alex3714/articles/5740985.html ------Python是一个优雅的大姐姐 学习方式 ...

  9. less基本用法:持续归纳中

    todo 1,嵌套语法:https://www.w3cschool.cn/less/nested_directives_bubbling.html 简单来说就是可以与html一样去写css,并且会继承 ...

  10. sqli-labs(4)

    sqli-libs(4)通关过程 0x01爱之初体验 首先我们进行注入试探 发现我们的单引号 回显事正常的 双引号回显反而是错误的 查看源码我们发现 多了一个给id赋值的语句 我们在php上面执行一下 ...