Skip to content

Have cam2map create results as ASP's mapproject#5988

Merged
acpaquette merged 13 commits intoDOI-USGS:devfrom
oleg-alexandrov:asp_map_v2
Mar 26, 2026
Merged

Have cam2map create results as ASP's mapproject#5988
acpaquette merged 13 commits intoDOI-USGS:devfrom
oleg-alexandrov:asp_map_v2

Conversation

@oleg-alexandrov
Copy link
Copy Markdown
Contributor

@oleg-alexandrov oleg-alexandrov commented Mar 10, 2026

Description

This adds to cam2map the option asp_map=true that produces mapprojected cubes in agreement with ASP at each grid point.

Documentation: https://stereopipeline.readthedocs.io/en/latest/tools/mapproject.html#isis-compatibility

Relevant issue: #5984

I added a unit test. I will put some more.

This does not bring over any classes from ASP. Projections are done with GDAL and the image processing with the ISIS logic.

It would be good to get some review on this as there is quite some new logic.

Related Issue

How Has This Been Validated?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation change (update to the documentation; no code change)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Infrastructure change (changes to things like CI or the build system that do not impact users)

Checklist:

  • I have read and agree to abide by the Code of Conduct
  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added myself to the .zenodo.json document.
  • I have added my user impacting change to the CHANGELOG.md document.

Licensing

This project is mostly composed of free and unencumbered software released into the public domain, and we are unlikely to accept contributions that are not also released into the public domain. Somewhere near the top of each file should have these words:

This work is free and unencumbered software released into the public domain. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain.

  • I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

@github-actions
Copy link
Copy Markdown

The build and test suite have started for your pull request.

To view your build log, please reference the build with source version: "PR_5988".

Additionally, check the latest "dev" source version to identify existing test failures. Please note that you are not responsible for the test failures that exist on both your PR and the dev branch.

oleg-alexandrov added a commit to oleg-alexandrov/ISIS3 that referenced this pull request Mar 10, 2026
@github-actions
Copy link
Copy Markdown

The build and test suite have started for your pull request.

To view your build log, please reference the build with source version: "PR_5988".

Additionally, check the latest "dev" source version to identify existing test failures. Please note that you are not responsible for the test failures that exist on both your PR and the dev branch.

@oleg-alexandrov
Copy link
Copy Markdown
Contributor Author

Looks like any pull request is failing at: ObservationPair.FunctionalTestJigsawOutputCsmState.

@acpaquette
Copy link
Copy Markdown
Collaborator

@oleg-alexandrov That test is also failing on dev so this PR is clean

@github-actions
Copy link
Copy Markdown

The build and test suite have started for your pull request.

To view your build log, please reference the build with source version: "PR_5988".

Additionally, check the latest "dev" source version to identify existing test failures. Please note that you are not responsible for the test failures that exist on both your PR and the dev branch.

1 similar comment
@github-actions
Copy link
Copy Markdown

The build and test suite have started for your pull request.

To view your build log, please reference the build with source version: "PR_5988".

Additionally, check the latest "dev" source version to identify existing test failures. Please note that you are not responsible for the test failures that exist on both your PR and the dev branch.

Comment thread isis/src/base/apps/cam2map/AspMapProjection.cpp Outdated
@github-actions
Copy link
Copy Markdown

The build and test suite have started for your pull request.

To view your build log, please reference the build with source version: "PR_5988".

Additionally, check the latest "dev" source version to identify existing test failures. Please note that you are not responsible for the test failures that exist on both your PR and the dev branch.

Comment thread isis/src/base/objs/Cube/Cube.cpp Outdated
@github-actions
Copy link
Copy Markdown

The build and test suite have started for your pull request.

To view your build log, please reference the build with source version: "PR_5988".

Additionally, check the latest "dev" source version to identify existing test failures. Please note that you are not responsible for the test failures that exist on both your PR and the dev branch.

@oleg-alexandrov
Copy link
Copy Markdown
Contributor Author

Getting auth error unrelated to the actual code.

@acpaquette
Copy link
Copy Markdown
Collaborator

@oleg-alexandrov I think Amy fixed the auth issues for running tests. Could you rebase this off dev and push to get a clean test run?

On macOS, `ulimit -n unlimited` returns a very large value that overflows
the unsigned int cast in CubeManager, producing 0 and causing a null
pointer dereference. Fix by capping at a reasonable maximum (8192) and
using size_t to avoid the overflow.
Implement a new asp_map=true mode in cam2map that performs per-pixel exact
camera model evaluation, matching ASP mapproject output. For each output
pixel, compute the full ground->image transform through the camera model
and DEM ray intersection, bypassing the patch-based affine approximation
in ProcessRubberSheet.

New files:
- AspMapProjection.cpp: per-pixel projection engine, GeoRef class with
  GDAL-based coordinate transforms, RasterReader with ISIS Portal-based
  tiled I/O and VW-matching bicubic interpolation, grid computation
  (auto bbox/GSD from camera footprint, snapping), option handling
  (map= files via GDAL and PVL, matchmap, PPD, lat/lon bounds override),
  pvlToWkt for 12 ISIS projections, PVL metadata output.
- AspMapProjection.h: header declarations.

Modified files:
- cam2map.cpp: wire asp_map mode, call asp::mapproject() when enabled.
- cam2map.xml: add ASP_MAP (bool) and DEM (filename) parameters.

Parity with ASP mapproject: ~1e-6 max abs diff on LROC NAC stereo pair,
tested across equicylindrical, sinusoidal, stereographic, and polar
stereographic projections.
Add TEST_F(DemCube, FunctionalTestCam2mapAspMap) that exercises the
asp_map=true path with equirectangular projection, explicit GSD and
bounds from a map file. Verifies the output cube has correct dimensions
and projection metadata.
Add Cube::addInMemoryBlob() to inject a blob without modifying the file
on disk. Add ISD parameter to cam2map.xml. When provided, loadCsmIntoCube()
constructs a CSM camera from the ISD, serializes its state into a CSMState
blob, and injects it into the cube so cube->camera() returns a CSMCamera.
Add band-dependent camera handling in ASP_MAP mode. Extracted
projectPixel() helper. Cached input image coords per output line
to avoid redundant re-projection across bands. For band-dependent
cameras (THEMIS IR, CRISM), SetBand() called per band with full
re-projection. For band-independent cameras, project once and reuse.
Unified PPD-to-MPP conversion via ppdToMpp helper. Added clarifying
comments for the spherical-radius bake-in behavior.
Add pixel-value accuracy check to FunctionalTestCam2mapAspMap (valid
pixel count + DN range). Add FunctionalTestCam2mapAspMapMultiBand
(3-band mock camera, band-independent). Extract shared
checkPixelValues() helper. Add FunctionalTestCam2mapAspMapCsm (CSM
framer using orbitalMarsFramer.json, auto-detects USGSCSM plugin).
Add FunctionalTestCam2mapAspMapMatchmapPvl (matchmap=true with PVL
.map file, self-consistency test exercising computeAutoGrid and
readGridFromPvl). Fix buildAspGroup to write CAMERA_MODEL_TYPE=csm
when ISD is provided. Add unsupported projection error test.
Enhance main ASP_MAP GTest with sinusoidal projection, user lat/lon
bounds (20% inset), and bounds verification.
Use ISIS Progress class when ProgressBar=On in user preferences
(feeds the GUI progress bar). Fall back to manual std::cout
percentage when ProgressBar=Off (the default). Print "Writing:"
before projection starts. Gate DEM and ISD parameters behind
ASP_MAP in cam2map.xml (grayed out in GUI when ASP_MAP is off).
Improve error messages for unsupported PVL projections. Rename
snap_ulx/uly and deltax/y to camelCase. Add pixel-edge vs
pixel-center convention comments. Simplify validateUi to silently
ignore unsupported DEFAULTRANGE values. Replace non-ASCII em-dash
with ASCII hyphen.
…-trip

Add CSMCamera(Cube&, pluginName, modelName, stateString) constructor
that calls init() directly, avoiding the blob serialize/deserialize
round-trip when loading CSM cameras from ISD files. Add Cube::setCamera()
to set a pre-constructed camera on a cube. Update cam2map ASP_MAP mode
to use the new constructor instead of addInMemoryBlob.
The CSM test changed ISISROOT to CONDA_PREFIX when the build dir
lacked csmplugins. This broke ISIS file lookups for
CubeFormatTemplate.pft on CI. CSM plugin loading already works
via TestPreferences which lists CONDA_PREFIX paths. Added try/catch
as safety net for environments where CSM setup is incomplete.
@oleg-alexandrov
Copy link
Copy Markdown
Contributor Author

Thanks. Looks like the workflow needs approval.

@acpaquette
Copy link
Copy Markdown
Collaborator

@oleg-alexandrov I think the auth token for our ci may have expired. Working on getting this back up and running

@github-actions
Copy link
Copy Markdown

The build and test suite have started for your pull request.

To view your build log, please reference the build with source version: "PR_5988".

Additionally, check the latest "dev" source version to identify existing test failures. Please note that you are not responsible for the test failures that exist on both your PR and the dev branch.

@oleg-alexandrov
Copy link
Copy Markdown
Contributor Author

The build went through with no failures.

@acpaquette acpaquette merged commit 07f3d7a into DOI-USGS:dev Mar 26, 2026
4 of 5 checks passed
amystamile-usgs pushed a commit to amystamile-usgs/ISIS3 that referenced this pull request Apr 16, 2026
* Fix CubeManager overflow when ulimit is unlimited

On macOS, `ulimit -n unlimited` returns a very large value that overflows
the unsigned int cast in CubeManager, producing 0 and causing a null
pointer dereference. Fix by capping at a reasonable maximum (8192) and
using size_t to avoid the overflow.

* Add ASP_MAP per-pixel exact projection mode to cam2map

Implement a new asp_map=true mode in cam2map that performs per-pixel exact
camera model evaluation, matching ASP mapproject output. For each output
pixel, compute the full ground->image transform through the camera model
and DEM ray intersection, bypassing the patch-based affine approximation
in ProcessRubberSheet.

New files:
- AspMapProjection.cpp: per-pixel projection engine, GeoRef class with
  GDAL-based coordinate transforms, RasterReader with ISIS Portal-based
  tiled I/O and VW-matching bicubic interpolation, grid computation
  (auto bbox/GSD from camera footprint, snapping), option handling
  (map= files via GDAL and PVL, matchmap, PPD, lat/lon bounds override),
  pvlToWkt for 12 ISIS projections, PVL metadata output.
- AspMapProjection.h: header declarations.

Modified files:
- cam2map.cpp: wire asp_map mode, call asp::mapproject() when enabled.
- cam2map.xml: add ASP_MAP (bool) and DEM (filename) parameters.

Parity with ASP mapproject: ~1e-6 max abs diff on LROC NAC stereo pair,
tested across equicylindrical, sinusoidal, stereographic, and polar
stereographic projections.

* Add GTest for cam2map ASP_MAP mode

Add TEST_F(DemCube, FunctionalTestCam2mapAspMap) that exercises the
asp_map=true path with equirectangular projection, explicit GSD and
bounds from a map file. Verifies the output cube has correct dimensions
and projection metadata.

* Add changelog entry for PR DOI-USGS#5988

* Fix bbox-to-grid, GSD fallback, DEM validation, remove debug prints

* Add CSM camera support via ISD parameter in cam2map ASP_MAP mode

Add Cube::addInMemoryBlob() to inject a blob without modifying the file
on disk. Add ISD parameter to cam2map.xml. When provided, loadCsmIntoCube()
constructs a CSM camera from the ISD, serializes its state into a CSMState
blob, and injects it into the cube so cube->camera() returns a CSMCamera.

* Add multi-band support with band-dependent camera handling

Add band-dependent camera handling in ASP_MAP mode. Extracted
projectPixel() helper. Cached input image coords per output line
to avoid redundant re-projection across bands. For band-dependent
cameras (THEMIS IR, CRISM), SetBand() called per band with full
re-projection. For band-independent cameras, project once and reuse.
Unified PPD-to-MPP conversion via ppdToMpp helper. Added clarifying
comments for the spherical-radius bake-in behavior.

* Add GTests: multi-band, CSM camera, matchmap PVL, pixel-value checks

Add pixel-value accuracy check to FunctionalTestCam2mapAspMap (valid
pixel count + DN range). Add FunctionalTestCam2mapAspMapMultiBand
(3-band mock camera, band-independent). Extract shared
checkPixelValues() helper. Add FunctionalTestCam2mapAspMapCsm (CSM
framer using orbitalMarsFramer.json, auto-detects USGSCSM plugin).
Add FunctionalTestCam2mapAspMapMatchmapPvl (matchmap=true with PVL
.map file, self-consistency test exercising computeAutoGrid and
readGridFromPvl). Fix buildAspGroup to write CAMERA_MODEL_TYPE=csm
when ISD is provided. Add unsupported projection error test.
Enhance main ASP_MAP GTest with sinusoidal projection, user lat/lon
bounds (20% inset), and bounds verification.

* Add ISIS Progress integration, GUI param gating, code cleanup

Use ISIS Progress class when ProgressBar=On in user preferences
(feeds the GUI progress bar). Fall back to manual std::cout
percentage when ProgressBar=Off (the default). Print "Writing:"
before projection starts. Gate DEM and ISD parameters behind
ASP_MAP in cam2map.xml (grayed out in GUI when ASP_MAP is off).
Improve error messages for unsupported PVL projections. Rename
snap_ulx/uly and deltax/y to camelCase. Add pixel-edge vs
pixel-center convention comments. Simplify validateUi to silently
ignore unsupported DEFAULTRANGE values. Replace non-ASCII em-dash
with ASCII hyphen.

* Add CSMCamera string constructor, use setCamera instead of blob round-trip

Add CSMCamera(Cube&, pluginName, modelName, stateString) constructor
that calls init() directly, avoiding the blob serialize/deserialize
round-trip when loading CSM cameras from ISD files. Add Cube::setCamera()
to set a pre-constructed camera on a cube. Update cam2map ASP_MAP mode
to use the new constructor instead of addInMemoryBlob.

* Remove unused addInMemoryBlob function per review feedback

* Fix CSM GTest crash on CI: stop overwriting ISISROOT

The CSM test changed ISISROOT to CONDA_PREFIX when the build dir
lacked csmplugins. This broke ISIS file lookups for
CubeFormatTemplate.pft on CI. CSM plugin loading already works
via TestPreferences which lists CONDA_PREFIX paths. Added try/catch
as safety net for environments where CSM setup is incomplete.

* Minor wording fix: map-projected to mapprojected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants