void step_learn( int key ) { // one input // Eigen::VectorXd i1 = Eigen::VectorXd::Random(1); // i1 = (i1.array() - -1.0) / (1.0 - -1.0); Eigen::VectorXd i1(1); i1 << (double) (_nb_iter % 3) / 4.0 + 0.1; _rdsom->forward( i1 ); _rdsom->deltaW( i1, 0.1, 0.2, true ); _c_weights.clear(); _c_sim_input.clear(); _c_sim_rec.clear(); _c_sim_merged.clear(); _c_sim_convol.clear(); _c_sim_hn_dist.clear(); _c_sim_hn_rec.clear(); for( unsigned int i = 0; i < _rdsom->v_neur.size(); ++i) { _c_weights.add_sample( {(double)i, _rdsom->v_neur[i]->weights(0), 0.0} ); _c_sim_input.add_sample( {(double)i, _rdsom->_sim_w[i], 0.0} ); _c_sim_rec.add_sample( {(double)i, _rdsom->_sim_rec[i], 0.0} ); _c_sim_merged.add_sample( {(double)i, _rdsom->_sim_merged[i], 0.0} ); _c_sim_convol.add_sample( {(double)i, _rdsom->_sim_convol[i], 0.0} ); _c_sim_hn_dist.add_sample( {(double)i, _rdsom->_sim_hn_dist[i], 0.0} ); _c_sim_hn_rec.add_sample( {(double)i, _rdsom->_sim_hn_rec[i], 0.0} ); } _nb_iter++; }
Surface makeSurfRev(const Curve &profile, unsigned steps) { Surface surface; if (!checkFlat(profile)) { cerr << "surfRev profile curve must be flat on xy plane." << endl; exit(0); } double angle = 2*PI/steps; Matrix3f M = Matrix3f((float)cos(angle),0,(float)sin(angle), 0,1,0, (float)(-sin(angle)),0,(float)cos(angle)); M.transpose(); Curve c = profile; int numPoints = c.size(); for(unsigned s=0;s<steps;s++){ Curve newc; for (unsigned i=0;i<numPoints;i++){ CurvePoint cp = c[i]; surface.VV.push_back(cp.V); surface.VN.push_back(-cp.N); Vector3f newV = M*cp.V; Vector3f newN = M*cp.N; newN.normalize(); struct CurvePoint newP = {newV, cp.T,newN,cp.B}; newc.push_back(newP); } c = newc; newc.clear(); } int another; for(unsigned s=0;s<steps;s++){ if(s==steps-1){ another=0; }else{ another = s+1; } for(unsigned i=0;i<numPoints-1;i++){ surface.VF.push_back(Tup3u(s*numPoints+i,another*numPoints+i,another*numPoints+i+1)); surface.VF.push_back(Tup3u(s*numPoints+i,another*numPoints+i+1,s*numPoints+i+1)); } } return surface; }
Surface makeGenCyl(const Curve &profile, const Curve &sweep ) { Surface surface; if (!checkFlat(profile)) { cerr << "genCyl profile curve must be flat on xy plane." << endl; exit(0); } // TODO: Here you should build the surface. See surf.h for details. Curve c = profile; Curve sweepL = sweep; unsigned step = sweep.size(); Matrix4f transform; Matrix4f transinverse; Curve newc; vector<Curve> clist; for(unsigned i=0;i<step;i++){//sweepL.size();i++){ CurvePoint p = sweepL[i]; transform = getTransform(p); transinverse = transform.inverse(); transinverse.transpose(); newc.clear(); for(unsigned j=0;j<c.size();j++){ Vector4f tempV = transform*Vector4f(c[j].V,1); Vector4f tempN = transinverse*Vector4f(c[j].N,1); Vector3f newV = Vector3f(tempV[0],tempV[1],tempV[2]); Vector3f newN = Vector3f(-tempN[0],-tempN[1],-tempN[2]); struct CurvePoint newp = {newV,c[j].T,newN,c[j].B}; newc.push_back(newp); } clist.push_back(newc); } for(unsigned k=0;k<clist.size()-1;k++){ pushVV(surface,clist[k]); addTriangle(surface,clist[k],clist[k+1],k); } pushVV(surface,clist[clist.size()-1]); pushVV(surface,clist[0]); addTriangle(surface,clist[clist.size()-1],clist[0],clist.size()-1); return surface; }