diff --git a/externals/libsemantic b/externals/libsemantic index 3d83870..2e3f78f 160000 --- a/externals/libsemantic +++ b/externals/libsemantic @@ -1 +1 @@ -Subproject commit 3d838709bf5154897fce22bb3b9f46f1a39c3fd1 +Subproject commit 2e3f78f6937d5689b2a99cfa51e43b338520bbf4 diff --git a/mapproxy/src/mapproxy/generator/geodata-semantic-tiled.cpp b/mapproxy/src/mapproxy/generator/geodata-semantic-tiled.cpp index 36301f4..c79d3a2 100644 --- a/mapproxy/src/mapproxy/generator/geodata-semantic-tiled.cpp +++ b/mapproxy/src/mapproxy/generator/geodata-semantic-tiled.cpp @@ -50,6 +50,7 @@ #include "../support/tileindex.hpp" #include "../support/revision.hpp" #include "../support/geo.hpp" +#include "../support/position.hpp" #include "geodata-semantic-tiled.hpp" #include "factory.hpp" @@ -106,8 +107,7 @@ GeodataSemanticTiled::GeodataSemanticTiled(const Params ¶ms) << "Missing configuration for vector format <" << definition_.format << ">."; } - - auto ds(geo::GeoDataset::open(dem_.dataset)); + geo::GeoDataset::open(dem_.dataset); if (styleUrl_.empty()) { styleUrl_ = "style.json"; @@ -142,6 +142,20 @@ void GeodataSemanticTiled::prepare_impl(Arsenal&) const auto &r(resource()); + { + semantic::GeoPackage gpkg(dataset_); + const auto extents(gpkg.extents()); + + auto position + (positionFromPoints + (referenceFrame(), gpkg.srs(), math::center(extents) + , [&](const auto &callback) { + for (const auto &p : math::vertices(extents)) { + callback(p); + } + })); + } + // try to open datasets geo::GeoDataset::open(dem_.dataset); geo::GeoDataset::open(dem_.dataset + ".min"); diff --git a/mapproxy/src/mapproxy/generator/geodata-semantic.cpp b/mapproxy/src/mapproxy/generator/geodata-semantic.cpp index b8770db..17fe498 100644 --- a/mapproxy/src/mapproxy/generator/geodata-semantic.cpp +++ b/mapproxy/src/mapproxy/generator/geodata-semantic.cpp @@ -51,6 +51,7 @@ #include "../support/revision.hpp" #include "../support/geo.hpp" +#include "../support/position.hpp" #include "geodata-semantic.hpp" #include "factory.hpp" @@ -248,32 +249,10 @@ void GeodataSemantic::prepare_impl(Arsenal&) auto fl(generateLayer(world, definition_.simplified)); if (const auto extents = fl.boundingBox()) { - // mesh center in navigation SRS - const auto c(vts::CsConvertor - (world.srs - , resource().referenceFrame->model.navigationSrs) - (math::center(*extents))); - - auto &pos(metadata_.position); - pos.type = vr::Position::Type::objective; - pos.heightMode = vr::Position::HeightMode::floating; - pos.position = c; - pos.position[2] = 0.0; // floating -> zero - pos.lookDown(); - pos.verticalFov = vr::Position::naturalFov(); - - // compute vertical extent by taking a "photo" of physical data from - // view's "camera" - const auto trafo(makePlaneTrafo(referenceFrame(), pos.position)); - math::Extents2 cameraExtents(math::InvalidExtents{}); - fl.for_each_vertex([&](const math::Point3d &p) - { - math::update(cameraExtents, math::transform(trafo, p)); - }); - - const auto cameraExtentsSize(math::size(cameraExtents)); - pos.verticalExtent = std::max(cameraExtentsSize.width - , cameraExtentsSize.height); + const auto center(math::center(*extents)); + metadata_.position = positionFromPoints + (referenceFrame(), world.srs, math::Point2(center(0), center(1)) + , [&](const auto &callback) { fl.for_each_vertex(callback); }); } // get physical srs diff --git a/mapproxy/src/mapproxy/support/position.hpp b/mapproxy/src/mapproxy/support/position.hpp new file mode 100644 index 0000000..3261093 --- /dev/null +++ b/mapproxy/src/mapproxy/support/position.hpp @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2017 Melown Technologies SE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef mapproxy_support_position_hpp_included_ +#define mapproxy_support_position_hpp_included_ + +#include "vts-libs/vts/csconvertor.hpp" + +#include "geo.hpp" + +/** Generate position looking at the scene center having all points in the + * extent. + * + * Data are generated by calling forEachVertex(callback) where callbacks has the + * following prototype: + * + * callback(const math::Point3d &p) + * + * \params rf reference frame + * \params srsDef source (data) SRS definition + * \params center scene center in srsDef + * \params pixel generator + * + + */ +template +vr::Position positionFromPoints(const vr::ReferenceFrame &rf + , const geo::SrsDefinition &srsDef + , const math::Point2 ¢er + , const ForEachVertex &forEachVertex); + +// inlines + +template +vr::Position positionFromPoints(const vr::ReferenceFrame &rf + , const geo::SrsDefinition &srsDef + , const math::Point2 ¢er + , const ForEachVertex &forEachVertex) +{ + // mesh center in navigation SRS + const auto c(vts::CsConvertor(srsDef, rf.model.navigationSrs)(center)); + + LOG(info4) << "c: " << c; + + vr::Position pos; + pos.type = vr::Position::Type::objective; + pos.heightMode = vr::Position::HeightMode::floating; + pos.position(0) = c(0); + pos.position(1) = c(1); + pos.position(2) = 0.0; // floating -> zero + pos.lookDown(); + pos.verticalFov = vr::Position::naturalFov(); + + // compute vertical extent by taking a "photo" of physical data from + // view's "camera" + const auto trafo(makePlaneTrafo(rf, c)); + const vts::CsConvertor cs(srsDef, rf.model.physicalSrs); + math::Extents2 cameraExtents(math::InvalidExtents{}); + + forEachVertex([&](const math::Point3d &p) + { + const auto pp(math::transform(trafo, cs(p))); + math::update(cameraExtents, pp(0), pp(1)); + }); + + const auto cameraExtentsSize(math::size(cameraExtents)); + pos.verticalExtent = std::max(cameraExtentsSize.width + , cameraExtentsSize.height); + return pos; +} + +#endif // mapproxy_support_position_hpp_included_