Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
xyz_export.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file xyz_export.h
20 * @brief Resample the UTM source mosaic into complete 256-pixel XYZ tiles.
21 * @details Tile pixels are transformed through geographic coordinates instead
22 * of assuming UTM and Web Mercator share a grid. Every interpolation tap with a
23 * nonzero weight must have source support; publishing partial or fabricated
24 * pixels would break opaque-tile compatibility and misstate coverage.
25 */
26#ifndef PANGEA_XYZ_EXPORT_H
27#define PANGEA_XYZ_EXPORT_H
28
29#include "xyz_tiles.h"
30#include "parallel_rows.h"
31
32namespace pangea_survey {
33/** @brief Colour and confidence planes for one aligned XYZ working batch. */
34struct XyzPixels {
35 int width = 0, height = 0;
36 std::vector<unsigned char> bgra, confidence;
37};
38
39/** @brief Require every one of the tile's 256 x 256 output pixels to be supported. */
40inline bool xyzCompleteCoverage(std::size_t valid) {
41 return valid == 65536;
42}
43
44/**
45 * @brief Resample an orthomosaic window onto one Web-Mercator pixel grid.
46 * @param[in] processor Prepared source-photo mapper.
47 * @param[in] config Validated survey settings and worker budget.
48 * @param[in] layout UTM layout used by the mapper.
49 * @param[in] zoom XYZ zoom level.
50 * @param[in] originX Global XYZ pixel x coordinate of the output window's first pixel.
51 * @param[in] originY Global XYZ pixel y coordinate of the output window's first pixel.
52 * @param[in] width Output window width, at most 1024 pixels.
53 * @param[in] height Output window height, at most 1024 pixels.
54 * @param[in] stopped Cooperative cancellation predicate.
55 * @return BGRA output and confidence for every resampled pixel.
56 * @throws std::runtime_error If the footprint exceeds its bounded UTM window,
57 * projection fails, or cancellation is requested.
58 */
59inline XyzPixels renderXyzPixels(Orthorectifier& processor, const MapConfig& config,
60 const OrthoLayout& layout, int zoom, std::uint64_t originX,
61 std::uint64_t originY, int width, int height,
62 const std::function<bool()>& stopped) {
63 if (width <= 0 || height <= 0 || width > 1024 || height > 1024)
64 throw std::runtime_error("XYZ working batch must fit 1024 x 1024 pixels");
65 const MapProjection projection((config.start.lat + config.end.lat) / 2,
66 (config.start.lon + config.end.lon) / 2);
67 struct Pixel { double x, y; };
68 const auto count = static_cast<std::size_t>(width) * height;
69 std::vector<Pixel> positions(count);
70 std::vector<double> longitude(width), latitude(height);
71 for (int x = 0; x < width; ++x)
72 longitude[x] = XyzTiles::pixel(originX + x, originY, zoom).second;
73 for (int y = 0; y < height; ++y)
74 latitude[y] = XyzTiles::pixel(originX, originY + y, zoom).first;
75 parallelRows(height, [&](int y) {
76 if (stopped()) throw std::runtime_error("XYZ coordinate transformation canceled");
77 for (int x = 0; x < width; ++x) {
78 const auto p = projection.forward(latitude[y], longitude[x]);
79 positions[static_cast<std::size_t>(y) * width + x] =
80 {(p.first - layout.west) / config.mapPixelSize - .5,
81 (layout.north - p.second) / config.mapPixelSize - .5};
82 }
83 }, config.mosaicThreads);
84 double minX = positions[0].x, maxX = minX, minY = positions[0].y, maxY = minY;
85 for (const auto& p : positions) {
86 minX = std::min(minX, p.x); maxX = std::max(maxX, p.x);
87 minY = std::min(minY, p.y); maxY = std::max(maxY, p.y);
88 }
89 const double left = std::floor(minX), top = std::floor(minY);
90 const int windowWidth = static_cast<int>(std::floor(maxX) - left + 2);
91 const int windowHeight = static_cast<int>(std::floor(maxY) - top + 2);
92 if (left < 0 || top < 0 || windowWidth > 4096 || windowHeight > 4096)
93 throw std::runtime_error("XYZ resampling footprint exceeds its padded working grid");
94 const auto source = processor.renderWindow(static_cast<std::size_t>(left), static_cast<std::size_t>(top),
95 windowWidth, windowHeight, stopped);
97 result.width = width; result.height = height;
98 result.bgra.assign(count * 4, 0); result.confidence.assign(count, 0);
99 parallelRows(height, [&](int y) {
100 if (stopped()) throw std::runtime_error("XYZ resampling canceled");
101 for (int x = 0; x < width; ++x) {
102 const auto i = static_cast<std::size_t>(y) * width + x;
103 const auto& p = positions[i];
104 const double bx = std::floor(p.x), by = std::floor(p.y);
105 const double fx = p.x - bx, fy = p.y - by;
106 const auto offset = static_cast<std::size_t>(by - top) * windowWidth +
107 static_cast<std::size_t>(bx - left);
108 const std::size_t taps[] = {offset, offset + 1, offset + windowWidth, offset + windowWidth + 1};
109 const double weights[] = {(1 - fx) * (1 - fy), fx * (1 - fy), (1 - fx) * fy, fx * fy};
110 bool valid = true;
111 unsigned char confidence = 255;
112 double colour[3]{};
113 // A bilinear result is supported only when every contributing tap is supported.
114 for (int t = 0; t < 4; ++t) {
115 if (weights[t] == 0) continue;
116 valid = valid && source.confidence[taps[t]] != 0;
117 confidence = std::min(confidence, source.confidence[taps[t]]);
118 for (int c = 0; c < 3; ++c) colour[c] += source.bgra[taps[t] * 4 + c] * weights[t];
119 }
120 if (!valid) continue;
121 result.confidence[i] = confidence;
122 for (int c = 0; c < 3; ++c)
123 result.bgra[i * 4 + c] = static_cast<unsigned char>(std::clamp(std::lround(colour[c]), 0L, 255L));
124 result.bgra[i * 4 + 3] = 255;
125 }
126 }, config.mosaicThreads);
127 return result;
128}
129
130/**
131 * @brief Build one lower-zoom level from aligned 2 x 2 child pixels.
132 * @param[in] input Complete, even-sized child pixel batch.
133 * @param[in] workers Upper bound on row workers.
134 * @param[in] stopped Cooperative cancellation predicate.
135 * @return Half-size overview; minimum child confidence propagates missingness.
136 * @throws std::runtime_error If dimensions are not aligned or cancellation is requested.
137 */
138inline XyzPixels xyzOverview(const XyzPixels& input, unsigned workers,
139 const std::function<bool()>& stopped) {
140 if (input.width <= 0 || input.height <= 0 || input.width % 2 || input.height % 2)
141 throw std::runtime_error("XYZ overview requires complete aligned child pixels");
143 output.width = input.width / 2; output.height = input.height / 2;
144 const auto count = static_cast<std::size_t>(output.width) * output.height;
145 output.bgra.resize(count * 4); output.confidence.resize(count);
146 parallelRows(output.height, [&](int y) {
147 if (stopped()) throw std::runtime_error("XYZ overview generation canceled");
148 for (int x = 0; x < output.width; ++x) {
149 const auto at = static_cast<std::size_t>(2 * y) * input.width + 2 * x;
150 const std::size_t taps[] = {at, at + 1, at + input.width, at + input.width + 1};
151 const auto i = static_cast<std::size_t>(y) * output.width + x;
152 unsigned char confidence = 255;
153 for (const auto t : taps) {
154 confidence = std::min(confidence, input.confidence[t]);
155 }
156 // A parent cannot claim stronger support than its weakest child pixel.
157 output.confidence[i] = confidence;
158 for (int c = 0; c < 4; ++c) {
159 unsigned sum = 0;
160 for (const auto t : taps) sum += input.bgra[t * 4 + c];
161 output.bgra[i * 4 + c] = static_cast<unsigned char>((sum + 2) / 4);
162 }
163 }
164 }, workers);
165 return output;
166}
167}
168
169/**
170 * @brief Render or reuse one identity-checked XYZ batch for low-memory resume.
171 * @param[in] processor Prepared orthorectifier.
172 * @param[in] working Working-grid configuration and checkpoint directory.
173 * @param[in] layout Projected working-grid bounds.
174 * @param[in] zoom Base XYZ zoom.
175 * @param[in] x Global XYZ pixel origin.
176 * @param[in] y Global XYZ pixel origin.
177 * @param[in] width Batch width in pixels.
178 * @param[in] height Batch height in pixels.
179 * @return Owned BGRA and confidence planes.
180 * @throws std::runtime_error If a saved batch has mismatched dimensions/hash or rendering fails.
181 */
183 const pangea_survey::OrthoLayout& layout, int zoom, std::uint64_t x, std::uint64_t y, int width, int height) {
184 const auto path = working.workingDirectory / "batches" / (std::to_string(x) + "_" + std::to_string(y));
185 const auto recordPath = path.string() + ".verified";
186 if (working.lowMemory && fs::exists(recordPath)) {
187 std::ifstream record(recordPath);
188 int savedWidth = 0, savedHeight = 0;
189 std::string digest, trailing;
190 if (!(record >> savedWidth >> savedHeight >> digest) || (record >> trailing) ||
191 savedWidth != width || savedHeight != height || pangea_survey::fileDigest(path, isStopping) != digest ||
192 fs::file_size(path) != static_cast<std::uint64_t>(width) * height * 5)
193 throw std::runtime_error("XYZ batch checksum or dimensions mismatch");
194 pangea_survey::XyzPixels pixels; pixels.width = width; pixels.height = height;
195 const auto count = static_cast<std::size_t>(width) * height;
196 pixels.bgra.resize(count * 4); pixels.confidence.resize(count);
197 std::ifstream input(path, std::ios::binary);
198 for (auto* plane : {&pixels.bgra, &pixels.confidence})
199 input.read(reinterpret_cast<char*>(plane->data()), static_cast<std::streamsize>(plane->size()));
200 if (!input) throw std::runtime_error("Cannot load XYZ batch");
201 std::cout << "Reusing verified XYZ batch " << x << ',' << y << '\n';
202 return pixels;
203 }
204 auto pixels = pangea_survey::renderXyzPixels(processor, working, layout, zoom, x, y, width, height, isStopping);
205 if (working.lowMemory) {
206 fs::create_directories(path.parent_path());
207 pangea_survey::storageHeadroom(path.parent_path(), static_cast<std::uint64_t>(width) * height * 5);
208 const auto temporary = path.string() + ".partial";
209 std::ofstream output(temporary, std::ios::binary | std::ios::trunc);
210 for (const auto* plane : {&pixels.bgra, &pixels.confidence})
211 output.write(reinterpret_cast<const char*>(plane->data()), static_cast<std::streamsize>(plane->size()));
212 output.close();
213 if (!output) throw std::runtime_error("Cannot checkpoint XYZ batch");
214 pangea_survey::publishWorkingFile(temporary, path);
215 pangea_survey::saveWorkingText(recordPath, std::to_string(width) + " " + std::to_string(height) + " " + pangea_survey::fileDigest(path, isStopping) + "\n");
216 }
217 return pixels;
218}
219
220/**
221 * @brief Render and publish the planned XYZ pyramid, optionally as diagnostics.
222 * @param[in] config Validated XYZ settings, coverage policy, and output root.
223 * @param[in] csv Fixed-session source manifest.
224 * @param[in] workDirectory Private report/checkpoint directory for this run.
225 * @param[in] diagnostic If true, save inspection images but leave completion false.
226 * @return Zero only after the report and all required tiles are finalized.
227 * @throws std::runtime_error On cancellation, incomplete coverage, write failure,
228 * or mismatched checkpoint content.
229 */
230static int exportXyzTiles(const pangea_survey::MapConfig& config, const fs::path& csv,
231 const fs::path& workDirectory, bool diagnostic = false) {
232 const pangea_survey::XyzPlan plan(config);
233 if (!diagnostic && !config.lowMemory) plan.checkOutput(config.output);
234 auto working = plan.workingConfig(config);
235 working.output = workDirectory;
236 pangea_survey::MapProgress progress(diagnostic ? "XYZ diagnostic progress" : "XYZ progress");
237 const auto incomplete = "{\"complete\":false,\"format\":\"xyz\",\"mode\":" +
239 if (config.lowMemory && fs::exists(workDirectory / "dataset.json"))
240 pangea_survey::publishWorkingFile(workDirectory / "dataset.json", workDirectory / "dataset.previous.json");
241 saveBinary(workDirectory / "dataset.incomplete.json", incomplete.data(), incomplete.size());
242 constexpr double first = 0;
243 progress.stage("Loading XYZ sources and grid", first, first + (99 - first) * .02);
244 pangea_survey::Orthorectifier processor(working, csv);
245 processor.prepareSources(isStopping);
246 const auto layout = pangea_survey::orthoLayout(working);
247 const auto latitude = (plan.north + plan.south) / 2;
248 std::cout << "Pangea " << config.mode << " XYZ: " << plan.size() << " tiles, zoom "
249 << plan.minZoom << ".." << plan.base.zoom << ", 256 x 256, EPSG:3857, no EXIF/XMP.\n"
250 << "Ground pixel at area centre: " << pangea_survey::XyzTiles::groundPixel(plan.base.zoom, latitude)
251 << " m; working UTM pixel: " << working.mapPixelSize << " m. CPU workers: "
252 << config.mosaicThreads << (config.lowMemory ? "; byte-bounded disk cache; " : "; 32-block LRU; ")
253 << "no full-map intermediate JPEG.\n"
254 << "Output: " << config.output.u8string() << "\nExport report: " << workDirectory.u8string() << '\n';
255 if (working.mapPixelSize > pangea_survey::XyzTiles::groundPixel(plan.base.zoom, latitude) * 1.05)
256 std::cout << "WARNING: Requested XYZ pixels are finer than the minimum working grid; "
257 "this resampling cannot add source detail.\n";
258 const auto manifestPath = workDirectory / (config.lowMemory ? "tiles.csv.partial" : "tiles.csv");
259 std::ofstream manifest(manifestPath);
260 manifest.imbue(std::locale::classic()); manifest << std::setprecision(17);
261 manifest << "zoom,x,y,width,height,valid_fraction,"
262 "reconstructed_fraction,reconstruction_blend_fraction,published\n";
263 if (!manifest) throw std::runtime_error("Cannot create XYZ tile manifest");
264 progress.stage(diagnostic ? "Rendering XYZ diagnostic tiles" : "Rendering and publishing XYZ tiles",
265 first + (99 - first) * .02, 99);
266 const auto started = Clock::now();
267 std::size_t published = 0, omitted = 0, reconstructed = 0, reconstructionBlend = 0;
268 for (auto y = plan.base.firstY; y <= plan.base.lastY;) {
269 const auto endY = std::min(plan.base.lastY + 1, (y / 4 + 1) * 4);
270 for (auto x = plan.base.firstX; x <= plan.base.lastX;) {
271 const auto endX = std::min(plan.base.lastX + 1, (x / 4 + 1) * 4);
272 if (isStopping()) throw std::runtime_error("XYZ export canceled; report remains incomplete");
273 auto pixels = xyzBatch(processor, working, layout, plan.base.zoom,
274 std::uint64_t{x} * 256, std::uint64_t{y} * 256,
275 static_cast<int>(endX - x) * 256, static_cast<int>(endY - y) * 256);
276 auto tileX = x, tileY = y;
277 for (int zoom = plan.base.zoom; zoom >= plan.minZoom; --zoom) {
278 const int columns = pixels.width / 256, rows = pixels.height / 256;
279 struct Counts {
280 std::size_t valid = 0;
281 std::size_t reconstructed = 0, reconstructionBlend = 0;
282 bool publish = true;
283 };
284 std::vector<Counts> counts(static_cast<std::size_t>(columns) * rows);
285 for (int ty = 0; ty < rows; ++ty) for (int tx = 0; tx < columns; ++tx) {
286 auto& c = counts[static_cast<std::size_t>(ty) * columns + tx];
287 for (int py = 0; py < 256; ++py) for (int px = 0; px < 256; ++px) {
288 const auto i = static_cast<std::size_t>(ty * 256 + py) * pixels.width + tx * 256 + px;
289 c.valid += pixels.confidence[i] != 0;
290 if (pangea_survey::mosaicMode(config.mode)) {
291 c.reconstructed += pixels.confidence[i] == 16;
292 c.reconstructionBlend += pixels.confidence[i] == 48;
293 }
294 }
295 // Missing colour blocks strict export; opt-in omissions remain explicit in the report.
296 if (!diagnostic && !pangea_survey::xyzCompleteCoverage(c.valid)) {
297 if (!config.xyzCompleteOnly)
298 throw std::runtime_error("XYZ tile " + std::to_string(zoom) + "/" +
299 std::to_string(tileX + tx) + "/" + std::to_string(tileY + ty) +
300 " lacks complete colour coverage; not published. "
301 "Acquire more source margin or reduce bounds; export report remains incomplete.");
302 c.publish = false;
303 }
304 }
305 pangea_survey::parallelRows(columns * rows, [&](int tile) {
306 if (isStopping()) throw std::runtime_error("XYZ JPEG publication canceled");
307 if (!counts[tile].publish) return;
308 const int tx = tile % columns, ty = tile / columns;
309 auto path = pangea_survey::XyzTiles::path(config.output, zoom, tileX + tx, tileY + ty);
310 if (diagnostic) path = workDirectory / (std::to_string(zoom) + "_" +
311 std::to_string(tileX + tx) + "_" + std::to_string(tileY + ty) + ".diagnostic.jpeg");
312 fs::create_directories(path.parent_path());
313 if (!config.lowMemory && (fs::exists(path) || fs::exists(path.string() + ".partial")))
314 throw std::runtime_error("Refusing to overwrite XYZ output: " + path.u8string());
316 const auto* data = pixels.bgra.data() +
317 (static_cast<std::size_t>(ty * 256) * pixels.width + tx * 256) * 4;
318 const auto jpeg = encoder.encode(data, 256, 256, pixels.width * 4, static_cast<int>(config.quality));
319 if (config.lowMemory && fs::exists(path)) {
320 if (pangea_survey::fileDigest(path, isStopping) != pangea_survey::dataDigest(jpeg.data, jpeg.size))
321 throw std::runtime_error("Existing XYZ tile differs from its working job; refusing overwrite");
322 } else JpegEncoder::save(jpeg, path, nullptr, 0, config.lowMemory);
323 }, config.mosaicThreads);
324 for (int tile = 0; tile < columns * rows; ++tile) {
325 const auto& c = counts[tile];
326 manifest << zoom << ',' << tileX + tile % columns << ',' << tileY + tile / columns
327 << ",256,256," << c.valid / 65536.0 << ','
328 << c.reconstructed / 65536.0 << ',' << c.reconstructionBlend / 65536.0 << ','
329 << (c.publish ? 1 : 0) << '\n';
330 if (c.publish) {
331 reconstructed += c.reconstructed;
332 reconstructionBlend += c.reconstructionBlend; ++published;
333 }
334 else ++omitted;
335 }
336 manifest.flush();
337 if (!manifest) throw std::runtime_error("Cannot write XYZ tile manifest");
338 progress.update(static_cast<double>(published + omitted) / plan.size(),
339 std::to_string(published) + " published, " + std::to_string(omitted) +
340 " omitted / " + std::to_string(plan.size()) + " tiles");
341 if (zoom > plan.minZoom) {
342 // Derive each parent level once from aligned child pixels to keep cuts consistent.
343 pixels = pangea_survey::xyzOverview(pixels, config.mosaicThreads, isStopping);
344 tileX /= 2; tileY /= 2;
345 }
346 }
347 x = endX;
348 }
349 y = endY;
350 }
351 manifest.close();
352 if (!manifest || published + omitted != plan.size()) throw std::runtime_error("XYZ tile manifest is incomplete");
353 if (!published && !config.incrementalPreview)
354 throw std::runtime_error("No XYZ tile has complete colour coverage; report remains incomplete");
355 if (config.lowMemory) pangea_survey::publishWorkingFile(manifestPath, workDirectory / "tiles.csv");
356 progress.stage("Finalizing XYZ export report", 99, 99.9);
357 std::ostringstream metadata;
358 metadata.imbue(std::locale::classic()); metadata << std::setprecision(17);
359 metadata << "{\"complete\":" << (diagnostic || omitted || config.incrementalPreview ? "false" : "true")
360 << ",\"provisional\":" << (config.incrementalPreview ? "true" : "false")
361 << ",\"processing_complete\":true,\"coverage_policy\":"
362 << pangea_survey::PhotoExif::jsonString(config.xyzCompleteOnly ? "complete_tiles_only" : "require_all")
363 << ",\"diagnostic\":" << (diagnostic ? "true" : "false")
364 << ",\"application\":\"pangea\",\"format\":\"xyz\",\"epsg\":3857,\"scheme\":\"xyz\","
365 "\"tile_size\":256,\"extension\":\"jpeg\",\"embedded_metadata\":false,"
366 "\"cuda\":false,\"accuracy_certified\":false,\"mode\":"
368 << ",\"relief_corrected\":false"
369 << ",\"zoom\":" << plan.base.zoom << ",\"min_zoom\":" << plan.minZoom
370 << ",\"tile_count\":" << published << ",\"requested_tile_count\":" << plan.size()
371 << ",\"omitted_tile_count\":" << omitted << ",\"first_x\":" << plan.base.firstX
372 << ",\"last_x\":" << plan.base.lastX << ",\"first_y\":" << plan.base.firstY
373 << ",\"last_y\":" << plan.base.lastY << ",\"north\":" << plan.north
374 << ",\"south\":" << plan.south << ",\"west\":" << plan.west << ",\"east\":" << plan.east
375 << ",\"ground_pixel_size_at_centre_m\":" << pangea_survey::XyzTiles::groundPixel(plan.base.zoom, latitude)
376 << ",\"working_pixel_size_m\":" << working.mapPixelSize
377 << ",\"threads\":" << config.mosaicThreads
378 << ",\"runtime_profile\":" << pangea_survey::PhotoExif::jsonString(config.lowMemory ? "low_memory" : "desktop")
379 << ",\"address_space_limit_mib\":" << (config.lowMemory ? config.memoryMiB : 0)
380 << ",\"mosaic_seam_method\":" << pangea_survey::PhotoExif::jsonString(config.mosaicSeamMethod)
381 << ",\"mosaic_blend_bands\":" << config.mosaicBlendBands
382 << ",\"mosaic_photo_cache_mib\":" << config.mosaicPhotoCacheMiB
383 << ",\"mosaic_overview_source_max_side\":" << config.mosaicOverviewSourceMaxSide
384 << ",\"mosaic_fill_gaps\":" << (config.mosaicFillGaps ? "true" : "false")
385 << ",\"gap_fill_method\":" << pangea_survey::PhotoExif::jsonString(config.mosaicFillGaps ? "global_source_push_pull" : "none")
386 << ",\"reconstructed_colour_pixel_count\":" << reconstructed
387 << ",\"reconstruction_blend_pixel_count\":" << reconstructionBlend
388 << ",\"observed_coverage_complete\":" << (omitted || reconstructed || reconstructionBlend ? "false" : "true")
389 << ",\"render_export_seconds\":" << seconds(Clock::now() - started)
390 << ",\"output\":" << pangea_survey::PhotoExif::jsonString(config.output.u8string())
391 << ",\"original_source_csv\":" << pangea_survey::PhotoExif::jsonString(config.originalSourceCsv.u8string())
392 << ",\"photo_directory\":" << pangea_survey::PhotoExif::jsonString(config.photoDirectory.u8string())
393 << ",\"camera_geometry\":" << pangea_survey::PhotoExif::jsonString(config.photoDirectory.empty() ?
394 "confirmed_survey_nadir" : config.allowRecordedPose ? "usher_recorded_exif_pose_perspective_unverified_timing" :
395 "usher_sensor_exposure_pose_perspective")
396 << ",\"optics_calibration\":" << pangea_survey::PhotoExif::jsonString(config.photoDirectory.empty() ?
397 "source_csv" : "raspberry_pi_ai_illustrative_radial_colour_model_not_measured")
398 << ",\"camera_profile\":" << pangea_survey::PhotoExif::jsonString(config.cameraProfile.u8string())
399 << ",\"admission_max_pose_uncertainty_m\":" << (config.allowRecordedPose ? "null" : std::to_string(config.maxPoseUncertainty))
400 << ",\"surveyed_accuracy_validated\":false"
401 << ",\"source_csv\":" << pangea_survey::PhotoExif::jsonString(csv.u8string()) << '}';
402 const auto text = metadata.str();
403 if (config.lowMemory) pangea_survey::saveWorkingText(workDirectory / "dataset.json", text);
404 else saveBinary(workDirectory / "dataset.json", text.data(), text.size());
405 if (!fs::remove(workDirectory / "dataset.incomplete.json"))
406 throw std::runtime_error("Cannot remove incomplete XYZ export marker");
407 if (diagnostic) std::cout << "XYZ diagnostic evidence completed; no cache tiles published.\n";
408 else std::cout << "XYZ export processing completed: " << published << " complete tiles published, "
409 << omitted << " unsupported tiles omitted; "
410 << (omitted ? "requested area coverage is incomplete.\n" : "full requested area covered.\n");
411 progress.finish();
412 return 0;
413}
414#endif
void saveBinary(const fs::path &path, const void *data, std::size_t size)
Write bytes to a new path and publish them by same-directory rename.
static double latitude
static double longitude
Reusable IJG compressor and JPEG publisher.
static void save(const Image &image, const std::filesystem::path &path, const unsigned char *exif=nullptr, std::size_t exifSize=0, bool durable=false)
Publish encoded JPEG bytes, optionally adding one EXIF APP1 segment.
Thread-safe progress reporter for staged map work.
void stage(const std::string &name, double first, double last, double estimateSeconds=0)
Begin a monotonic percentage range for one named stage.
void finish()
Mark the entire operation complete and permit 100 percent output.
void update(double fraction, const std::string &detail={})
Advance the current stage without allowing its fraction to regress.
Forward and inverse WGS-84 Transverse Mercator conversion for one UTM zone.
std::pair< double, double > forward(double latitude, double longitude) const
Project a geographic position into UTM easting and northing.
Load a fixed-session source set and render its projected tiles/windows.
Definition ortho_map.h:98
void prepareSources(const std::function< bool()> &stopped)
Prepare shared source rasters/mosaic state before repeated rendering.
OrthoImage renderWindow(std::size_t originX, std::size_t originY, int width, int height, const std::function< bool()> &stopped, const std::function< void(double)> &progress={})
Render an arbitrary bounded window of the configured map grid.
static std::string jsonString(const std::string &text)
Escape a string as a JSON string literal.
Definition photo_exif.h:456
static double groundPixel(int zoom, double latitude)
Ground metres per pixel at a latitude after Mercator scale correction.
Definition xyz_tiles.h:71
static std::filesystem::path path(const std::filesystem::path &root, int zoom, std::uint32_t x, std::uint32_t y)
Build the canonical zoom/x/y.jpeg path after range validation.
Definition xyz_tiles.h:105
static std::pair< double, double > pixel(std::uint64_t x, std::uint64_t y, int zoom)
Return the geographic centre of one global pixel address.
Definition xyz_tiles.h:100
static int record(const union dc_shot_union *shot)
Retrieve a point and admit a new observation only when its credit is free.
static bool started
static bool publish(const char *path, const uint8_t *frame, size_t bytes, unsigned width, unsigned height, bool synthetic, bool raw, const struct lwir_evidence *evidence, const struct lwir_render_options *render)
Durably publish a JPEG or raw companion under a new name.
Definition lwir_image.c:422
struct jpeg_compress_struct encoder
Definition lwir_image.c:59
bool xyzCompleteCoverage(std::size_t valid)
Require every one of the tile's 256 x 256 output pixels to be supported.
Definition xyz_export.h:40
OrthoLayout orthoLayout(const MapConfig &config)
Compute a north-up, non-overlapping image grid for the requested bounds.
void storageHeadroom(const std::filesystem::path &directory, std::uint64_t bytes)
Require requested free space plus a fixed safety reserve.
void parallelRows(int rows, Function function, unsigned requested=4)
Apply a row operation in parallel without creating nested teams.
std::string fileDigest(const std::filesystem::path &path, const std::function< bool()> &stopped={})
Hash a file in bounded chunks, optionally honoring cancellation.
Definition map_storage.h:89
XyzPixels xyzOverview(const XyzPixels &input, unsigned workers, const std::function< bool()> &stopped)
Build one lower-zoom level from aligned 2 x 2 child pixels.
Definition xyz_export.h:138
void publishWorkingFile(const std::filesystem::path &temporary, const std::filesystem::path &target, bool replace=true)
Fsync a completed working file, rename it, then sync its directory.
std::string dataDigest(const void *data, std::size_t size)
Compute a lowercase SHA-256 digest for an in-memory byte range.
Definition map_storage.h:77
void saveWorkingText(const std::filesystem::path &target, const std::string &text)
Save checkpoint text through the durable working-file publisher.
XyzPixels renderXyzPixels(Orthorectifier &processor, const MapConfig &config, const OrthoLayout &layout, int zoom, std::uint64_t originX, std::uint64_t originY, int width, int height, const std::function< bool()> &stopped)
Resample an orthomosaic window onto one Web-Mercator pixel grid.
Definition xyz_export.h:59
bool mosaicMode(const std::string &mode)
Return whether a supported processing mode uses the Great mosaic.
Definition map_config.h:80
Run independent row work with a bounded native thread team.
static size_t count
Definition pose_log.c:79
static FILE * output
Definition pose_log.c:77
Fully parsed settings shared by orthomap and XYZ export.
Definition map_config.h:41
std::filesystem::path workingDirectory
Definition map_config.h:57
std::filesystem::path originalSourceCsv
Definition map_config.h:71
std::filesystem::path cameraProfile
Definition map_config.h:60
unsigned long quality
Definition map_config.h:44
std::filesystem::path output
Definition map_config.h:71
std::filesystem::path photoDirectory
Definition map_config.h:60
std::string mosaicSeamMethod
Definition map_config.h:50
UTM-aligned extent and tile count for one requested map area.
Definition ortho_map.h:38
Colour and confidence planes for one aligned XYZ working batch.
Definition xyz_export.h:34
std::vector< unsigned char > bgra
Definition xyz_export.h:36
std::vector< unsigned char > confidence
Definition xyz_export.h:36
Derive requested XYZ bounds, map grid, and per-zoom tile ranges.
Definition xyz_tiles.h:119
static bool isStopping()
Check cancellation at a cooperative mapping boundary.
Definition survey.cpp:68
static double seconds(Clock::duration duration)
Convert a monotonic interval without truncating fractional seconds.
Definition survey.cpp:100
bool valid
Definition usher.c:537
struct usher_control_result result
Definition usher.c:377
static int exportXyzTiles(const pangea_survey::MapConfig &config, const fs::path &csv, const fs::path &workDirectory, bool diagnostic=false)
Render and publish the planned XYZ pyramid, optionally as diagnostics.
Definition xyz_export.h:230
static pangea_survey::XyzPixels xyzBatch(pangea_survey::Orthorectifier &processor, const pangea_survey::MapConfig &working, const pangea_survey::OrthoLayout &layout, int zoom, std::uint64_t x, std::uint64_t y, int width, int height)
Render or reuse one identity-checked XYZ batch for low-memory resume.
Definition xyz_export.h:182
Plan interoperable XYZ tile ranges in Web Mercator.