Skip to content

Commit

Permalink
Implemenet set/getViewpoint for MapManipulator; add demos to rdemo; s…
Browse files Browse the repository at this point in the history
…ome minor API changes
  • Loading branch information
gwaldron committed Aug 14, 2023
1 parent ea9e407 commit 7b1c17b
Show file tree
Hide file tree
Showing 22 changed files with 328 additions and 354 deletions.
4 changes: 2 additions & 2 deletions src/apps/rdemo/Demo_Label.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ auto Demo_Label = [](Application& app)

if (ImGuiLTable::SliderFloat("Latitude", &vec.y, -85.0, 85.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), vec.x, vec.y, vec.z));
object->xform->setPosition(GeoPoint(pos.srs, vec.x, vec.y, vec.z));
}

if (ImGuiLTable::SliderFloat("Longitude", &vec.x, -180.0, 180.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), vec.x, vec.y, vec.z));
object->xform->setPosition(GeoPoint(pos.srs, vec.x, vec.y, vec.z));
}

ImGuiLTable::End();
Expand Down
6 changes: 3 additions & 3 deletions src/apps/rdemo/Demo_LineString.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ auto Demo_LineString_Relative = [](Application& app)

if (ImGuiLTable::SliderFloat("Latitude", &v.y, -85.0, 85.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), v.x, v.y, v.z));
object->xform->setPosition(GeoPoint(pos.srs, v.x, v.y, v.z));
}

if (ImGuiLTable::SliderFloat("Longitude", &v.x, -180.0, 180.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), v.x, v.y, v.z));
object->xform->setPosition(GeoPoint(pos.srs, v.x, v.y, v.z));
}

if (ImGuiLTable::SliderFloat("Altitude", &v.z, 0.0, 2500000.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), v.x, v.y, v.z));
object->xform->setPosition(GeoPoint(pos.srs, v.x, v.y, v.z));
}

ImGuiLTable::End();
Expand Down
90 changes: 89 additions & 1 deletion src/apps/rdemo/Demo_MapManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,98 @@
*/
#pragma once

#include <rocky/Viewpoint.h>
#include <rocky/SRS.h>
#include <rocky_vsg/MapManipulator.h>

#include "helpers.h"
using namespace ROCKY_NAMESPACE;

auto Demo_MapManipulator = [](Application& app)
{
ImGui::Text("Not yet implemented");
auto view = app.displayConfiguration.windows.begin()->second.front();
if (view)
{
auto manip = view->getObject<MapManipulator>("rocky.manip");
if (manip)
{
Viewpoint vp;
vp = manip->getViewpoint();

if (vp.valid())
{
ImGui::SeparatorText("Current viewpoint");
ImGuiLTable::Begin("Viewpoint");
if (vp.target)
{
ImGuiLTable::Text("ECEF X:", "%.1lf", vp.target->point.x);
ImGuiLTable::Text("ECEF Y:", "%.1lf", vp.target->point.z);
ImGuiLTable::Text("ECEF Z:", "%.1lf", vp.target->point.x);

GeoPoint LL;
if (vp.target->point.transform(vp.target->point.srs.geoSRS(), LL))
{
ImGuiLTable::Text("Longitude:", "%.3lf", LL.x);
ImGuiLTable::Text("Latitude:", "%.3lf", LL.y);
//ImGuiLTable::Text("Altitude HAE", "%.1lf", LL.z);
}
}
ImGuiLTable::Text("Heading:", "%.1lf", (double)vp.heading.value());
ImGuiLTable::Text("Pitch:", "%.1lf", (double)vp.pitch.value());
ImGuiLTable::Text("Range:", "%.1lf", (double)vp.range.value());
ImGuiLTable::End();
}

ImGui::SeparatorText("Fly to");
static float duration_s = 2.0f;

Viewpoint vp1;
vp1.name = "Washington";
vp1.heading = 0.0;
vp1.pitch = -45.0;
vp1.range = 250000.0;
vp1.target->point = GeoPoint{ SRS::WGS84, -77.0, 38.9, 0.0 };

if (ImGui::Button(vp1.name->c_str()))
{
manip->setViewpoint(vp1, std::chrono::duration<float>(duration_s));
}

Viewpoint vp2;
vp2.name = "Barcelona";
vp2.heading = -56.0;
vp2.pitch = -25.0;
vp2.range = 25000.0;
vp2.target->point = GeoPoint{ SRS::WGS84, 2.16, 41.384, 0.0 };

ImGui::SameLine();
if (ImGui::Button(vp2.name->c_str()))
{
manip->setViewpoint(vp2, std::chrono::duration<float>(duration_s));
}

Viewpoint vp3;
vp3.name = "Perth";
vp3.heading = 0.0;
vp3.pitch = -67;
vp3.range = 30000.0;
vp3.target->point = GeoPoint{ SRS::WGS84, 115.8, -32, 0.0 };

ImGui::SameLine();
if (ImGui::Button(vp3.name->c_str()))
{
manip->setViewpoint(vp3, std::chrono::duration<float>(duration_s));
}

ImGui::SameLine();
if (ImGui::Button("Home"))
{
manip->home();
}

ImGuiLTable::Begin("fly to settings");
ImGuiLTable::SliderFloat("Duration (s)", &duration_s, 0.0f, 10.0f, "%.1f");
ImGuiLTable::End();
}
}
};
6 changes: 3 additions & 3 deletions src/apps/rdemo/Demo_Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ auto Demo_Mesh_Relative = [](Application& app)

if (ImGuiLTable::SliderFloat("Latitude", &vec.y, -85.0, 85.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), vec.x, vec.y, vec.z));
object->xform->setPosition(GeoPoint(pos.srs, vec.x, vec.y, vec.z));
}

if (ImGuiLTable::SliderFloat("Longitude", &vec.x, -180.0, 180.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), vec.x, vec.y, vec.z));
object->xform->setPosition(GeoPoint(pos.srs, vec.x, vec.y, vec.z));
}

if (ImGuiLTable::SliderFloat("Altitude", &vec.z, 0.0, 2500000.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), vec.x, vec.y, vec.z));
object->xform->setPosition(GeoPoint(pos.srs, vec.x, vec.y, vec.z));
}

ImGuiLTable::End();
Expand Down
6 changes: 3 additions & 3 deletions src/apps/rdemo/Demo_Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ auto Demo_Model = [](Application& app)

if (ImGuiLTable::SliderFloat("Latitude", &v.y, -85.0, 85.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), v.x, v.y, v.z));
object->xform->setPosition(GeoPoint(pos.srs, v.x, v.y, v.z));
}

if (ImGuiLTable::SliderFloat("Longitude", &v.x, -180.0, 180.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), v.x, v.y, v.z));
object->xform->setPosition(GeoPoint(pos.srs, v.x, v.y, v.z));
}

if (ImGuiLTable::SliderFloat("Altitude", &v.z, 0.0, 2500000.0, "%.1f"))
{
object->xform->setPosition(GeoPoint(pos.srs(), v.x, v.y, v.z));
object->xform->setPosition(GeoPoint(pos.srs, v.x, v.y, v.z));
}

ImGuiLTable::End();
Expand Down
17 changes: 11 additions & 6 deletions src/apps/rdemo/rdemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ void setup_demos(rocky::Application& app)
Demo{ "RTT", Demo_RTT }
);

demos.emplace_back(
Demo{ "Manipulator", Demo_MapManipulator }
);

demos.emplace_back(
Demo{ "Stats", Demo_Stats });
demos.emplace_back(
Expand Down Expand Up @@ -158,6 +162,13 @@ int main(int argc, char** argv)
if (layer->status().failed())
return layerError(layer);

// add an elevation layer to the map
auto elev = rocky::TMSElevationLayer::create();
elev->setURI("https://readymap.org/readymap/tiles/1.0.0/116/");
app.map()->layers().add(elev);
if (elev->status().failed())
return layerError(elev);

#if 0 // test multi-layer compositing
auto layer2 = rocky::TMSImageLayer::create();
layer2->setName("Hawaii inset");
Expand Down Expand Up @@ -186,12 +197,6 @@ int main(int argc, char** argv)
app.map()->layers().add(layer5);
if (layer5->status().failed())
return layerError(layer5);

auto elev = rocky::TMSElevationLayer::create();
elev->setURI("https://readymap.org/readymap/tiles/1.0.0/116/");
app.map()->layers().add(elev);
if (elev->status().failed())
return layerError(elev);
#endif
#endif

Expand Down
56 changes: 0 additions & 56 deletions src/rocky/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,62 +117,6 @@ Geometry::contains(double x, double y) const
}
}

#if 0
Geometry::const_iterator::const_iterator(const Geometry& geom)
{
_stack.push(&geom);
fetch();
}

bool
Geometry::const_iterator::hasMore() const
{
return _next != nullptr;
}

const Geometry&
Geometry::const_iterator::next()
{
auto n = _next;
fetch();
return *n;
}

void
Geometry::const_iterator::fetch()
{
_next = nullptr;

if (_stack.size() == 0)
return;

const Geometry* current = _stack.top();
_stack.pop();

bool is_multi =
current->type == Geometry::Type::MultiLineString ||
current->type == Geometry::Type::MultiPoints ||
current->type == Geometry::Type::MultiPolygon;

if (is_multi && _traverse_multi)
{
for (auto& part : current->parts)
_stack.push(&part);
fetch();
}
else
{
_next = current;

if (current->type == Type::Polygon && _traverse_polygon_holes)
{
for (auto& ring : current->parts)
_stack.push(&ring);
}
}
}
#endif

bool
Feature::FieldNameComparator::operator()(const std::string& L, const std::string& R) const
{
Expand Down
13 changes: 10 additions & 3 deletions src/rocky/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,30 @@ namespace ROCKY_NAMESPACE
GeoExtent extent;
};


/**
* Interface/base class for factories for Feature objects.
*/
class ROCKY_EXPORT FeatureSource : public rocky::Inherit<Object, FeatureSource>
{
public:
//! Iterator that returns features
class iterator
{
public:
virtual bool hasMore() const = 0;
virtual const Feature& next() = 0;
};

//! Creates a feature iterator
virtual std::shared_ptr<iterator> iterate(IOOptions& io) = 0;
};


#ifdef GDAL_FOUND

/**
* Reads Feature objects from various sources using the GDAL OGR library.
*/
class ROCKY_EXPORT OGRFeatureSource : public rocky::Inherit<FeatureSource, OGRFeatureSource>
{
public:
Expand All @@ -255,13 +262,11 @@ namespace ROCKY_NAMESPACE
optional<std::string> ogrDriver;
std::string layerName;
bool writable = false;
//Profile profile;

private:
void* _dsHandle;
void* _layerHandle;
std::thread::id _dsHandleThreadId;
//Geometry::Type _geometryType;
FeatureProfile _featureProfile;
std::string _source;

Expand Down Expand Up @@ -297,11 +302,13 @@ namespace ROCKY_NAMESPACE
type(in_type),
points(begin, end)
{
//nop
}
template<class VEC3_CONTAINER>
Geometry::Geometry(Type in_type, const VEC3_CONTAINER& container) :
type(in_type),
points(container.begin(), container.end())
{
//nop
}
}
2 changes: 1 addition & 1 deletion src/rocky/GeoCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace ROCKY_NAMESPACE
void setRadius( double value ) { _radius = value; }

/** SRS of the center point */
const SRS& srs() const { return _center.srs(); }
const SRS& srs() const { return _center.srs; }

/** equality test */
bool operator == ( const GeoCircle& rhs ) const;
Expand Down
2 changes: 1 addition & 1 deletion src/rocky/GeoExtent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ GeoExtent::contains(double x, double y, const SRS& xy_srs) const
bool
GeoExtent::contains(const GeoPoint& rhs) const
{
return contains(rhs.x, rhs.y, rhs.srs());
return contains(rhs.x, rhs.y, rhs.srs);
}

bool
Expand Down
2 changes: 1 addition & 1 deletion src/rocky/GeoImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ GeoImage::read(glm::fvec4& output, const GeoPoint& p) const
}

// transform if necessary
if (!p.srs().isHorizEquivalentTo(srs()))
if (!p.srs.isHorizEquivalentTo(srs()))
{
GeoPoint c;
return p.transform(srs(), c) && read(output, c);
Expand Down
Loading

0 comments on commit 7b1c17b

Please sign in to comment.