// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2016 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "readBF.h" #include "list_to_matrix.h" #include #include #include #include #include template < typename DerivedWI, typename DerivedP, typename DerivedO> IGL_INLINE bool igl::readBF( const std::string & filename, Eigen::PlainObjectBase & WI, Eigen::PlainObjectBase & P, Eigen::PlainObjectBase & O) { using namespace std; ifstream is(filename); if(!is.is_open()) { return false; } string line; std::vector vWI; std::vector vP; std::vector > vO; 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); vO.push_back({cx,cy,cz}); } list_to_matrix(vWI,WI); list_to_matrix(vP,P); 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 & WI, Eigen::PlainObjectBase & bfP, Eigen::PlainObjectBase & offsets, Eigen::PlainObjectBase & C, Eigen::PlainObjectBase & BE, Eigen::PlainObjectBase & P) { using namespace Eigen; using namespace std; if(!readBF(filename,WI,bfP,offsets)) { return false; } C.resize(WI.rows(),3); vector computed(C.rows(),false); // better not be cycles in bfP std::function 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=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, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif