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 ...
随机推荐
- Summer training round2 #7 (Training #23)
A:约瑟夫环 套公式 B:线性筛素数 C:投骰子 概率DP F:有权无向图的生成树(边最大值和最小值只差最小) 直接kruskal G:状压BFS或者双向BFS H:模拟题 I:几何题 J:高斯消元
- java将一数组乱序排列
JAVA的Collections类中shuffle方法模拟了“洗牌”动作可以对list列表进行随机排序.如果一定要自己写,算法也很简单:假设数组array长度为n.用标准随机函数rand(n)生成[0 ...
- 从Buck-Boost到Flyback
电源的拓扑有很多种,但是其实我们能够理解一种拓扑,就可以理解其他拓扑结构.因为组成各种拓扑的基本元素是一样的. 对于隔离电源.大家接触最多的电路拓扑应该是 flyback. 但是大家一开始做电源的时候 ...
- beautifulsoup4 用法一二
声明一个beautifulsoup4对象 bs = ( url,//路由 html_parser,//解析html代码 encoding//编码)//另一种请求解析方法 import requests ...
- 【转载】awk入门
作者: 阮一峰 http://www.ruanyifeng.com/blog/2018/11/awk.html awk是处理文本文件的一个应用程序,几乎所有 Linux 系统都自带这个程序. 它依次处 ...
- buunctf@reverse2
- 小米手机安装https证书报错:无法安装该证书 因为无法读取该证书文件
Fiddler]手机安装https证书报错:无法安装该证书 因为无法读取该证书文件 之前在手机上使用 “ip:端口号” 的方法就能直接在手机上自动下载安装fiddler证书,但是现在有些手机并不能 ...
- Windows环境下MySQL面试技巧
对话一: 面试官:重新安装mysql卡在最后一步,怎么解决? 应聘者:第一次安装完mysql,由于各种原因需要重新安装是经常遇到的问题,解决方案如下. 1)在注册表里搜索my ...
- JavaScript生成随机数的方法
一,函数 Math.ceil(); //向上取整. Math.floor(); //向下取整. Math.round(); //四舍五入. Math.random(); //0.0 ~ 1.0 ...
- 让IE8一下兼容CSS3选择器
来自英国的网页开发工程师Keith Clark 开发了一个JavaScript方案来使IE支持CSS3选择器.该脚本支持从IE5到IE8的各个版本. 首先,您需要下载DOMAssistant脚本和ie ...