1.显示一个地球各大洲板块的轮廓线
#include <vtkEarthSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractorStyleTrackball.h>
int main(int, char *[])
{
vtkSmartPointer<vtkEarthSource> earthSource = vtkSmartPointer<vtkEarthSource>::New();//生成一个地球图层资源
earthSource->SetRadius(500);//设置地球半径大小
earthSource->Update();//更新资源
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(earthSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->SetBackground(1,1,1);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
renderWindowInteractor->SetInteractorStyle( style );//设置交互器风格
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
2. 地图指北针图例
#include <vtkEarthSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractorStyleTrackball.h>
#include <vtkCompassWidget.h>
#include <vtkCompassRepresentation.h>
int main(int, char *[])
{
vtkSmartPointer<vtkEarthSource> earthSource = vtkSmartPointer<vtkEarthSource>::New();//生成一个地球图层资源
earthSource->SetRadius(500);//设置地球半径大小
earthSource->Update();//更新资源
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(earthSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->SetBackground(1,1,1);
vtkSmartPointer<vtkCompassRepresentation> compassRepresentation = vtkSmartPointer<vtkCompassRepresentation>::New();
vtkSmartPointer<vtkCompassWidget> compassWidget = vtkSmartPointer<vtkCompassWidget>::New();//创建指北针小装置
compassRepresentation->SetDistance(1000);//设置指北针上的距离数值
compassRepresentation->SetHeading(500);//设置指北针上的高程数值
compassRepresentation->SetTilt(1);//设置指北针上的title
compassWidget->SetInteractor(renderWindowInteractor);//与交互器相关联
compassWidget->SetRepresentation(compassRepresentation);//与指北针相关联
renderWindow->Render();
compassWidget->EnabledOn();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
renderWindowInteractor->SetInteractorStyle( style );//设置交互器风格
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}