• VTK初学一,a_Vertex图形点的绘制


    系统:Win8.1

    QT版本:2.4.2,Mingw

    VTK版本:6.3


    2. main.cpp
    #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 "vtkWin32OpenGLRenderWindow.h"
    #include "vtkRenderWindow.h"
    #include "vtkRenderWindowInteractor.h"
    #include "vtkRenderer.h"
    #include "vtkPoints.h"
    #include "vtkWin32RenderWindowInteractor.h"
    #include "vtkProperty.h"
    #include "vtkFloatArray.h"
    #include "vtkPolyData.h"
    #include "vtkDataSetMapper.h"
    #include "vtkActor2D.h"
    #include "vtkContourFilter.h"
    #include "vtkContourValues.h"
    #include "vtkUnstructuredGrid.h"
    #include "vtkPointData.h"
    #include "vtkVertex.h"
    #include "vtkInteractorStyleTrackballCamera.h"
    
    
    void myShow(vtkSmartPointer<vtkUnstructuredGrid> aGrid);
    
    
    int  main()
    {
    
    
        // create a scene with one of each cell type
    //Vertex
        vtkPoints *vertexPoints=vtkPoints::New();
        vertexPoints-> SetNumberOfPoints (1);
        vertexPoints-> InsertPoint( 0, 0, 0, 0);
        vtkFloatArray *vertexScalars=vtkFloatArray::New();
        vertexScalars-> SetNumberOfTuples (1);
        vertexScalars-> InsertValue (0, 1);
        vtkVertex *aVertex=vtkVertex::New();
        aVertex-> GetPointIds()-> SetId (0, 0);
        vtkUnstructuredGrid *aVertexGrid=vtkUnstructuredGrid::New();
        aVertexGrid-> Allocate (1, 1);
        aVertexGrid-> InsertNextCell (aVertex-> GetCellType(), aVertex ->GetPointIds());
        aVertexGrid ->SetPoints (vertexPoints);
        aVertexGrid-> GetPointData() ->SetScalars (vertexScalars);
    
    
        myShow(aVertexGrid);
    
    
        return 0;
    }
    void myShow(vtkSmartPointer<vtkUnstructuredGrid> aGrid)
    {
        //设置映射器
        vtkSmartPointer<vtkDataSetMapper> aMapper=vtkSmartPointer<vtkDataSetMapper>::New();
        aMapper->SetInputData(aGrid);
        aMapper->ScalarVisibilityOn();
    
    
        vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
        anActor->SetMapper(aMapper);
        anActor->GetProperty()->SetRepresentationToPoints();
    //    anActor->GetProperty()->SetRepresentationToWireframe();
        anActor->GetProperty()->SetDiffuseColor(1,0,0);
    //    anActor->GetProperty()->SetLineWidth(5);
    //    anActor->GetProperty()->SetEdgeColor(1,0,0);
        anActor->GetProperty()->SetPointSize(10);
     //创建显示窗口
        vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
        vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
        ren1->AddActor(anActor);
        renWin->AddRenderer(ren1);
    
    
        vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
        vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
        iren->SetInteractorStyle(style);
        iren->SetRenderWindow(renWin);
    
    
        renWin->SetSize(700,700);
        ren1->ResetCamera();
        renWin->Render();
        iren->Start();
    }

    
    
    
    
  • 相关阅读:
    [JavaScript权威指南]Introduce to JavaScript
    IT项目开发的75条管理守则
    .net调用存储过程
    应聘项目经理需要学的
    DropDownList静态数据绑定
    数据库的查询优化技术 (摘)
    UNION运算符
    网站项目策划书
    .net验证码
    小问题,关于Page.Request.QueryString["pro"]
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6116199.html
Copyright © 2020-2023  润新知