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 ;
}

最新文章

  1. CSS清浮动处理(Clear与BFC)
  2. Alamofire 的使用
  3. ChromePHP - Chrome浏览器下的PHP debug工具
  4. 进入appstore中指定的应用
  5. [分享]好用的Markdown编辑器
  6. 【Hibernate】--实体状体与主键生成策略
  7. 通过内省机制设置JavaBean
  8. hbulider mui框架
  9. Eclipse在点击运行后不能自动保存的解决
  10. Unity中的CG编写Shader系列(Blend)
  11. Git 下载代码简单说明
  12. 一张图说明TCP和UCP协议
  13. nw.js---创建一个点击菜单
  14. linux的查找命令 find whereis locate
  15. mysql不存在插入否则更新
  16. 非接触IC卡中typeA卡和typeB卡的区别--总结,二者的调制方式和编码方式不同
  17. Linux运维之--zabbix使用(实时更新)
  18. P问题,NP问题,NPC问题,NP-hard问题
  19. 【python笔记】使用matplotlib,pylab进行python绘图
  20. JQuery EasyUI combobox 省市两级联动

热门文章

  1. java基础笔试题一
  2. Django学习系列14:第一个数据库迁移
  3. BZOJ1233 [Usaco2009Open]干草堆tower[贪心+单调队列优化]
  4. linux中的selinux到底是什么
  5. HNOI2010 平面图判定(planar)
  6. H5 video全屏与取消全屏兼容
  7. 消息队列rabbitmq/kafka
  8. C++入门经典-例5.15-回收动态内存的一般处理步骤
  9. C#操作WMI文章汇总
  10. git设置mergetool可视化工具