Mat* create_translation_mat(double x, double y, double z) { Mat* m = identity_mat(); m->m[12] = x; m->m[13] = y; m->m[14] = z; return m; }
Mat* create_look_at_mat(Vec* cam_pos, Vec* targ_pos, Vec* up) { Mat* p = create_translation_mat(-cam_pos->x, -cam_pos->y, -cam_pos->z); Vec* d = vec_minus_vec(targ_pos, cam_pos); Vec* f = normalize_vec(d); Vec* c1 = cross_vec(f, up); Vec* r = normalize_vec(c1); Vec* c2 = cross_vec(r, f); Vec* u = normalize_vec(c2); Mat* ori = identity_mat(); ori->m[0] = r->x; ori->m[4] = r->y; ori->m[8] = r->z; ori->m[1] = u->x; ori->m[5] = u->y; ori->m[9] = u->z; ori->m[2] = -f->x; ori->m[6] = -f->y; ori->m[10] = -f->z; Mat* ret = mat_times_mat(ori, p); delete_mat(p); delete_mat(ori); delete_vec(d); delete_vec(f); delete_vec(r); delete_vec(u); delete_vec(c1); delete_vec(c2); return ret; }
void reparametrize_func(const vec & lmk, vec & lnew, mat & LNEW_lmk) const { lnew = lmk; LNEW_lmk = identity_mat(size()); }
//static int iter=0; void cgd(Mesh & m) { int height=11*m.t.size()+6*m.v.size(); // int height=2*m.t.size()+3*m.v.size(); // int width = 3*(m.v.size()); int width = 3*(m.v.size()+m.t.size()); //nvar=m.v.size(); std::cout << "compute mesh info\n"; nvar=m.v.size()+m.t.size(); std::vector<Plane>plane; get_plane(m,plane); add_v4(m); std::vector<Mat3>mat; vmat(m,mat); m.adjlist(); CCS ccs; std::vector<double >b; std::cout << "compute matrix rows info\n"; //b for smoothness matrix is 0 //smooth_mat(m,mat,wS,ccs); vert_smooth_mat(m,wS,ccs,b); identity_mat(m, mat, wI, ccs , b); vertex_mat(m,wV0,ccs,b); planar_mat(m,plane,wPt,ccs); b.resize(height,0.0); SparseCCS* s = new SparseCCS(width, height, &ccs.vals[0], &ccs.rowInds[0], &ccs.colPtr[0]); SparseCCS* st = s->transposed(); std::cout << "compute AA^T\n"; SparseCCS* sst=s->multiply_LM(*st); SparseMatrixOutline *outline = new SparseMatrixOutline(width); //printAB(ccs,b,0); double * ATb= s->operator* (&b[0]); // int rowcnt=sst->rows_count(); int colcnt=sst->columns_count(); const real * vals=sst->values(); const int * row_indices=sst->row_indices(); const int * col_pointers=sst->column_pointers(); for(int ii=0; ii<colcnt; ii++) { for(int jj=col_pointers[ii]; jj<col_pointers[ii+1]; jj++) { outline->AddEntry(row_indices[jj],ii,vals[jj]); } } // delete s; delete st; delete sst; std::cout << "matrix assembly\n"; SparseMatrix A(outline); delete outline; std::cout << "lin solve\n"; CGSolver solver(&A); double * x=new double [width]; vertex2arr(m,x); double eps = 1E-6; int maxIter = 50; int verbose = 0; int ret = solver.SolveLinearSystemWithJacobiPreconditioner(x, ATb, eps, maxIter, verbose);// //if(ret<0) { // printf("optimization error\n"); // } A.CheckLinearSystemSolution(x,ATb); printf("\n"); array2vertex(x,m); delete []x; delete []ATb; }