Joint
Description
Default class for joints, i.e. points in space at a specific timestamp. The methods in this class are mainly handled by the methods in the class Pose, but some of them can be directly accessed.
Initialisation
- class krajjat.classes.joint.Joint(joint_label=None, x=None, y=None, z=None)
Creates a Joint instance, with a joint label and x, y, and z coordinates.
New in version 2.0.
- Parameters:
joint_label (str, optional) – The label of the joint (e.g.
"Head").x (float, optional) – The position of the joint on the x-axis (in meters).
y (float, optional) – The position of the joint on the y-axis (in meters).
z (float, optional) – The position of the joint on the z-axis (in meters).
- joint_label
The label of the joint (e.g.
"Head").- Type:
str
- x
The position of the joint on the x-axis (in meters).
- Type:
float
- y
The position of the joint on the y-axis (in meters).
- Type:
float
- z
The position of the joint on the z-axis (in meters).
- Type:
float
- _velocity_over_threshold
Defines if the velocity of this joint, compared to the previous joint, has been found to be over threshold defined in the parameters
Sequence.correct_jitter().- Type:
bool
- _interpolated
Defines if the coordinates of this joint have been modified by
Sequence.correct_zeros().- Type:
bool
- _dejittered
Defines if the coordinates of this joint have been modified by
Sequence.correct_jitter().- Type:
bool
- _rereferenced
Defines if the coordinates of this joint have been modified by
Sequence.re_reference().- Type:
bool
- _randomized
Defines if the coordinates of this joint have been randomly generated by (typically, by
Sequence.randomize()).- Type:
bool
Example
>>> j = Joint("Head", 4.8, 15.16, 23.42)
Magic methods
- Joint.__repr__()
Returns a string containing the joint label, the x, y ans z coordinates, and adds information if one or more of the private attributes
_has_velocity_over_threshold,_is_correctedor_is_randomizedare True.- Returns:
A formatted string of the information contained in all the attributes of the object.
- Return type:
str
Examples
>>> joint = Joint("Head", 4.8, 15.16, 23.42) >>> print(joint) Head: (4.8, 15.16, 23.42)
- Joint.__eq__(other)
Returns True if the attributes
x,y,zandjoint_labelare identical between the twoJointobjects (with a precision of 5 decimal places).New in version 2.0.
Examples
>>> joint_1 = Joint("Head", 1, 2, 3) >>> joint_2 = Joint("Head", 1, 2, 3) >>> joint_1 == joint_2 True >>> joint_3 = Joint("Neck", 1, 2, 3) >>> joint_1 == joint_3 False >>> joint_4 = Joint("Head", 1, 2, 4) >>> joint_1 == joint_4 False >>> joint_5 = joint_1.copy() >>> joint_1 == joint_5 True
- Joint.__getitem__(key)
Returns the value of the coordinate
x,yorzdepending on the value of key. This function is a wrapper forget_coordinate().New in version 2.0.
- Parameters:
key (str) – A coordinate, either
"x","y"or"z".- Returns:
The value of the coordinate.
- Return type:
float|None
- Raises:
InvalidParameterValueException – If the key is neither
"x","y"nor"z".
Example
>>> joint = Joint("Head", 1, 2, 3) >>> joint["x"] 1
- Joint.__setitem__(key, value)
Sets the value of the coordinate
x,yorz. This function is a wrapper forset_position().New in version 2.0.
- Parameters:
key (str) – The coordinate, either
"x","y"or"z".value (float|None) – The value of the coordinate.
- Raises:
InvalidParameterValueException – If the key is neither
"x","y"nor"z".
Example
>>> joint = Joint("Head", 1, 2, 3) >>> joint["x"] = 4 >>> joint.get_x() 4
Public methods
Setter functions
- Joint.set_joint_label(joint_label)
Sets the
joint_labelattribute of the joint.New in version 2.0.
- Parameters:
joint_label (str) – The label of the joint (e.g.
"Head").
Example
>>> joint = Joint() >>> joint.set_joint_label("Hand") >>> print(joint.joint_label) "Hand"
- Joint.set_x(x)
Sets the
xcoordinate of the joint.New in version 2.0.
- Parameters:
x (float|None) – The position of the joint on the x-axis.
Example
>>> joint = Joint("Head", 0, 0, 0) >>> joint.set_x(4) >>> print(joint.get_position()) (4, 0, 0)
- Joint.set_y(y)
Sets the
ycoordinate of the joint.New in version 2.0.
- Parameters:
y (float|None) – The position of the joint on the y-axis.
Example
>>> joint = Joint("Head", 0, 0, 0) >>> joint.set_y(8) >>> print(joint.get_position()) (0, 8, 0)
- Joint.set_z(z)
Sets the
zcoordinate of the joint.New in version 2.0.
- Parameters:
z (float|None) – The position of the joint on the z-axis.
Example
>>> joint = Joint("Head", 0, 0, 0) >>> joint.set_z(15) >>> print(joint.get_position()) (0, 0, 15)
- Joint.set_coordinate(axis, value)
Sets the coordinate on the specified axis (x, y, or z).
New in version 2.0.
- Parameters:
axis (str) – The axis (
"x","y", or"z") on which to set the coordinate.value (float|None) – The value of the coordinate.
Example
>>> joint = Joint("Head", 0, 0, 0) >>> joint.set_coordinate("x", 1) >>> joint.x 1
- Joint.set_position(x, y, z)
Sets the
x,yandzcoordinates of the joint.New in version 2.0.
- Parameters:
x (float|None) – The position of the joint on the x-axis.
y (float|None) – The position of the joint on the y-axis.
z (float|None) – The position of the joint on the z-axis.
Example
>>> joint = Joint() >>> joint.set_position(4, 8, 15)
- Joint.set_to_zero()
Sets the joints coordinates to (0, 0, 0).
New in version 2.0.
Example
>>> joint = Joint() >>> joint.set_to_zero() >>> print(joint.get_position()) (0, 0, 0)
- Joint.set_to_none()
Sets the joints coordinates to (None, None, None).
New in version 2.0.
Example
>>> joint = Joint() >>> joint.set_to_none() >>> print(joint.get_position()) (None, None, None)
Getter functions
- Joint.get_joint_label()
Returns the
joint_labelattribute.New in version 2.0.
- Returns:
The label of the joint (e.g.
"Head").- Return type:
str
Example
>>> joint = Joint("Head", 1, 2, 3) >>> joint.get_joint_label() "Head"
- Joint.get_x()
Returns the
xcoordinate of the joint.New in version 2.0.
- Returns:
The x coordinate of the joint (in meters).
- Return type:
float
Example
>>> joint = Joint("Head", 1, 2, 3) >>> joint.get_x() 1
- Joint.get_y()
Returns the
ycoordinate of the joint.New in version 2.0.
- Returns:
The y coordinate of the joint (in meters).
- Return type:
float
Example
>>> joint = Joint("Head", 1, 2, 3) >>> joint.get_y() 2
- Joint.get_z()
Returns the
zcoordinate of the joint.New in version 2.0.
- Returns:
The z coordinate of the joint (in meters).
- Return type:
float
Example
>>> joint = Joint("Head", 1, 2, 3) >>> joint.get_z() 3
- Joint.get_coordinate(axis)
Returns the coordinate on the specified axis (x, y, or z).
New in version 2.0.
- Parameters:
axis (str) – The axis (
"x","y", or"z") from which to get the coordinate.- Returns:
The x, y or z coordinate of the joint (in meters).
- Return type:
float
- Raises:
InvalidParameterValueException – If the axis is neither
"x","y"nor"z".
Example
>>> joint = Joint("Head", 1, 2, 3) >>> joint.get_coordinate("x") 1 >>> joint.get_coordinate("z") 3
Predicates
- Joint.has_velocity_over_threshold()
Returns the value of the attribute
_has_velocity_over_threshold, which will be True if the distance travelled by this joint over time, compared to the previous joint, has been found to be over threshold defined in the parameters ofSequence.correct_jitter(). This value allows to show the joint in color when displaying the sequence in the functiondisplay_functions.compare_sequences().New in version 2.0.
- Returns:
Value of the attribute
_has_velocity_over_threshold.- Return type:
bool
- Joint.is_corrected()
Returns True if at least one of the values of the attributes
_zero_corrected,_dejittered, or_rereferencedis True. These parameters will be True if they have been modified by eitherSequence.correct_zeros(),Sequence.correct_jitter(), orSequence.re_reference()respectively.New in version 2.0.
- Returns:
Value of the attribute
_is_corrected.- Return type:
bool
- Joint.is_randomized()
Returns the value of the attribute
_is_randomized, which will be True if the coordinates of this joint have been randomly generated bySequence.randomize().New in version 2.0.
- Returns:
Value of the attribute
_is_randomized.- Return type:
bool
- Joint.is_zero()
Returns True if the coordinates of the joint are (0, 0, 0).
… versionadded:: 2.0
- Returns:
True if the coordinates of the joint are (0, 0, 0).
- Return type:
bool
Examples
>>> joint = Joint("Head", 1, 2, 3) >>> joint.is_zero() False >>> joint = Joint("Head", 0, 0, 0) >>> joint.is_zero() True >>> joint = Joint() >>> joint.is_zero() # Joints are None False
- Joint.is_none()
Returns True if the coordinates of the joint are (None, None, None).
… versionadded:: 2.0
- Returns:
True if the coordinates of the joint are (None, None, None).
- Return type:
bool
Examples
>>> joint = Joint("Head", 1, 2, 3) >>> joint.is_none() False >>> joint = Joint("Head", 0, 0, 0) >>> joint.is_none() False >>> joint = Joint() >>> joint.is_none() True
Other methods
- Joint.copy()
Returns a deep copy of itself.
New in version 2.0.
- Returns:
A deep copy of the Joint instance.
- Return type:
- Joint.rotate(yaw=0, pitch=0, roll=0)
Returns converted coordinates given three rotations: yaw, pitch and roll.
New in version 2.0.
Warning
This function is experimental as of version 2.0.
- Parameters:
yaw (float, optional) – The angle of yaw, or rotation on the z-axis, in degrees (default: 0).
pitch (float, optional) – The angle of pitch, or rotation on the y-axis, in degrees (default: 0).
roll (float, optional) – The angle of roll, or rotation on the x-axis, in degrees (default: 0).
- Returns:
float – The converted x coordinate.
float – The converted y coordinate.
float – The converted z coordinate.
Example
>>> joint = Joint("Head", 1, 2, 0) >>> joint.rotate(90, 0, 0) (-2, 1, 0)
Private method
- Joint._randomize_coordinates_keep_movement(joint_pose_0, joint_random, verbosity=1)
Returns a joint with modified coordinates while keeping the relative position compared to the position of the joint at the beginning of the sequence. This function is used by .Sequence.randomize().
New in version 2.0.
- Parameters:
joint_pose_0 (Joint) – The joint from the first pose of the sequence, with the same
joint_label.joint_random (Joint) – A joint with random coordinates, generated by
Sequence.randomize()verbosity (int, optional) –
Sets how much feedback the code will provide in the console output:
0: Silent mode. The code won’t provide any feedback, apart from error messages.
1: Normal mode (default). The code will provide essential feedback such as progression markers and current steps.
2: Chatty mode. The code will provide all possible information on the events happening. Note that this may clutter the output and slow down the execution.
- Returns:
The original joint with added random coordinates.
- Return type: