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工具包,目标是普及自然语言处理在生产环 ...
随机推荐
- Python常用方法
Python strip()方法 描述: Python strip()方法用于移除字符串头尾指定的字符(默认为空格). 语法: str.strip([chars]) 参数: chars -- 移除字符 ...
- SVN“验证位置时发生错误”的解决办法
验证位置时发生错误:“org.tigris.subversion.javahl.ClientException...... 验证位置时发生错误:“org.tigris.subversion.javah ...
- (转)socket Aio demo
原文地址: https://my.oschina.net/tangcoffee/blog/305656 参考文档: http://my.oschina.net/u/862897/blog/164425 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- 《WePayUI组件设计的秘密》——2016年第一届前端体验大会分享
本文是博主参加第一届前端体验大会 | 物勒工名做的分享<WePayUI组件设计的秘密>,内容主要分为2个部分: 一.浅析UI库/框架的未来 讨论的UI库或者框架,主要包含展示和交互的css ...
- 如何用Unity创建一个的简单的HoloLens 3D程序
注:本文提到的代码示例下载地址>How to create a Hello World 3D holographic app with Unity 之前我们有讲过一次如何在HoloLens中创建 ...
- Android国际化--I18N
在res下创建对应国家的环境的目录如:values-zh,values-en,然后在对应的目录下将对应的字符串翻译成对应国家的语言即可.
- 【BZOJ 4579】【Usaco2016 Open】Closing the Farm
http://www.lydsy.com/JudgeOnline/problem.php?id=4579 把时间倒过来,只是加点,并查集维护连通块. #include<cstdio> #i ...
- 递推 HDU 2569
考虑n-2 n-1 n z[n] 代表n个块 可行方案 1 n-2 和n-1 同 3*z[n-2] 2 n-2和n-1不同 2*(z[n-1]-z[n-2]); 减一减 然后可能是其中一种 *2 ...
- Uncaught RangeError: Maximum call stack size exceeded 超出最大调用值(个人解释)
写了段jq后,报这个错,度娘未解,灵光一闪,找到原因,上代码: Html 结构: <a href="javascript:;" class="item-pic&qu ...