chain_tree.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*!
  2. * @file chain.h
  3. * @brief Manages synthesising the user specified tree of nodes (ik_node_t)
  4. * into a structure more optimal for solvers.
  5. *
  6. *
  7. */
  8. #ifndef IK_CHAIN_H
  9. #define IK_CHAIN_H
  10. #include "ik/config.h"
  11. #include "ik/ordered_vector.h"
  12. C_HEADER_BEGIN
  13. struct chain_t
  14. {
  15. /*
  16. * List of ik_node_t* references that belong to this chain.
  17. * NOTE: The first node in this list is the effector (i.e. the *end* of the
  18. * chain). The nodes are in reverse.
  19. */
  20. ordered_vector_t nodes;
  21. /* list of chain_t objects */
  22. ordered_vector_t children;
  23. };
  24. struct chain_island_t
  25. {
  26. chain_t root_chain;
  27. /*
  28. * List of ik_node_t* objects. This list contains the child nodes of IK
  29. * effectors, the children of which aren't part of the IK problem but need
  30. * to be properly updated to match the new transform of the solved tree.
  31. * TODO Is this implemented yet?
  32. */
  33. ordered_vector_t transform_dependent_nodes;
  34. };
  35. struct chain_tree_t
  36. {
  37. ordered_vector_t islands; /* list of chain_island_t objects */
  38. };
  39. void
  40. chain_tree_construct(chain_tree_t* chain_trees);
  41. void
  42. chain_tree_destruct(chain_tree_t* chain_trees);
  43. void
  44. chain_island_construct(chain_island_t* chain_island);
  45. void
  46. chain_island_destruct(chain_island_t* chain_island);
  47. chain_t*
  48. chain_create(void);
  49. void
  50. chain_destroy(chain_t* chain);
  51. /*!
  52. * @brief Initialises an allocated chain object.
  53. */
  54. void
  55. chain_construct(chain_t* chain);
  56. /*!
  57. * @brief Destroys and frees all members, but does not deallocate the chain
  58. * object itself.
  59. */
  60. void
  61. chain_destruct(chain_t* chain);
  62. /*!
  63. * @brief Clears all children and nodes.
  64. */
  65. void
  66. chain_clear_free(chain_t* chain);
  67. /*!
  68. * @brief Breaks down the relevant nodes of the scene graph into a tree of
  69. * chains. FABRIK can then more efficiently solve each chain individually.
  70. *
  71. * A "sub-base joint" is a node in the scene graph where at least two end
  72. * effector nodes eventually join together. FABRIK only works on single
  73. * chains of joints at a time. The end position of every sub-base joint is
  74. * the average of the resulting multiple positions after running FABRIK on
  75. * each chain. Said average position becomes the new target position for
  76. * the next chain connected to it.
  77. *
  78. * This algorithm finds all sub-base joints and generates chains between
  79. * base, sub-base joints, and end effectors. These chains are inserted into
  80. * the chain tree.
  81. */
  82. int
  83. rebuild_chain_tree(ik_solver_t* solver);
  84. void
  85. calculate_segment_lengths(chain_tree_t* chain_tree);
  86. /*!
  87. * @brief Counts all of the chains in the tree, excluding the root chain.
  88. */
  89. int
  90. count_chains_exclude_root(chain_tree_t* chain_tree);
  91. void
  92. calculate_global_rotations(chain_t* chain);
  93. #ifdef IK_DOT_OUTPUT
  94. /*!
  95. * @brief Dumps the chain tree to DOT format.
  96. * @param[in] root The root node of the user created tree. This is a parameter
  97. * because the root chain does not necessarily hold the root node of the tree
  98. * because the root node doesn't have to be part of the IK problem.
  99. * @note Doesn't necessarily have to be the root node, it will dump the tree
  100. * beginning at this node.
  101. * @param[in] chain Usually the root chain. Doesn't necessarily have to be the
  102. * root, in which case it will dump beginning at this chain.
  103. * @param[in] file_name The name of the file to dump to.
  104. */
  105. void
  106. dump_to_dot(ik_node_t* root, chain_tree_t* chain_tree, const char* file_name);
  107. #endif /* IK_DOT_OUTPUT */
  108. C_HEADER_END
  109. #endif /* IK_CHAIN_H */