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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值