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个人围成一圈,顺序排号.从第一个人开始 ...
随机推荐
- 【LuoguP4557】[JSOI2018]战争
题目链接 题意 给你两个点集. q次询问 , 每次把其中一个点集往一个方向移动 , 问两个点集的凸包还有没有交. Sol 闵可夫斯基和板子题. 把问题做如下转换: 我们本来两个凸包相交是相当于是对于移 ...
- qt5--文件操作
文本文件的读写操作: #include "win.h" #include "ui_win.h" #include <QDebug> #include ...
- JAVA笔记5-package和import
1.基本介绍 为便于管理大型软件系统中数目众多的类,解决类的命名冲突问题,Java引入包(package)机制,提供类的多重类命名空间.在实际项目开发中任何类都应该定义在包中. (1)package语 ...
- SQL server 大量数据导入和系统运行慢的问题
1.日常排查语句 --当前正在执行的语句 SELECT der.[session_id],der.[blocking_session_id], sp.lastwaittype,sp.hostname, ...
- Java基础——集合框架(待整理)
ArrayList 和 和 Vector 的区别 从代码的最终的操作形式上可以发现,代码的输出结果与之前是一样的,而且没有区别,但是两者的区别还在于其内部的组成上. No. 区别点 Vector Ve ...
- C#写入文件内容时提示:文件正被另一个人或程序使用
创建文件后未将文件关闭 string sTransLogFile = sTransLogPath + "\\" + DateTime.Now.ToString("yyyy ...
- Struts2-Action接受参数方式、method属性使用及通配符的配置
一.Action接受参数的方式 1.属性方式接收 首先编写一个用于上传参数的页面 <%@ page contentType="text/html;charset=UTF-8" ...
- Unity3D_(插件)使用Camera渲染制作Minimap小地图
制作小地图:使用Camera渲染出来Render Texture 原理:使用摄像机从上到下获得场景游戏物体,摄像机Culling Mask渲染层级可设置是否需要在小地图上展示游戏物体,将摄像机获得的场 ...
- Android学习_7/23
1. 在活动中使用Menu 1) 什么是Menu? 2) 怎么实现? step1:res目录下创建Menu resource file,使用<item… ...
- scrollWidth、clientWidth、offsetWidth、width的区别
scrollWidth:对象的实际内容的宽度,不包边线宽度,会随对象中内容超过可视区后而变大. clientWidth:对象内容的可视区的宽度,不包滚动条等边线,会随对象显示大小的变化而改变. off ...