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



原文地址:https://www.cnblogs.com/phoenixdsg/p/6116199.html