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

最新文章

  1. ios 弹出不同的键盘
  2. jquery替换URL参数值
  3. Ajax长连接应用
  4. Mindjet MindManager 2012 从模板创建出现“Runtime Error pure virtual function call” 解决方法
  5. Gvim7.4简单配置
  6. c语言,结构体
  7. POJ 3076 Sudoku DLX精确覆盖
  8. Vuex核心知识(2.0)
  9. MarkDown---超强文本编辑器
  10. JFinal 极速开发框架的优点和不足的地方
  11. (六十五)iOS的socket实现(GCDAsyncSocket)
  12. Liunx小白须知
  13. 获取Windows服务下当前路径的方法
  14. Android Wear 2.0 AlarmManager 后台定时任务
  15. SPOJ33&amp;POJ1934 Trip LCS
  16. latex 字体大小设置
  17. C library:&lt;cctype&gt;(ctype.h)
  18. VIO回顾:从滤波和优化的视角
  19. Elastix 2.4 双服务器热备搭建文档
  20. 20145310 《Java程序设计》第8周学习总结

热门文章

  1. Juniper SSG5 PPTP VPN 619错误解决
  2. Centos7 关闭防火墙
  3. Ubuntu16.04 LTS下apt安装WireShark
  4. python读取文件夹
  5. click与 mousedown
  6. 侯捷老师C++大系之C++面向对象开发:(一)不带指针的类:Complex复数类的实现过程
  7. Spark MLlib - LFW
  8. 字节流VS缓冲流
  9. Ceph RGW 创建默认的pool
  10. Django Admin