GeoGraticle.cxx 2.44 KB
Newer Older
Bill Lorensen's avatar
Bill Lorensen committed
1
#include <vtkActor.h>
2
#include <vtkGeoGraticule.h>
Bill Lorensen's avatar
Bill Lorensen committed
3
4
#include <vtkGeoProjection.h>
#include <vtkGeoTransform.h>
5
6
#include <vtkNew.h>
#include <vtkNamedColors.h>
Bill Lorensen's avatar
Bill Lorensen committed
7
8
9
10
11
12
13
14
15
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkTransformFilter.h>
#include <vtkXMLPolyDataReader.h>

int main( int argc, char* argv[] )
{
16
  vtkNew<vtkNamedColors> colors;
Bill Lorensen's avatar
Bill Lorensen committed
17
18
19
20
21

  int latLevel = 2;
  int lngLevel = 2;
  const char* pname = "rouss";

22
23
24
25
26
27
28
29
30
31
32
  vtkNew<vtkGeoGraticule> geoGraticle;
  vtkNew<vtkGeoTransform> transformProjection;
  vtkNew<vtkGeoProjection> destinationProjection;
  vtkNew<vtkGeoProjection> sourceProjection;
  vtkNew<vtkTransformFilter> transformGraticle;
  vtkNew<vtkXMLPolyDataReader> reader;
  vtkNew<vtkTransformFilter> transformReader;
  vtkNew<vtkPolyDataMapper> graticleMapper;
  vtkNew<vtkPolyDataMapper> readerMapper;
  vtkNew<vtkActor> graticleActor;
  vtkNew<vtkActor> readerActor;
Bill Lorensen's avatar
Bill Lorensen committed
33

Bill Lorensen's avatar
Bill Lorensen committed
34
35
36
37
38
  geoGraticle->SetGeometryType( vtkGeoGraticule::POLYLINES );
  geoGraticle->SetLatitudeLevel( latLevel );
  geoGraticle->SetLongitudeLevel( lngLevel );
  geoGraticle->SetLongitudeBounds( -180, 180 );
  geoGraticle->SetLatitudeBounds( -90, 90 );
Bill Lorensen's avatar
Bill Lorensen committed
39

Bill Lorensen's avatar
Bill Lorensen committed
40
41
42
43
44
45
46
47
48
  // destinationProjection defaults to latlong.
  destinationProjection->SetName( pname );
  destinationProjection->SetCentralMeridian( 0. );
  transformProjection->SetSourceProjection( sourceProjection );
  transformProjection->SetDestinationProjection( destinationProjection );
  transformGraticle->SetInputConnection( geoGraticle->GetOutputPort() );
  transformGraticle->SetTransform( transformProjection );
  graticleMapper->SetInputConnection( transformGraticle->GetOutputPort() );
  graticleActor->SetMapper( graticleMapper );
Bill Lorensen's avatar
Bill Lorensen committed
49

Bill Lorensen's avatar
Bill Lorensen committed
50
51
52
53
54
  reader->SetFileName(argv[1]);
  transformReader->SetTransform( transformProjection );
  transformReader->SetInputConnection( reader->GetOutputPort() );
  readerMapper->SetInputConnection( transformReader->GetOutputPort() );
  readerActor->SetMapper( readerMapper );
Bill Lorensen's avatar
Bill Lorensen committed
55

56
57
58
  vtkNew<vtkRenderWindow> renderWindow;
  vtkNew<vtkRenderer> renderer;
  vtkNew<vtkRenderWindowInteractor> interactor;
Bill Lorensen's avatar
Bill Lorensen committed
59
60
61
62
63
  renderWindow->SetInteractor( interactor );
  renderWindow->AddRenderer( renderer );
  renderWindow->SetSize(640, 480);
  renderer->SetBackground(colors->GetColor3d("BurlyWood").GetData());

Bill Lorensen's avatar
Bill Lorensen committed
64
65
  renderer->AddActor( readerActor );
  renderer->AddActor( graticleActor );
Bill Lorensen's avatar
Bill Lorensen committed
66
67

  renderWindow->Render();
68

Bill Lorensen's avatar
Bill Lorensen committed
69
  interactor->Initialize();
Bill Lorensen's avatar
Bill Lorensen committed
70
  interactor->Start();
71

Bill Lorensen's avatar
Bill Lorensen committed
72
  return EXIT_SUCCESS;
73
}