标签:
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPoints.h>
#include <vtkLine.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
int main()
{
vtkSmartPointer<vtkPolyData> linesPolyData =
vtkSmartPointer<vtkPolyData>::New();
double origin[3] = { 0.0, 0.0, 0.0 };
double p0[3] = { 1.0, 0.0, 0.0 };
double p1[3] = { 0.0, 1.0, 0.0 };
vtkSmartPointer<vtkPoints> pts =
vtkSmartPointer<vtkPoints>::New();
pts->InsertNextPoint(origin);
pts->InsertNextPoint(p0);
pts->InsertNextPoint(p1);
linesPolyData->SetPoints(pts);
vtkSmartPointer<vtkLine> line0 =
vtkSmartPointer<vtkLine>::New();
line0->GetPointIds()->SetId(0, 0); // 第二个0表示pts中的origin点
line0->GetPointIds()->SetId(1, 1); //第二个1表示pts中的p0点
vtkSmartPointer<vtkLine> line1 =
vtkSmartPointer<vtkLine>::New();
line1->GetPointIds()->SetId(0, 0);
line1->GetPointIds()->SetId(1, 2);
vtkSmartPointer<vtkCellArray> lines =
vtkSmartPointer<vtkCellArray>::New();
lines->InsertNextCell(line0);
lines->InsertNextCell(line1);
linesPolyData->SetLines(lines);
unsigned char red[3] = { 255, 0, 0 };
unsigned char green[3] = { 0, 255, 0 };
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->InsertNextTupleValue(red);
colors->InsertNextTupleValue(green);
linesPolyData->GetCellData()->SetScalars(colors);
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(linesPolyData);
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
vtkSmartPointer<vtkRenderWindow> window =
vtkSmartPointer<vtkRenderWindow>::New();
window->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(window);
window->Render();
interactor->Start();
return 0;
}
标签:
原文地址:http://blog.csdn.net/u012176176/article/details/51344301