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

Commit

Permalink
surface metadriver: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavblazek committed Nov 15, 2019
1 parent 1ea0f2a commit 899b250
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 11 deletions.
27 changes: 27 additions & 0 deletions mapproxy/src/mapproxy/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class Generator : boost::noncopyable {
*/
bool updatedSince(std::uint64_t timestamp) const;

/** Generic type for provider handling
*/
struct Provider { virtual ~Provider() {} };

protected:
Generator(const Params &params, const Properties &props = Properties());

Expand Down Expand Up @@ -265,6 +269,16 @@ class Generator : boost::noncopyable {
*/
bool changeEnforced() const { return changeEnforced_; }

/** Returns generators provider machinery. Returns null if provider of given
* type is not available.
*/
template <typename ProviderType>
ProviderType* getProvider() const;

/** Sets new provider. Value is stolen.
*/
void setProvider(std::unique_ptr<Provider> &&provider);

private:
virtual void prepare_impl(Arsenal &arsenal) = 0;
virtual vts::MapConfig mapConfig_impl(ResourceRoot root) const = 0;
Expand All @@ -284,6 +298,7 @@ class Generator : boost::noncopyable {
std::atomic<std::uint64_t> readySince_;
DemRegistry::pointer demRegistry_;
Generator::pointer replace_;
std::unique_ptr<Provider> provider_;
};

/** Set of dataset generators.
Expand Down Expand Up @@ -396,4 +411,16 @@ Generator::otherGenerator(Resource::Generator::Type generatorType
return generatorFinder_->findGenerator(generatorType, resourceId);
}

template <typename ProviderType>
ProviderType* Generator::getProvider() const
{
if (!provider_) { return nullptr; }
return dynamic_cast<ProviderType>(provider_.get());
}

inline void Generator::setProvider(std::unique_ptr<Provider> &&provider)
{
provider_ = std::move(provider);
}

#endif // mapproxy_generator_hpp_included_
114 changes: 114 additions & 0 deletions mapproxy/src/mapproxy/generator/interfaces.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* 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_generator_interface_hpp_included_
#define mapproxy_generator_interface_hpp_included_

#include <boost/optional.hpp>

#include "vts-libs/registry/extensions.hpp"
#include "vts-libs/vts/tileset/properties.hpp"
#include "vts-libs/vts/mesh.hpp"

#include "../heightfunction.hpp"
#include "../support/mesh.hpp"
#include "../support/mmapped/tilesetindex.hpp"
#include "../generator.hpp"
#include "../definition.hpp"

namespace vts = vtslibs::vts;
namespace vre = vtslibs::registry::extensions;

namespace generator {

class VtsTilesetProvider {
public:
virtual ~VtsTilesetProvider() {}

/** Generates mesh and sends it to the output.
*/
Generator::Task generateMesh(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode
= vts::SubMesh::external) const;

/** Alias for surface file generation.
*/
Generator::Task generateFile(const FileInfo &fileInfo, Sink sink) const;

/** Returns path to VTS file if supported.
*/
boost::optional<boost::filesystem::path> path(vts::File file) const;

private:
virtual Generator::Task
generateMesh_impl(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode)
const = 0;

virtual Generator::Task
generateFile_impl(const FileInfo &fileInfo, Sink sink) const = 0;

virtual boost::optional<boost::filesystem::path> path_impl(vts::File file)
const = 0;
};

// inlines

/** Generates mesh and sends it to the output.
*/
Generator::Task
VtsTilesetProvider::generateMesh(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode
= vts::SubMesh::external) const
{
return generateMesh_impl(tileId, sink, fileInfo, arsenal, textureMode);
}

Generator::Task
VtsTilesetProvider::generateFile(const FileInfo &fileInfo, Sink sink)
const
{
return generatorFile_impl(fileInfo, sink);
}

boost::optional<boost::filesystem::path>
VtsTilesetProvider::path(vts::File file) const
{
return path_impl(file);
}

} // namespace generator

#endif // mapproxy_generator_interface_hpp_included_
113 changes: 113 additions & 0 deletions mapproxy/src/mapproxy/generator/providers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* 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_generator_providers_hpp_included_
#define mapproxy_generator_providers_hpp_included_

#include <boost/optional.hpp>

#include "vts-libs/registry/extensions.hpp"
#include "vts-libs/vts/tileset/properties.hpp"
#include "vts-libs/vts/mesh.hpp"

#include "../heightfunction.hpp"
#include "../support/mesh.hpp"
#include "../support/mmapped/tilesetindex.hpp"
#include "../generator.hpp"
#include "../definition.hpp"

namespace vts = vtslibs::vts;
namespace vre = vtslibs::registry::extensions;

namespace generator {

class VtsTilesetProvider {
public:
virtual ~VtsTilesetProvider() {}

/** Generates mesh and sends it to the output.
*/
Generator::Task generateMesh(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode
= vts::SubMesh::external) const;

/** Alias for surface file generation.
*/
Generator::Task generateFile(const FileInfo &fileInfo, Sink sink) const;

/** Returns path to VTS file if supported.
*/
boost::optional<boost::filesystem::path> path(vts::File file) const;

private:
virtual Generator::Task
generateMesh_impl(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode)
const = 0;

virtual Generator::Task
generateFile_impl(const FileInfo &fileInfo, Sink sink) const = 0;

virtual boost::optional<boost::filesystem::path> path_impl(vts::File file)
const = 0;
};

// inlines

/** Generates mesh and sends it to the output.
*/
Generator::Task
VtsTilesetProvider::generateMesh(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode) const
{
return generateMesh_impl(tileId, sink, fileInfo, arsenal, textureMode);
}

Generator::Task
VtsTilesetProvider::generateFile(const FileInfo &fileInfo, Sink sink)
const
{
return generateFile_impl(fileInfo, sink);
}

boost::optional<boost::filesystem::path>
VtsTilesetProvider::path(vts::File file) const
{
return path_impl(file);
}

} // namespace generator

#endif // mapproxy_generator_providers_hpp_included_
55 changes: 53 additions & 2 deletions mapproxy/src/mapproxy/generator/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

#include "files.hpp"
#include "surface.hpp"
#include "providers.hpp"

namespace fs = boost::filesystem;
namespace bio = boost::iostreams;
Expand All @@ -94,6 +95,54 @@ terrainSupport(const Generator::Params &params)

} // namespace

class SurfaceProvider
: public Generator::Provider
, public VtsTilesetProvider
{
public:
SurfaceProvider(SurfaceBase &surface)
: surface_(surface)
{}

private:
Generator::Task generateMesh_impl(const vts::TileId &tileId
, Sink&
, const SurfaceFileInfo &fileInfo
, Arsenal&
, vts::SubMesh::TextureMode textureMode)
const override
{
return[=](Sink &sink, Arsenal &arsenal) {
return surface_.generateMesh
(tileId, sink, fileInfo, arsenal, textureMode);
};
}

Generator::Task generateFile_impl(const FileInfo &fileInfo, Sink sink)
const override
{
return surface_.generateFile(fileInfo, sink);
}

/** Returns path to VTS file if supported.
*/
boost::optional<fs::path> path_impl(vts::File file) const override
{
switch (file) {
case vts::File::config:
case vts::File::tileIndex:
break;

default:
return boost::none;
}

return surface_.filePath(file);
}

SurfaceBase &surface_;
};

fs::path SurfaceBase::filePath(vts::File fileType) const
{
switch (fileType) {
Expand Down Expand Up @@ -360,7 +409,8 @@ ::generateFile_impl(const FileInfo &fileInfo, Sink &sink) const
void SurfaceBase::generateMesh(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fi
, Arsenal &arsenal) const
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode) const
{
auto flags(index_->tileIndex.get(tileId));
if (!vts::TileIndex::Flag::isReal(flags)) {
Expand All @@ -385,7 +435,8 @@ void SurfaceBase::generateMesh(const vts::TileId &tileId
vts::Mesh mesh(false);
if (!lm.mesh.vertices.empty()) {
// local mesh is valid -> add as a submesh into output mesh
auto &sm(addSubMesh(mesh, lm.mesh, nodeInfo, lm.geoidGrid));
auto &sm(addSubMesh(mesh, lm.mesh, nodeInfo, lm.geoidGrid
, textureMode));
if (lm.textureLayerId) {
sm.textureLayer = lm.textureLayerId;
}
Expand Down
6 changes: 5 additions & 1 deletion mapproxy/src/mapproxy/generator/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class SurfaceBase : public Generator {
void generateMesh(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal) const;
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode
= vts::SubMesh::external) const;

void generate2dMask(const vts::TileId &tileId
, Sink &sink
Expand Down Expand Up @@ -130,6 +132,8 @@ class SurfaceBase : public Generator {

const Definition &definition_;
const vre::Tms *tms_;

friend class SurfaceProvider;
};

} // namespace generator
Expand Down
Loading

0 comments on commit 899b250

Please sign in to comment.