vtkExampleWarpVector和vtkWarpScalar
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的更多相关文章
- vtk多线程简单测试
vtkMultithreader is a class that provides support for multithreaded execution using sproc() on an SG ...
随机推荐
- Attention机制中权重的计算
Attention mechanism中,给输入序列中对应的每一个Ht分配权重(打分)究竟是如何打分? 输入序列打分,a(s, h) 其中s是输出序列的t-1时刻的隐藏层状态,h是输入的多个状态,
- 【leetcode】341. Flatten Nested List Iterator
题目如下: Given a nested list of integers, implement an iterator to flatten it. Each element is either a ...
- IDEA+SpringBoot+Freemark 构造一个简单的页面
访问地址 http://localhost:8083/m2detail 1.在Controller中配置 /** * m2detail */ @RequestMapping(value = " ...
- layui的数据表格加上操作
数据表格加上操作. <script type="text/html" id="barDemo"> <a class="layui-b ...
- [Linux系统] (6)LVS负载均衡
部分内容转自:https://blog.csdn.net/weixin_40470303/article/details/80541639 一.LVS简介 LVS(Linux Virtual Ser ...
- [采坑] VS2015 warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
问题: Visual Studio 2015出现warning C4819: 该文件包含不能在当前代码页(936)中表示的字符.请将该文件保存为 Unicode 格式以防止数据丢失. 解决方案: 1. ...
- C/C++ - 指针 与 引用
一.指针 1.指针与指针变量的区分 a.指针:指针就是内存编号,也就是内存地址,通俗的讲,指针就是变量的地址. 注1:指针的大小是根据计算机的操作系统而定的,跟变量类型无关 注2:如果是32位的操作系 ...
- LinkedList类源码浅析(二)
1.上一节介绍了LinkedList的几个基本的方法,其他方法类似,就不一一介绍: 现在再来看一个删除的方法:remove(Object o) remove方法接受一个Object参数,这里需要对参数 ...
- java跨平台的原因
java跨平台的原因 java有虚拟机(JVM),JAVA程序不是直接在电脑上运行的,是在虚拟机上进行的,每个系统平台都是有自己的虚拟机(JVM),所以JAVA语言能跨平台. 1.java代码不是直接 ...
- Python学习笔记:list的各种操作
向一个列表中添加单个元素: my_list = []my_list.append('我爱你') 移除列表中的某个元素: my_list.pop(0) # 0是需要移除元素在列表中的index 或者是移 ...