#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include
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 "vtkPolyVertex.h"
#include "vtkInteractorStyleTrackballCamera.h"
void myShow(vtkSmartPointeraGrid);
int main()
{
//几何数据
vtkSmartPointerpoints=vtkSmartPointer ::New();
// points->SetNumberOfPoints(5);//此行可有可无
points->InsertPoint(0,0,0,0);
points->InsertPoint(1,0.5,0.5,0);
points->InsertPoint(2,-0.3,-0.2,0);
points->InsertPoint(3,0.8,-0.5,0);
points->InsertPoint(4,1,0.5,0.3);
//拓扑数据
vtkSmartPointerpolyVertex=vtkSmartPointer ::New();
polyVertex->GetPointIds()->SetNumberOfIds(5);//必须设置Id个数,否则可以编译,不能运行
polyVertex->GetPointIds()->SetId(0,0);//第一个参数是几何point的ID号,第2个参数是拓扑中的Id号
polyVertex->GetPointIds()->SetId(1,1);
polyVertex->GetPointIds()->SetId(2,2);
polyVertex->GetPointIds()->SetId(3,3);
polyVertex->GetPointIds()->SetId(4,4);
//属性数据
vtkSmartPointerpointsScalars=vtkSmartPointer ::New();
pointsScalars->SetNumberOfTuples(5);//此行可有可无
pointsScalars->InsertValue(0,0);//第1个参数是points点的Id,第2个参数是该点的属性值
pointsScalars->InsertValue(1,0);//第1个参数是points点的Id,第2个参数是该点的属性值
pointsScalars->InsertValue(2,0);//第1个参数是points点的Id,第2个参数是该点的属性值
pointsScalars->InsertValue(3,0);//第1个参数是points点的Id,第2个参数是该点的属性值
pointsScalars->InsertValue(4,0);//第1个参数是points点的Id,第2个参数是该点的属性值
//将以上三部分数据组合成一个结构vtkUnstructureGrid
vtkSmartPointeraGrid=vtkSmartPointer ::New();
aGrid->Allocate(1,1);
aGrid->SetPoints(points);
aGrid->GetPointData()->SetScalars(pointsScalars);
aGrid->InsertNextCell(polyVertex->GetCellType(),polyVertex->GetPointIds());
//在窗口中显示多个Vertex
myShow(aGrid);
return 0;
}
void myShow(vtkSmartPointeraGrid)
{
//设置映射器
vtkSmartPointeraMapper=vtkSmartPointer ::New();
aMapper->SetInputData(aGrid);
aMapper->ScalarVisibilityOn();
vtkSmartPointeranActor=vtkSmartPointer ::New();
anActor->SetMapper(aMapper);
anActor->GetProperty()->SetRepresentationToPoints();
anActor->GetProperty()->SetDiffuseColor(1,0,0);
anActor->GetProperty()->SetPointSize(10);
//创建显示窗口
vtkSmartPointerren1=vtkSmartPointer ::New();
vtkSmartPointerrenWin=vtkSmartPointer ::New();
ren1->AddActor(anActor);
renWin->AddRenderer(ren1);
vtkSmartPointeriren=vtkSmartPointer ::New();
vtkSmartPointerstyle=vtkSmartPointer ::New();
iren->SetInteractorStyle(style);
iren->SetRenderWindow(renWin);
renWin->SetSize(700,700);
ren1->ResetCamera();
renWin->Render();
iren->Start();
}