zoukankan      html  css  js  c++  java
  • 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();
    }

    
    
    
    
  • 相关阅读:
    置换加密算法
    堆和优先队列的应用
    定时发送邮件小程序
    Hibernate的缓存
    Spring中使用JDBC
    Spring AOP(创建切面)
    处理不可中断阻塞
    SQL语句实例说明
    spring_声明式事务
    Flex_includeIn属性的作用
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6116199.html
Copyright © 2011-2022 走看看