aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze.test/AreaOfInterest/AOIFeatures.py45
-rw-r--r--src/argaze/AreaOfInterest/AOIFeatures.py27
2 files changed, 70 insertions, 2 deletions
diff --git a/src/argaze.test/AreaOfInterest/AOIFeatures.py b/src/argaze.test/AreaOfInterest/AOIFeatures.py
index 586d2bd..bced0aa 100644
--- a/src/argaze.test/AreaOfInterest/AOIFeatures.py
+++ b/src/argaze.test/AreaOfInterest/AOIFeatures.py
@@ -62,7 +62,6 @@ class TestAreaOfInterestClass(unittest.TestCase):
self.assertIsNone(numpy.testing.assert_array_equal(aoi_2D.size, [1, 1]))
self.assertIsNone(numpy.testing.assert_array_equal(aoi_2D.bounding_box, [[0, 0], [1, 0], [1, 1], [0, 1]]))
- self.assertIsNone(numpy.testing.assert_array_equal(aoi_2D.bounding_box_size, [1, 1]))
# Check 8 points 3D AreaOfInterest creation
aoi_3D = AOIFeatures.AreaOfInterest([[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0], [0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
@@ -150,6 +149,7 @@ class TestAOISceneClass(unittest.TestCase):
self.assertEqual(aoi_2d_scene.dimension, 2)
self.assertEqual(len(aoi_2d_scene.items()), 0)
+ self.assertEqual(len(vars(aoi_2d_scene)), 2 + len(aoi_2d_scene.items()))
# Check 2D AOIScene creation
aoi_2D = AOIFeatures.AreaOfInterest([[0, 0], [0, 1], [1, 1], [1, 0]])
@@ -158,7 +158,7 @@ class TestAOISceneClass(unittest.TestCase):
self.assertEqual(aoi_2d_scene.dimension, 2)
self.assertEqual(len(aoi_2d_scene.items()), 1)
self.assertEqual(list(aoi_2d_scene.keys()), ["A"])
- self.assertEqual(len(vars(aoi_2d_scene)), 3)
+ self.assertEqual(len(vars(aoi_2d_scene)), 2 + len(aoi_2d_scene.items()))
def test___set_item__(self):
"""Test AOIScene __set_item__ method."""
@@ -172,6 +172,47 @@ class TestAOISceneClass(unittest.TestCase):
with self.assertRaises(AssertionError):
aoi_2d_scene["B"] = AOIFeatures.AreaOfInterest([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]])
+ def test_merge(self):
+ """Test AOIScene merge operator."""
+
+ # Create first scene with A and B aoi
+ aoi_2d_scene_AB = AOIFeatures.AOIScene(2,)
+
+ aoi_2d_scene_AB["A"] = AOIFeatures.AreaOfInterest([[0, 0], [0, 1], [1, 1], [1, 0]])
+ aoi_2d_scene_AB["B"] = AOIFeatures.AreaOfInterest([[0, 0], [0, 2], [2, 2], [2, 0]])
+
+ print('aoi_2d_scene_AB vars: ', vars(aoi_2d_scene_AB))
+
+ # Create second scene with C and D aoi
+ aoi_2d_scene_CD = AOIFeatures.AOIScene(2,)
+
+ aoi_2d_scene_CD["C"] = AOIFeatures.AreaOfInterest([[0, 0], [0, 3], [3, 3], [3, 0]])
+ aoi_2d_scene_CD["D"] = AOIFeatures.AreaOfInterest([[0, 0], [0, 4], [4, 4], [4, 0]])
+
+ print('aoi_2d_scene_CD vars: ', vars(aoi_2d_scene_CD))
+
+ # Merge first scene and second scene into a third scene
+ aoi_2d_scene_ABCD = aoi_2d_scene_AB | aoi_2d_scene_CD
+
+ print('aoi_2d_scene_ABCD vars: ', vars(aoi_2d_scene_ABCD))
+
+ # Check third scene
+ self.assertEqual(aoi_2d_scene_ABCD.dimension, 2)
+ self.assertEqual(len(aoi_2d_scene_ABCD.items()), 4)
+ self.assertEqual(list(aoi_2d_scene_ABCD.keys()), ["A", "B", "C", "D"])
+ self.assertEqual(len(vars(aoi_2d_scene_ABCD)), 2 + len(aoi_2d_scene_ABCD.items()))
+
+ # Merge second scene into first scene
+ aoi_2d_scene_AB |= aoi_2d_scene_CD
+
+ print('aoi_2d_scene_AB vars: ', vars(aoi_2d_scene_AB))
+
+ # Check first scene
+ self.assertEqual(aoi_2d_scene_AB.dimension, 2)
+ self.assertEqual(len(aoi_2d_scene_AB.items()), 4)
+ self.assertEqual(list(aoi_2d_scene_AB.keys()), ["A", "B", "C", "D"])
+ self.assertEqual(len(vars(aoi_2d_scene_AB)), 2 + len(aoi_2d_scene_AB.items()))
+
def test___repr__(self):
"""Test AOIScene string representation."""
diff --git a/src/argaze/AreaOfInterest/AOIFeatures.py b/src/argaze/AreaOfInterest/AOIFeatures.py
index 68a5b6b..cbe4483 100644
--- a/src/argaze/AreaOfInterest/AOIFeatures.py
+++ b/src/argaze/AreaOfInterest/AOIFeatures.py
@@ -263,6 +263,33 @@ class AOIScene():
# Stop area exposition as an attribute of the class
delattr(self, key)
+ def __or__(self, other):
+
+ assert(other.dimension == self.__dimension)
+
+ merged_areas = dict(self.__areas)
+ merged_areas.update(other.__areas)
+
+ return AOIScene(self.dimension, merged_areas)
+
+ def __ror__(self, other):
+
+ assert(other.dimension == self.__dimension)
+
+ merged_areas = dict(other.__areas)
+ merged_areas.update(self.__areas)
+
+ return AOIScene(self.dimension, merged_areas)
+
+ def __ior__(self, other):
+
+ assert(other.dimension == self.__dimension)
+
+ self.__areas.update(other.__areas)
+ self.__dict__.update(other.__areas)
+
+ return self
+
def __len__(self):
"""Get number of AOI into scene."""
return len(self.__areas)