VTK/Examples/Cxx/Geovis/GeoAssignCoordinates

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Revision as of 14:08, 18 January 2012 by Lorensen (talk | contribs) (VTK6 migration)
Jump to navigationJump to search
VTK Examples Baseline Geovis TestGeoAssignCoordinates.png

GeoAssignCoordinates.cxx

#include <vtkSmartPointer.h>
#include <vtkDataSetAttributes.h>
#include <vtkGeoAssignCoordinates.h>
#include <vtkDoubleArray.h>
#include <vtkGraphMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkMutableDirectedGraph.h>

int main(int, char* [])
{

  vtkSmartPointer<vtkMutableDirectedGraph> g =
    vtkSmartPointer<vtkMutableDirectedGraph>::New();

  vtkSmartPointer<vtkDoubleArray> latitude =
    vtkSmartPointer<vtkDoubleArray>::New();
  latitude->SetName("latitude");
  
  vtkSmartPointer<vtkDoubleArray> longitude =
    vtkSmartPointer<vtkDoubleArray>::New();
  longitude->SetName("longitude");
  
  for(int lat = -90; lat <= 90; lat += 10)
    {
    for(int lon = -180; lon <= 180; lon += 20)
      {
      g->AddVertex();
      latitude->InsertNextValue(lat);
      longitude->InsertNextValue(lon);
      }
    }
    
  g->GetVertexData()->AddArray(latitude);
  g->GetVertexData()->AddArray(longitude);

  vtkSmartPointer<vtkGeoAssignCoordinates> assign =
    vtkSmartPointer<vtkGeoAssignCoordinates>::New();
#if VTK_MAJOR_VERSION <= 5
  assign->SetInput(g);
#else
  assign->SetInputData(g);
#endif
  assign->SetLatitudeArrayName("latitude");
  assign->SetLongitudeArrayName("longitude");
  assign->SetGlobeRadius(1.0);
  assign->Update();

  vtkSmartPointer<vtkGraphMapper> mapper =
    vtkSmartPointer<vtkGraphMapper>::New();
  mapper->SetInputConnection(assign->GetOutputPort());
  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  
  vtkSmartPointer<vtkRenderer> ren =
    vtkSmartPointer<vtkRenderer>::New();
  ren->AddActor(actor);
  
  vtkSmartPointer<vtkRenderWindowInteractor> iren =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
    
  vtkSmartPointer<vtkRenderWindow> win =
    vtkSmartPointer<vtkRenderWindow>::New();
  win->AddRenderer(ren);
  win->SetInteractor(iren);
  ren->ResetCamera();

  iren->Initialize();
  iren->Start();

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(GeoAssignCoordinates)

FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(GeoAssignCoordinates GeoAssignCoordinates.cxx)
TARGET_LINK_LIBRARIES(GeoAssignCoordinates vtkHybrid vtkGeovis)