Skip to content

Commit

Permalink
Update the stream deduction system for mime types; update some icon i…
Browse files Browse the repository at this point in the history
…mages
  • Loading branch information
gwaldron committed Nov 1, 2024
1 parent a534e94 commit 93bfdd8
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 135 deletions.
4 changes: 2 additions & 2 deletions src/apps/rocky_demo/Demo_Geocoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ auto Demo_Geocoder = [](Application& app)
{
// Load an icon image
auto& io = app.io();
auto image = io.services.readImageFromURI("https://raw.githubusercontent.com/gwaldron/osgearth/master/data/placemark64.png", io);
auto image = io.services.readImageFromURI("https://readymap.org/readymap/filemanager/download/public/icons/placemark32.png", io);
if (image.status.failed())
{
status = image.status;
Expand Down Expand Up @@ -69,7 +69,7 @@ auto Demo_Geocoder = [](Application& app)
feature_view.styles.line->depth_offset = 9000.0f; //meters

app.entities.setVisible(entity, false);
app.entities.setVisible(feature_view.entity, false);
//app.entities.setVisible(feature_view.entity, false);

// Transform to place the entity:
auto& xform = app.entities.emplace<Transform>(entity);
Expand Down
2 changes: 1 addition & 1 deletion src/apps/rocky_demo/Demo_Icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ auto Demo_Icon = [](Application& app)
{
// Load an icon image
auto io = app.instance.io();
auto image = io.services.readImageFromURI("https://user-images.githubusercontent.com/326618/236923465-c85eb0c2-4d31-41a7-8ef1-29d34696e3cb.png", io);
auto image = io.services.readImageFromURI("https://readymap.org/readymap/filemanager/download/public/icons/BENDER.png", io);
if (image.status.failed())
{
status = image.status;
Expand Down
3 changes: 1 addition & 2 deletions src/apps/rocky_demo/Demo_Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ auto Demo_Simulation = [](Application& app)
{
// add an icon:
auto io = app.instance.io();
//auto image = io.services.readImageFromURI("https://github.com/gwaldron/osgearth/blob/master/data/airport.png?raw=true", io);
auto image = io.services.readImageFromURI("https://user-images.githubusercontent.com/326618/236923465-c85eb0c2-4d31-41a7-8ef1-29d34696e3cb.png", io);
auto image = io.services.readImageFromURI("https://readymap.org/readymap/filemanager/download/public/icons/airport.png", io);
status = image.status;
if (image.status.ok())
{
Expand Down
8 changes: 4 additions & 4 deletions src/apps/rocky_demo/rocky_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ std::vector<Demo> demos =
Demo{ "Polygon features", Demo_PolygonFeatures },
Demo{ "Line features", Demo_LineFeatures }
} },
Demo{ "Simulation", Demo_Simulation },
Demo{ "RTT", Demo_RTT },
Demo{ "Geocoding", Demo_Geocoder },
Demo{ "Camera", {},
{
Demo{ "Viewpoints", Demo_Viewpoints },
Demo{ "Tethering", Demo_Tethering }
} },
Demo{ "Rendering", Demo_Rendering },
Demo{ "Geocoding", Demo_Geocoder },
Demo{ "Environment", Demo_Environment },
Demo{ "RTT", Demo_RTT },
Demo{ "Simulation", Demo_Simulation },
Demo{ "Views", Demo_Views },
Demo{ "Environment", Demo_Environment },
Demo{ "Serialization", Demo_Serialization },
Demo{ "Stats", Demo_Stats },
Demo{ "About", Demo_About }
Expand Down
83 changes: 12 additions & 71 deletions src/rocky/vsg/ECS.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,70 +27,8 @@ namespace ROCKY_NAMESPACE
{
using time_point = std::chrono::steady_clock::time_point;

#if 0
/**
* Helper class to create double-buffered (or multi-buffered) components.
* https://skypjack.github.io/2019-02-25-entt-double-buffering/
*/
template<typename...Types>
class Buffering
{
using ident = entt::ident<Types...>;

template<typename Type, typename... Tail, typename... Other, typename Func>
void _run(entt::type_list<Other...>, entt::registry& registry, Func&& func) {
if (curr == ident::template type<Type>) {
registry.view<Type, Other...>().each(std::forward<Func>(func));
}
else {
if (sizeof...(Tail) == 0) {
assert(false);
}
else {
execute<Tail...>(entt::type_list<Other...>{}, registry, std::forward<Func>(func));
}
}
}

template<typename BaseType, typename Type, typename... Tail>
BaseType* _try_get(entt::registry& registry, entt::entity entity) const {
if (curr == ident::value<Type>) {
return registry.try_get<Type>(entity);
}
else {
if constexpr (sizeof...(Tail) == 0) {
assert(false);
return nullptr;
}
else {
return _try_get<BaseType, Tail...>(registry, entity);
}
}
}

public:

template<typename BaseType>
BaseType* try_get(entt::registry& registry, entt::entity entity) {
return _try_get<BaseType, Types...>(registry, entity);
}

template<typename... Other, typename Func>
void run(entt::registry& registry, Func&& func) {
_run<Types...>(entt::type_list<Other...>{}, registry, std::forward<Func>(func));
}

void next() {
curr = (curr + 1) % sizeof...(Types);
}

private:
std::size_t curr{};
};
#endif

/**
* Superclass for ECS components meant to be rendered.
* Superclass for ECS components meant to be revisioned and/or with an attach point.
*/
struct RevisionedComponent
{
Expand All @@ -105,7 +43,9 @@ namespace ROCKY_NAMESPACE
RevisionedComponent() = default;
};


/**
* Component representing an entity's visibility.
*/
struct Visibility
{
bool visible = true;
Expand Down Expand Up @@ -136,7 +76,10 @@ namespace ROCKY_NAMESPACE
Status status;

//! Initialize the ECS system (once at startup)
virtual void initializeSystem(Runtime& runtime) { }
virtual void initializeSystem(Runtime& runtime)
{
//nop
}

//! Update the ECS system (once per frame)
virtual void update(Runtime& runtime)
Expand All @@ -149,7 +92,10 @@ namespace ROCKY_NAMESPACE
registry(in_registry) { }

//! Override this to handle any components that need initial setup
virtual void updateComponents(Runtime& rutime) { }
virtual void updateComponents(Runtime& rutime)
{
//nop
}
};

/**
Expand Down Expand Up @@ -335,17 +281,12 @@ namespace ROCKY_NAMESPACE
void setVisible(entt::entity e, bool value)
{
get<ECS::Visibility>(e).visible = value;
//if (value)
// emplace_or_replace<Visible>(e);
//else
// remove<Visible>(e);
}

//! Whether an entity is visible
bool visible(entt::entity e)
{
return get<ECS::Visibility>(e).visible;
//return try_get<Visible>(e) != nullptr;
}
};
}
Expand Down
4 changes: 3 additions & 1 deletion src/rocky/vsg/GeoTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ GeoTransform::traverse(vsg::RecordTraversal& record) const
bool
GeoTransform::push(vsg::RecordTraversal& record, const vsg::dmat4& local_matrix) const
{
if (!position.valid())
return false;

auto* state = record.getState();

// fetch the view-local data:
Expand Down Expand Up @@ -84,7 +87,6 @@ GeoTransform::push(vsg::RecordTraversal& record, const vsg::dmat4& local_matrix)
// Frustum cull (by center point)
if (frustumCulling)
{
// frustum cull
vsg::dvec4 clip = view.mvp[3] / view.mvp[3][3];
const double t = 1.0;
if (clip.x < -t || clip.x > t || clip.y < -t || clip.y > t || clip.z < -t || clip.z > t)
Expand Down
80 changes: 44 additions & 36 deletions src/rocky/vsg/InstanceVSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,48 +355,56 @@ InstanceVSG::ctor(int& argc, char** argv)
// To read from a stream, we have to search all the VS readerwriters to
// find one that matches the 'extension' we want. We also have to put that
// extension in the options structure as a hint.
io().services.readImageFromStream = [options(runtime.readerWriterOptions)](
std::istream& location, std::string contentType, const rocky::IOOptions& io)
-> Result<shared_ptr<Image>>
{
if (contentType.empty())
{
contentType = deduceContentTypeFromStream(location);
}

if (contentType.empty())
io().services.readImageFromStream = [options(runtime.readerWriterOptions)](std::istream& location, std::string contentType, const rocky::IOOptions& io) -> Result<shared_ptr<Image>>
{
return Status(Status::ResourceUnavailable, "No content-type");
}
// try the mime-type mapping:
auto i = ext_for_mime_type.find(contentType);
if (i != ext_for_mime_type.end())
{
auto rw = findReaderWriter(i->second, options->readerWriters);
if (rw != nullptr)
{
auto local_options = vsg::Options::create(*options);
local_options->extensionHint = i->second;
auto result = rw->read_cast<vsg::Data>(location, local_options);
return util::makeImageFromVSG(result);
}
}

// try the mime-type mapping:
auto i = ext_for_mime_type.find(contentType);
if (i != ext_for_mime_type.end())
{
auto rw = findReaderWriter(i->second, options->readerWriters);
if (rw != nullptr)
// mime-type didn't work; try the content type directly as an extension
if (!contentType.empty())
{
auto local_options = vsg::Options::create(*options);
local_options->extensionHint = i->second;
auto result = rw->read_cast<vsg::Data>(location, local_options);
return util::makeImageFromVSG(result);
auto contentTypeAsExtension = contentType[0] != '.' ? ("." + contentType) : contentType;
auto rw = findReaderWriter(contentTypeAsExtension, options->readerWriters);
if (rw != nullptr)
{
auto local_options = vsg::Options::create(*options);
local_options->extensionHint = contentTypeAsExtension;
auto result = rw->read_cast<vsg::Data>(location, local_options);
return util::makeImageFromVSG(result);
}
}
}

// mime-type didn't work; try the content type directly as an extension
if (contentType[0] != '.')
contentType = "." + contentType;
auto rw = findReaderWriter(contentType, options->readerWriters);
if (rw != nullptr)
{
auto local_options = vsg::Options::create(*options);
local_options->extensionHint = contentType;
auto result = rw->read_cast<vsg::Data>(location, local_options);
return util::makeImageFromVSG(result);
}
// last resort, try checking the data itself
auto decudedContentType = deduceContentTypeFromStream(location);
if (!decudedContentType.empty())
{
auto i = ext_for_mime_type.find(decudedContentType);
if (i != ext_for_mime_type.end())
{
auto rw = findReaderWriter(i->second, options->readerWriters);
if (rw != nullptr)
{
auto local_options = vsg::Options::create(*options);
local_options->extensionHint = i->second;
auto result = rw->read_cast<vsg::Data>(location, local_options);
return util::makeImageFromVSG(result);
}
}
}

return Status(Status::ServiceUnavailable, "No image reader for \"" + contentType + "\"");
};
return Status(Status::ServiceUnavailable, "No image reader for \"" + contentType + "\"");
};

io().services.contentCache = std::make_shared<ContentCache>(128);

Expand Down
11 changes: 8 additions & 3 deletions src/rocky/vsg/Line.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace ROCKY_NAMESPACE
//! in the SRS of the referencePoint.
GeoPoint referencePoint;

//! Geometry
//! Geometry. Stored on the heap since it can change size.
using Part = std::vector<vsg::dvec3>;
std::vector<Part> parts;
std::unique_ptr<std::vector<Part>> parts;

//! Pushes a new sub-geometry along with its range of points. Each point
//! is expressed in normal VSG coordinates, UNLESS referencePoint is set,
Expand All @@ -64,7 +64,12 @@ namespace ROCKY_NAMESPACE
{
part.emplace_back(i->x, i->y, i->z);
}
parts.emplace_back(std::move(part));
parts->emplace_back(std::move(part));
}

Line()
{
parts = std::make_unique<std::vector<Part>>();
}
};
}
24 changes: 11 additions & 13 deletions src/rocky/vsg/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace ROCKY_NAMESPACE

Transform()
{
node = GeoTransform::create();
}

void setPosition(const GeoPoint& p)
Expand All @@ -45,37 +46,34 @@ namespace ROCKY_NAMESPACE

void dirty()
{
if (!node)
node = GeoTransform::create();

node->setPosition(position);
node->localTangentPlane = localTangentPlane;
}

//! Returns true if the push succeeded (and a pop will be required)
//! Applies a transformation and returns true if successful.
//! If this method retuns true, you must issue a correspond pop() later.
inline bool push(vsg::RecordTraversal& rt, const vsg::dmat4& m)
{
if (node)
if (parent)
{
return node->push(rt, m * localMatrix);
return parent->push(rt, m * localMatrix);
}
else if (parent)
else
{
return parent->push(rt, m * localMatrix);
return node->push(rt, m * localMatrix);
}
else return false;
}

//! Pops a transform applied if push() returned true.
inline void pop(vsg::RecordTraversal& rt)
{
if (node)
if (parent)
{
node->pop(rt);
parent->pop(rt);
}
else if (parent)
else
{
parent->pop(rt);
node->pop(rt);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/rocky/vsg/engine/LineSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ LineSystemNode::update(entt::entity entity, Runtime& runtime)

auto group = vsg::Group::create();
vsg::dvec3 temp;
for (auto& part : line.parts)
for (auto& part : *line.parts)
{
auto geom = LineGeometry::create();
for (auto& vert : part)
Expand All @@ -204,7 +204,7 @@ LineSystemNode::update(entt::entity entity, Runtime& runtime)
{
// no reference point -- push raw geometry
auto group = vsg::Group::create();
for (auto& part : line.parts)
for (auto& part : *line.parts)
{
auto geom = LineGeometry::create();
for (auto& vert : part)
Expand Down

0 comments on commit 93bfdd8

Please sign in to comment.