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

Commit

Permalink
surface-meta: proper credits handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavblazek committed Nov 28, 2019
1 parent c67fd32 commit 4eaf55e
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 82 deletions.
16 changes: 9 additions & 7 deletions mapproxy/src/mapproxy/generator/metatile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ metatileFromDemImpl(const vts::TileId &tileId, Sink &sink, Arsenal &arsenal
, const MaskTree &maskTree
, const boost::optional<int> &displaySize
, const HeightFunction::pointer &heightFunction
, vts::SubMesh::TextureMode textureMode)
, const MetatileOverrides &overrides)
{
auto blocks(metatileBlocks(resource, tileId));

Expand All @@ -194,7 +194,9 @@ metatileFromDemImpl(const vts::TileId &tileId, Sink &sink, Arsenal &arsenal
vts::MetaTile metatile(tileId, rf.metaBinaryOrder);

const std::size_t internalTextureCount
(textureMode == vts::SubMesh::internal);
(overrides.textureMode == vts::SubMesh::internal);

const auto credits(overrides.mergedCredits(resource.credits));

auto setChildren([&](const MetatileBlock &block
, const vts::TileId &nodeId, vts::MetaNode &node)
Expand Down Expand Up @@ -414,7 +416,7 @@ metatileFromDemImpl(const vts::TileId &tileId, Sink &sink, Arsenal &arsenal
// calculate texel size and surrogate
if (geometry) {
// set credits
node.updateCredits(resource.credits);
node.updateCredits(credits);

// texturing
node.internalTextureCount(internalTextureCount);
Expand Down Expand Up @@ -472,12 +474,12 @@ metatileFromDem(const vts::TileId &tileId, Sink &sink, Arsenal &arsenal
, const MaskTree &maskTree
, const boost::optional<int> &displaySize
, const HeightFunction::pointer &heightFunction
, vts::SubMesh::TextureMode textureMode)
, const MetatileOverrides &overrides)

{
return metatileFromDemImpl(tileId, sink, arsenal, resource, tileIndex
, demDataset, geoidGrid, maskTree, displaySize
, heightFunction, textureMode);
, heightFunction, overrides);
}


Expand All @@ -490,10 +492,10 @@ metatileFromDem(const vts::TileId &tileId, Sink &sink, Arsenal &arsenal
, const MaskTree &maskTree
, const boost::optional<int> &displaySize
, const HeightFunction::pointer &heightFunction
, vts::SubMesh::TextureMode textureMode)
, const MetatileOverrides &overrides)
{
return metatileFromDemImpl(tileId, sink, arsenal, resource, tileIndex
, demDataset, geoidGrid, maskTree, displaySize
, heightFunction, textureMode);
, heightFunction, overrides);

}
65 changes: 61 additions & 4 deletions mapproxy/src/mapproxy/generator/metatile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@

#include "../heightfunction.hpp"

struct MetatileOverrides {
enum class CreditsMode { replace, add };

vts::SubMesh::TextureMode textureMode;
DualId::set credits;
CreditsMode creditsMode;

MetatileOverrides()
: textureMode(vts::SubMesh::external)
, creditsMode(CreditsMode::add)
{}

MetatileOverrides(vts::SubMesh::TextureMode textureMode)
: textureMode(textureMode)
, creditsMode(CreditsMode::add)

{}

void addCredits(const DualId::set &addition);

DualId::set mergedCredits(const DualId::set &original) const;

vr::IdSet mergedCredits(const vr::IdSet &original) const;
};

vts::MetaTile metatileFromDem(const vts::TileId &tileId, Sink &sink
, Arsenal &arsenal
, const Resource &resource
Expand All @@ -48,8 +73,8 @@ vts::MetaTile metatileFromDem(const vts::TileId &tileId, Sink &sink
= boost::none
, const HeightFunction::pointer &heightFunction
= HeightFunction::pointer()
, vts::SubMesh::TextureMode textureMode
= vts::SubMesh::external);
, const MetatileOverrides &overrides
= MetatileOverrides());

vts::MetaTile metatileFromDem(const vts::TileId &tileId, Sink &sink
, Arsenal &arsenal
Expand All @@ -62,7 +87,39 @@ vts::MetaTile metatileFromDem(const vts::TileId &tileId, Sink &sink
= boost::none
, const HeightFunction::pointer &heightFunction
= HeightFunction::pointer()
, vts::SubMesh::TextureMode textureMode
= vts::SubMesh::external);
, const MetatileOverrides &overrides
= MetatileOverrides());

// inines

inline DualId::set
MetatileOverrides::mergedCredits(const DualId::set &original) const
{
// just send configured credits
if (creditsMode == CreditsMode::replace) { return credits; }

// merge original with configured credits
auto c(original);
c.insert(credits.begin(), credits.end());
return c;
}

inline vr::IdSet
MetatileOverrides::mergedCredits(const vr::IdSet &original) const
{
const auto thisCredits(asIntSet(credits));
// just send configured credits
if (creditsMode == CreditsMode::replace) { return thisCredits; }

// merge original with configured credits
auto c(original);
c.insert(thisCredits.begin(), thisCredits.end());
return c;
}

inline void MetatileOverrides::addCredits(const DualId::set &addition)
{
credits.insert(addition.begin(), addition.end());
}

#endif // mapproxy_metatile_hpp_included_
76 changes: 38 additions & 38 deletions mapproxy/src/mapproxy/generator/providers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "../generator.hpp"
#include "../definition.hpp"

#include "metatile.hpp"

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

Expand All @@ -50,22 +52,21 @@ class VtsTilesetProvider {

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

/** Generates metatile/debug node and sends it to the output.
*/
Generator::Task generateMetatile(const vts::TileId &tileId, Sink &sink
, const SurfaceFileInfo &fileInfo
, vts::SubMesh::TextureMode textureMode
= vts::SubMesh::external) const;
Generator::Task metatile(const vts::TileId &tileId, Sink &sink
, const SurfaceFileInfo &fileInfo
, const MetatileOverrides &overrides
= MetatileOverrides()) const;

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

/** Returns path to VTS file if supported.
*/
Expand All @@ -77,17 +78,17 @@ class VtsTilesetProvider {

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

virtual Generator::Task
generateMetatile_impl(const vts::TileId &tileId, Sink &sink
, const SurfaceFileInfo &fileInfo
, vts::SubMesh::TextureMode textureMode) const = 0;
metatile_impl(const vts::TileId &tileId, Sink &sink
, const SurfaceFileInfo &fileInfo
, const MetatileOverrides &overrides) const = 0;

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

virtual boost::optional<boost::filesystem::path> path_impl(vts::File file)
const = 0;
Expand All @@ -101,44 +102,43 @@ class VtsAtlasProvider {

/** Generates image/atlas and sends it to the output.
*/
Generator::Task generateAtlas(const vts::TileId &tileId, Sink &sink
, const Sink::FileInfo &sfi
, bool atlas = false) const;
Generator::Task atlas(const vts::TileId &tileId, Sink &sink
, const Sink::FileInfo &sfi
, bool atlas = false) const;

private:
/** Generates image/atlas and sends it to the output.
*/
virtual Generator::Task
generateAtlas_impl(const vts::TileId &tileId, Sink &sink
, const Sink::FileInfo &sfi
, bool atlas = false) const = 0;
atlas_impl(const vts::TileId &tileId, Sink &sink
, const Sink::FileInfo &sfi
, bool atlas = false) const = 0;
};

// inlines

inline Generator::Task
VtsTilesetProvider::generateMesh(const vts::TileId &tileId, Sink &sink
, const SurfaceFileInfo &fileInfo
, vts::SubMesh::TextureMode textureMode)
VtsTilesetProvider::mesh(const vts::TileId &tileId, Sink &sink
, const SurfaceFileInfo &fileInfo
, vts::SubMesh::TextureMode textureMode)
const
{
return generateMesh_impl(tileId, sink, fileInfo, textureMode);
return mesh_impl(tileId, sink, fileInfo, textureMode);
}

inline Generator::Task
VtsTilesetProvider::generateMetatile(const vts::TileId &tileId, Sink &sink
, const SurfaceFileInfo &fileInfo
, vts::SubMesh::TextureMode
textureMode)
VtsTilesetProvider::metatile(const vts::TileId &tileId, Sink &sink
, const SurfaceFileInfo &fileInfo
, const MetatileOverrides &overrides)
const
{
return generateMetatile_impl(tileId, sink, fileInfo, textureMode);
return metatile_impl(tileId, sink, fileInfo, overrides);
}

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

inline boost::optional<boost::filesystem::path>
Expand All @@ -153,11 +153,11 @@ inline vts::FullTileSetProperties VtsTilesetProvider::properties() const
}

inline Generator::Task
VtsAtlasProvider::generateAtlas(const vts::TileId &tileId, Sink &sink
, const Sink::FileInfo &sfi
, bool atlas) const
VtsAtlasProvider::atlas(const vts::TileId &tileId, Sink &sink
, const Sink::FileInfo &sfi
, bool atlas) const
{
return generateAtlas_impl(tileId, sink, sfi, atlas);
return atlas_impl(tileId, sink, sfi, atlas);
}

} // namespace generator
Expand Down
8 changes: 4 additions & 4 deletions mapproxy/src/mapproxy/generator/surface-dem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void SurfaceDem::generateMetatile(const vts::TileId &tileId
, Sink &sink
, const SurfaceFileInfo &fi
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode)
, const MetatileOverrides &overrides)
const
{
sink.checkAborted();
Expand All @@ -239,7 +239,7 @@ void SurfaceDem::generateMetatile(const vts::TileId &tileId
return;
}

auto metatile(generateMetatileImpl(tileId, sink, arsenal, textureMode));
auto metatile(generateMetatileImpl(tileId, sink, arsenal, overrides));

// write metatile to stream
std::ostringstream os;
Expand All @@ -250,13 +250,13 @@ void SurfaceDem::generateMetatile(const vts::TileId &tileId
vts::MetaTile
SurfaceDem::generateMetatileImpl(const vts::TileId &tileId
, Sink &sink, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode) const
, const MetatileOverrides &overrides) const
{
return metatileFromDem(tileId, sink, arsenal, resource()
, index_->tileIndex, dem_.dataset
, dem_.geoidGrid, maskTree_, boost::none
, definition_.heightFunction
, textureMode);
, overrides);
}

namespace {
Expand Down
6 changes: 3 additions & 3 deletions mapproxy/src/mapproxy/generator/surface-dem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SurfaceDem : public SurfaceBase {
, Sink &sink
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode)
, const MetatileOverrides &overrides)
const;

virtual AugmentedMesh
Expand All @@ -69,8 +69,8 @@ class SurfaceDem : public SurfaceBase {

vts::MetaTile generateMetatileImpl(const vts::TileId &tileId
, Sink &sink, Arsenal &arsenal
, vts::SubMesh::TextureMode textureMode
= vts::SubMesh::external)
, const MetatileOverrides &overrides
= MetatileOverrides())
const;

void addToRegistry();
Expand Down
Loading

0 comments on commit 4eaf55e

Please sign in to comment.