Skip to content

Python binding: add iteration support for Poses and Landmark Observations#2099

Draft
Copilot wants to merge 2 commits into
developfrom
copilot/update-binding-iterate-poses-landmarks
Draft

Python binding: add iteration support for Poses and Landmark Observations#2099
Copilot wants to merge 2 commits into
developfrom
copilot/update-binding-iterate-poses-landmarks

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Extends the Python SWIG binding to allow iteration over Poses (already a SharedPtrMap<CameraPose>) and over each Landmark's observations.

Description

Poses already had SPMAP_EXTENSIONS applied, giving it __iter__, keys(), values(), and items() — but this was untested. Landmark.getObservations() returned stl::flat_map<IndexT, Observation> (boost::container::flat_map), which SWIG cannot wrap as an iterable Python object.

Features list

  • Iterate over Poses with for pose_id in sfm_data.getPoses(), .keys(), .values(), .items()
  • Iterate over Landmark observations via landmark.getObservations(), returning a dict-like Observations object
# Poses
for pose_id, pose in sfm_data.getPoses().items():
    print(pose_id, pose.isLocked())

# Landmark observations
for view_id, obs in landmark.getObservations().items():
    print(view_id, obs.getX(), obs.getY())

Implementation remarks

getObservations() returns stl::flat_map (a boost::container::flat_map alias), which has no SWIG support. Rather than wrapping boost containers, the existing getMapObservations() C++ method (which converts to std::map<IndexT, Observation>) is surfaced via a %extend replacement in Landmark.i. The %template(Observations) std::map<IndexT, Observation> already present in SfMData.i then provides the full dict-like Python interface via SWIG's std_map.i.

Both features are covered by new/updated tests in pyTests/sfmData/.

@fabiencastan fabiencastan reopened this May 19, 2026
@fabiencastan fabiencastan force-pushed the copilot/update-binding-iterate-poses-landmarks branch from dd6a671 to db5f145 Compare May 19, 2026 10:57
@sonarqubecloud
Copy link
Copy Markdown

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