void add_train( string item, int label, MatVec & images, IntVec & labels ) { Mat img = load(item); if ( img.empty() ) return ; images.push_back(img); labels.push_back(label); }
template <class F> CpuIterativeSolver<F>::CpuIterativeSolver (const DDAParams<ftype>& ddaParams, MatVec<ftype>& matVec, csize_t maxResIncrease, csize_t maxIter) : IterativeSolverBase<ftype> (ddaParams, maxResIncrease, maxIter), matVec_ (matVec), Avecbuffer_ (g ().vecSize ()), rvec_ (g ().vecSize ()), xvec_ (g ().vecSize ()), tmpVec1_ (g ().vecSize ()) { ASSERT (g ().procs () == 1); ASSERT (&ddaParams == &matVec.ddaParams ()); }
bool MaxScene::Load(const char *filename) { this->meshes.clear(); this->mins = vec3::bogus_max; this->maxs = vec3::bogus_min; this->origin = vec3::zero; FILE *fp = fopen(filename, "rb"); if (!fp) return false; U32 id, version; fread(&id, sizeof(U32), 1, fp); fread(&version, sizeof(U32), 1, fp); if (id != Id || (version < Version2 || version > Version)) { fclose(fp); return false; } MatVec mats; U32 n; // materials. std::vector<std::string> matnames; fread(&n, sizeof(U32), 1, fp); for (U32 i = 0; i < n; ++i) { Material m; m.name = ReadString(fp); fread(&m.flags, sizeof(U32), 1, fp); if (m.flags & 1) // multisub { U32 z; fread(&z, sizeof(U32), 1, fp); for (U32 j = 0; j < z; ++j) { Material::Sub s; fread(&s.id, sizeof(U32), 1, fp); s.name = ReadString(fp); s.emitId = (UReg)matnames.size(); matnames.push_back(s.name); m.subs.insert(Material::SubHash::value_type(s.id, s)); } } else { m.emitId = (UReg)matnames.size(); matnames.push_back(m.name); } mats.push_back(m); } if (version > Version2) // load cameras (tread discards all this) { fread(&n, sizeof(U32), 1, fp); for (U32 i = 0; i < n; ++i) { U32 unused, z; ReadString(fp); fread(&unused, sizeof(U32), 1, fp); fread(&unused, sizeof(U32), 1, fp); fread(&z, sizeof(U32), 1, fp); fread(&unused, sizeof(U32), 1, fp); for (U32 k = 0; k < z; ++k) { ReadString(fp); fread(&unused, sizeof(U32), 1, fp); fread(&unused, sizeof(U32), 1, fp); U32 numFrames; fread(&numFrames, sizeof(U32), 1, fp); for (U32 j = 0; j < numFrames; ++j) { fread(&unused, sizeof(U32), 1, fp); ReadBoneTM(fp); ReadString(fp); } } } } // entities fread(&n, sizeof(U32), 1, fp); TriModel mdl; for (U32 i = 0; i < n; ++i) { ReadString(fp); U32 unused; fread(&unused, sizeof(U32), 1, fp); origin += ReadVec3(fp); U32 z; fread(&z, sizeof(U32), 1, fp); std::vector<int> skelBoneCounts; skelBoneCounts.reserve(z); // skels. for (U32 j = 0; j < z; ++j) { U32 numBones; fread(&numBones, sizeof(U32), 1, fp); skelBoneCounts.push_back(numBones); for (U32 b = 0; b < numBones; ++b) { ReadString(fp); fread(&unused, sizeof(U32), 1, fp); ReadMat3(fp); } } fread(&z, sizeof(U32), 1, fp); for (U32 j = 0; j < z; ++j) { Material *m = 0; U32 flags; S32 skel; fread(&mdl.id, sizeof(int), 1, fp); fread(&flags, sizeof(U32), 1, fp); fread(&skel, sizeof(S32), 1, fp); if (flags & HasMaterialFlag) // has material { U32 idx; fread(&idx, sizeof(U32), 1, fp); m = &mats[idx]; } /*if (flags & 0x40000000) { mdl.contents = Map::ContentsDetail; } else if (flags & 0x20000000) { mdl.contents = Map::ContentsAreaportal; } else { mdl.contents = Map::ContentsSolid; } if (!(flags & 0x00800000)) { mdl.contents |= Map::ContentsNoClip; } if (!(flags & 0x00400000)) { mdl.contents |= Map::ContentsNoDraw; }*/ if (flags&(HasMeshFlag|HasAnimsFlag)) ReadTriModel(fp, version, mdl, flags, skel >= 0 ? skelBoneCounts[skel] : 0); if (!mdl.tris.empty()) { for (TriFaceVec::iterator it = mdl.tris.begin(); it != mdl.tris.end(); ++it) { if (m) { Material::SubHash::iterator sub = m->subs.find((U32)it->mat); if (sub != m->subs.end()) { it->mat = (int)sub->second.emitId; } else { it->mat = m->emitId; } } else { it->mat = -1; } } Build(matnames, mdl, this->meshes, this->mins, this->maxs); } } } this->origin /= (float)n; fclose(fp); return true; }
/*! * A const function that for every value in a vector calculates the matrix * exponential of the matrix multiplied with that value * The exponential is calculated by finding the eigenvalues and eigenvectors * of the matrix, exponentiating the eigenvalues. The eigenvalues is stored in * a matrix V, eigenvectors is stored in a matrix A, inv(A) is calculated. * The product A*V*inv(A) is returned. * @param s A vector with values to be multiplied with the matrix before * the exponent is calculated. * @return A vector with the exponential of the matrix multiplied with every * value in s */ MatVec Matrix::expm(const DblVec &s) const { // Can only calculate eigenvalues and vectors of square matrices if (get_rows() != get_cols()) throw std::out_of_range("Matrix needs to be square"); int size = get_rows(); DblVec eg_val_real(size, 0); // Real part of eigenvalues DblVec eg_val_im(size, 0); // Imaginary part of eigenvalues // should be zero double dummy[1]; int dummy_size = 1; double dummy_one = 1; int info[1]; char n = 'N'; // Do not want to use this argument char v = 'V'; // Want to use this argument double workspace_size[1]; int w_query = -1; // Need to make a copy of the data in Q to send into dgeev_ because // the data sent in is overwritten int data_size = get_rows()*get_cols(); DblVec data(m_data); // Matrix for the eigenvectors Matrix t_mat = Matrix(size, size); //workspace-query // SUBROUTINE DGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR, // LDVR, WORK, LWORK, INFO ) dgeev_(&n, &v, &size, &data[0], &size, &eg_val_real[0], &eg_val_im[0], dummy, &dummy_size, &t_mat.m_data[0], &size, workspace_size, &w_query, info); DblVec workspace_vec(static_cast<int>(workspace_size[0]), 0); int w_size = static_cast<int>(workspace_size[0]); // Real calculation of eigenvalues and eigenvectors for Q dgeev_(&n, &v, &size, &data[0], &size, &eg_val_real[0], &eg_val_im[0], dummy, &dummy_size, &t_mat.m_data[0], &size, &workspace_vec[0], &w_size, info); // Calculating inverse of matrix with eigenvectors Matrix t_mat_inv(t_mat); int ipiv[size]; // LU factorization, t_mat_inv.m_data is overwritten with the LU factorization dgetrf_(&size, &size, &t_mat_inv.m_data[0], &size, ipiv, info); //workspace-query, nothing happens with t_mat_inv.m_data dgetri_(&size, &t_mat_inv.m_data[0], &size, ipiv, workspace_size, &w_query, info); double workspace_vec2[static_cast<int>(workspace_size[0])]; w_size = static_cast<int>(workspace_size[0]); // Inverse calculation from LU values, the inverse is stored in t_mat_inv.m_data dgetri_(&size, &t_mat_inv.m_data[0], &size, ipiv, workspace_vec2, &w_size, info); MatVec result; result.reserve(s.size()); // e^(this) = T*D*T^-1 // T = matrix with eigenvectors (t_mat), D = matrix with exponentiated eigenvalues // Calculate for every value in incoming vector s DblVec eg_val_exp; eg_val_exp.reserve(size); for (DblVec::const_iterator it=s.begin(); it != s.end(); it++){ for (int i=0; i<size; i++) eg_val_exp.push_back(exp(eg_val_real[i]*(*it))); Matrix left = Matrix::mult(t_mat, Matrix(eg_val_exp)); Matrix res = Matrix::mult( left, t_mat_inv); result.push_back(res); eg_val_exp.clear(); } return result; }