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

Commit

Permalink
proper initial position computation
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavblazek committed Jul 10, 2019
1 parent 66823b8 commit 52152e8
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 29 deletions.
2 changes: 1 addition & 1 deletion externals/libsemantic
Submodule libsemantic updated from 3d8387 to 2e3f78
18 changes: 16 additions & 2 deletions mapproxy/src/mapproxy/generator/geodata-semantic-tiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -106,8 +107,7 @@ GeodataSemanticTiled::GeodataSemanticTiled(const Params &params)
<< "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";
Expand Down Expand Up @@ -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");
Expand Down
31 changes: 5 additions & 26 deletions mapproxy/src/mapproxy/generator/geodata-semantic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

#include "../support/revision.hpp"
#include "../support/geo.hpp"
#include "../support/position.hpp"

#include "geodata-semantic.hpp"
#include "factory.hpp"
Expand Down Expand Up @@ -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
Expand Down
95 changes: 95 additions & 0 deletions mapproxy/src/mapproxy/support/position.hpp
Original file line number Diff line number Diff line change
@@ -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 <typename ForEachVertex>
vr::Position positionFromPoints(const vr::ReferenceFrame &rf
, const geo::SrsDefinition &srsDef
, const math::Point2 &center
, const ForEachVertex &forEachVertex);

// inlines

template <typename ForEachVertex>
vr::Position positionFromPoints(const vr::ReferenceFrame &rf
, const geo::SrsDefinition &srsDef
, const math::Point2 &center
, 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_

0 comments on commit 52152e8

Please sign in to comment.