diff options
author | Théo de la Hogue | 2023-09-20 18:03:06 +0200 |
---|---|---|
committer | Théo de la Hogue | 2023-09-20 18:03:06 +0200 |
commit | bc9257268bb54ea68f777cbb853dc6498274dd99 (patch) | |
tree | 06d0d00a8905027a405f9b7cfe9fe35cc619297d /src | |
parent | 1f36c34242791145a1b33dd17cf351018456310f (diff) | |
download | argaze-bc9257268bb54ea68f777cbb853dc6498274dd99.zip argaze-bc9257268bb54ea68f777cbb853dc6498274dd99.tar.gz argaze-bc9257268bb54ea68f777cbb853dc6498274dd99.tar.bz2 argaze-bc9257268bb54ea68f777cbb853dc6498274dd99.tar.xz |
Adding expand to AOIScene.
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze.test/AreaOfInterest/AOIFeatures.py | 25 | ||||
-rw-r--r-- | src/argaze/AreaOfInterest/AOIFeatures.py | 12 |
2 files changed, 29 insertions, 8 deletions
diff --git a/src/argaze.test/AreaOfInterest/AOIFeatures.py b/src/argaze.test/AreaOfInterest/AOIFeatures.py index bced0aa..cc75ed8 100644 --- a/src/argaze.test/AreaOfInterest/AOIFeatures.py +++ b/src/argaze.test/AreaOfInterest/AOIFeatures.py @@ -181,21 +181,15 @@ class TestAOISceneClass(unittest.TestCase): 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) @@ -205,13 +199,28 @@ class TestAOISceneClass(unittest.TestCase): # 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_expand(self): + """Test AOIScene expand method.""" + + # Create 2D scene + aoi_2d_scene = AOIFeatures.AOIScene(2,) + aoi_2d_scene["A"] = AOIFeatures.AreaOfInterest([[0, 0], [0, 1], [1, 1], [1, 0]]) + aoi_2d_scene["B"] = AOIFeatures.AreaOfInterest([[0, 0], [0, 2], [2, 2], [2, 0]]) + + # Expand to 3D scene + aoi_3d_scene = aoi_2d_scene.expand() + + self.assertEqual(aoi_3d_scene.dimension, 3) + self.assertEqual(len(aoi_3d_scene.items()), 2) + self.assertEqual(list(aoi_3d_scene.keys()), ["A", "B"]) + self.assertEqual(aoi_3d_scene["A"].shape[1], 3) + self.assertEqual(aoi_3d_scene["B"].shape[1], 3) def test___repr__(self): """Test AOIScene string representation.""" diff --git a/src/argaze/AreaOfInterest/AOIFeatures.py b/src/argaze/AreaOfInterest/AOIFeatures.py index e5585c5..8987beb 100644 --- a/src/argaze/AreaOfInterest/AOIFeatures.py +++ b/src/argaze/AreaOfInterest/AOIFeatures.py @@ -383,6 +383,18 @@ class AOIScene(): return self.__dimension + def expand(self) -> AOISceneType: + """Add 1 dimension to the AOIs in scene.""" + + new_areas = {} + + for name, area in self.__areas.items(): + + zeros = numpy.zeros((len(self.__areas[name]), 1)) + new_areas[name] = numpy.concatenate((self.__areas[name], zeros), axis=1) + + return AOIScene(dimension = self.__dimension + 1, areas = new_areas) + @property def bounds(self) -> numpy.array: """Get scene's bounds.""" |