vtkTubeFilter实例
filter that generates tubes around lines
vtkTubeFilter is a filter that generates a tube around each input line. The tubes are made up of triangle strips and rotate around the tube with the rotation of the line normals. (If no normals are present, they are computed automatically.) The radius of the tube can be set to vary with scalar or vector value. If the radius varies with scalar value the radius is linearly adjusted. If the radius varies with vector value, a mass flux preserving variation is used. The number of sides for the tube also can be specified. You can also specify which of the sides are visible. This is useful for generating interesting striping effects. Other options include the ability to cap the tube and generate texture coordinates. Texture coordinates can be used with an associated texture map to create interesting effects such as marking the tube with stripes corresponding to length or time.
This filter is typically used to create thick or dramatic lines. Another common use is to combine this filter with vtkStreamLine to generate streamtubes.
- Warning:
- The number of tube sides must be greater than 3. If you wish to use fewer sides (i.e., a ribbon), use vtkRibbonFilter.
- The input line must not have duplicate points, or normals at points that are parallel to the incoming/outgoing line segments. (Duplicate points can be removed with vtkCleanPolyData.) If a line does not meet this criteria, then that line is not tubed.
- See also:
- vtkRibbonFilter vtkStreamLine
在本例中,先创建一个螺旋线,然后用vtkTubeFilter使线的半径随着螺旋放生变化。
#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include <iostream>
using namespace std;
// VTK: Spiral with vtkTubeFilter
// Varying tube radius and independent RGB colors with an unsignedCharArray
// Contributed by Marcus Thamson #include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkDoubleArray.h>
#include <vtkPolyData.h>
#include <vtkPointData.h> #include <vtkCell.h>
#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkDataSetAttributes.h>
#include <vtkProperty.h>
#include <vtkSmartPointer.h>
#include <vtkTubeFilter.h> #include <vtkDataSetMapper.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCamera.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkMath.h> int main()
{
//螺旋管道;
double vx,vy,vz;
unsigned int nv=;//vertices的个数
unsigned int nCyc=;//螺旋的旋转周数
double rT1=0.1,rT2=0.5;//管道的起点和终点半径
double rs=; //螺旋半径
double h=; //高度
unsigned int nTv=;//管道上的每个vertex,曲面数量
unsigned int i; //创建用于螺旋管的points和cells
vtkSmartPointer<vtkPoints>points=vtkSmartPointer<vtkPoints>::New();
double pi=vtkMath::Pi();
for(i=;i<nv;i++)
{
//螺旋坐标
vx=rs*cos(*pi*nCyc*i/(nv-));
vy=rs*sin(*pi*nCyc*i/(nv-));
vz=h*i/nv;
points->InsertPoint(i,vx,vy,vz);
}
vtkSmartPointer<vtkCellArray> lines=vtkSmartPointer<vtkCellArray>::New();
lines->InsertNextCell(nv);
for(i=;i<nv;i++)
{
lines->InsertCellPoint(i);
}
vtkSmartPointer<vtkPolyData>polyData=vtkSmartPointer<vtkPolyData>::New();
polyData->SetPoints(points);
polyData->SetLines(lines); //半径随着正弦函数曲线变化
vtkSmartPointer<vtkDoubleArray> tubeRadius=vtkSmartPointer<vtkDoubleArray>::New();
tubeRadius->SetName("TubeRadius");//
tubeRadius->SetNumberOfTuples(nv);
for(i=;i<nv;i++)
{
tubeRadius->SetTuple1(i,
rT1+(rT2-rT1)*sin(pi*i/(nv-)));
}
polyData->GetPointData()->AddArray(tubeRadius);
polyData->GetPointData()->SetActiveScalars("TubeRadius");
//RBG 数组(也许也可以添加Alpha通道)
//颜色从蓝-->到红
vtkSmartPointer<vtkUnsignedCharArray>colors=vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetName("Colors");//为该数组起名为"Colors"
colors->SetNumberOfComponents();
colors->SetNumberOfTuples(nv);
for(i=;i<nv;i++)
{
colors->InsertTuple3(i,
int(*i/(nv-)),
,
int(*(nv--i)/(nv-)));
}
polyData->GetPointData()->AddArray(colors);//添加颜色属性标量scalar
//创建未经vtkTubeFilter处理的螺旋线Actor vtkSmartPointer<vtkPolyDataMapper>mapperSpiral=vtkSmartPointer<vtkPolyDataMapper>::New();
mapperSpiral->SetInputData(polyData);
mapperSpiral->ScalarVisibilityOn();
mapperSpiral->SetScalarModeToUsePointFieldData();//使用FieldData为对象上色
mapperSpiral->SelectColorArray("Colors");
vtkSmartPointer<vtkActor> actorSpiral=vtkSmartPointer<vtkActor>::New();
actorSpiral->SetMapper(mapperSpiral); //管道筛选器
vtkSmartPointer<vtkTubeFilter> tube=vtkSmartPointer<vtkTubeFilter>::New();
tube->SetInputData(polyData);
tube->SetNumberOfSides(nTv);
tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar(); vtkSmartPointer<vtkPolyDataMapper>mapper=vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection(tube->GetOutputPort()); mapper->ScalarVisibilityOn();
mapper->SetScalarModeToUsePointFieldData();//使用FieldData为对象上色
mapper->SelectColorArray("Colors"); vtkSmartPointer<vtkActor> actor=vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer>renderer=vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
// actorSpiral->SetPosition(5,0,0);
actorSpiral->AddPosition(,,);
renderer->AddActor(actorSpiral);//添加未经vtkTubeFilter处理的螺旋线Actor renderer->SetBackground(0.2,0.3,0.4);
//设定一个倾斜的视角
renderer->GetActiveCamera()->Azimuth();
renderer->GetActiveCamera()->Elevation();
renderer->ResetCamera(); vtkSmartPointer<vtkRenderWindow>renWin=vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor>iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleTrackballCamera>style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New(); renWin->AddRenderer(renderer);
renWin->SetSize(,);
renWin->Render();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
iren->Start();
return ;
}
vtkTubeFilter实例的更多相关文章
- 最近学习工作流 推荐一个activiti 的教程文档
全文地址:http://www.mossle.com/docs/activiti/ Activiti 5.15 用户手册 Table of Contents 1. 简介 协议 下载 源码 必要的软件 ...
- js-静态、原型、实例属性
本篇来说一下js中的属性: 1.静态属性 2.原型属性 3.实例属性 静态属性: function klass(){} var obj=new klass(); klass.count=0; klas ...
- ZIP压缩算法详细分析及解压实例解释
最近自己实现了一个ZIP压缩数据的解压程序,觉得有必要把ZIP压缩格式进行一下详细总结,数据压缩是一门通信原理和计算机科学都会涉及到的学科,在通信原理中,一般称为信源编码,在计算机科学里,一般称为数据 ...
- EntityFramework Core 1.1是如何创建DbContext实例的呢?
前言 上一篇我们简单讲述了在EF Core1.1中如何进行迁移,本文我们来讲讲EF Core1.1中那些不为人知的事,细抠细节,从我做起. 显式创建DbContext实例 通过带OnConfiguri ...
- redis集成到Springmvc中及使用实例
redis是现在主流的缓存工具了,因为使用简单.高效且对服务器要求较小,用于大数据量下的缓存 spring也提供了对redis的支持: org.springframework.data.redis.c ...
- 流程开发Activiti 与SpringMVC整合实例
流程(Activiti) 流程是完成一系列有序动作的概述.每一个节点动作的结果将对后面的具体操作步骤产生影响.信息化系统中流程的功能完全等同于纸上办公的层级审批,尤其在oa系统中各类电子流提现较为明显 ...
- UWP开发之Template10实践:本地文件与照相机文件操作的MVVM实例(图文付原代码)
前面[UWP开发之Mvvmlight实践五:SuspensionManager中断挂起以及复原处理]章节已经提到过Template10,为了认识MvvmLight的区别特做了此实例. 原代码地址:ht ...
- echarts+php+mysql 绘图实例
最近在学习php+mysql,因为之前画图表都是直接在echart的实例demo中修改数据,便想着两相结合练习一下,通过ajax调用后台数据画图表. 我使用的是echart3,相比较第二版,echar ...
- 【HanLP】HanLP中文自然语言处理工具实例演练
HanLP中文自然语言处理工具实例演练 作者:白宁超 2016年11月25日13:45:13 摘要:HanLP是hankcs个人完成一系列模型与算法组成的Java工具包,目标是普及自然语言处理在生产环 ...
随机推荐
- javascript判断是否为闰年
//判断年份year是否为闰年,是闰年则返回true,否则返回false function isLeapYear(year){ var a = year % 4; var b = year % 100 ...
- github入门到上传本地项目
GitHub是基于git实现的代码托管.git是目前最好用的版本控制系统了,非常受欢迎,比之svn更好. GitHub可以免费使用,并且快速稳定.即使是付费帐户,每个月不超过10美刀的费用也非常便宜. ...
- Linux 进程与线程五
pthread_self函数 pthread_t pthread_self(void); 一般会成功,返回当前线程的ID 注意:在子线程中执行exit()函数会退出整个进程,一般使用pthread_e ...
- Power Management开发的一般流程
本文作为一个提纲挈领的介绍性文档,后面会以此展开,逐渐丰富. 开发流程 针对一个PM feature进行开发,设计模型是第一步.模型设计好之后,还要保留参数接口,可以基于这些参数针对特殊个体进行优化. ...
- Workload Automation分析及其使用
Workload Automation介绍 Workload Automation是提供一个在设备上运行各种workload的工具,使用Python编写.WA具有良好的框架结构,方便快捷的扩展.包含几 ...
- kubernetes 1.4.5集群部署
2016/11/16 23:39:58 环境: centos7 [fu@centos server]$ uname -a Linux centos 3.10.0-327.el7.x86_64 #1 S ...
- Html-浅谈如何正确给table加边框
一般来说,给表格加边框都会出现不同的问题,以下是给表格加边框后展现比较好的方式 <style> table,table tr th, table tr td { border:1px so ...
- 内核控制Meta标签:让360浏览器默认使用极速模式打开网页(转)
为了让网站页面不那么臃肿,也懒的理IE了,同时兼顾更多的国内双核浏览器,在网页页头中添加了下面两行Meta控制标签. 1,网页头部加入 <meta name="renderer&quo ...
- Android自定义九宫格图案解锁
转自: http://blog.csdn.net/shineflowers/article/details/50408350
- [转]ExtJs入门之filefield:文件上传的配置+结合Ajax完美实现文件上传的asp.net示例
原文地址:http://www.stepday.com/topic/?459 作文一个ExtJs的入门汉子,学习起来的确是比较费劲的事情,不过如今在这样一个网络资源如此丰富的时代,依然不是那么难了的. ...