Created
October 26, 2021 16:26
-
-
Save gwaldron/1206958dd4580cb28ea8c2f2c402407d to your computer and use it in GitHub Desktop.
TimeGUI example (with WMS-T)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** PASTE ME OVER osgearth_imgui.cpp **/ | |
#include <osgEarth/ImGui/ImGui> | |
#include <osgEarth/EarthManipulator> | |
#include <osgEarth/ImageLayer> | |
#include <osg/ImageSequence> | |
#include <osgDB/ReadFile> | |
#include <osgViewer/Viewer> | |
using namespace osgEarth; | |
using namespace osgEarth::Util; | |
struct App | |
{ | |
DateTime _time; | |
}; | |
struct TimeGUI : public GUI::BaseGUI | |
{ | |
App& _app; | |
float _time; | |
DateTime _start, _end; | |
bool _initialized; | |
osg::observer_ptr<MapNode> _mapNode; | |
TimeGUI(App& app) : BaseGUI("Time Control"), | |
_app(app), _time(0.0f), _start(UINT_MAX), _end(0), _initialized(false) { } | |
void draw(osg::RenderInfo& ri) override | |
{ | |
if (!isVisible()) return; | |
if (!findNode(_mapNode, ri)) return; | |
if (!_initialized) | |
{ | |
LayerVector layers; | |
_mapNode->getMap()->getLayers(layers); | |
for (auto& layer : layers) { | |
DateTimeExtent ex = layer->getDateTimeExtent(); | |
if (ex.valid()) { | |
if (ex.getStart() < _start) | |
_start = ex.getStart(); | |
if (ex.getEnd() > _end) | |
_end = ex.getEnd(); | |
} | |
} | |
_initialized = true; | |
} | |
ImGui::Begin(name(), visible()); | |
if (_end > _start) | |
{ | |
if (ImGui::SliderFloat("Offset (s)", &_time, 0.0f, (float)(_end.asTimeStamp()-_start.asTimeStamp()))) | |
{ | |
_app._time = DateTime(_time+_start.asTimeStamp()); | |
} | |
ImGui::Text("%s", DateTime(_time + _start.asTimeStamp()).asISO8601().c_str()); | |
} | |
else | |
{ | |
ImGui::Text("No time extents found in map."); | |
} | |
ImGui::End(); | |
} | |
}; | |
int | |
main(int argc, char** argv) | |
{ | |
osgEarth::initialize(); | |
App app; | |
osg::ArgumentParser arguments(&argc, argv); | |
osgViewer::Viewer viewer(arguments); | |
viewer.setThreadingModel(viewer.SingleThreaded); | |
viewer.setCameraManipulator(new EarthManipulator(arguments)); | |
viewer.setRealizeOperation(new GUI::ApplicationGUI::RealizeOperation); | |
auto gui = new GUI::ApplicationGUI(arguments, true); | |
gui->add(new TimeGUI(app), true); | |
viewer.getEventHandlers().push_front(gui); | |
auto node = MapNodeHelper().loadWithoutControls(arguments, &viewer); | |
viewer.setSceneData(node); | |
viewer.realize(); | |
while (!viewer.done()) { | |
viewer.frame(app._time.asTimeStamp()); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment