zoukankan      html  css  js  c++  java
  • 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;
    }
    
    
    
    
  • 相关阅读:
    CSS3 之 RGBa 可透明颜色
    编写高效的CSS选择器
    CSS3中轻松实现渐变效果
    Sublime Text:学习资源篇
    [1]移动端页面调试之“weinre大法”
    解决win10 phptoshop #fff纯白不是这样的白 显示器高级的问题
    Jquery过滤选择器,选择前几个元素,后几个元素,内容过滤选择器等
    如何理解Box-sizing模型?
    使用CSS3制作酷炫防苹果复选框 自行测试!
    mysql 将时间戳直接转换成日期时间
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6120493.html
Copyright © 2011-2022 走看看