readBF.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_READBF_H
  9. #define IGL_READBF_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <string>
  13. /// @file readBF.h
  14. ///
  15. /// A .bf file contains a “bone forest”. Normally a skeleton for linear blend
  16. /// skinning is a “bone tree” with a single root. But this format may store
  17. /// multiple trees, hence a forest.
  18. ///
  19. /// Each line contains data about a vertex (joint) of the bone forest:
  20. ///
  21. /// [weight index] [parent index] [x] [y] [z] [undocument optional data]
  22. ///
  23. /// Indices begin with 0. The weight index is -1 if the bone does not have an
  24. /// associated weight. The parent index is -1 for root nodes. The x,y,z
  25. /// coordinates are offset vectors from this joint’s parent’s location (for
  26. /// roots, an offset from the origin).
  27. namespace igl
  28. {
  29. /// Read a bones forest from a file, returns a list of bone roots
  30. ///
  31. /// @param[in] file_name path to .bf bones tree file
  32. /// @param[out] WI #B list of unique weight indices
  33. /// @param[out] P #B list of parent indices into B, -1 for roots
  34. /// @param[out] O #B by 3 list of tip offset vectors from parent (or position for roots)
  35. /// @return true on success, false on errors
  36. template <
  37. typename DerivedWI,
  38. typename DerivedP,
  39. typename DerivedO>
  40. IGL_INLINE bool readBF(
  41. const std::string & filename,
  42. Eigen::PlainObjectBase<DerivedWI> & WI,
  43. Eigen::PlainObjectBase<DerivedP> & P,
  44. Eigen::PlainObjectBase<DerivedO> & O);
  45. /// Read bone forest into pure bone-skeleton format, expects only bones (no
  46. /// point handles), and that a root in the .bf <---> no weight attachment.
  47. ///
  48. /// @param[in] file_name path to .bf bones tree file
  49. /// @param[out] WI #B list of unique weight indices
  50. /// @param[out] P #B list of parent indices into B, -1 for roots
  51. /// @param[out] O #B by 3 list of tip offset vectors from parent (or position for roots)
  52. /// @param[out] C #C by 3 list of absolute joint locations
  53. /// @param[out] BE #BE by 3 list of bone indices into C, in order of weight index
  54. /// @param[out] P #BE list of parent bone indices into BE, -1 means root bone
  55. /// @return true on success, false on errors
  56. ///
  57. /// \see readTGF, bone_parents, forward_kinematics
  58. template <
  59. typename DerivedWI,
  60. typename DerivedbfP,
  61. typename DerivedO,
  62. typename DerivedC,
  63. typename DerivedBE,
  64. typename DerivedP>
  65. IGL_INLINE bool readBF(
  66. const std::string & filename,
  67. Eigen::PlainObjectBase<DerivedWI> & WI,
  68. Eigen::PlainObjectBase<DerivedbfP> & bfP,
  69. Eigen::PlainObjectBase<DerivedO> & O,
  70. Eigen::PlainObjectBase<DerivedC> & C,
  71. Eigen::PlainObjectBase<DerivedBE> & BE,
  72. Eigen::PlainObjectBase<DerivedP> & P);
  73. }
  74. #ifndef IGL_STATIC_LIBRARY
  75. # include "readBF.cpp"
  76. #endif
  77. #endif