Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions pyTests/sfmData/test_landmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# image::RGBColor& color) / not binded
# - operator==(other) => DONE
# - [inline] operator!=(other) => DONE
# - Observations& getObservations() / Observations (stl::flat_map) not binded
# - Observations& getObservations() => DONE (returns MapObservations copy)
##################

def test_landmark_default_constructor():
Expand Down Expand Up @@ -53,7 +53,25 @@ def test_landmark_compare():
# TODO: Update the describer type, the Vec3 or the image before comparing again


@pytest.mark.skip(reason="stl::flat_map<Observation> not binded")
def test_landmark_get_observations():
""" Test creating Landmarks and retrieving their Observations. """
assert True
""" Test creating a Landmark and retrieving its (empty) Observations. """
landmark = av.Landmark()
observations = landmark.getObservations()

# A default Landmark has no observations
assert len(observations) == 0, \
"A default Landmark should have no observations"

# Verify the observations container is iterable and dict-like
iterated_ids = [obs_id for obs_id in observations]
assert iterated_ids == [], \
"Iterating over empty observations should yield no items"

keys = observations.keys()
assert len(keys) == 0, "keys() on empty observations should return an empty list"

values = observations.values()
assert len(values) == 0, "values() on empty observations should return an empty list"

items = observations.items()
assert len(items) == 0, "items() on empty observations should return an empty list"
39 changes: 39 additions & 0 deletions pyTests/sfmData/test_sfmdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,45 @@ def test_sfmdata_get_poses():
assert len(data.getPoses()) == len(poses) == 1, "The list of Poses should have been updated"


def test_sfmdata_iterate_poses():
""" Test creating an SfMData object, filling it with Poses, and iterating over them. """
data = av.SfMData()
poses = data.getPoses()

pose_ids = [1, 2, 3, 4, 5]
for pose_id in pose_ids:
camera_pose = av.CameraPose()
poses[pose_id] = camera_pose

assert len(poses) == len(pose_ids), "The list of Poses should contain all added Poses"

# Test __iter__: iterating yields all pose IDs
iterated_ids = [pose_id for pose_id in poses]
assert sorted(iterated_ids) == sorted(pose_ids), \
"Iterating over Poses should yield all pose IDs"

# Test keys()
keys = poses.keys()
assert sorted(keys) == sorted(pose_ids), \
"keys() should return all pose IDs"

# Test values()
values = poses.values()
assert len(values) == len(pose_ids), \
"values() should return one CameraPose per pose ID"
assert all(isinstance(v, av.CameraPose) for v in values), \
"Each value returned by values() should be a CameraPose"

# Test items()
items = poses.items()
assert len(items) == len(pose_ids), \
"items() should return one (pose_id, CameraPose) pair per pose"
for pose_id, pose in items:
assert pose_id in pose_ids, "Each key from items() should be a valid pose ID"
assert isinstance(pose, av.CameraPose), \
"Each value from items() should be a CameraPose"


def test_sfmdata_get_rigs():
""" Test creating an empty SfMData object, retrieving and editing its Rigs. """
data = av.SfMData()
Expand Down
10 changes: 10 additions & 0 deletions src/aliceVision/sfmData/Landmark.i
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
%ignore aliceVision::sfmData::Landmark::_X;
%ignore aliceVision::sfmData::Landmark::_pointFetcher;

// Ignore getObservations() which returns stl::flat_map (not natively supported by SWIG).
// A compatible replacement returning MapObservations (std::map) is provided via %extend below.
%ignore aliceVision::sfmData::Landmark::getObservations;

//Add new swig only C++ code
%extend aliceVision::sfmData::Landmark {

Expand All @@ -45,6 +49,12 @@
color.b() = value.z();
$self->setRgb(color);
}

// Return observations as a std::map (MapObservations) so that SWIG can expose
// a fully iterable Python dict-like object.
aliceVision::sfmData::MapObservations getObservations() const {
return $self->getMapObservations();
}

// If the user asks for the rgb property
// It is not a direct access to the rgb
Expand Down
Loading