RodTracker.ui.rodimagewidget
TBD
- class RodImageWidget(*args, **kwargs)[source]
Bases:
QLabelA custom
QLabelthat displays an image and can overlay rods.- Parameters:
*args (iterable) – Positional arguments for the
QLabelsuperclass.**kwargs (dict) – Keyword arguments for the
QLabelsuperclass.
Signals
- base_pixmap
A clean image in the correct scaled size.
- Type:
QPixmap
- rod_pixmap
Image that is temporarily painted on when rod corrections are put in by the user.
- Type:
QPixmap
- startPos
Start position for new rod position.
- Type:
QtCore.QPoint
- property active_rod
Property that returns the currently activated rod, if applicable.
- Returns:
int | None
- adjust_rod_length(amount: float = 1.0, only_selected: bool = True)[source]
Adjusts rod length(s) by a given amount in px.
Adds the length (in px) given in
amountto the active rod or all rods. Negative values shorten the rod(s).- Parameters:
amount (float, optional) – Amount in px by which the lenght will be adjusted. By default
1.only_selected (bool, optional) – Whether to only adjust the currently active rod’s length. By default
True.
- adjust_rod_position(rod: RodNumberWidget) List[int][source]
Adjusts a rod number position to be on the right side of its rod.
The position of the
RodNumberWidgetis adjusted, such that it is displayed to the right side and in the middle of its corresponding rod. This adjustment is mainly due to scaling of the image. It also returns the rods position in the image associated with the movedRodNumberWidget.- Parameters:
rod (RodNumberWidget) –
- Returns:
List[int]
- autoselect: bool = True
- property cam_id: str
Property that holds a string used as and ID for logging and data selection.
It must be human readable as it is used for labelling the performed actions displayed in the GUI.
- Returns:
str
- catch_rodnumber_change(new_rod: RodNumberWidget, last_id: int) ChangedRodNumberAction[source]
Handles the number/ID change of rods for logging.
Constructs an Action for a number/ID change of a rod that can be used for logging with an ActionLogger.
- Parameters:
new_rod (RodNumberWidget) – The rod in its new (changed) state.
last_id (int) – The rod’s previous ID, i.e. directly prior to the change.
- Returns:
ChangedRodNumberAction
- check_exchange(drop_position)[source]
Evaluates, whether a position is on top of a
RodNumberWidget.Evaluates, whether a position is on top of a
RodNumberWidgetmaintained by this object.
- check_rod_conflicts(set_rod: RodNumberWidget, last_id: int) None[source]
Checks whether a new/changed rod has a number conflict with others.
Checks whether a new/changed rod has an ID that conflicts with is already occupied by one/multiple other rods in this widget. The user is displayed multiple options for resolving these conflicts.
- Parameters:
set_rod (RodNumberWidget) – The rod in its new (changed) state.
last_id (int) – The rod’s previous ID, i.e. directly prior to the change.
- Returns:
None
Hint
Emits:
number_switches[NumberChangeActions, int, int, str]number_switches[NumberChangeActions, int, int, str, int, str]
- create_rod(number: int, new_position: list)[source]
Create a new rod, display it and log this action.
- Parameters:
number (int) –
new_position (list) – Positon coordinates: [x1, y1, x2, y2]
- delete_rod(rod: RodNumberWidget) None[source]
Deletes the given rod, thus sets its position to
(-1, -1).- Parameters:
rod (RodNumberWidget) –
- Returns:
None
- draw_rods() QPixmap | None[source]
Updates the visual display of overlayed rods in the widget.
Updates the visual appearance of all rods that are overlaying the original image. It specifically handles the different visual states a rod can be assigned.
- Returns:
Union[QPixmap, None]
- eventFilter(source: QObject, event: QEvent) bool[source]
Intercepts events, here
QKeyEventsfor frame switching and edit aborting.- Parameters:
source (QObject) –
event (QEvent) –
- Returns:
bool –
True, if the event shall not be propagated further.False, if the event shall be passed to the next object to be handled.
- extract_rods(data: DataFrame, color: str) None[source]
Extract rod positions for a color and create the
RodNumberWidget(s).Extracts the rod position data one color in one frame from
data. It creates theRodNumberWidgetthat is associated with each rod. If a rod has been activated previously, it is attempted to activate a rod with the same number again.- Parameters:
data (DataFrame) – Data from which to extract the 2D rod positions relevant to this camera view. Required columns:
"x1_{self.cam_id}","x2_{self.cam_id}","y1_{self.cam_id}","y2_{self.cam_id}","seen_{self.cam_id}","particle","frame"color (str) – Color of the rods given in
data.
- Returns:
None
- frame(frame: int)[source]
Set the frame number information about the displayed image.
- Parameters:
frame (int) – Frame number that is associated with the currently displayed image.
- image(new_image: QImage)[source]
Show a new image in this widget.
- Parameters:
new_image (QImage) –
- Raises:
ValueError – If the image is Null.
- loaded_rods
Notifies objects, how many rods have just been loaded for display.
- Type:
pyqtSignal(int)
- property logger: ActionLogger
Property that holds a logger object keeping track of users’ actions performed on this widget and its contents.
- Returns:
ActionLogger
- mouseMoveEvent(mouse_event: QMouseEvent) None[source]
Reimplements
QLabel.mouseMoveEvent(event).Handles the drawing and updating of a draft rod during start and end point selection.
- Parameters:
mouse_event (QMouseEvent) –
- Returns:
None
- mousePressEvent(event: QMouseEvent) None[source]
Reimplements
QLabel.mousePressEvent(event).Handles the beginning and ending actions for rod corrections by the user.
- Parameters:
event (QMouseEvent) –
- Returns:
None
- normal_frame_change
Requests a normal change of frame.
The payload is the index of the desired frame, relative to the current one, e.g.
-1to request the previous image.- Type:
pyqtSignal(int)
- notify_undone
Notifies objects, that the
Actionin the payload has been reverted.- Type:
pyqtSignal(Action)
- number_switches
Indicates switches of numbers between rods.
[NumberChangeActions, int, int, str]:
Notifies data maintainance objects, that the user attempts to change rod IDs in more than just the frame displayed by this
RodImageWidget.Payload: type of the attempted change, previous rod ID, new rod ID, and camera ID
[NumberChangeActions, int, int, str, str, int]:
The second version of this signal will be obsolete.
Payload: type of the attempted change, previous rod ID, new rod ID, camera ID, rod color, and frame
- Type:
pyqtSignal
- request_color_change
Request to change the displayed colors.
Currently this is used to revert actions performed on a color other than the displayed one.
- Type:
pyqtSignal(str)
- request_frame_change
Request to change the displayed frames.
Currently this is used to revert actions performed on a frame other than the displayed one.
- Type:
pyqtSignal(int)
- resizeEvent(a0: QResizeEvent) None[source]
Adjust rod positions after resizing of the widget happened, e.g. the slider was actuated or the image was scaled.
- Parameters:
a0 (QResizeEvent) –
- Returns:
None
- rod_activated(rod_id: int) None[source]
Changes the rod state of the one given to active.
The rod state of the rod, which ID is given to active and deactivates all other rods maintained by this widget.
- Parameters:
rod_id (int) – ID of the rod that shall be activated.
- Returns:
None
- property rods: List[RodNumberWidget]
Property that hold
RodNumberWidgetrepresenting rods that are displayable on the Widget.- Returns:
List[RodNumberWidget]
- save_line(start: QPoint, end: QPoint)[source]
Saves a line selected by the user to be a rod with a rod number.
The user’s selected start and end point are saved in a
RodNumberWidget. Either in one that was activated prior to the point selection, or that is selected by the user post point selection as part of this function.- Parameters:
start (QPoint) –
end (QPoint) –
- Returns:
None
- property scale_factor: float
Property that holds the scaling factor by which the original image is scaled when displayed.
- Returns:
float
- scale_to_size(new_size: QSize)[source]
Scales the image to a specified size.
Scales the image to a specified size, while retaining the image’s aspect ratio.
- Parameters:
new_size (QSize) –
- Returns:
None
- set_autoselect(state: bool)[source]
En-/Disable autoselection of rods based on the mouse distance.
- Parameters:
state (bool) – New state of the autoselection.
- static subtract_offset(point: QPoint, offset: List[int]) QPoint[source]
Subtracts a given offset from a point and returns the new point.
- Parameters:
point (QPoint) –
offset (List[int]) –
- Returns:
QPoint
- undo_action(action: Action | ChangeRodPositionAction | ChangedRodNumberAction | DeleteRodAction)[source]
Reverts an
Actionperformed on a rod.Reverts the
Actiongiven this function, if it was constructed by the object. It can handle actions performed on a rod. This includes position changes, number changes and deletions. It returns without further actions, if theActionwas not originally performed on this object or if it has is of an unknown type.- Parameters:
action (Union[Action, ChangeRodPositionAction, ChangedRodNumberAction,) – DeleteRodAction] An
Actionthat was logged previously. It will only be reverted, if it associated with this object.- Returns:
None