texture: add CUDA orthomap generation backend (cherry-pick of 3181f4a)#1269
Open
cdcseacave wants to merge 4 commits into
Open
texture: add CUDA orthomap generation backend (cherry-pick of 3181f4a)#1269cdcseacave wants to merge 4 commits into
cdcseacave wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a CUDA-backed orthographic map (“orthomap”) generation path to the MVS scene texturing pipeline, intended to generate top-down maps on geo-referenced reconstructions without running full mesh texturing. The new functionality is gated behind _USE_CUDA and a new TextureMesh --ortho-only runtime flag.
Changes:
- Introduces
Scene::GenerateOrthoMap(...)and implements the CUDA orthomap pipeline in a newSceneOrthoCUDA.inl. - Extends CURAST with orthographic projection/rasterization + a substantial GPU-side collapse/blending pipeline for per-tile orthomap synthesis.
- Adds new
TextureMeshCLI flags (--ortho-only,--tile-size,--max-tile-res,--resume-orthomap) to drive the orthomap generation mode.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/MVS/SceneTextureCUDA.inl | Includes the new orthomap implementation into the CUDA scene texturing compilation unit. |
| libs/MVS/SceneOrthoCUDA.inl | New orthomap generation implementation: view projection, tile-size search, per-tile rasterization, tile blending/assembly. |
| libs/MVS/Scene.h | Adds the CUDA-gated Scene::GenerateOrthoMap(...) API. |
| libs/MVS/CURAST/curast.h | Extends CURAST/OrthoCURAST interfaces and adds new CUDA-side structs/workspace declarations for orthomap collapse. |
| libs/MVS/CURAST/curast.cu | Adds orthographic projection/rasterization kernels and a large orthomap stack-collapse implementation. |
| libs/MVS/CURAST/curast.cpp | Implements OrthoCURAST methods (projection, rasterization, normal map generation, collapse orchestration). |
| apps/TextureMesh/TextureMesh.cpp | Adds CLI flags and an early-exit --ortho-only mode that calls Scene::GenerateOrthoMap(...). |
- curast.h: strip UTF-8 BOM; fix "fort"->"for" typo in SetFacesForView doc - curast.cu UpdateBestViewsOrtho: apply computed edgeMap to visibilityMap via MultiplyKernel (matches perspective UpdateBestViews; previously the JFA distance-to-edge map was computed and freed unused) - curast.cu OrthoRasterizeKernelBis: add per-tile depth buffer gated by atomicMaxFloat(pW.z()) so only the topmost world-Z surface contributes samples per pixel (eliminates the inter-triangle race that allowed far surfaces to overwrite near ones) - curast.cu OrthoRasterize: drop cudaDeviceSynchronize and switch the pointer-table + new depth buffer to cudaMallocAsync/cudaFreeAsync on the stream, keeping the per-tile pipeline fully stream-scoped - curast.cu GetNormalOrthoMap: switch per-call depth-buffer malloc/free to async on the stream and move thrust fills onto thrust::cuda::par.on to avoid implicit host syncs - SceneOrthoCUDA.inl auto tile-size search: when no candidate satisfies max-tile-res / GPU memory, clamp tileRes to maxTileRes with a warning instead of allocating beyond the user/GPU budget - SceneOrthoCUDA.inl final crop: guard the no-non-black-pixel case so we fall back to writing the full orthoMap rather than building a degenerate ROI - TextureMesh --ortho-only: clarify --output-file semantics in this mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cherry-picks
3181f4afromjustin/justin/cuda-ortho(Justin Gabriel's fork) on top of thecuda-texturebranch (#1268): adds a CUDA-accelerated orthographic-map generator that runs without full mesh texturing. Useful for top-down map generation on geo-referenced reconstructions.The new path is gated behind
#ifdef _USE_CUDAAND a runtime--ortho-onlyflag, so default behavior is unchanged.New CLI flags on
TextureMesh(require_USE_CUDA)--ortho-only— generate only the orthomap, skip mesh texturing--tile-size— world-space tile size (0= auto binary search, default)--max-tile-res— max per-tile pixel resolution (default 8192)--resume-orthomap— skip re-rasterization when tile PNGs already exist on diskNew API
Scene::GenerateOrthoMap(tileSize, maxImgRes, maxTileRes, outputName, bResume)inlibs/MVS/Scene.h, implemented in the newlibs/MVS/SceneOrthoCUDA.inl. Pipeline:outputName(resolved againstWORKING_FOLDERif relative; absolute paths also accepted)Build fix (CCCL 13 / Thrust)
Two
make_transform_iteratorlambdas incurast.cuwere declared__device__-only. CCCL 13 (CUDA 13.x) instantiatescuda::std::invoke_result_t<lambda, ...>from host code, which requires the lambda to be__host__ __device__(or wrapped viacuda::proclaim_return_type, or a named functor). Promoted both lambdas to__host__ __device__and gave them an explicit-> uinttrailing return type — see commite2f8ba2.Path-handling cleanup
Replaced manual
WORKING_FOLDER + nameconcatenations inSceneOrthoCUDA.inlwith the existingMAKE_PATH/MAKE_PATH_SAFEmacros fromlibs/Common/Common.h. The user-provided output filename now usesMAKE_PATH_SAFE, so both relative and absolute-opaths work correctly (previously an absolute path silently failedcv::imwritebecause of the literal string concatenation).Documentation
Added
docs/CUDA_TEXTURE_AND_ORTHOMAP.md— a short user-facing README covering the goals, methods, example invocations, and observed behavior of bothcuda-textureandcuda-ortho.Validation
In-tree
Tests 2 1 0(regression check on cuda-texture path), 3 consecutive runs:(One earlier run flaked with CUDA <45 — known pre-existing PatchMatch threading non-determinism, not caused by this PR.)
Tanks-and-Temples Truck (251 images, mesh decimated to 30% = 900k faces):
--ortho-onlywall timeCredit
Original author: JuSiGab (Justin Gabriel) — the cuda-ortho commit was authored by him on
justin/justin/cuda-ortho. Cherry-picked here with author re-attribution to facilitate review on this fork.Test plan
OpenMVS_USE_CUDA=ONon Windows (MSVC, CUDA 13.x) and LinuxTextureMesh(no--ortho-only) behavior is unchangedTests 2 1 0— expect cuda-texture path to still pass (CPU + CUDA scores ≥ 45)TextureMesh --ortho-only -w <scene_dir> -o ortho.pngon a geo-referenced scene — expect<scene_dir>/ortho.png-o /abs/path/ortho.png— should also work after the path-handling cleanup🤖 Generated with Claude Code