|
@@ -3,15 +3,17 @@
|
|
|
#include <vector>
|
|
|
#include <cstdio>
|
|
|
#include <fstream>
|
|
|
+#include <cassert>
|
|
|
+#include <functional>
|
|
|
template <
|
|
|
typename DerivedWI,
|
|
|
typename DerivedP,
|
|
|
- typename DerivedC>
|
|
|
+ typename DerivedO>
|
|
|
IGL_INLINE bool igl::readBF(
|
|
|
const std::string & filename,
|
|
|
Eigen::PlainObjectBase<DerivedWI> & WI,
|
|
|
Eigen::PlainObjectBase<DerivedP> & P,
|
|
|
- Eigen::PlainObjectBase<DerivedC> & C)
|
|
|
+ Eigen::PlainObjectBase<DerivedO> & O)
|
|
|
{
|
|
|
using namespace std;
|
|
|
ifstream is(filename);
|
|
@@ -22,7 +24,7 @@ IGL_INLINE bool igl::readBF(
|
|
|
string line;
|
|
|
std::vector<typename DerivedWI::Scalar> vWI;
|
|
|
std::vector<typename DerivedP::Scalar> vP;
|
|
|
- std::vector<std::vector<typename DerivedC::Scalar> > vC;
|
|
|
+ std::vector<std::vector<typename DerivedO::Scalar> > vO;
|
|
|
while(getline(is, line))
|
|
|
{
|
|
|
int wi,p;
|
|
@@ -33,14 +35,73 @@ IGL_INLINE bool igl::readBF(
|
|
|
}
|
|
|
vWI.push_back(wi);
|
|
|
vP.push_back(p);
|
|
|
- vC.push_back({cx,cy,cz});
|
|
|
+ vO.push_back({cx,cy,cz});
|
|
|
}
|
|
|
list_to_matrix(vWI,WI);
|
|
|
list_to_matrix(vP,P);
|
|
|
- list_to_matrix(vC,C);
|
|
|
+ list_to_matrix(vO,O);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+template <
|
|
|
+ typename DerivedWI,
|
|
|
+ typename DerivedbfP,
|
|
|
+ typename DerivedO,
|
|
|
+ typename DerivedC,
|
|
|
+ typename DerivedBE,
|
|
|
+ typename DerivedP>
|
|
|
+IGL_INLINE bool igl::readBF(
|
|
|
+ const std::string & filename,
|
|
|
+ Eigen::PlainObjectBase<DerivedWI> & WI,
|
|
|
+ Eigen::PlainObjectBase<DerivedbfP> & bfP,
|
|
|
+ Eigen::PlainObjectBase<DerivedO> & offsets,
|
|
|
+ Eigen::PlainObjectBase<DerivedC> & C,
|
|
|
+ Eigen::PlainObjectBase<DerivedBE> & BE,
|
|
|
+ Eigen::PlainObjectBase<DerivedP> & P)
|
|
|
+{
|
|
|
+ using namespace Eigen;
|
|
|
+ using namespace std;
|
|
|
+ if(!readBF(filename,WI,bfP,offsets))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ C.resize(WI.rows(),3);
|
|
|
+ vector<bool> computed(C.rows(),false);
|
|
|
+ // better not be cycles in bfP
|
|
|
+ std::function<Eigen::RowVector3d(const int)> locate_tip;
|
|
|
+ locate_tip =
|
|
|
+ [&offsets,&computed,&bfP,&locate_tip,&C](const int w)->Eigen::RowVector3d
|
|
|
+ {
|
|
|
+ if(w<0) return Eigen::RowVector3d(0,0,0);
|
|
|
+ if(computed[w]) return C.row(w);
|
|
|
+ computed[w] = true;
|
|
|
+ return C.row(w) = locate_tip(bfP(w)) + offsets.row(w);
|
|
|
+ };
|
|
|
+ int num_roots = (bfP.array() == -1).count();
|
|
|
+ BE.resize(WI.rows()-num_roots,2);
|
|
|
+ P.resize(BE.rows());
|
|
|
+ for(int c = 0;c<C.rows();c++)
|
|
|
+ {
|
|
|
+ locate_tip(c);
|
|
|
+ assert(c>=0);
|
|
|
+ // weight associated with this bone
|
|
|
+ const int wi = WI(c);
|
|
|
+ if(wi >= 0)
|
|
|
+ {
|
|
|
+ // index into C
|
|
|
+ const int p = bfP(c);
|
|
|
+ assert(p >= 0 && "No weights for roots allowed");
|
|
|
+ // index into BE
|
|
|
+ const int pwi = WI(p);
|
|
|
+ P(wi) = pwi;
|
|
|
+ BE(wi,0) = p;
|
|
|
+ BE(wi,1) = 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> >&);
|
|
|
+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>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::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> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
|
|
|
#endif
|