File: TestGPXReader.cxx

package info (click to toggle)
volview 3.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 25,204 kB
  • sloc: cpp: 132,585; ansic: 11,612; tcl: 236; sh: 64; makefile: 25; xml: 8
file content (108 lines) | stat: -rw-r--r-- 3,360 bytes parent folder | download
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
35
36
37
38
39
40
41
42
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*=========================================================================

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/VolViewCopyright.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.

=========================================================================*/
#include "vtkGPXReader.h"
#include "vtkXMLPolyDataWriter.h"
#include "vtkPolyDataWriter.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"

int main(int argc, char* argv[])
{
  if ( argc < 3 )
    {
    cout << "Usage: " << argv[0] << " <infile> <outfile>" << endl;
    return 1;
    }
  vtkGPXReader* reader = vtkGPXReader::New();
  vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New();
  //vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
  writer->SetDataModeToAscii();
  reader->SetFileName(argv[1]);
  int cc;
  for ( cc = 0; cc < reader->GetNumberOfOutputs(); ++ cc )
    {
    char buffer[1024];
    sprintf(buffer, "%s_%d.vtp", argv[2], cc);
    writer->SetInput(reader->GetOutput(cc));
    writer->SetFileName(buffer);
    writer->Write();
    }

  vtkPoints* wpts = reader->GetOutput(0)->GetPoints();
  vtkIdType ii;
  for ( ii = 0; ii < wpts->GetNumberOfPoints(); ++ ii )
    {
    double *pt = wpts->GetPoint(ii);
    cout << "Way Point: " << ii
     << " ["
     << reader->GetWayPointLongitude(ii) << ", "
     << reader->GetWayPointLatitude(ii) << ", "
     << reader->GetWayPointElevation(ii) << "] ("
     << pt[0] << ", "
     << pt[1] << ", "
     << pt[2] << ") t: "
     << reader->GetWayPointTime(ii)
     << " n: " << reader->GetWayPointName(ii)
     << " d: " << reader->GetWayPointDescription(ii)
     << " s: " << reader->GetWayPointSymbol(ii)
     << endl;
    }
  vtkPoints* pts = reader->GetOutput(1)->GetPoints();
  for ( ii = 0; ii < pts->GetNumberOfPoints(); ++ ii )
    {
    double *pt = pts->GetPoint(ii);
    cout << "Route Point: " << ii
     << " ["
     << reader->GetRoutePointLongitude(ii) << ", "
     << reader->GetRoutePointLatitude(ii) << ", "
     << reader->GetRoutePointElevation(ii) << "] ("
     << pt[0] << ", "
     << pt[1] << ", "
     << pt[2] << ") t: "
     << reader->GetRoutePointTime(ii)
     << " n: " << reader->GetRoutePointName(ii)
     << " d: " << reader->GetRoutePointDescription(ii)
     << " s: " << reader->GetRoutePointSymbol(ii)
     << endl;
    }
  pts = reader->GetOutput(2)->GetPoints();
  for ( ii = 0; ii < pts->GetNumberOfPoints(); ++ ii )
    {
    double *pt = pts->GetPoint(ii);
    
    cout << "Track Point: " << ii
     << " ["
     << reader->GetTrackPointLongitude(ii) << ", "
     << reader->GetTrackPointLatitude(ii) << ", "
     << reader->GetTrackPointElevation(ii) << "] ("
     << pt[0] << ", "
     << pt[1] << ", "
     << pt[2] << ") t: "
     << reader->GetTrackPointTime(ii);

    // Does not work
    vtkIdType wpid = reader->GetWayPointFromTrackPoint(ii);
    if ( wpid >= 0 )
      {
      cout
        << " n: " << reader->GetWayPointName(wpid)
        << " d: " << reader->GetWayPointDescription(wpid)
        << " s: " << reader->GetWayPointSymbol(wpid);
      }
    
    cout << endl;
    }

  reader->Delete();
  writer->Delete();
  return 0;
}