diff --git a/externals/libgeometry b/externals/libgeometry index 34086d9..8548396 160000 --- a/externals/libgeometry +++ b/externals/libgeometry @@ -1 +1 @@ -Subproject commit 34086d9f0b1f4fe08428282b48fde68b6bd48350 +Subproject commit 85483961fe82afbfe9cf513c111cb0eb3803523b diff --git a/mapproxy/src/mapproxy/generator.hpp b/mapproxy/src/mapproxy/generator.hpp index db34306..8e2d5be 100644 --- a/mapproxy/src/mapproxy/generator.hpp +++ b/mapproxy/src/mapproxy/generator.hpp @@ -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 ¶ms, const Properties &props = Properties()); @@ -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 + ProviderType* getProvider() const; + + /** Sets new provider. Value is stolen. + */ + void setProvider(std::unique_ptr &&provider); + private: virtual void prepare_impl(Arsenal &arsenal) = 0; virtual vts::MapConfig mapConfig_impl(ResourceRoot root) const = 0; @@ -284,6 +298,7 @@ class Generator : boost::noncopyable { std::atomic readySince_; DemRegistry::pointer demRegistry_; Generator::pointer replace_; + std::unique_ptr provider_; }; /** Set of dataset generators. @@ -396,4 +411,16 @@ Generator::otherGenerator(Resource::Generator::Type generatorType return generatorFinder_->findGenerator(generatorType, resourceId); } +template +ProviderType* Generator::getProvider() const +{ + if (!provider_) { return nullptr; } + return dynamic_cast(provider_.get()); +} + +inline void Generator::setProvider(std::unique_ptr &&provider) +{ + provider_ = std::move(provider); +} + #endif // mapproxy_generator_hpp_included_ diff --git a/mapproxy/src/mapproxy/generator/interfaces.hpp b/mapproxy/src/mapproxy/generator/interfaces.hpp new file mode 100644 index 0000000..7126e85 --- /dev/null +++ b/mapproxy/src/mapproxy/generator/interfaces.hpp @@ -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 + +#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 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 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 +VtsTilesetProvider::path(vts::File file) const +{ + return path_impl(file); +} + +} // namespace generator + +#endif // mapproxy_generator_interface_hpp_included_ diff --git a/mapproxy/src/mapproxy/generator/providers.hpp b/mapproxy/src/mapproxy/generator/providers.hpp new file mode 100644 index 0000000..1ee6957 --- /dev/null +++ b/mapproxy/src/mapproxy/generator/providers.hpp @@ -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 + +#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 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 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 +VtsTilesetProvider::path(vts::File file) const +{ + return path_impl(file); +} + +} // namespace generator + +#endif // mapproxy_generator_providers_hpp_included_ diff --git a/mapproxy/src/mapproxy/generator/surface.cpp b/mapproxy/src/mapproxy/generator/surface.cpp index 3915f04..8d6b146 100644 --- a/mapproxy/src/mapproxy/generator/surface.cpp +++ b/mapproxy/src/mapproxy/generator/surface.cpp @@ -71,6 +71,7 @@ #include "files.hpp" #include "surface.hpp" +#include "providers.hpp" namespace fs = boost::filesystem; namespace bio = boost::iostreams; @@ -94,6 +95,54 @@ terrainSupport(const Generator::Params ¶ms) } // 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 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) { @@ -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)) { @@ -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; } diff --git a/mapproxy/src/mapproxy/generator/surface.hpp b/mapproxy/src/mapproxy/generator/surface.hpp index 53272f4..2cd1aff 100644 --- a/mapproxy/src/mapproxy/generator/surface.hpp +++ b/mapproxy/src/mapproxy/generator/surface.hpp @@ -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 @@ -130,6 +132,8 @@ class SurfaceBase : public Generator { const Definition &definition_; const vre::Tms *tms_; + + friend class SurfaceProvider; }; } // namespace generator diff --git a/mapproxy/src/mapproxy/support/mesh.cpp b/mapproxy/src/mapproxy/support/mesh.cpp index e7f0faa..f4f121b 100644 --- a/mapproxy/src/mapproxy/support/mesh.cpp +++ b/mapproxy/src/mapproxy/support/mesh.cpp @@ -382,29 +382,38 @@ class TextureNormalizer { vts::SubMesh& addSubMesh(vts::Mesh &mesh, const geometry::Mesh &gmesh , const vts::NodeInfo &nodeInfo - , const boost::optional &geoidGrid) + , const boost::optional &geoidGrid + , vts::SubMesh::TextureMode textureMode) { const auto extents(nodeInfo.extents()); const auto l2g(geo::local2geo(extents)); mesh.submeshes.emplace_back(); auto &sm(mesh.submeshes.back()); - sm.textureMode = vts::SubMesh::external; + sm.textureMode = textureMode; + const bool generateTc(textureMode == vts::SubMesh::TextureMode::internal); TextureNormalizer tn(extents); const auto conv(sds2phys(nodeInfo, geoidGrid)); - bool generateEtc(nodeInfo.node().externalTexture); + const bool generateEtc(nodeInfo.node().externalTexture); + + const bool textured(generateEtc || generateTc); for (const auto &v : gmesh.vertices) { // convert v from local coordinates to division SRS then to physical SRS sm.vertices.push_back(conv(transform(l2g, v))); - // generate external texture coordinates if instructed - if (generateEtc) { - sm.etc.push_back(tn(v)); + // generate external/internal texture coordinates if instructed + if (textured) { + const auto tc(tn(v)); + if (generateEtc) { sm.etc.push_back(tc); } + if (generateTc) { sm.tc.push_back(tc); } } } + // texture faces same as regular faces + if (generateTc) { sm.facesTc = sm.faces; } + for (const auto &f : gmesh.faces) { sm.faces.emplace_back(f.a, f.b, f.c); } diff --git a/mapproxy/src/mapproxy/support/mesh.hpp b/mapproxy/src/mapproxy/support/mesh.hpp index 066940a..5f3ee4e 100644 --- a/mapproxy/src/mapproxy/support/mesh.hpp +++ b/mapproxy/src/mapproxy/support/mesh.hpp @@ -89,7 +89,9 @@ void addSkirt(geometry::Mesh &mesh, const vts::NodeInfo &nodeInfo); vts::SubMesh& addSubMesh(vts::Mesh &mesh, const geometry::Mesh &gmesh , const vts::NodeInfo &nodeInfo - , const boost::optional &geoidGrid); + , const boost::optional &geoidGrid + , vts::SubMesh::TextureMode textureMode + = vts::SubMesh::external); qmf::Mesh qmfMesh(const geometry::Mesh &gmesh, const vts::NodeInfo &nodeInfo , const std::string &srs