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

				
时间: 2024-11-08 22:37:59

VTK初学一,a Mesh from vtkImageData的相关文章

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 <vtkPolyD

VTK初学一,比较常见的错误2

我的开发环境: 系统:win8.1 QT:5.4.2MinGW版 VTK:6.3 按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR: ERROR: In D:\VTK6.3\VTK-src\Rendering\Core\vtkTextActor.cxx, line 110vtkTextActor (0509BA90): Failed getting the TextRenderer instance! 解决办法: 在头文件中加入VTK_MODULE_INIT(vt

VTK初学一,线段的CellArray绘制c_Line_CellArray

VTK窗口默认坐标方向: #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL) VTK_MODULE_INIT(vtkInteractionStyle) #endif #include <iostream> using namespace std; #include "vtkPolyDataMapper.h&quo

VTK初学一,比较常见的错误

  错误原因: 通常是在文件头部没有初始化 #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL) VTK_MODULE_INIT(vtkInteractionStyle) #endif

VTK初学一,vtkDelaunay2D创建球冠曲面

#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL) VTK_MODULE_INIT(vtkInteractionStyle) #endif #include <iostream> using namespace std; #include "vtkPolyDataMapper.h" #include &

VTK初学一,线段的绘制c_Line

#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL) VTK_MODULE_INIT(vtkInteractionStyle) #endif #include <iostream> using namespace std; #include "vtkPolyDataMapper.h" #include &

VTK计算网格模型上的最短路径

Dijkstra algorithm to compute the graph geodesic.Takes as input a polygonal mesh and performs a single source shortest path calculation. Dijkstra's algorithm is used. 用鼠标右键拾取平面网格上的点,观察输出路径: #!usrbinenv python import vtk def loadSTL(filenameSTL): read

第07章-体绘制(1)

[译者:这个系列教程是以Kitware公司出版的<VTK User's Guide -11th edition>一书作的中文翻译(出版时间2010年,ISBN: 978-1-930934-23-8),由于时间关系,我们不能保证每周都能更新本书内容,但尽量做到一周更新一篇到两篇内容.敬请期待^_^.欢迎转载,另请转载时注明本文出处,谢谢合作!同时,由于译者水平有限,出错之处在所难免,欢迎指出订正!] [本节对应原书中的第139页至第142页] 第7章体绘制 体绘制是一种三维空间中而非三维空间中的

AMROC可视化

备注 通过修改Filetype来改变输出数据的类型. .twikiToc li { list-style-image: url("http://www.vtf.website/asc/wiki/pub/TWiki/VTFSkin/i_arrow_down.gif") } .twikiWebIndicator { background-color: #FFFF66 } Skip to topic | Skip to bottom Jump: Software Description FS