Difference between revisions of "VTK/Examples/Cxx/Geovis/GeoAssignCoordinates"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(Missing vtkVersion.h)
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Geovis/GeoAssignCoordinates GeoAssignCoordinates] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExa...")
 
Line 1: Line 1:
<div class="floatright">[[File:VTK_Examples_Baseline_Geovis_TestGeoAssignCoordinates.png]]</div>
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Geovis/GeoAssignCoordinates GeoAssignCoordinates] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
==GeoAssignCoordinates.cxx==
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkVersion.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;
 
}
 
</source>
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 

Latest revision as of 15:43, 16 August 2019

See GeoAssignCoordinates on the new VTKExamples website.