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实例的更多相关文章

  1. 最近学习工作流 推荐一个activiti 的教程文档

    全文地址:http://www.mossle.com/docs/activiti/ Activiti 5.15 用户手册 Table of Contents 1. 简介 协议 下载 源码 必要的软件 ...

  2. js-静态、原型、实例属性

    本篇来说一下js中的属性: 1.静态属性 2.原型属性 3.实例属性 静态属性: function klass(){} var obj=new klass(); klass.count=0; klas ...

  3. ZIP压缩算法详细分析及解压实例解释

    最近自己实现了一个ZIP压缩数据的解压程序,觉得有必要把ZIP压缩格式进行一下详细总结,数据压缩是一门通信原理和计算机科学都会涉及到的学科,在通信原理中,一般称为信源编码,在计算机科学里,一般称为数据 ...

  4. EntityFramework Core 1.1是如何创建DbContext实例的呢?

    前言 上一篇我们简单讲述了在EF Core1.1中如何进行迁移,本文我们来讲讲EF Core1.1中那些不为人知的事,细抠细节,从我做起. 显式创建DbContext实例 通过带OnConfiguri ...

  5. redis集成到Springmvc中及使用实例

    redis是现在主流的缓存工具了,因为使用简单.高效且对服务器要求较小,用于大数据量下的缓存 spring也提供了对redis的支持: org.springframework.data.redis.c ...

  6. 流程开发Activiti 与SpringMVC整合实例

    流程(Activiti) 流程是完成一系列有序动作的概述.每一个节点动作的结果将对后面的具体操作步骤产生影响.信息化系统中流程的功能完全等同于纸上办公的层级审批,尤其在oa系统中各类电子流提现较为明显 ...

  7. UWP开发之Template10实践:本地文件与照相机文件操作的MVVM实例(图文付原代码)

    前面[UWP开发之Mvvmlight实践五:SuspensionManager中断挂起以及复原处理]章节已经提到过Template10,为了认识MvvmLight的区别特做了此实例. 原代码地址:ht ...

  8. echarts+php+mysql 绘图实例

    最近在学习php+mysql,因为之前画图表都是直接在echart的实例demo中修改数据,便想着两相结合练习一下,通过ajax调用后台数据画图表. 我使用的是echart3,相比较第二版,echar ...

  9. 【HanLP】HanLP中文自然语言处理工具实例演练

    HanLP中文自然语言处理工具实例演练 作者:白宁超 2016年11月25日13:45:13 摘要:HanLP是hankcs个人完成一系列模型与算法组成的Java工具包,目标是普及自然语言处理在生产环 ...

随机推荐

  1. easyUI的基础布局easyui-accordion

    ---恢复内容开始--- <html> <head> <meta charset="UTF-8"> <title>树状图</t ...

  2. Linux下如何遍历指定目录下的所有文件并删除指定天数之前创建的文件

    脚本内容如下: #!/bin/bash function delete_file { days=$[$-] for i in `find $dir -type f -ctime +$days` do ...

  3. monkeyrunner之坐标或控件ID获取方法-续

    在之前的文章中,介绍过控件坐标和ID的获取方法,这里,我们再介绍一个新的工具-uiautomatorviewer. Uiautomatorviewer是Android sdk自带的工具,位置在sdk/ ...

  4. Dubbo学习之简单环境搭建

    Dubbo服务的发展和作用: 首先,看下一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越多之后的常规方案演进历程. 其次,当服务越来越多之后,我们需要做哪些服务治理? 最后,是d ...

  5. struts2中Ajax校验

    Ajax(Asynchronous JavaScript and Xml),整合了JavaScript,XML,CSS,DOM,Ajax引擎(XMLHttpRequest). JavaScript语言 ...

  6. MarkDown+LaTex 数学内容编辑样例收集

    $\color{green}{MarkDown+LaTex 数学内容编辑样例收集}$ 1.大小标题的居中,大小,颜色 [例1] $\color{Blue}{一元二次方程根的分布}$ $\color{R ...

  7. jsp基础

    1.1动态页面 动态页面的优势: 1.交互性:网页会根据用户的要求和选而动态改变和显示内容; 2.自动更新:无需改变页面代码,便会自动更新的页面内容; 3.随机性:当不同的时间,不同的人访问同一网址时 ...

  8. [LeetCode] Sum of Left Leaves 左子叶之和

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

  9. java版简易socket客户端

    android项目需要使用到心跳, 于是编写了一个简易的socket客户端程序 主要功能是给服务端发送心跳包,保持在线状态 没有使用框架,这样避免了需要引入包,直接使用的阻塞Socket通信. 主要逻 ...

  10. linux下查看最消耗CPU、内存的进程

    2012-11-19 15:38:04 分类: LINUX 1.CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 2.内存消耗 ...