aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2024-04-02 09:56:34 +0200
committerThéo de la Hogue2024-04-02 09:56:34 +0200
commitcd48c4857834c2bef0d42475de12eb906ef7d82c (patch)
treeae121ed67b906a0a83861c28685dce1af6420395
parentc5d7fbcc8570a05eceab4c2d221e92f80d722336 (diff)
downloadargaze-cd48c4857834c2bef0d42475de12eb906ef7d82c.zip
argaze-cd48c4857834c2bef0d42475de12eb906ef7d82c.tar.gz
argaze-cd48c4857834c2bef0d42475de12eb906ef7d82c.tar.bz2
argaze-cd48c4857834c2bef0d42475de12eb906ef7d82c.tar.xz
Fixing context entrance.
-rw-r--r--src/argaze/ArFeatures.py42
-rw-r--r--src/argaze/DataFeatures.py29
-rw-r--r--src/argaze/GazeFeatures.py2
3 files changed, 62 insertions, 11 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py
index 1585780..91b63ac 100644
--- a/src/argaze/ArFeatures.py
+++ b/src/argaze/ArFeatures.py
@@ -1052,6 +1052,28 @@ class ArScene(DataFeatures.PipelineStepObject):
"distance_tolerance": self.__distance_tolerance
}
+ @DataFeatures.PipelineStepEnter
+ def __enter__(self):
+
+ for name, layer in self._layers.items():
+
+ layer.__enter__()
+
+ for name, frame in self.__frames.items():
+
+ frame.__enter__()
+
+ @DataFeatures.PipelineStepExit
+ def __exit__(self, exception_type, exception_value, exception_traceback):
+
+ for name, layer in self._layers.items():
+
+ layer.__exit__(exception_type, exception_value, exception_traceback)
+
+ for name, frame in self.__frames.items():
+
+ frame.__exit__(exception_type, exception_value, exception_traceback)
+
@DataFeatures.PipelineStepMethod
def estimate_pose(self, detected_features: any) -> tuple[numpy.array, numpy.array, any]:
"""Define abstract estimate scene pose method.
@@ -1269,6 +1291,24 @@ class ArCamera(ArFrame):
layer.aoi_matcher.exclude = excluded_aoi_list
+ @DataFeatures.PipelineStepEnter
+ def __enter__(self):
+
+ super().__enter__()
+
+ for name, scene in self._scenes.items():
+
+ scene.__enter__()
+
+ @DataFeatures.PipelineStepExit
+ def __exit__(self, exception_type, exception_value, exception_traceback):
+
+ super().__exit__(exception_type, exception_value, exception_traceback)
+
+ for name, scene in self._scenes.items():
+
+ scene.__exit__(exception_type, exception_value, exception_traceback)
+
@DataFeatures.PipelineStepMethod
def watch(self, image: numpy.array):
"""Detect AR features from image and project scenes into camera frame.
@@ -1461,7 +1501,7 @@ class ArContext(DataFeatures.PipelineStepObject):
else:
# Edit gaze position
- self.__pipeline.look( GazeFeatures.GazePosition( (x, y), precision = precision, timestamp = timestamp) )
+ self.__pipeline.look( GazeFeatures.GazePosition( (x, y), precision = precision, timestamp = timestamp))
except DataFeatures.TimestampedException as e:
diff --git a/src/argaze/DataFeatures.py b/src/argaze/DataFeatures.py
index bad2009..032e7e5 100644
--- a/src/argaze/DataFeatures.py
+++ b/src/argaze/DataFeatures.py
@@ -999,13 +999,14 @@ def PipelineStepMethod(method):
PipelineStepMethod must have a timestamp as first argument.
"""
- def wrapper(self, *args, timestamp: int|float = None, unwrap: bool = False, **kwargs):
+ def wrapper(self, *args, timestamp: int|float = None, unwrap: bool = False, debug: bool = False, **kwargs):
"""Wrap pipeline step method to measure execution time.
Parameters:
args: any arguments defined by PipelineStepMethod.
timestamp: optional method call timestamp (unit does'nt matter) if first args parameter is not a TimestampedObject instance.
unwrap: extra arguments used in wrapper function to call wrapped method directly.
+ debug: extra arguments used in wrapper function to not catch exception.
"""
if timestamp is None and len(args) > 0:
@@ -1025,20 +1026,30 @@ def PipelineStepMethod(method):
start = time.perf_counter()
exception = None
result = None
-
- try:
- # Execute wrapped method
+ if debug:
+
+ # Execute wrapped method without catching exceptions
result = method(self, *args, **kwargs)
- except Exception as e:
+ # Measure execution time
+ self.execution_times[method.__name__] = (time.perf_counter() - start) * 1e3
+
+ else:
+
+ try:
- exception = e
+ # Execute wrapped method
+ result = method(self, *args, **kwargs)
- finally:
+ except Exception as e:
- # Measure execution time
- self.execution_times[method.__name__] = (time.perf_counter() - start) * 1e3
+ exception = e
+
+ finally:
+
+ # Measure execution time
+ self.execution_times[method.__name__] = (time.perf_counter() - start) * 1e3
# Notify observers that method has been called
subscription_name = f'on_{method.__name__}'
diff --git a/src/argaze/GazeFeatures.py b/src/argaze/GazeFeatures.py
index bd7970b..c0e5a36 100644
--- a/src/argaze/GazeFeatures.py
+++ b/src/argaze/GazeFeatures.py
@@ -380,7 +380,7 @@ class GazeMovement(TimeStampedGazePositions, DataFeatures.TimestampedObject):
@timestamp.setter
def timestamp(self, timestamp: int|float):
"""Block gaze movement timestamp setting."""
- raise('GazeMovement timestamp is first positon timestamp.')
+ raise('GazeMovement timestamp is first position timestamp.')
def is_finished(self) -> bool:
"""Is the movement finished?"""