amino  1.0-beta2
Lightweight Robot Utility Library
scenegraph.h
Go to the documentation of this file.
1 /* -*- mode: C; c-basic-offset: 4; -*- */
2 /* ex: set shiftwidth=4 tabstop=4 expandtab: */
3 /*
4  * Copyright (c) 2015, Rice University
5  * 2020, Colorado School of Mines
6  * All rights reserved.
7  *
8  * Author(s): Neil T. Dantam <ntd@rice.edu>
9  * Matthew A. Schack <mschack@mines.edu>
10  *
11  * Redistribution and use in source and binary forms, with or
12  * without modification, are permitted provided that the following
13  * conditions are met:
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of copyright holder the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
32  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  */
39 
40 #ifndef AMINO_SCENEGRAPH_H
41 #define AMINO_SCENEGRAPH_H
42 
43 #include "amino/mat.h"
44 #include "rxtype.h"
45 
54 typedef signed long aa_rx_frame_id;
55 
59 typedef signed long aa_rx_config_id;
60 
64 #define AA_RX_FRAME_ROOT ((aa_rx_frame_id)-1)
65 AA_EXTERN const aa_rx_frame_id aa_rx_frame_root;
66 
70 #define AA_RX_FRAME_NONE ((aa_rx_frame_id)-2)
71 AA_EXTERN const aa_rx_frame_id aa_rx_frame_none;
72 
76 #define AA_RX_CONFIG_NONE ((aa_rx_config_id)-1)
77 AA_EXTERN const aa_rx_config_id aa_rx_config_none;
78 
82 #define AA_RX_CONFIG_MULTI ((aa_rx_config_id)-2)
83 AA_EXTERN const aa_rx_config_id aa_rx_config_multi;
84 
92 };
93 
97 AA_API struct aa_rx_sg *
99 
103 AA_API void aa_rx_sg_destroy(struct aa_rx_sg *scene_graph);
104 
111 AA_API int aa_rx_sg_init ( struct aa_rx_sg *scene_graph );
112 
121  const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame_id );
122 
129 AA_API const char *
131  const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame_id );
132 
139 AA_API const char *
141  const struct aa_rx_sg *scene_graph, aa_rx_config_id config_id );
142 
151  const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame_id );
152 
153 
157 AA_API size_t
159  const struct aa_rx_sg *scene_graph );
160 
164 AA_API size_t
166  const struct aa_rx_sg *scene_graph );
167 
176  const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame);
177 
182 AA_API size_t
184  const struct aa_rx_sg *scene_graph, size_t n_names,
185  const char **names );
186 
194  const struct aa_rx_sg *scene_graph, const char *config_name);
195 
202 AA_API void
204  const struct aa_rx_sg *scene_graph, size_t n,
205  const char **config_name, aa_rx_config_id *ids );
206 
207 
211 AA_API void
213  const struct aa_rx_sg *scene_graph, size_t n_all, size_t n_subset,
214  const aa_rx_config_id *ids,
215  const double *config_all,
216  double *config_subset );
217 
221 AA_API void
223  const struct aa_rx_sg *scene_graph, size_t n_all, size_t n_subset,
224  const aa_rx_config_id *ids, const double *config_subset,
225  double *config_all
226  );
227 
228 
236  const struct aa_rx_sg *scene_graph, const char *frame_name);
237 
238 
239 /* /\** */
240 /* * Return the index of a configuration variable for the given frame. */
241 /* *\/ */
242 /* AA_API aa_rx_config_id aa_rx_sg_frame_config_id( */
243 /* struct aa_rx_sg *scene_graph, aa_rx_frame_id frame_id); */
244 
261 ( struct aa_rx_sg *scene_graph,
262  const char *parent, const char *name,
263  const double q[4], const double v[3] );
264 
282 ( struct aa_rx_sg *scene_graph,
283  const char *parent, const char *name,
284  const double q[4], const double v[3],
285  const char *config_name,
286  const double axis[3], double offset );
287 
305 ( struct aa_rx_sg *scene_graph,
306  const char *parent, const char *name,
307  const double q[4], const double v[3],
308  const char *config_name,
309  const double axis[3], double offset );
310 
315 ( struct aa_rx_sg *scene_graph,
316  const char *name );
317 
321 AA_API void
322 aa_rx_sg_set_limit_pos( struct aa_rx_sg *scenegraph,
323  const char *config_name,
324  double min, double max );
325 
329 AA_API void
330 aa_rx_sg_set_limit_vel( struct aa_rx_sg *scenegraph,
331  const char *config_name,
332  double min, double max );
333 
337 AA_API void
338 aa_rx_sg_set_limit_acc( struct aa_rx_sg *scenegraph,
339  const char *config_name,
340  double min, double max );
341 
345 AA_API void
346 aa_rx_sg_set_limit_eff( struct aa_rx_sg *scenegraph,
347  const char *config_name,
348  double min, double max );
357 AA_API int
358 aa_rx_sg_get_limit_pos( const struct aa_rx_sg *scenegraph,
359  aa_rx_config_id config_id,
360  double *min, double *max );
361 
370 AA_API int
371 aa_rx_sg_get_limit_vel( const struct aa_rx_sg *scenegraph,
372  aa_rx_config_id config_id,
373  double *min, double *max );
374 
383 AA_API int
384 aa_rx_sg_get_limit_acc( const struct aa_rx_sg *scenegraph,
385  aa_rx_config_id config_id,
386  double *min, double *max );
387 
394 AA_API int
395 aa_rx_sg_get_limit_eff( const struct aa_rx_sg *scenegraph,
396  aa_rx_config_id config_id,
397  double *min, double *max );
398 
399 
403 AA_API double
404 aa_rx_sg_config_center( const struct aa_rx_sg *sg, aa_rx_config_id config_id );
405 
409 AA_API void
411  size_t n, double *q );
412 
419 ( const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame );
420 
421 
422 /* AA_API void */
423 /* aa_rx_sg_tf_alloc( const struct aa_rx_sg *scene_graph, */
424 /* struct aa_mem_region *reg, */
425 /* double **TF_rel, size_t *ld_rel, */
426 /* double **TF_abs, size_t *ld_abs); */
427 
428 /* AA_API void */
429 /* aa_rx_sg_tf_pop( const struct aa_rx_sg *scene_graph, */
430 /* struct aa_mem_region *reg, */
431 /* double *TF_rel, double *TF_abs ); */
432 
433 
434 /* #define AA_RX_SG_TF_ALLOC( SCENE_GRAPH, REG, TF_REL, LD_REL, TF_ABS, LD_ABS ) \ */
435 /* double *TF_REL, *TF_ABS; \ */
436 /* size_t LD_REL, LD_ABS; \ */
437 /* aa_rx_sg_tf_alloc( SCENE_GRAPH, REG, &TF_REL, &LD_REL, &TF_ABS, &LD_ABS ); */
438 
439 /* #define AA_RX_SG_TF_COUNT_GET( SCENE_GRAPH, REG, N_Q, Q, N_TF, TF_REL, LD_REL, TF_ABS, LD_ABS ) \ */
440 /* double *TF_REL, *TF_ABS; \ */
441 /* size_t LD_REL, LD_ABS; \ */
442 /* size_t N_TF = aa_rx_sg_frame_count(SCENE_GRAPH); \ */
443 /* aa_rx_sg_tf_alloc( SCENE_GRAPH, REG, &TF_REL, &LD_REL, &TF_ABS, &LD_ABS ); \ */
444 /* aa_rx_sg_tf(SCENE_GRAPH, N_Q, Q, N_TF, \ */
445 /* TF_REL, LD_REL, \ */
446 /* TF_ABS, LD_ABS ); */ \
447 
448 
449 
470 ( const struct aa_rx_sg *scene_graph,
471  size_t n_q, const double *q,
472  size_t n_tf,
473  double *TF_rel, size_t ld_rel,
474  double *TF_abs, size_t ld_abs );
475 
476 
490 AA_API struct aa_dmat *
491 aa_rx_sg_get_tf_abs( const struct aa_rx_sg *scene_graph,
492  struct aa_mem_region *reg,
493  const struct aa_dvec *q );
494 
495 AA_API void
496 aa_rx_sg_fill_tf_abs( const struct aa_rx_sg *scene_graph,
497  const struct aa_dvec *q,
498  struct aa_dmat *tf_abs );
499 
519 ( const struct aa_rx_sg *scene_graph,
520  size_t n_q, const double *q,
521  size_t n_tf,
522  double *TF_rel, size_t ld_rel,
523  double *TF_abs, size_t ld_abs );
524 
525 
545 ( const struct aa_rx_sg *scene_graph,
546  size_t n_q, const double *q,
547  size_t n_tf,
548  double *TF_rel, size_t ld_rel,
549  double *TF_abs, size_t ld_abs );
550 
580 ( const struct aa_rx_sg *scene_graph,
581  size_t n_q,
582  const double *q0,
583  const double *q,
584  size_t n_tf,
585  const double *TF_rel0, size_t ld_rel0,
586  const double *TF_abs0, size_t ld_abs0,
587  double *TF_rel, size_t ld_rel,
588  double *TF_abs, size_t ld_abs );
589 
590 
591 
603  const struct aa_rx_sg *scene_graph,
604  void (*function)(void *context, aa_rx_frame_id frame_id, struct aa_rx_geom *geom),
605  void *context );
606 
618  const struct aa_rx_sg *scene_graph,
619  const aa_rx_frame_id frame_from,
620  const aa_rx_frame_id frame_to,
621  const double * tf_abs,
622  size_t ld_abs,
623  double * from_tf_to);
624 
628 AA_API void aa_rx_sg_reparent_id ( const struct aa_rx_sg *scene_graph,
629  aa_rx_frame_id new_parent,
630  aa_rx_frame_id frame,
631  const double *E1);
632 
636 AA_API void aa_rx_sg_reparent_name ( const struct aa_rx_sg *scene_graph,
637  const char *new_parent,
638  const char *frame,
639  const double *E1);
640 
646 AA_API struct aa_rx_sg * aa_rx_sg_copy( const struct aa_rx_sg * orig);
647 
651 AA_API void aa_rx_sg_allow_collision( struct aa_rx_sg *scene_graph,
652  aa_rx_frame_id id0, aa_rx_frame_id id1, int allowed );
653 
658  const char* frame0, const char* frame1, int allowed );
659 
660 
661 AA_API void
662 aa_rx_sg_copy_frame_geom( struct aa_rx_sg *scene_graph,
663  const char* src_frame, const char* dst_frame );
664 
665 
666 
670 AA_API double *
671 aa_rx_sg_alloc_tf ( const struct aa_rx_sg *sg, struct aa_mem_region *region );
672 
676 AA_API double *
677 aa_rx_sg_alloc_config ( const struct aa_rx_sg *sg, struct aa_mem_region *region );
678 
679 
680 AA_API void
681 aa_rx_sg_add_octree(
682  struct aa_rx_sg *scene_graph,
683  const char *parent, const char *name,
684  struct aa_rx_octree* ocTree, struct aa_rx_geom_opt* opt);
685 
686 
687 #endif /*AMINO_SCENEGRAPH_H*/
#define AA_API
calling and name mangling convention for functions
Definition: amino.h:95
#define AA_EXTERN
name mangling convention external symbols
Definition: amino.h:97
Block matrix descriptors and linear algebra operations.
Scenegraph-related type declarations.
AA_API void aa_rx_sg_config_indices(const struct aa_rx_sg *scene_graph, size_t n, const char **config_name, aa_rx_config_id *ids)
Return the indices of a configuration variable in the scene graph.
AA_API void aa_rx_sg_add_frame_revolute(struct aa_rx_sg *scene_graph, const char *parent, const char *name, const double q[4], const double v[3], const char *config_name, const double axis[3], double offset)
Add a revolute-joint frame to the scene graph.
AA_API size_t aa_rx_sg_config_count(const struct aa_rx_sg *scene_graph)
Return the number of configuration variables in scene_graph.
AA_API void aa_rx_sg_tf(const struct aa_rx_sg *scene_graph, size_t n_q, const double *q, size_t n_tf, double *TF_rel, size_t ld_rel, double *TF_abs, size_t ld_abs)
Compute transforms for the scene graph as quaternion-translations.
AA_API int aa_rx_sg_get_limit_acc(const struct aa_rx_sg *scenegraph, aa_rx_config_id config_id, double *min, double *max)
Get acceleration limit values.
signed long aa_rx_config_id
Type for configuration indices.
Definition: scenegraph.h:59
AA_API int aa_rx_sg_get_limit_vel(const struct aa_rx_sg *scenegraph, aa_rx_config_id config_id, double *min, double *max)
Get velocity limit values.
AA_API int aa_rx_sg_get_limit_pos(const struct aa_rx_sg *scenegraph, aa_rx_config_id config_id, double *min, double *max)
Get position limit values.
AA_API void aa_rx_sg_set_limit_pos(struct aa_rx_sg *scenegraph, const char *config_name, double min, double max)
Set position limit values.
AA_API void aa_rx_sg_rel_tf(const struct aa_rx_sg *scene_graph, const aa_rx_frame_id frame_from, const aa_rx_frame_id frame_to, const double *tf_abs, size_t ld_abs, double *from_tf_to)
Get transform between two given frames.
AA_API struct aa_dmat * aa_rx_sg_get_tf_abs(const struct aa_rx_sg *scene_graph, struct aa_mem_region *reg, const struct aa_dvec *q)
Allocate and compute absolute transforms for the scene graph.
AA_API aa_rx_config_id aa_rx_sg_frame_config(const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame)
Return the config id of frame.
AA_API aa_rx_frame_id aa_rx_sg_frame_id(const struct aa_rx_sg *scene_graph, const char *frame_name)
Return the index of a frame in the scene graph.
AA_API void aa_rx_sg_tf_update(const struct aa_rx_sg *scene_graph, size_t n_q, const double *q0, const double *q, size_t n_tf, const double *TF_rel0, size_t ld_rel0, const double *TF_abs0, size_t ld_abs0, double *TF_rel, size_t ld_rel, double *TF_abs, size_t ld_abs)
Updated transforms efficiently when only some configurations change.
AA_API void aa_rx_sg_map_geom(const struct aa_rx_sg *scene_graph, void(*function)(void *context, aa_rx_frame_id frame_id, struct aa_rx_geom *geom), void *context)
Call function for every geometry object in the scene graph.
AA_API void aa_rx_sg_add_frame_prismatic(struct aa_rx_sg *scene_graph, const char *parent, const char *name, const double q[4], const double v[3], const char *config_name, const double axis[3], double offset)
Add a prismatic-joint frame to the scene graph.
AA_API const char * aa_rx_sg_config_name(const struct aa_rx_sg *scene_graph, aa_rx_config_id config_id)
Return the config of the given frame.
AA_API aa_rx_frame_id aa_rx_sg_frame_parent(const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame_id)
Return the parent id of the frame.
AA_API void aa_rx_sg_set_limit_vel(struct aa_rx_sg *scenegraph, const char *config_name, double min, double max)
Set velocity limit values.
AA_API void aa_rx_sg_allow_collision(struct aa_rx_sg *scene_graph, aa_rx_frame_id id0, aa_rx_frame_id id1, int allowed)
Set allowed collisions between frames id0 and id1.
AA_API void aa_rx_sg_rm_frame(struct aa_rx_sg *scene_graph, const char *name)
Remove a frame.
AA_API const double * aa_rx_sg_frame_axis(const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame)
Return pointer to frame axis.
AA_API double aa_rx_sg_config_center(const struct aa_rx_sg *sg, aa_rx_config_id config_id)
Get the centered position of a configuration variable.
AA_API void aa_rx_sg_reparent_id(const struct aa_rx_sg *scene_graph, aa_rx_frame_id new_parent, aa_rx_frame_id frame, const double *E1)
Change the parent of frame in the scenegraph.
AA_API double * aa_rx_sg_alloc_tf(const struct aa_rx_sg *sg, struct aa_mem_region *region)
Allocate storage for TF array from region.
AA_API struct aa_rx_sg * aa_rx_sg_copy(const struct aa_rx_sg *orig)
Deeply copy a scenegraph.
AA_API size_t aa_rx_sg_frame_count(const struct aa_rx_sg *scene_graph)
Return the number of frames in scene_graph.
AA_API double * aa_rx_sg_alloc_config(const struct aa_rx_sg *sg, struct aa_mem_region *region)
Allocate storage for config array from region.
AA_API aa_rx_config_id aa_rx_sg_config_id(const struct aa_rx_sg *scene_graph, const char *config_name)
Return the index of a configuration variable in the scene graph.
AA_API void aa_rx_sg_config_get(const struct aa_rx_sg *scene_graph, size_t n_all, size_t n_subset, const aa_rx_config_id *ids, const double *config_all, double *config_subset)
Retrieve a subset of the configuration vector.
AA_API void aa_rx_sg_add_frame_fixed(struct aa_rx_sg *scene_graph, const char *parent, const char *name, const double q[4], const double v[3])
Add a fixed-transform frame to the scene graph.
AA_API void aa_rx_sg_allow_collision_name(struct aa_rx_sg *scene_graph, const char *frame0, const char *frame1, int allowed)
Set allowed collisions between frame0 and frame1.
AA_API void aa_rx_sg_tfmat(const struct aa_rx_sg *scene_graph, size_t n_q, const double *q, size_t n_tf, double *TF_rel, size_t ld_rel, double *TF_abs, size_t ld_abs)
Compute transforms for the scene graph as matrices.
AA_API struct aa_rx_sg * aa_rx_sg_create()
Construct a new, empty scene graph.
AA_API void aa_rx_sg_duqu(const struct aa_rx_sg *scene_graph, size_t n_q, const double *q, size_t n_tf, double *TF_rel, size_t ld_rel, double *TF_abs, size_t ld_abs)
Compute transforms for the scene graph as dual quaternions.
AA_API int aa_rx_sg_init(struct aa_rx_sg *scene_graph)
Setup the scenegraph internal indices.
AA_API int aa_rx_sg_get_limit_eff(const struct aa_rx_sg *scenegraph, aa_rx_config_id config_id, double *min, double *max)
Get effort limit values.
AA_API size_t aa_rx_sg_config_names(const struct aa_rx_sg *scene_graph, size_t n_names, const char **names)
Fill names with pointers to config names.
AA_API void aa_rx_sg_center_configs(const struct aa_rx_sg *sg, size_t n, double *q)
Fill q with the centered positions of each configuration.
AA_API const char * aa_rx_sg_frame_name(const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame_id)
Return the name of the given frame.
AA_API void aa_rx_sg_destroy(struct aa_rx_sg *scene_graph)
Destroy a scene graph.
aa_rx_frame_type
Enum of frame types.
Definition: scenegraph.h:88
@ AA_RX_FRAME_PRISMATIC
A prismatic (sliding) transform.
Definition: scenegraph.h:91
@ AA_RX_FRAME_REVOLUTE
A rotating transform.
Definition: scenegraph.h:90
@ AA_RX_FRAME_FIXED
A fixed transform.
Definition: scenegraph.h:89
AA_API void aa_rx_sg_reparent_name(const struct aa_rx_sg *scene_graph, const char *new_parent, const char *frame, const double *E1)
Change the parent of frame in the scenegraph.
AA_API enum aa_rx_frame_type aa_rx_sg_frame_type(const struct aa_rx_sg *scene_graph, aa_rx_frame_id frame_id)
Return the type of the given frame.
AA_API void aa_rx_sg_set_limit_acc(struct aa_rx_sg *scenegraph, const char *config_name, double min, double max)
Set acceleration limit values.
AA_API void aa_rx_sg_config_set(const struct aa_rx_sg *scene_graph, size_t n_all, size_t n_subset, const aa_rx_config_id *ids, const double *config_subset, double *config_all)
Fill a subset of the configuration vector.
signed long aa_rx_frame_id
Type for frame indices.
Definition: scenegraph.h:54
AA_API void aa_rx_sg_set_limit_eff(struct aa_rx_sg *scenegraph, const char *config_name, double min, double max)
Set effort limit values.
Descriptor for a block matrix.
Definition: mat.h:72
Descriptor for a vector.
Definition: mat.h:63
Data Structure for Region-Based memory allocation.
Definition: mem.h:199
Opaque structure for geometry options.
Definition: rxtype.h:69
Container for scene geometry.
Definition: rxtype.h:63
Opaque type for a scene_graph.