VTK初学一,a Mesh from vtkImageData

#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 <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkMath.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageData.h>
#include <vtkGreedyTerrainDecimation.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractionWidgetsModule.h>
void myShow(vtkGreedyTerrainDecimation* anInput)
{
vtkSmartPointer<vtkPolyDataMapper> aMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
aMapper->SetInputConnection(anInput->GetOutputPort());
aMapper->ScalarVisibilityOn();
vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
anActor->SetMapper(aMapper);
anActor->GetProperty()->SetInterpolationToFlat();
anActor->GetProperty()->EdgeVisibilityOn();
anActor->GetProperty()->SetEdgeColor(1,0,0);
vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
ren1->AddActor(anActor);
ren1->ResetCamera();
ren1->SetBackground(1,1,1);
renWin->AddRenderer(ren1);
renWin->SetSize(512,512);
vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
iren->Start();
}
int main()
{
vtkSmartPointer<vtkImageData> image=vtkSmartPointer<vtkImageData>::New();
image->SetDimensions(20,20,1);//头两个参数分别是沿x、y方向的取样点数,第三个参数是z方向的取样点数
image->AllocateScalars(VTK_UNSIGNED_CHAR,1);
int dims[3];
image->GetDimensions(dims);
for(double i=0;i<dims[0];i++)
{
for(double j=0;j<dims[1];j++)
{
unsigned char* pixel=static_cast<unsigned char*>(image->GetScalarPointer(i,j,0));
pixel[0]=vtkMath::Round(vtkMath::Random(0,5));//在(i,j)位置上的“高”
}
}
vtkSmartPointer<vtkGreedyTerrainDecimation>decimation=vtkSmartPointer<vtkGreedyTerrainDecimation>::New();
decimation->SetInputData(image);
decimation->Update();
//可视化
myShow(decimation);
return 0;
}
VTK初学一,a Mesh from vtkImageData的更多相关文章
- VTK初学一,a Mesh from vtkImageData—球冠
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...
- VTK初学一,比较常见的错误2
我的开发环境: 系统:win8.1 QT:5.4.2MinGW版 VTK:6.3 按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR: ERROR: In D:\VTK6 ...
- VTK初学一,c_Line_CellArray线段的CellArray绘制
VTK窗口默认坐标方向: #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE ...
- VTK初学一,a_Vertex图形点的绘制
系统:Win8.1 QT版本:2.4.2,Mingw VTK版本:6.3 2. main.cpp #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #incl ...
- VTK初学一,动画加AVI录制终于做出来了
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRe ...
- VTK初学一,vtkDelaunay2D创建球冠曲面
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...
- VTK初学一,比较常见的错误1
错误原因: 通常是在文件头部没有初始化 #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> V ...
- VTK初学一,Pro文件的配置
1. pro文件的配置 TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG += qt QT += core gui greate ...
- VTK初学一,b_PolyVertex_CellArray多个点的绘制
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...
随机推荐
- struts2 CVE-2013-2251 S2-016 action、redirect code injection remote command execution
catalog . Description . Effected Scope . Exploit Analysis . Principle Of Vulnerability . Patch Fix 1 ...
- Circular Queue Implementation Principle
目录 . 引言 . 环形队列的实现原理 . 环形队列编程实现 . 环形队列的内核实现 1. 引言 环形队列是在实际编程极为有用的数据结构,它有如下特点 . 它是一个首尾相连的FIFO(First In ...
- STM32的12864液晶串行控制
发现12864只有主函数中不断刷新才有数据显示,,原因是写指令和写数据中没有加延时,加一个延时就好了.
- 巧妙的重载魔术方法__call()
工作半年了,感觉这半年学到的东西比大学四年学到的还要多,主要原因是心静下来了,目标也明确了,不会去整天的和游戏纠缠在一起了.大学时候其实也意识到了玩游戏会影响自己的正常学习和工作的,但是一直控制不了自 ...
- django 快速搭建blog
如果本文看不懂的,去看的我视频吧!http://www.testpub.cn/ ------------------------------------------- Django 自称是“最适合开发 ...
- python从Microsoft Excel文件中导入数据
excel中后缀为csv和xls,二者区别如下:1.xls 文件就是Microsoft excel电子表格的文件格式.2.csv是最通用的一种文件格式,它可以非常容易地被导入各种PC表格及数据库中. ...
- spring--学习之IOC DI
2.1.1 IoC是什么 Ioc-Inversion of Control,即"控制反转",不是什么技术,而是一种设计思想.在Java开发中,Ioc意味着将你设计好的对象交给容器 ...
- Excel_replace
有时候我们需要对单元格中的数据需要一些精确的处理,比如将部分以70开的工号升为706,这时简单的查找替换就不能满足我的需求,因为这样会替换掉工号中末尾或者中间位的70,造成工号的错误. 如何实现这种精 ...
- 获取<img src="sdf.jpg" Big="sf.jpg">中的big的值
原代码: <img src="sdf.jpg" Big="sf.jpg" onclick="getsrc($(this).attr(" ...
- jquery左边滚动,完毕后跳转回来
代码如下 function in_scroll(){ $liW = ; $num = $(".in-cy li").size(); $ulW = $liW*$num; $(&quo ...