vtkWarpVector :

deform geometry with vector data

vtkWarpVector is a filter that modifies point coordinates by moving points along vector times the scale factor. Useful for showing flow profiles or mechanical deformation.

The filter passes both its point data and cell data to its output.

Examples:
vtkWarpVector (Examples)
Tests:
vtkWarpVector (Tests)

示例程序1:

#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 <vtkCellArray.h>
#include <vtkDoubleArray.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 <vtkWarpVector.h> int main()
{
///沿x轴方向创建5个点,x坐标分别为0、1、2、3、4。
/// 所有点的y、z坐标为0。即初始的5个点在水平线上
vtkSmartPointer<vtkPoints>points=vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(,,);
points->InsertNextPoint(,,);
points->InsertNextPoint(,,);
points->InsertNextPoint(,,);
points->InsertNextPoint(,,);
//将以上5个点,连成4段线
vtkSmartPointer<vtkCellArray> lines=vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkLine> line=vtkSmartPointer<vtkLine>::New();
for(int i=;i<;i++)
{
line->GetPointIds()->SetId(,i);
line->GetPointIds()->SetId(,i+);
lines->InsertNextCell(line);
} vtkSmartPointer<vtkDoubleArray> warpData=vtkSmartPointer<vtkDoubleArray>::New();
warpData->SetNumberOfComponents();
warpData->SetName("warpData");
//第1个点不动
double warp[]={,,};
warp[]=0.0;
warpData->InsertNextTuple(warp);
//第2个点沿y轴移动0.5
warp[]=0.5;
warpData->InsertNextTuple(warp);
//第3个点沿y轴移动0.3
warp[]=0.3;
warpData->InsertNextTuple(warp);
//第4个点沿y轴移动0.0
warp[] = 0.0;
warpData->InsertNextTuple(warp);
//第5个点沿y轴移动0.1
warp[] = 0.1;
warpData->InsertNextTuple(warp); //创建PolyData对象
vtkSmartPointer<vtkPolyData> polydata=vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->SetLines(lines);
polydata->GetPointData()->AddArray(warpData);
polydata->GetPointData()->SetActiveVectors(warpData->GetName());
//WarpVector will use the array marked as active vector in polydata
//it has to be a 3 component array
//with the same number of tuples as points in polydata
vtkSmartPointer<vtkWarpVector> warpVector =vtkSmartPointer<vtkWarpVector>::New();
warpVector->SetInputData(polydata);
warpVector->Update(); vtkSmartPointer<vtkPolyDataMapper>mapper=vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(warpVector->GetPolyDataOutput()); vtkSmartPointer<vtkActor> actor=vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); vtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(., ., .); vtkSmartPointer<vtkRenderWindow> renderWindow =vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindow->Render();
renderWindowInteractor->Start();
return ;
}

vtkWarpScalar

vtkWarpVector 是根据矢量数据移动指定的点。vtkWarpScalar则是根据设定法向量normal和标量Scalar,移动变形点。

vtkWarpScalar is a filter that modifies point coordinates by moving points along point normals by the scalar amount times the scale factor. Useful for creating carpet or x-y-z plots.

If normals are not present in data, the Normal instance variable will be used as the direction along which to warp the geometry. If normals are present but you would like to use the Normal instance variable, set the UseNormal boolean to true.

If XYPlane boolean is set true, then the z-value is considered to be a scalar value (still scaled by scale factor), and the displacement is along the z-axis. If scalars are also present, these are copied through and can be used to color the surface.

Note that the filter passes both its point data and cell data to its output, except for normals, since these are distorted by the warping.

Examples:
vtkWarpScalar (Examples)
Tests:
vtkWarpScalar (Tests)

vtkWarpScalar示例:

#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include <iostream>
using namespace std;
#include "vtkSmartPointer.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkDataSetMapper.h"
#include "vtkDebugLeaks.h"
#include "vtkFloatArray.h"
#include "vtkPlaneSource.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkTransform.h"
#include "vtkTransformPolyDataFilter.h"
#include "vtkWarpScalar.h"
int main()
{
int i, numPts;
double x[];
double r, deriv; vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(ren); vtkSmartPointer<vtkRenderWindowInteractor> iren =vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin); // create plane to warp
vtkSmartPointer<vtkPlaneSource> plane =vtkSmartPointer<vtkPlaneSource>::New();
plane->SetResolution (,); vtkSmartPointer<vtkTransform> transform =vtkSmartPointer<vtkTransform>::New();
transform->Scale(10.0,10.0,1.0); vtkSmartPointer<vtkTransformPolyDataFilter> transF =vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transF->SetInputConnection(plane->GetOutputPort());
transF->SetTransform(transform);
transF->Update(); // compute Bessel function and derivatives. This portion could be
// encapsulated into source or filter object.
//
vtkSmartPointer<vtkPolyData> input = transF->GetOutput();
numPts = input->GetNumberOfPoints(); vtkSmartPointer<vtkPoints> newPts =vtkSmartPointer<vtkPoints>::New();
newPts->SetNumberOfPoints(numPts); vtkSmartPointer<vtkFloatArray> derivs =vtkSmartPointer<vtkFloatArray>::New();
derivs->SetNumberOfTuples(numPts); vtkSmartPointer<vtkPolyData> bessel =vtkSmartPointer<vtkPolyData>::New();
bessel->CopyStructure(input);
bessel->SetPoints(newPts);
bessel->GetPointData()->SetScalars(derivs); for (i=; i<numPts; i++)
{
input->GetPoint(i,x);
r = sqrt(static_cast<double>(x[]*x[]) + x[]*x[]);
x[] = exp(-r) * cos (10.0*r);
newPts->SetPoint(i,x);
deriv = -exp(-r) * (cos(10.0*r) + 10.0*sin(10.0*r));
derivs->SetValue(i,deriv);
} // warp plane
vtkSmartPointer<vtkWarpScalar> warp =vtkSmartPointer<vtkWarpScalar>::New();
warp->SetInputData(bessel);
warp->XYPlaneOn();
warp->SetScaleFactor(0.5); // mapper and actor
vtkSmartPointer<vtkDataSetMapper> mapper =vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputConnection(warp->GetOutputPort());
double tmp[];
bessel->GetScalarRange(tmp);
mapper->SetScalarRange(tmp[],tmp[]); vtkSmartPointer<vtkActor> carpet =vtkSmartPointer<vtkActor>::New();
carpet->SetMapper(mapper); // assign our actor to the renderer
ren->AddActor(carpet);
ren->SetBackground(,,);
renWin->SetSize(,); // draw the resulting scene
ren->ResetCamera();
ren->GetActiveCamera()->Zoom(1.4);
ren->GetActiveCamera()->Elevation(-);
ren->GetActiveCamera()->Azimuth();
ren->ResetCameraClippingRange();
renWin->Render(); iren->Start();
return ;
}

vtkExampleWarpVector和vtkWarpScalar的更多相关文章

  1. vtk多线程简单测试

    vtkMultithreader is a class that provides support for multithreaded execution using sproc() on an SG ...

随机推荐

  1. 为了保护dll这么做吗?

    生成dll时候 附带生成的lib文件

  2. ES数据架构与关系数据库Mysql

    ES数据架构的主要概念(与关系数据库Mysql对比) MySQL ElasticSearch Database Index Table Type Row Document Column Field S ...

  3. 如何获取到app的包名

    相信很多朋友在刚开始接触测试app的时候都不清楚app的包名是什么,接下来给大家介绍几种方法去获取. 一.手机设备已连接到电脑,点击进入app中,前提是电脑上装备了android-SDK,tools文 ...

  4. java 学习笔记(四) java连接ZooKeeper

    public class Demo2 { public static void main(String[] args) { String connectString = "192.168.1 ...

  5. 【每日一包0001】is-sorted

    github地址:https://github.com/ABCDdouyae... is-sorted 用于判断数组是否被排序了 文档地址:https://www.npmjs.com/package/ ...

  6. 弹出框 popover.js

    弹出框 popover.js 为任意元素添加一小块浮层,就像 iPad 上一样,用于存放非主要信息. 弹出框的标题和内容的长度都是零的话将永远不会被显示出来. 插件依赖 弹出框依赖 工具提示插件 ,因 ...

  7. grunt-contrib-imagemin 图像压缩

    grunt-contrib-imagemin:图像压缩 安装插件:npm install grunt-contrib-imagemin --save-dev 参数 optimizationLevel( ...

  8. 关于enter事件的触发

    如果您使用了antd的Button组件,那么恭喜已经封装好了,只要加上htmlType='submit', 如果没有使用其他框架,使用onPress或者onKeydown事件,判断e.keycode ...

  9. CSS的 背景属性

    ㈠背景色  background-color ⑴background-color 属性设置元素的背景颜色. ⑵元素背景的范围: background-color 属性为元素设置一种纯色.这种颜色会填充 ...

  10. 排序(sort)

    1.定义 排序 所谓排序,就是要整理文件中的记录,使之按关键字递增(或递减)次序排列起来.其确切定义如下: 输入:n个记录R1,R2,…,Rn,其相应的关键字分别为K1,K2,…,Kn. 输出:Ril ...