forked from Kitware/VTK
/
vtkGeoGlobeSource.cxx
136 lines (117 loc) · 4.24 KB
/
vtkGeoGlobeSource.cxx
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGeoGlobeSource.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 "vtkGeoGlobeSource.h"
#include "vtkGeoTerrainNode.h"
#include "vtkGlobeSource.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
vtkStandardNewMacro(vtkGeoGlobeSource);
//----------------------------------------------------------------------------
vtkGeoGlobeSource::vtkGeoGlobeSource()
{
}
//----------------------------------------------------------------------------
vtkGeoGlobeSource::~vtkGeoGlobeSource()
{
}
//----------------------------------------------------------------------------
bool vtkGeoGlobeSource::FetchRoot(vtkGeoTreeNode* r)
{
vtkGeoTerrainNode* root = 0;
if (!(root = vtkGeoTerrainNode::SafeDownCast(r)))
{
vtkErrorMacro(<< "Can only fetch surface nodes from this source.");
}
vtkSmartPointer<vtkGlobeSource> source =
vtkSmartPointer<vtkGlobeSource>::New();
source->SetStartLatitude(-90.0);
source->SetEndLatitude(90.0);
source->SetStartLongitude(-180.0);
source->SetEndLongitude(180.0);
source->SetLatitudeResolution(20);
source->SetLongitudeResolution(20);
source->SetCurtainHeight(2000);
source->Update();
root->GetModel()->ShallowCopy(source->GetOutput());
root->SetLatitudeRange(-90, 90);
root->SetLongitudeRange(-180, 180);
root->UpdateBoundingSphere();
// Make sure bounds are up to date so we don't have threading issues
// when we hand this off to the main thread.
root->GetModel()->ComputeBounds();
return true;
}
//----------------------------------------------------------------------------
bool vtkGeoGlobeSource::FetchChild(vtkGeoTreeNode* p, int index, vtkGeoTreeNode* c)
{
vtkGeoTerrainNode* parent = 0;
if (!(parent = vtkGeoTerrainNode::SafeDownCast(p)))
{
vtkErrorMacro(<< "Can only fetch surface nodes from this source.");
}
vtkGeoTerrainNode* child = 0;
if (!(child = vtkGeoTerrainNode::SafeDownCast(c)))
{
vtkErrorMacro(<< "Can only fetch surface nodes from this source.");
}
double lonRange[2];
double latRange[2];
double center[2];
parent->GetLongitudeRange(lonRange);
parent->GetLatitudeRange(latRange);
center[0] = (lonRange[1] + lonRange[0])/2.0;
center[1] = (latRange[1] + latRange[0])/2.0;
int level = parent->GetLevel() + 1;
child->SetLevel(level);
if (index / 2)
{
child->SetLatitudeRange(center[1], latRange[1]);
}
else
{
child->SetLatitudeRange(latRange[0], center[1]);
}
if (index % 2)
{
child->SetLongitudeRange(center[0], lonRange[1]);
}
else
{
child->SetLongitudeRange(lonRange[0], center[0]);
}
int id = 0;
id = parent->GetId() | (index << (2*level - 2));
child->SetId(id);
vtkSmartPointer<vtkGlobeSource> source =
vtkSmartPointer<vtkGlobeSource>::New();
source->SetStartLatitude(child->GetLatitudeRange()[0]);
source->SetEndLatitude(child->GetLatitudeRange()[1]);
source->SetStartLongitude(child->GetLongitudeRange()[0]);
source->SetEndLongitude(child->GetLongitudeRange()[1]);
source->SetCurtainHeight(2000);
source->Update();
child->GetModel()->ShallowCopy(source->GetOutput());
child->UpdateBoundingSphere();
// Make sure bounds are up to date so we don't have threading issues
// when we hand this off to the main thread.
child->GetModel()->ComputeBounds();
return true;
}
//----------------------------------------------------------------------------
void vtkGeoGlobeSource::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}