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个人围成一圈,顺序排号.从第一个人开始 ...
随机推荐
- struts2与SpringMVC区别
1.springmvc基于方法开发的,struts2基于类开发的. 2.单例和多例的区别:springmvc在映射的时候,通过形参来接收参数的,是将url和controller方法映射,映射成功后,s ...
- Centos 7搭建Gitlab服务器以及操作(创建项目,创建群组,创建用户,添加密钥)
一. 安装并配置依赖包 在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget,以下这些命令也会打开 系统防火墙中的HTTP和SSH端口访问 安装前准备 命令: ...
- vue cli3 项目配置
[转]https://juejin.im/post/5c63afd56fb9a049b41cf5f4 基于vue-cli3.0快速构建vue项目 本章详细介绍使用vue-cli3.0来搭建项目. 本章 ...
- Spark入Hbase的四种方式效率对比
一.方式介绍 本次测试一种采用了四种方式进行了对比,分别是:1.在RDD内部调用java API.2.调用saveAsNewAPIHadoopDataset()接口.3.saveAsHadoopDat ...
- win10 1903 更改文字大小
标题栏 - 菜单 - 消息框 - 调色板标题11- 图标 - 工具提示 - Caption 标题 的 宽/高 - ; 14的宽高 - 菜单 的 宽/高 - ; 的宽高 -; 设置 注册表 HKEY_C ...
- OpenCV笔记(1)(图片读取与现实、色彩空间、基础运算、均值方差、逻辑运算、泛洪填充、均值中值及自定义平滑)
一.图片读取和显示 import cv2 as cv # 图片读取cv.imread(img_path) car_img = cv.imread("car1.png") # 图片显 ...
- GooFlow
目前的下载网址:基于JQUERY的WEB在线流程图设计器GOOFLOW 0.7版
- POJ 3723 征兵问题(最小生成树算法的应用)
Conscription Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15923 Accepted: 5510 Des ...
- UVA 11178 Morley's Theorem 计算几何模板
题意:训练指南259页 #include <iostream> #include <cstdio> #include <cstring> #include < ...
- unittest详解(七) 自动生成测试报告
用例执行完成后,执行结果默认是输出在屏幕上,其实我们可以把结果输出到一个文件中,形成测试报告. unittest自带的测试报告是文本形式的,如下代码: import unittest if __nam ...