Skip to content

Commit 3174665

Browse files
committed
add support for the max visible range to the simple pager
1 parent 411a064 commit 3174665

File tree

6 files changed

+66
-6
lines changed

6 files changed

+66
-6
lines changed

src/osgEarth/ImGui/ImGui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,16 @@ namespace ImGuiLTable
403403
return ImGui::ColorEdit4(label, col, flags);
404404
}
405405

406+
static void PlotLines(const char* label, float(*getter)(void*, int), void* data, int values_count, int values_offset, const char* overlay = nullptr,
407+
float scale_min = FLT_MAX, float scale_max = FLT_MAX)
408+
{
409+
ImGui::TableNextColumn();
410+
ImGui::Text(label);
411+
ImGui::TableNextColumn();
412+
ImGui::SetNextItemWidth(-1);
413+
ImGui::PlotLines("", getter, data, values_count, values_offset, overlay, scale_min, scale_max);
414+
}
415+
406416
static void End()
407417
{
408418
ImGui::EndTable();

src/osgEarth/NodeUtils

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,30 @@ namespace osgEarth { namespace Util
192192
std::vector<T*> _results;
193193
};
194194

195+
template<typename T, typename FUNC>
196+
struct NodeFunctorVisitor : public osg::NodeVisitor
197+
{
198+
NodeFunctorVisitor(FUNC& func) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _func(func) { }
199+
200+
void apply(osg::Node& node) override
201+
{
202+
T* result = dynamic_cast<T*>( &node );
203+
if ( result )
204+
_func( result );
205+
traverse(node);
206+
}
207+
208+
FUNC _func;
209+
};
210+
211+
template<typename T, typename FUNC>
212+
inline void forEachNodeOfType(osg::Node* root, FUNC& functor)
213+
{
214+
NodeFunctorVisitor<T, FUNC> visitor(functor);
215+
if (root)
216+
root->accept( visitor );
217+
}
218+
195219
/**
196220
* Searchs the scene graph downward starting at [node] and returns the first node found
197221
* that matches the template parameter type.

src/osgEarth/SimplePager

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ namespace osgEarth { namespace Util
5959
float getRangeFactor() const { return _rangeFactor; }
6060
void setRangeFactor(float value) { _rangeFactor = value; }
6161

62+
float getMaxRange() const { return _maxRange; }
63+
void setMaxRange(float value);
64+
6265
float getPriorityScale() const { return _priorityScale; }
6366
void setPriorityScale(float value) { _priorityScale = value; }
6467

@@ -120,6 +123,7 @@ namespace osgEarth { namespace Util
120123

121124
bool _additive;
122125
double _rangeFactor;
126+
float _maxRange = FLT_MAX;
123127
unsigned int _minLevel;
124128
unsigned int _maxLevel;
125129
osg::ref_ptr<const Profile> _profile;

src/osgEarth/SimplePager.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <osgEarth/PagedNode>
77
#include <osgEarth/ElevationLayer>
88
#include <osgEarth/ElevationRanges>
9+
#include <osgEarth/NodeUtils>
910
#include <osgDB/Registry>
1011
#include <osgDB/FileNameUtils>
1112
#include <osg/ShapeDrawable>
@@ -52,6 +53,16 @@ bool SimplePager::getEnableCancelation() const
5253
return _canCancel;
5354
}
5455

56+
void SimplePager::setMaxRange(float value)
57+
{
58+
_maxRange = value;
59+
60+
forEachNodeOfType<PagedNode2>(this, [&](PagedNode2* node)
61+
{
62+
node->setMaxRange(value);
63+
});
64+
}
65+
5566
void SimplePager::setDone()
5667
{
5768
_done = true;
@@ -232,11 +243,13 @@ SimplePager::createPagedNode(const TileKey& key, ProgressCallback* progress)
232243
return result;
233244
}
234245
);
246+
235247
loadRange = (float)(tileRadius * _rangeFactor);
248+
236249
pagedNode->setRefinePolicy(_additive ? REFINE_ADD : REFINE_REPLACE);
237250
}
238251

239-
pagedNode->setMaxRange(loadRange);
252+
pagedNode->setMaxRange(std::min(loadRange, _maxRange));
240253

241254
//OE_INFO << "PagedNode2: key="<<key.str()<<" hasChildren=" << hasChildren << ", range=" << loadRange << std::endl;
242255

src/osgEarth/VisibleLayer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#include "VisibleLayer"
2020
#include "VirtualProgram"
2121
#include "Utils"
22+
#include "NodeUtils"
2223
#include "ShaderLoader"
24+
#include "SimplePager"
2325

2426
#include <osg/BlendFunc>
2527
#include <osgUtil/RenderBin>
@@ -442,7 +444,14 @@ VisibleLayer::setMaxVisibleRange( float maxVisibleRange )
442444
(float)options().minVisibleRange().get(),
443445
(float)options().maxVisibleRange().get(),
444446
(float)options().attenuationRange().get()));
445-
fireCallback( &VisibleLayerCallback::onVisibleRangeChanged );
447+
448+
forEachNodeOfType<SimplePager>(getNode(),
449+
[&](SimplePager* node) {
450+
node->setMaxRange(maxVisibleRange);
451+
}
452+
);
453+
454+
fireCallback(&VisibleLayerCallback::onVisibleRangeChanged);
446455
}
447456

448457
float

src/osgEarth/XYZModelLayer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void XYZModelLayer::setProfile(const Profile* profile)
113113
void
114114
XYZModelLayer::init()
115115
{
116-
TiledModelLayer::init();
116+
super::init();
117117

118118
_root = new osg::Group();
119119

@@ -151,7 +151,7 @@ XYZModelLayer::getNode() const
151151
Status
152152
XYZModelLayer::openImplementation()
153153
{
154-
Status parent = TiledModelLayer::openImplementation();
154+
Status parent = super::openImplementation();
155155
if (parent.isError())
156156
return parent;
157157

@@ -171,7 +171,7 @@ void
171171
XYZModelLayer::addedToMap(const Map* map)
172172
{
173173
OE_TEST << LC << "addedToMap" << std::endl;
174-
TiledModelLayer::addedToMap(map);
174+
super::addedToMap(map);
175175

176176
_map = map;
177177

@@ -184,7 +184,7 @@ XYZModelLayer::addedToMap(const Map* map)
184184
void
185185
XYZModelLayer::removedFromMap(const Map* map)
186186
{
187-
TiledModelLayer::removedFromMap(map);
187+
super::removedFromMap(map);
188188

189189
if (_root.valid())
190190
{

0 commit comments

Comments
 (0)