Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
using feature layers from semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavblazek committed Jul 10, 2019
1 parent f53a097 commit 66823b8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 142 deletions.
2 changes: 1 addition & 1 deletion externals/libsemantic
Submodule libsemantic updated from fe561a to 3d8387
78 changes: 2 additions & 76 deletions mapproxy/src/mapproxy/generator/geodata-semantic-tiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@

#include "math/transform.hpp"

#include "geo/featurelayers.hpp"
#include "geometry/meshop.hpp"

#include "jsoncpp/as.hpp"
#include "jsoncpp/io.hpp"

#include "semantic/io.hpp"
#include "semantic/mesh.hpp"
#include "semantic/gpkg.hpp"
#include "semantic/featurelayers.hpp"

#include "vts-libs/storage/fstreams.hpp"
#include "vts-libs/registry/json.hpp"
Expand Down Expand Up @@ -139,77 +136,6 @@ GeodataSemanticTiled::GeodataSemanticTiled(const Params &params)
LOG(info1) << "Generator for <" << id() << "> not ready.";
}

namespace {

class LayerBuilder {
public:
/** TODO:
* * Add clipping
* * Add destination SRS
*/
LayerBuilder(const semantic::World &world, int lod = 2)
: world_(world), fid_()
, materials_(semantic::materials())
{
semantic::mesh(world, semantic::MeshConfig()
, [this](auto&&... args) {
this->mesh(std::forward<decltype(args)>(args)...);
}
, lod);
}

geo::FeatureLayers featureLayers() {
geo::FeatureLayers fl;
for (auto &item : layers_) {
fl.layers.emplace_back(std::move(item.second));
}
return fl;
}

private:
using Layer = geo::FeatureLayers::Layer;
using LayerMap = std::map<semantic::Class, Layer>;
using Features = geo::FeatureLayers::Features;

template <typename Entity>
void mesh(const Entity &entity, const geometry::Mesh &mesh)
{
auto &l(layer(entity.cls));

for (const auto &sm : geometry::splitById(mesh)) {
// TODO: get more properties from the source
Features::Properties props;
props["material"] = materials_[sm.faces.front().imageId];

// add surface
auto &s(l.features.addSurface(++fid_, entity.id, props));
s.vertices = sm.vertices;
for (const auto &face : sm.faces) {
s.surface.emplace_back(face.a, face.b, face.c);
}
}
}

Layer& layer(semantic::Class cls) {
auto flayers(layers_.find(cls));
if (flayers != layers_.end()) { return flayers->second; }

const auto name(boost::lexical_cast<std::string>(cls));
return layers_.emplace
(std::piecewise_construct
, std::forward_as_tuple(cls)
, std::forward_as_tuple(name, world_.srs, true))
.first->second;
}

const semantic::World &world_;
LayerMap layers_;
Features::Fid fid_;
std::vector<std::string> materials_;
};

} // namespace

void GeodataSemanticTiled::prepare_impl(Arsenal&)
{
LOG(info2) << "Preparing <" << id() << ">.";
Expand Down Expand Up @@ -477,7 +403,7 @@ class SemanticJob : public WorkRequest {
auto world(ds.world(query));

// TODO: add meshconfig
auto fl(LayerBuilder(world, lod_).featureLayers());
auto fl(semantic::featureLayers(world, {}, lod_));
fl.transform(outputSrs_, outputAdjustVertical_);

{
Expand Down
67 changes: 2 additions & 65 deletions mapproxy/src/mapproxy/generator/geodata-semantic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@

#include "math/transform.hpp"

#include "geo/featurelayers.hpp"
#include "geometry/meshop.hpp"

#include "jsoncpp/as.hpp"
#include "jsoncpp/io.hpp"

#include "semantic/io.hpp"
#include "semantic/mesh.hpp"
#include "semantic/featurelayers.hpp"

#include "vts-libs/storage/fstreams.hpp"
#include "vts-libs/registry/json.hpp"
Expand Down Expand Up @@ -224,69 +224,6 @@ geo::FeatureLayers mesh2fl(const geometry::Mesh::list meshes
return fl;
}

class LayerBuilder {
public:
LayerBuilder(const semantic::World &world)
: world_(world), fid_()
, materials_(semantic::materials())
{
semantic::mesh(world, semantic::MeshConfig()
, [this](auto&&... args) {
this->mesh(std::forward<decltype(args)>(args)...);
}
, 2);
}

geo::FeatureLayers featureLayers() {
geo::FeatureLayers fl;
for (auto &item : layers_) {
fl.layers.emplace_back(std::move(item.second));
}
return fl;
}

private:
using Layer = geo::FeatureLayers::Layer;
using LayerMap = std::map<semantic::Class, Layer>;
using Features = geo::FeatureLayers::Features;

template <typename Entity>
void mesh(const Entity &entity, const geometry::Mesh &mesh)
{
auto &l(layer(entity.cls));

for (const auto &sm : geometry::splitById(mesh)) {
// TODO: get more properties from the source
Features::Properties props;
props["material"] = materials_[sm.faces.front().imageId];

// add surface
auto &s(l.features.addSurface(++fid_, entity.id, props));
s.vertices = sm.vertices;
for (const auto &face : sm.faces) {
s.surface.emplace_back(face.a, face.b, face.c);
}
}
}

Layer& layer(semantic::Class cls) {
auto flayers(layers_.find(cls));
if (flayers != layers_.end()) { return flayers->second; }

const auto name(boost::lexical_cast<std::string>(cls));
return layers_.emplace
(std::piecewise_construct
, std::forward_as_tuple(cls)
, std::forward_as_tuple(name, world_.srs, true))
.first->second;
}

const semantic::World &world_;
LayerMap layers_;
Features::Fid fid_;
std::vector<std::string> materials_;
};

geo::FeatureLayers generateLayer(const semantic::World &world, bool simplified)
{
if (simplified) {
Expand All @@ -297,7 +234,7 @@ geo::FeatureLayers generateLayer(const semantic::World &world, bool simplified)
, semantic::materials(), world.srs, true);
}

return LayerBuilder(world).featureLayers();
return semantic::featureLayers(world, {});
}

} // namespace
Expand Down

0 comments on commit 66823b8

Please sign in to comment.