Эх сурвалжийг харах

missing bone reader

Former-commit-id: 150d59c4a761c79c9b37409315d722041edab44e
Alec Jacobson 9 жил өмнө
parent
commit
f97d42748b

+ 46 - 0
include/igl/readBF.cpp

@@ -0,0 +1,46 @@
+#include "readBF.h"
+#include "list_to_matrix.h"
+#include <vector>
+#include <cstdio>
+#include <fstream>
+template < 
+  typename DerivedWI,
+  typename DerivedP,
+  typename DerivedC>
+IGL_INLINE bool igl::readBF(
+  const std::string & filename,
+  Eigen::PlainObjectBase<DerivedWI> & WI,
+  Eigen::PlainObjectBase<DerivedP> & P,
+  Eigen::PlainObjectBase<DerivedC> & C)
+{
+  using namespace std;
+  ifstream is(filename);
+  if(!is.is_open())
+  {
+    return false;
+  }
+  string line;
+  std::vector<typename DerivedWI::Scalar> vWI;
+  std::vector<typename DerivedP::Scalar> vP;
+  std::vector<std::vector<typename DerivedC::Scalar> > vC;
+  while(getline(is, line))
+  {
+    int wi,p;
+    double cx,cy,cz;
+    if(sscanf(line.c_str(), "%d %d %lg %lg %lg",&wi,&p,&cx,&cy,&cz) != 5)
+    {
+      return false;
+    }
+    vWI.push_back(wi);
+    vP.push_back(p);
+    vC.push_back({cx,cy,cz});
+  }
+  list_to_matrix(vWI,WI);
+  list_to_matrix(vP,P);
+  list_to_matrix(vC,C);
+  return true;
+}
+
+#ifdef IGL_STATIC_LIBRARY
+template bool igl::readBF<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+#endif

+ 30 - 0
include/igl/readBF.h

@@ -0,0 +1,30 @@
+#ifndef IGL_READBF_H
+#define IGL_READBF_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+#include <string>
+namespace igl
+{
+  // Read a bones forest from a file, returns a list of bone roots
+  // Input:
+  //   file_name  path to .bf bones tree file
+  // Output:
+  //   WI  #B list of unique weight indices
+  //   P  #B list of parent indices into B, -1 for roots
+  //   C  #B list of tip positions
+  // Returns true on success, false on errors
+  template < 
+    typename DerivedWI,
+    typename DerivedP,
+    typename DerivedC>
+  IGL_INLINE bool readBF(
+    const std::string & filename,
+    Eigen::PlainObjectBase<DerivedWI> & WI,
+    Eigen::PlainObjectBase<DerivedP> & P,
+    Eigen::PlainObjectBase<DerivedC> & C);
+}
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "readBF.cpp"
+#endif
+#endif