MMatrix* AMCParser::loadMocapData(std::string filePath,AMC_OPTIONS opts) { std::ifstream loader(filePath); if(loader.fail()) return false; std::string strContent; while(strContent != "1") std::getline(loader,strContent); std::vector<std::vector<float>> RawData; while(!loader.eof()) { int curDOF = 0; std::vector<float> pose(mTotalDOF); std::getline(loader,strContent); while(strContent.length() && (strContent[0] <= '0' || strContent[0] >'9')) { std::stringstream filter(strContent); filter >> strContent; while(!filter.eof()) filter >> pose[curDOF++]; std::getline(loader,strContent); } RawData.push_back(pose); } MMatrix *data = new MMatrix(RawData.size(),RawData[0].size()); for(size_t i = 0;i < data->sizeRow(); i++) for(size_t j = 0; j < data->sizeCol(); j++) data->assign(RawData[i][j],i,j); return data; }
void Kernel::computeDiag(MMatrix &d, const MMatrix &X) const { assert(X.rowsMatch(d) && d.sizeCol()== 1); size_t nRows = X.sizeRow(); for(size_t t = 0; t < nRows; t++) d.assign(computeDiagElement(X,t),t); }
void Kernel::computeKernel(MMatrix &K, const MMatrix &X) const { assert(K.rowsMatch(X) && K.isSquare()); for(size_t i = 0; i < K.sizeRow(); i++) { for(size_t j = 0; j < i; j++) { double k = computeElement(X, i, X, j); K.assign(k,i,j); K.assign(k,j,i); } K.assign(computeDiagElement(X,i), i, i); } }
void Kernel::getParams(MMatrix &parmas) const { for(size_t i = 0; i < mhps.size(); i++) { parmas.assign(getParam(i),i); } }
void Transformable::getParams(MMatrix& matParams) const { assert(matParams.sizeCol() == 1 && matParams.sizeRow() == getNumParams()); for(size_t i = 0; i < matParams.sizeCol(); i++) { matParams.assign(getParam(i), i); } }
void Transformable::getTransParams(MMatrix& matTransParams) const { //assert(matTransParams.sizeCol() == 1 && matTransParams.sizeRow() == getNumParams()); for(size_t i = 0; i < matTransParams.sizeCol(); i++) { matTransParams.assign(m_vTransform[i]->XtoA(getParam(i)), i); } }
void Kernel::computeKernel(MMatrix& K, const MMatrix& X, const MMatrix& X2, size_t row) const { assert(K.rowsMatch(X) && K.sizeCol() == 1); for(size_t i = 0; i < K.sizeRow(); i++) { K.assign(computeElement(X,i,X2,row),i, 0); } }
void Kernel::computeKernel(MMatrix &K, const MMatrix &X, const MMatrix &X2) const { assert(K.rowsMatch(X) && K.sizeCol() == X2.sizeRow()); for(size_t i = 0; i < K.sizeRow(); i++) { for(size_t j = 0; j < K.sizeCol(); j++) { K.assign(computeElement(X, i, X2, j), i, j); } } }
void Kernel::getGradientParams(MMatrix &g, const MMatrix &X, const MMatrix &X2,const MMatrix &cvGrad,bool regularise) const { assert(g.sizeRow() == 1 && g.sizeCol() == mhps.size()); for(size_t t = 0; t < mhps.size(); t++) { g.assign(getGradientParam(t,X,X2,cvGrad),t); } if(regularise) { // AddPriorGrad(g); } }
void Transformable::getGradientTransParams(MMatrix& matGrad) const { assert(matGrad.sizeCol() == 1 && matGrad.sizeRow() == getNumParams()); getGradientParams(matGrad); size_t unParamsNum = getNumTransform(); for(size_t i = 0; i < unParamsNum; i++) { double tdVal = matGrad.get(i); double tdValX = getParam(i); matGrad.assign(tdVal * m_vTransform[i]->Gradient(tdValX),i); } }
void Kernel::getGradTransParams(MMatrix& g, const MMatrix& X, const MMatrix& cvGrd, bool regularise) const { assert(g.sizeRow()==1); assert(g.sizeCol()== mhps.size()); getGradientParams(g, X,cvGrd, regularise); for(size_t i = 0; i < getNumTransform(); i++) { double val = g.get(i); double param = getParam(i); g.assign(val * getGradientTransform(param, i),i); } }
void MotionSyn::toCircle(MMatrix & mat) const { for (size_t i = 1; i < mSegments.size(); i++) { double theta = mFactors[0]->get(i-1, 0); double delta = mFactors[0]->get(i-1, 1); for (size_t j = mSegments[i-1]; j < mSegments[i]; j++) { double cosTheta = cos(theta + (j - mSegments[i-1]) * delta); double sinTheta = sin(theta + (j - mSegments[i-1]) * delta); mat.assign(cosTheta, j, 0); mat.assign(sinTheta, j, 1); //precompute for saving time //mGradTs[0]->assign(-sinTheta, j, 0); //mGradTs[0]->assign( cosTheta, j, 1); //mGradTs[1]->assign(-sinTheta*(j - mSegments[i-1]), j, 0); //mGradTs[1]->assign( cosTheta*(j - mSegments[i-1]), j, 1); } } }