···11+Rename `xrt_space_graph` (and related `m_space_graph_*` functions in `m_space.h`) to `xrt_relation_chain` to more accurately reflect the function of this structure.
+17-17
src/xrt/auxiliary/math/m_space.cpp
···22// SPDX-License-Identifier: BSL-1.0
33/*!
44 * @file
55- * @brief Functions for manipulating a @ref xrt_space_graph struct.
55+ * @brief Functions for manipulating a @ref xrt_relation_chain struct.
66 * @author Jakob Bornecrantz <jakob@collabora.com>
77 * @ingroup aux_math
88 */
···6161}
62626363static void
6464-dump_graph(const struct xrt_space_graph *xsg)
6464+dump_chain(const struct xrt_relation_chain *xrc)
6565{
6666- fprintf(stderr, "%s %u\n", __func__, xsg->step_count);
6767- for (uint32_t i = 0; i < xsg->step_count; i++) {
6868- const struct xrt_space_relation *r = &xsg->steps[i];
6666+ fprintf(stderr, "%s %u\n", __func__, xrc->step_count);
6767+ for (uint32_t i = 0; i < xrc->step_count; i++) {
6868+ const struct xrt_space_relation *r = &xrc->steps[i];
6969 fprintf(stderr, "\t%2u: ", i);
7070 dump_relation(r);
7171 }
···7979 */
80808181static bool
8282-has_step_with_no_pose(const struct xrt_space_graph *xsg)
8282+has_step_with_no_pose(const struct xrt_relation_chain *xrc)
8383{
8484 const enum xrt_space_relation_flags pose_flags = (enum xrt_space_relation_flags)(
8585 XRT_SPACE_RELATION_POSITION_VALID_BIT | XRT_SPACE_RELATION_ORIENTATION_VALID_BIT);
86868787- for (uint32_t i = 0; i < xsg->step_count; i++) {
8888- const struct xrt_space_relation *r = &xsg->steps[i];
8787+ for (uint32_t i = 0; i < xrc->step_count; i++) {
8888+ const struct xrt_space_relation *r = &xrc->steps[i];
8989 if ((r->relation_flags & pose_flags) == 0) {
9090 return true;
9191 }
···216216 struct xrt_pose body_pose = XRT_POSE_IDENTITY;
217217 struct xrt_pose base_pose = XRT_POSE_IDENTITY;
218218219219- // Only valid poses handled in graph. Flags are determined later.
219219+ // Only valid poses handled in chain. Flags are determined later.
220220 make_valid_pose(af, &a->pose, &body_pose);
221221 make_valid_pose(bf, &b->pose, &base_pose);
222222···276276 */
277277278278void
279279-m_space_graph_resolve(const struct xrt_space_graph *xsg, struct xrt_space_relation *out_relation)
279279+m_relation_chain_resolve(const struct xrt_relation_chain *xrc, struct xrt_space_relation *out_relation)
280280{
281281- if (xsg->step_count == 0 || has_step_with_no_pose(xsg)) {
281281+ if (xrc->step_count == 0 || has_step_with_no_pose(xrc)) {
282282 *out_relation = XRT_SPACE_RELATION_ZERO;
283283 return;
284284 }
285285286286- struct xrt_space_relation r = xsg->steps[0];
287287- for (uint32_t i = 1; i < xsg->step_count; i++) {
288288- apply_relation(&r, &xsg->steps[i], &r);
286286+ struct xrt_space_relation r = xrc->steps[0];
287287+ for (uint32_t i = 1; i < xrc->step_count; i++) {
288288+ apply_relation(&r, &xrc->steps[i], &r);
289289 }
290290291291#if 0
292292- dump_graph(xsg);
292292+ dump_chain(xrc);
293293 fprintf(stderr, "\tRR: ");
294294 dump_relation(&r);
295295#else
296296- (void)dump_graph;
296296+ (void)dump_chain;
297297#endif
298298299299- // Ensure no errors has crept in.
299299+ // Ensure no errors have crept in.
300300 math_quat_normalize(&r.pose.orientation);
301301302302 *out_relation = r;
+55-20
src/xrt/auxiliary/math/m_space.h
···33/*!
44 * @file
55 * @brief Functions for manipulating @ref xrt_pose, @ref xrt_space_relation and
66- * @ref xrt_space_graph structs.
66+ * @ref xrt_relation_chain structs.
77 * @author Jakob Bornecrantz <jakob@collabora.com>
88 * @ingroup aux_math
99 */
···85858686/*
8787 *
8888- * Space graph functions.
8888+ * Relation chain functions.
8989 *
9090 */
91919292/*!
9393- * Reserve a step in the graph and return a pointer to the relation.
9393+ * Reserve a step in the chain and return a pointer to the relation.
9494+ *
9595+ * @note The data pointed to by the returned pointer is not initialized:
9696+ * you must populate it before using @ref m_relation_chain_resolve
9797+ *
9898+ * @public @memberof xrt_relation_chain
9499 */
95100static inline struct xrt_space_relation *
9696-m_space_graph_reserve(struct xrt_space_graph *xsg)
101101+m_relation_chain_reserve(struct xrt_relation_chain *xrc)
97102{
9898- if (xsg->step_count < XRT_SPACE_GRAPHS_MAX) {
9999- return &xsg->steps[xsg->step_count++];
103103+ if (xrc->step_count < XRT_RELATION_CHAIN_CAPACITY) {
104104+ return &xrc->steps[xrc->step_count++];
100105 } else {
101106 return NULL;
102107 }
103108}
104109105110/*!
106106- * Flattens a space graph into a single relation.
111111+ * Append a new relation
112112+ *
113113+ * @public @memberof xrt_relation_chain
107114 */
108115static inline void
109109-m_space_graph_add_relation(struct xrt_space_graph *xsg, const struct xrt_space_relation *relation)
116116+m_relation_chain_push_relation(struct xrt_relation_chain *xrc, const struct xrt_space_relation *relation)
110117{
111111- if (xsg->step_count >= XRT_SPACE_GRAPHS_MAX) {
118118+ if (xrc->step_count >= XRT_RELATION_CHAIN_CAPACITY) {
112119 return;
113120 }
114121115115- xsg->steps[xsg->step_count++] = *relation;
122122+ xrc->steps[xrc->step_count++] = *relation;
116123}
117124125125+/*!
126126+ * Append the inverse of the provided relation.
127127+ *
128128+ * Validity flags stay the same, only the pose and velocities are inverted.
129129+ *
130130+ * @public @memberof xrt_relation_chain
131131+ */
118132static inline void
119119-m_space_graph_add_inverted_relation(struct xrt_space_graph *xsg, const struct xrt_space_relation *relation)
133133+m_relation_chain_push_inverted_relation(struct xrt_relation_chain *xrc, const struct xrt_space_relation *relation)
120134{
121135 struct xrt_space_relation r = *relation;
122136123137 struct xrt_space_relation invert;
124138 m_space_relation_invert(&r, &invert);
125125- m_space_graph_add_relation(xsg, &invert);
139139+ m_relation_chain_push_relation(xrc, &invert);
126140}
127141142142+/*!
143143+ * Append a new pose as a relation without velocity
144144+ *
145145+ * @public @memberof xrt_relation_chain
146146+ */
128147static inline void
129129-m_space_graph_add_pose(struct xrt_space_graph *xsg, const struct xrt_pose *pose)
148148+m_relation_chain_push_pose(struct xrt_relation_chain *xrc, const struct xrt_pose *pose)
130149{
131150 struct xrt_space_relation relation;
132151 m_space_relation_from_pose(pose, &relation);
133133- m_space_graph_add_relation(xsg, &relation);
152152+ m_relation_chain_push_relation(xrc, &relation);
134153}
135154155155+/*!
156156+ * Append a new pose as a relation without velocity, if it is not the identity pose.
157157+ *
158158+ * @public @memberof xrt_relation_chain
159159+ */
136160static inline void
137137-m_space_graph_add_pose_if_not_identity(struct xrt_space_graph *xsg, const struct xrt_pose *pose)
161161+m_relation_chain_push_pose_if_not_identity(struct xrt_relation_chain *xrc, const struct xrt_pose *pose)
138162{
139163 struct xrt_pose p = *pose;
140164···142166 return;
143167 }
144168145145- m_space_graph_add_pose(xsg, &p);
169169+ m_relation_chain_push_pose(xrc, &p);
146170}
147171172172+/*!
173173+ * Append the inverse of a pose as a relation without velocity, if it is not the identity pose.
174174+ *
175175+ * Validity flags stay the same, only the pose is inverted.
176176+ *
177177+ * @public @memberof xrt_relation_chain
178178+ */
148179static inline void
149149-m_space_graph_add_inverted_pose_if_not_identity(struct xrt_space_graph *xsg, const struct xrt_pose *pose)
180180+m_relation_chain_push_inverted_pose_if_not_identity(struct xrt_relation_chain *xrc, const struct xrt_pose *pose)
150181{
151182 struct xrt_pose p = *pose;
152183···156187157188 struct xrt_pose invert;
158189 math_pose_invert(&p, &invert);
159159- m_space_graph_add_pose(xsg, &invert);
190190+ m_relation_chain_push_pose(xrc, &invert);
160191}
161192162193/*!
163163- * Flattens a space graph into a single relation.
194194+ * Compute the equivalent single relation from flattening a relation chain.
195195+ *
196196+ * The input chain is not modified.
197197+ *
198198+ * @public @memberof xrt_relation_chain
164199 */
165200void
166166-m_space_graph_resolve(const struct xrt_space_graph *xsg, struct xrt_space_relation *out_relation);
201201+m_relation_chain_resolve(const struct xrt_relation_chain *xrc, struct xrt_space_relation *out_relation);
167202168203/*!
169204 * @}
+5-5
src/xrt/auxiliary/util/u_hand_tracking.c
···662662 l[i].relation.relation_flags |= data->relation.relation_flags;
663663 l[i].radius = hand_joint_default_set_curl_model_defaults[i].radius;
664664665665- struct xrt_space_graph graph = {0};
666666- m_space_graph_add_relation(&graph, &data->relation);
667667- m_space_graph_add_pose(&graph, hand_offset);
668668- m_space_graph_resolve(&graph, &l[i].relation);
665665+ struct xrt_relation_chain chain = {0};
666666+ m_relation_chain_push_relation(&chain, &data->relation);
667667+ m_relation_chain_push_pose(&chain, hand_offset);
668668+ m_relation_chain_resolve(&chain, &l[i].relation);
669669670670 // joint relations can not be "more valid" than the hand relation
671671- // after space graph to make sure flags are not "upgraded"
671671+ // after relation chain to make sure flags are not "upgraded"
672672 l[i].relation.relation_flags &= hand_relation->relation_flags;
673673 }
674674
···486486 }
487487488488/*!
489489- * The maximum number of steps that can be in a space graph chain.
489489+ * The maximum number of steps that can be in a relation chain.
490490 *
491491- * @see xrt_space_graph::steps
491491+ * @see xrt_relation_chain::steps
492492+ * @relates xrt_relation_chain
492493 * @ingroup xrt_iface math
493494 */
494494-#define XRT_SPACE_GRAPHS_MAX 8
495495+#define XRT_RELATION_CHAIN_CAPACITY 8
495496496497/*!
497497- * A graph of space relations, technically more of a chain of transformation
498498- * since it's not branching, but a flat graph is still a graph. Functions for
499499- * manipulating this are available in `math/m_space.h`.
498498+ * A chain of space relations and their associated validity flags.
499499+ * Functions for manipulating this are available in `math/m_space.h`.
500500 *
501501 * @see xrt_space_relation
502502 * @ingroup xrt_iface math
503503 */
504504-struct xrt_space_graph
504504+struct xrt_relation_chain
505505{
506506- struct xrt_space_relation steps[XRT_SPACE_GRAPHS_MAX];
506506+ struct xrt_space_relation steps[XRT_RELATION_CHAIN_CAPACITY];
507507 uint32_t step_count;
508508};
509509