FlightGear next
tileentry.cxx
Go to the documentation of this file.
1// tileentry.cxx -- routines to handle a scenery tile
2//
3// Written by Curtis Olson, started May 1998.
4//
5// Copyright (C) 1998 - 2001 Curtis L. Olson - http://www.flightgear.org/~curt
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License as
9// published by the Free Software Foundation; either version 2 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21#ifdef HAVE_CONFIG_H
22# include <config.h>
23#endif
24
25#include <simgear/compiler.h>
26
27#include <string>
28#include <sstream>
29#include <istream>
30
31#include <osg/LOD>
32
33#include <simgear/bucket/newbucket.hxx>
34#include <simgear/debug/logstream.hxx>
35#include <simgear/scene/tgdb/SGOceanTile.hxx>
36
37#include "tileentry.hxx"
38
39using std::string;
40
41// Base constructor
42TileEntry::TileEntry ( const SGBucket& b )
43 : tile_bucket( b ),
44 _node( new osg::LOD ),
45 _priority(-FLT_MAX),
46 _current_view(false),
47 _time_expired(-1.0)
48{
49 _create_orthophoto();
50
51 // Give a default LOD range so that traversals that traverse
52 // active children (like the groundcache lookup) will work before
53 // tile manager has had a chance to update this node.
54 _node->setRange(0, 0.0, 10000.0);
55}
56
60 _node( new osg::LOD ),
61 _priority(t._priority),
62 _current_view(t._current_view),
63 _time_expired(t._time_expired)
64{
65 _create_orthophoto();
66
67 _node->setName(tileFileName);
68 // Give a default LOD range so that traversals that traverse
69 // active children (like the groundcache lookup) will work before
70 // tile manager has had a chance to update this node.
71 _node->setRange(0, 0.0, 10000.0);
72}
73
74void TileEntry::_create_orthophoto() {
75 bool use_photoscenery = fgGetBool("/sim/rendering/photoscenery/enabled");
76 if (use_photoscenery) {
77 _orthophoto = simgear::Orthophoto::fromBucket(tile_bucket, globals->get_fg_scenery());
78 if (_orthophoto) {
79 simgear::OrthophotoManager::instance()->registerOrthophoto(tile_bucket.gen_index(), _orthophoto);
80 }
81 }
82}
83
84// Destructor
88
89// Update the ssg transform node for this tile so it can be
90// properly drawn relative to our (0,0,0) point
91void TileEntry::prep_ssg_node(float vis) {
92 if (!is_loaded())
93 return;
94 // visibility can change from frame to frame so we update the
95 // range selector cutoff's each time.
96 float bounding_radius = _node->getChild(0)->getBound().radius();
97 _node->setRange( 0, 0, vis + bounding_radius );
98}
99
100void
101TileEntry::addToSceneGraph(osg::Group *terrain_branch)
102{
103 terrain_branch->addChild( _node.get() );
104
105 SG_LOG( SG_TERRAIN, SG_DEBUG,
106 "connected a tile into scene graph. _node = "
107 << _node.get() );
108 SG_LOG( SG_TERRAIN, SG_DEBUG, "num parents now = "
109 << _node->getNumParents() );
110}
111
112
113void
115{
116 if (! is_loaded()) {
117 SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a not-fully loaded tile!" );
118 } else {
119 SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a fully loaded tile! _node = " << _node.get() );
120 }
121
122 // Only remove Ocean Tiles. All other tiles are removed by the DatabasePager
123 if ((_node->getNumChildren() > 0) &&
124 (_node->getChild(0)->getName() == "Ocean") &&
125 (_node->getNumParents() > 0 ) ) {
126 // find the first parent (should only be one)
127 osg::Group *parent = _node->getParent( 0 ) ;
128 if( parent ) {
129
130 parent->removeChild( _node.get() );
131 }
132 }
133}
134
135// Constructor - STG Variant
136STGTileEntry::STGTileEntry ( const SGBucket& b ) : TileEntry(b)
137{
138 tileFileName = b.gen_index_str() + ".stg";
139 _node->setName(tileFileName);
140}
141
142// Destructor - STG Variant
146
147// Constructor - VPB version
148VPBTileEntry::VPBTileEntry ( const SGBucket& b, osg::ref_ptr<simgear::SGReaderWriterOptions> options ) : TileEntry(b)
149{
150 tileFileName = "vpb/" + b.gen_vpb_base() + ".osgb";
151 std::string zipFileName = "vpb/" + b.gen_base_path() + ".zip";
152
153 bool found = false;
154 auto filePathList = options->getDatabasePathList();
155 for (auto path : filePathList) {
156 SGPath p(path, tileFileName);
157 if (p.exists()) {
158 found = true;
159 break;
160 }
161
162 SGPath archive(path, zipFileName);
163 if (archive.exists()) {
164 found = true;
165 break;
166 }
167
168 }
169
170 if (found) {
171 // File exists - set it up for loading later
172 _node->setName(tileFileName);
173
174 // Give a default LOD range so that traversals that traverse
175 // active children (like the groundcache lookup) will work before
176 // tile manager has had a chance to update this node.
177 _node->setRange(0, 0.0, 160000.0);
178 } else {
179 // File doesn't exist, so add a 1x1 degree Ocean tile.
180 double lat = floor(b.get_center_lat()) + 0.5;
181 double lon = floor(b.get_center_lon()) + 0.5;
182 SG_LOG( SG_TERRAIN, SG_DEBUG, "Generating Ocean Tile for " << lat << ", " << lon);
183
184 // Standard for WS2.0 is 5 points per bucket (~30km), or 8km spacing.
185 // 1 degree latitude and 1 degree of longitude at the equator is 111km, 15 points
186 // are equivalent resolution.
187 osg::Node* oceanTile = SGOceanTile(lat, lon, 1.0, 1.0, options->getMaterialLib(), 15, 15);
188 _node->addChild(oceanTile, 0, 250000.0);
189 }
190}
191
192// Destructor - VPB Variant
196
#define p(x)
bool options(int, char **)
Definition JSBSim.cpp:568
STGTileEntry(const SGBucket &b)
std::string tileFileName
Definition tileentry.hxx:58
void prep_ssg_node(float vis)
Definition tileentry.cxx:91
void addToSceneGraph(osg::Group *terrain_branch)
Add terrain mesh and ground lighting to scene graph.
bool is_loaded() const
Return true if the tile entry is loaded, otherwise return false indicating that the loading thread is...
void removeFromSceneGraph()
disconnect terrain mesh and ground lighting nodes from scene graph for this tile.
TileEntry(const SGBucket &b)
Definition tileentry.cxx:42
virtual ~TileEntry()=0
Definition tileentry.cxx:85
SGBucket tile_bucket
Definition tileentry.hxx:57
osg::ref_ptr< osg::LOD > _node
Definition tileentry.hxx:62
VPBTileEntry(const SGBucket &b, osg::ref_ptr< simgear::SGReaderWriterOptions > options)
FGGlobals * globals
Definition globals.cxx:142
Definition AIBase.hxx:25
bool fgGetBool(char const *name, bool def)
Get a bool value for a property.
Definition proptest.cpp:25