TransformState¶
-
class TransformState¶
Bases:
NodeCachedReferenceCountIndicates a coordinate-system transform on vertices. TransformStates are the primary means for storing transformations on the scene graph.
Transforms may be specified in one of two ways: componentwise, with a pos- hpr-scale, or with an arbitrary transform matrix. If you specify a transform componentwise, it will remember its original components.
TransformState objects are managed very much like
RenderStateobjects. They are immutable and reference-counted automatically.You should not attempt to create or modify a TransformState object directly. Instead, call one of the make() functions to create one for you. And instead of modifying a TransformState object, create a new one.
Inheritance diagram
digraph inheritancea48ba2f0f4 { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "CachedTypedWritableReferenceCount" [URL="acron.core.CachedTypedWritableReferenceCount.html#acron.core.CachedTypedWritableReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedWritableReferenceCount" -> "CachedTypedWritableReferenceCount" [arrowsize=0.75,style=""]; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "NodeCachedReferenceCount" [URL="acron.core.NodeCachedReferenceCount.html#acron.core.NodeCachedReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "CachedTypedWritableReferenceCount" -> "NodeCachedReferenceCount" [arrowsize=0.75,style=""]; "ReferenceCount" [URL="acron.core.ReferenceCount.html#acron.core.ReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "ReferenceCount" [arrowsize=0.75,style=""]; "TransformState" [URL="acron.core.TransformState.html#acron.core.TransformState",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "NodeCachedReferenceCount" -> "TransformState" [arrowsize=0.75,style=""]; "TypedObject" [URL="acron.core.TypedObject.html#acron.core.TypedObject",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "TypedObject" [arrowsize=0.75,style=""]; "TypedWritable" [URL="acron.core.TypedWritable.html#acron.core.TypedWritable",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedObject" -> "TypedWritable" [arrowsize=0.75,style=""]; "TypedWritableReferenceCount" [URL="acron.core.TypedWritableReferenceCount.html#acron.core.TypedWritableReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedWritable" -> "TypedWritableReferenceCount" [arrowsize=0.75,style=""]; "ReferenceCount" -> "TypedWritableReferenceCount" [arrowsize=0.75,style=""]; }- TransformState.__eq__()¶
- TransformState.__ne__()¶
- TransformState.cache_ref()¶
Overrides this method to update PStats appropriately.
- TransformState.cache_unref()¶
Overrides this method to update PStats appropriately.
- static TransformState.clear_cache()¶
Empties the cache of composed
TransformStates. This makes everyTransformStateforget what results when it is composed with otherTransformStates.This will eliminate any
TransformStateobjects that have been allocated but have no references outside of the internalTransformStatemap. It will not eliminateTransformStateobjects that are still in use.Nowadays, this method should not be necessary, as reference-count cycles in the composition cache should be automatically detected and broken.
The return value is the number of
TransformStatesfreed by this operation.
- TransformState.compare_to()¶
Provides an arbitrary ordering among all unique
TransformStates, so we can store the essentially different ones in a big set and throw away the rest.Note that if this returns 0, it doesn’t necessarily imply that operator == returns true; it uses a very slightly different comparison threshold.
Provides an arbitrary ordering among all unique
TransformStates, so we can store the essentially different ones in a big set and throw away the rest.Note that if this returns 0, it doesn’t necessarily imply that operator == returns true; it uses a very slightly different comparison threshold.
If uniquify_matrix is true, then matrix-defined
TransformStatesare also uniqified. If uniquify_matrix is false, then only component-definedTransformStatesare uniquified, which is less expensive.
- TransformState.components_given()¶
Returns true if the transform was specified componentwise, or false if it was specified with a general 4x4 matrix. If this is true, the components returned by
get_pos()andget_scale()will be exactly those that were set; otherwise, these functions will return computed values. If this is true, the rotation may have been set either with a hpr trio or with a quaternion;hpr_given()orquat_given()can resolve the difference.
- TransformState.compose()¶
Returns a new
TransformStateobject that represents the composition of this state with the other state.The result of this operation is cached, and will be retained as long as both this
TransformStateobject and the otherTransformStateobject continue to exist. Should one of them destruct, the cached entry will be removed, and its pointer will be allowed to destruct as well.
- static TransformState.garbage_collect()¶
Performs a garbage-collection cycle. This must be called periodically if garbage-collect-states is true to ensure that
TransformStatesget cleaned up appropriately. It does no harm to call it even if this variable is not true, but there is probably no advantage in that case.
- static TransformState.get_class_type()¶
- TransformState.get_composition_cache()¶
- TransformState.get_composition_cache_num_entries()¶
Returns the number of entries in the composition cache for this
TransformState. This is the number of otherTransformStateswhose composition with this one has been cached. This number is not useful for any practical reason other than performance analysis.
- TransformState.get_composition_cache_result()¶
Returns the result
TransformStateof the nth element in the composition cache. Returns NULL if there doesn’t happen to be an entry in the nth element.In general, a->compose(a->get_composition_cache_source(n)) == a->get_composition_cache_result(n).
This has no practical value other than for examining the cache for performance analysis.
- TransformState.get_composition_cache_size()¶
Returns the number of slots in the composition cache for this
TransformState. You may use this as an upper bound when walking through all of the composition cache results viaget_composition_cache_source()or result().This has no practical value other than for examining the cache for performance analysis.
- TransformState.get_composition_cache_source()¶
Returns the source
TransformStateof the nth element in the composition cache. Returns NULL if there doesn’t happen to be an entry in the nth element. Seeget_composition_cache_result().This has no practical value other than for examining the cache for performance analysis.
- TransformState.get_geom_rendering()¶
Returns the union of the Geom::GeomRendering bits that will be required once this
TransformStateis applied to a geom which includes the indicated geom_rendering bits. The RenderState’s get_geom_rendering() should already have been applied.
- TransformState.get_hash()¶
Returns a suitable hash value for phash_map.
- TransformState.get_hpr()¶
Returns the rotation component of the transform as a trio of Euler angles. It is an error to call this if
has_components()returned false.
- TransformState.get_inverse()¶
Returns the inverse of this transform. If you are going to immediately compose this result with another
TransformState, it is faster to do it in one operation withinvert_compose().
- TransformState.get_inverse_mat()¶
Returns the inverse of the matrix, or nullptr if it’s singular.
- TransformState.get_invert_composition_cache()¶
- TransformState.get_invert_composition_cache_num_entries()¶
Returns the number of entries in the invert_composition cache for this
TransformState. This is similar to the composition cache, but it records cache entries for theinvert_compose()operation. Seeget_composition_cache_num_entries().
- TransformState.get_invert_composition_cache_result()¶
Returns the result
TransformStateof the nth element in the invert composition cache. Returns NULL if there doesn’t happen to be an entry in the nth element.In general, a->invert_compose(a->get_invert_composition_cache_source(n)) == a->get_invert_composition_cache_result(n).
This has no practical value other than for examining the cache for performance analysis.
- TransformState.get_invert_composition_cache_size()¶
Returns the number of slots in the composition cache for this
TransformState. You may use this as an upper bound when walking through all of the composition cache results viaget_invert_composition_cache_source()or result().This has no practical value other than for examining the cache for performance analysis.
- TransformState.get_invert_composition_cache_source()¶
Returns the source
TransformStateof the nth element in the invert composition cache. Returns NULL if there doesn’t happen to be an entry in the nth element. Seeget_invert_composition_cache_result().This has no practical value other than for examining the cache for performance analysis.
- TransformState.get_mat()¶
Returns the matrix that describes the transform.
- TransformState.get_mat3()¶
Returns the 3x3 matrix that describes the 2-d transform. It is an error to call this if
is_2d()returned false.
- TransformState.get_norm_quat()¶
Returns the rotation component of the transform as a quaternion. Unlike the result of
get_quat(), the return value of this method is guaranteed to be normalized. It is an error to call this ifhas_components()returned false.
- static TransformState.get_num_states()¶
Returns the total number of unique
TransformStateobjects allocated in the world. This will go up and down during normal operations.
- static TransformState.get_num_unused_states()¶
Returns the total number of
TransformStateobjects that have been allocated but have no references outside of the internalTransformStatecache.A nonzero return value is not necessarily indicative of leaked references; it is normal for two
TransformStateobjects, both of which have references held outside the cache, to have the result of their composition stored within the cache. This result will be retained within the cache until one of the baseTransformStatesis released.Use
list_cycles()to get an idea of the number of actual “leaked”TransformStateobjects.
- TransformState.get_pos()¶
Force interrogate to make a copy as a temporary solution for #1625.
Force interrogate to make a copy as a temporary solution for #1625.
Returns the pos component of the transform. It is an error to call this if
has_pos()returned false.
- TransformState.get_pos2d()¶
Returns the pos component of the 2-d transform. It is an error to call this if
has_pos()oris_2d()returned false.
- TransformState.get_quat()¶
Returns the rotation component of the transform as a quaternion. The return value will be normalized if a normalized quaternion was given to the constructor (or if the quaternion was computed implicitly); it will be non- normalized if a non-normalized quaternion was given to the constructor. See also
get_norm_quat().It is an error to call this if
has_components()returned false.
- TransformState.get_rotate2d()¶
Returns the rotation component of the 2-d transform as an angle in degrees clockwise about the origin. It is an error to call this if
has_components()oris_2d()returned false.
- TransformState.get_scale()¶
Returns the scale component of the transform. It is an error to call this if
has_components()returned false.
- TransformState.get_scale2d()¶
Returns the scale component of the 2-d transform. It is an error to call this if
has_components()oris_2d()returned false.
- TransformState.get_shear()¶
Returns the shear component of the transform. It is an error to call this if
has_components()returned false.
- TransformState.get_shear2d()¶
Returns the shear component of the 2-d transform. It is an error to call this if
has_components()oris_2d()returned false.
- static TransformState.get_states()¶
- TransformState.get_uniform_scale()¶
Returns the scale component of the transform, as a single number. It is an error to call this if
has_uniform_scale()returned false.
- TransformState.get_unique()¶
Returns the pointer to the unique
TransformStatein the cache that is equivalent to this one. This may be the same pointer as this object, or it may be a different pointer; but it will be an equivalent object, and it will be a shared pointer. This may be called from time to time to improve cache benefits.
- static TransformState.get_unused_states()¶
- TransformState.has_components()¶
Returns true if the transform can be described by separate pos, hpr, and scale components. Most transforms we use in everyday life can be so described, but some kinds of transforms (for instance, those involving a skew) cannot.
This is not related to whether the transform was originally described componentwise. Even a transform that was constructed with a 4x4 may return true here if the matrix is a simple affine matrix with no skew.
If this returns true, you may safely call
get_hpr()andget_scale()to retrieve the components. (You may always safely callget_pos()whether this returns true or false.)
- TransformState.has_hpr()¶
Returns true if the transform’s rotation component can be extracted out separately and described as a set of Euler angles. This is generally true only when
has_components()is true.
- TransformState.has_identity_scale()¶
Returns true if the scale is uniform 1.0, or false if the scale has some real value.
- TransformState.has_mat()¶
Returns true if the transform can be described as a matrix. This is generally always true, unless
is_invalid()is true.
- TransformState.has_nonzero_shear()¶
Returns true if the shear component is non-zero, false if it is zero or if the matrix cannot be decomposed.
- TransformState.has_pos()¶
Returns true if the transform’s pos component can be extracted out separately. This is generally always true, unless the transform is invalid (i.e.
is_invalid()returns true).
- TransformState.has_quat()¶
Returns true if the transform’s rotation component can be extracted out separately and described as a quaternion. This is generally true only when
has_components()is true.
- TransformState.has_scale()¶
Returns true if the transform’s scale component can be extracted out separately. This is generally true only when
has_components()is true.
- TransformState.has_shear()¶
Returns true if the transform’s shear component can be extracted out separately. This is generally true only when
has_components()is true.
- TransformState.has_uniform_scale()¶
Returns true if the scale is uniform across all three axes (and therefore can be expressed as a single number), or false if the transform has a different scale in different dimensions.
- TransformState.hpr_given()¶
Returns true if the rotation was specified via a trio of Euler angles, false otherwise. If this is true,
get_hpr()will be exactly as set; otherwise, it will return a computed value.
- TransformState.invert_compose()¶
Returns a new
TransformStateobject that represents the composition of this state’s inverse with the other state.This is similar to
compose(), but is particularly useful for computing the relative state of a node as viewed from some other node.
- TransformState.is_2d()¶
Returns true if the transform has been constructed entirely using the 2-d transform operations, e.g.
make_pos2d(), and therefore operates strictly in two-dimensional space on X and Y only.
- TransformState.is_identity()¶
Returns true if the transform represents the identity matrix, false otherwise.
- TransformState.is_invalid()¶
Returns true if the transform represents an invalid matrix, for instance the result of inverting a singular matrix, or false if the transform is valid.
- TransformState.is_singular()¶
Returns true if the transform represents a singular transform (that is, it has a zero scale, and it cannot be inverted), or false otherwise.
- static TransformState.list_cycles()¶
Detects all of the reference-count cycles in the cache and reports them to standard output.
These cycles may be inadvertently created when state compositions cycle back to a starting point. Nowadays, these cycles should be automatically detected and broken, so this method should never list any cycles unless there is a bug in that detection logic.
The cycles listed here are not leaks in the strictest sense of the word, since they can be reclaimed by a call to
clear_cache(); but they will not be reclaimed automatically.
- static TransformState.list_states()¶
Lists all of the
TransformStatesin the cache to the output stream, one per line. This can be quite a lot of output if the cache is large, so be prepared.
- static TransformState.make_hpr()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_identity()¶
Constructs an identity transform.
- static TransformState.make_invalid()¶
Constructs an invalid transform; for instance, the result of inverting a singular matrix.
- static TransformState.make_mat()¶
Makes a new
TransformStatewith the specified transformation matrix.
- static TransformState.make_mat3()¶
Makes a new two-dimensional
TransformStatewith the specified 3x3 transformation matrix.
- static TransformState.make_pos()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_pos2d()¶
Makes a new 2-d
TransformStatewith the specified components.
- static TransformState.make_pos_hpr()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_pos_hpr_scale()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_pos_hpr_scale_shear()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_pos_quat()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_pos_quat_scale()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_pos_quat_scale_shear()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_pos_rotate2d()¶
Makes a new 2-d
TransformStatewith the specified components.
- static TransformState.make_pos_rotate_scale2d()¶
Makes a new 2-d
TransformStatewith the specified components.
- static TransformState.make_pos_rotate_scale_shear2d()¶
Makes a new two-dimensional
TransformStatewith the specified components.
- static TransformState.make_quat()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_rotate2d()¶
Makes a new 2-d
TransformStatewith the specified components.
- static TransformState.make_scale()¶
Makes a new
TransformStatewith the specified components.Makes a new
TransformStatewith the specified components.
- static TransformState.make_scale2d()¶
Makes a new 2-d
TransformStatewith the specified components.Makes a new 2-d
TransformStatewith the specified components.
- static TransformState.make_shear()¶
Makes a new
TransformStatewith the specified components.
- static TransformState.make_shear2d()¶
Makes a new 2-d
TransformStatewith the specified components.
- TransformState.node_ref()¶
Overrides this method to update PStats appropriately.
- TransformState.node_unref()¶
Overrides this method to update PStats appropriately.
- TransformState.output()¶
- TransformState.quat_given()¶
Returns true if the rotation was specified via a quaternion, false otherwise. If this is true,
get_quat()will be exactly as set; otherwise, it will return a computed value.
- TransformState.set_hpr()¶
Returns a new
TransformStateobject that represents the originalTransformStatewith its rotation component replaced with the indicated value, if possible.
- TransformState.set_pos()¶
Returns a new
TransformStateobject that represents the originalTransformStatewith its pos component replaced with the indicated value.
- TransformState.set_pos2d()¶
Returns a new
TransformStateobject that represents the original 2-dTransformStatewith its pos component replaced with the indicated value.
- TransformState.set_quat()¶
Returns a new
TransformStateobject that represents the originalTransformStatewith its rotation component replaced with the indicated value, if possible.
- TransformState.set_rotate2d()¶
Returns a new
TransformStateobject that represents the original 2-dTransformStatewith its rotation component replaced with the indicated value, if possible.
- TransformState.set_scale()¶
Returns a new
TransformStateobject that represents the originalTransformStatewith its scale component replaced with the indicated value, if possible.
- TransformState.set_scale2d()¶
Returns a new
TransformStateobject that represents the original 2-dTransformStatewith its scale component replaced with the indicated value, if possible.
- TransformState.set_shear()¶
Returns a new
TransformStateobject that represents the originalTransformStatewith its shear component replaced with the indicated value, if possible.
- TransformState.set_shear2d()¶
Returns a new
TransformStateobject that represents the original 2-dTransformStatewith its shear component replaced with the indicated value, if possible.
- TransformState.validate_composition_cache()¶
Returns true if the composition cache and invert composition cache for this particular
TransformStateare self-consistent and valid, false otherwise.
- static TransformState.validate_states()¶
Ensures that the cache is still stored in sorted order, and that none of the cache elements have been inadvertently deleted. Returns true if so, false if there is a problem (which implies someone has modified one of the supposedly-const
TransformStateobjects).
- TransformState.write()¶
- TransformState.write_composition_cache()¶
Writes a brief description of the composition cache and invert composition cache to the indicated ostream. This is not useful except for performance analysis, to examine the cache structure.