-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathRasterOverlayUpsampler.cpp
More file actions
158 lines (142 loc) · 6.01 KB
/
RasterOverlayUpsampler.cpp
File metadata and controls
158 lines (142 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "RasterOverlayUpsampler.h"
#include <Cesium3DTilesSelection/RasterMappedTo3DTile.h>
#include <Cesium3DTilesSelection/Tile.h>
#include <Cesium3DTilesSelection/TileContent.h>
#include <Cesium3DTilesSelection/TileLoadResult.h>
#include <Cesium3DTilesSelection/TilesetContentLoader.h>
#include <CesiumAsync/Future.h>
#include <CesiumGeometry/Axis.h>
#include <CesiumGeometry/QuadtreeTileID.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGeospatial/Projection.h>
#include <CesiumRasterOverlays/RasterOverlay.h>
#include <CesiumRasterOverlays/RasterOverlayTileProvider.h>
#include <CesiumRasterOverlays/RasterOverlayUtilities.h>
#include <CesiumUtility/Assert.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <utility>
#include <variant>
#include <vector>
using namespace CesiumRasterOverlays;
namespace Cesium3DTilesSelection {
CesiumAsync::Future<TileLoadResult>
RasterOverlayUpsampler::loadTileContent(const TileLoadInput& loadInput) {
const Tile* pParent = loadInput.tile.getParent();
if (pParent == nullptr) {
return loadInput.asyncSystem.createResolvedFuture(
TileLoadResult::createFailedResult(loadInput.pAssetAccessor, nullptr));
}
const CesiumGeometry::UpsampledQuadtreeNode* pTileID =
std::get_if<CesiumGeometry::UpsampledQuadtreeNode>(
&loadInput.tile.getTileID());
if (pTileID == nullptr) {
// this tile is not marked to be upsampled, so just fail it
return loadInput.asyncSystem.createResolvedFuture(
TileLoadResult::createFailedResult(loadInput.pAssetAccessor, nullptr));
}
// The tile content manager guarantees that the parent tile is already loaded
// before upsampled tile is loaded. If that's not the case, it's a bug
CESIUM_ASSERT(
pParent->getState() == TileLoadState::Done &&
"Parent must be loaded before upsampling");
const TileContent& parentContent = pParent->getContent();
const TileRenderContent* pParentRenderContent =
parentContent.getRenderContent();
if (!pParentRenderContent) {
// parent doesn't have mesh, so it's not possible to upsample
return loadInput.asyncSystem.createResolvedFuture(
TileLoadResult::createFailedResult(loadInput.pAssetAccessor, nullptr));
}
if (pParentRenderContent->getGltfModifierState() ==
GltfModifierState::WorkerRunning) {
// Parent is currently being modified, so it would be useless to upsample
// the version about to be replaced - also, its rasterOverlayProjections
// may have been emptied in order to be recomputed as well.
return loadInput.asyncSystem.createResolvedFuture(
TileLoadResult::createRetryLaterResult(
loadInput.pAssetAccessor,
nullptr));
}
size_t index = 0;
const std::vector<CesiumGeospatial::Projection>& parentProjections =
pParentRenderContent->getRasterOverlayDetails().rasterOverlayProjections;
CESIUM_ASSERT(!parentProjections.empty());
for (const RasterMappedTo3DTile& mapped : pParent->getMappedRasterTiles()) {
if (mapped.isMoreDetailAvailable()) {
const CesiumGeospatial::Projection& projection =
mapped.getReadyTile()->getTileProvider().getProjection();
auto it = std::find(
parentProjections.begin(),
parentProjections.end(),
projection);
index = static_cast<size_t>(it - parentProjections.begin());
break;
}
}
const CesiumGeospatial::Projection& projection = parentProjections[index];
const CesiumGeospatial::Ellipsoid& ellipsoid =
getProjectionEllipsoid(projection);
const CesiumGltf::Model& parentModel = pParentRenderContent->getModel();
pParentRenderContent->incrementUpSamplingTaskCount();
return loadInput.asyncSystem
.runInWorkerThread([&parentModel,
pParentRenderContent,
ellipsoid,
transform = loadInput.tile.getTransform(),
textureCoordinateIndex = index,
tileID = *pTileID,
pAssetAccessor = loadInput.pAssetAccessor]() mutable {
if (pParentRenderContent->getGltfModifierState() ==
GltfModifierState::WorkerRunning) {
// Parent tile is being modified, no need to spend time upsampling an
// obsolete version.
return TileLoadResult::createRetryLaterResult(
pAssetAccessor,
nullptr);
}
auto model = RasterOverlayUtilities::upsampleGltfForRasterOverlays(
parentModel,
tileID,
false,
RasterOverlayUtilities::DEFAULT_TEXTURE_COORDINATE_BASE_NAME,
static_cast<int32_t>(textureCoordinateIndex),
ellipsoid);
if (!model) {
return TileLoadResult::createFailedResult(pAssetAccessor, nullptr);
}
// Adopt the glTF up axis from the glTF itself.
// It came from the parent, which by this point has already been
// populated from the Tile, if necessary.
CesiumGeometry::Axis upAxis = CesiumGeometry::Axis::Y;
auto upIt = model->extras.find("gltfUpAxis");
if (upIt != model->extras.end()) {
upAxis = CesiumGeometry::Axis(
upIt->second.getInt64OrDefault(int64_t(CesiumGeometry::Axis::Y)));
}
return TileLoadResult{
std::move(*model),
upAxis,
std::nullopt,
std::nullopt,
std::nullopt,
nullptr,
nullptr,
{},
TileLoadResultState::Success,
ellipsoid};
})
.thenInMainThread([pParentRenderContent](TileLoadResult&& result) {
CESIUM_ASSERT(pParentRenderContent->isBeingUpSampled());
pParentRenderContent->decrementUpSamplingTaskCount();
return std::move(result);
});
}
TileChildrenResult RasterOverlayUpsampler::createTileChildren(
[[maybe_unused]] const Tile& tile,
[[maybe_unused]] const CesiumGeospatial::Ellipsoid& ellipsoid) {
return {{}, TileLoadResultState::Failed};
}
} // namespace Cesium3DTilesSelection