vtkGeoRandomGraphSource.cxx 2.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkGeoRandomGraphSource.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

#include "vtkGeoRandomGraphSource.h"

#include "vtkDataSetAttributes.h"
#include "vtkDoubleArray.h"
#include "vtkGraph.h"
#include "vtkInformation.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"

vtkStandardNewMacro(vtkGeoRandomGraphSource);

// ----------------------------------------------------------------------

Sankhesh Jhaveri's avatar
Sankhesh Jhaveri committed
35 36 37 38
vtkGeoRandomGraphSource::vtkGeoRandomGraphSource()
{
  VTK_LEGACY_BODY(vtkGeoRandomGraphSource::vtkGeoRandomGraphSource, "VTK 8.2");
}
39 40 41

// ----------------------------------------------------------------------

42
vtkGeoRandomGraphSource::~vtkGeoRandomGraphSource() = default;
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

// ----------------------------------------------------------------------

void vtkGeoRandomGraphSource::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

// ----------------------------------------------------------------------

int vtkGeoRandomGraphSource::RequestData(
  vtkInformation* info,
  vtkInformationVector** inputVector,
  vtkInformationVector* outputVector)
{
  vtkRandomGraphSource::RequestData(info, inputVector, outputVector);

  // Set random lat/long points into the output
  vtkGraph* output = vtkGraph::GetData(outputVector);
  vtkDoubleArray* latArr = vtkDoubleArray::New();
  vtkDoubleArray* lonArr = vtkDoubleArray::New();
  latArr->SetNumberOfTuples(output->GetNumberOfVertices());
  lonArr->SetNumberOfTuples(output->GetNumberOfVertices());
  latArr->SetName("latitude");
  lonArr->SetName("longitude");
  for (vtkIdType v = 0; v < output->GetNumberOfVertices(); ++v)
69
  {
70 71 72 73
    double lat = vtkMath::Random()*180.0 - 90.0;
    double lon = vtkMath::Random()*360.0 - 180.0;
    latArr->SetValue(v, lat);
    lonArr->SetValue(v, lon);
74
  }
75 76 77 78 79 80 81
  output->GetVertexData()->AddArray(latArr);
  output->GetVertexData()->AddArray(lonArr);
  latArr->Delete();
  lonArr->Delete();

  return 1;
}