void do_reverse_keyframes( curve_t<K>& c) { typedef typename curve_t<K>::iterator iterator; iterator s_it( c.begin()); iterator e_it( c.end() - 1); while( s_it != e_it) { s_it->swap_value( *e_it); ++s_it; --e_it; } }
void DecimationModel::draw() { if (meshtype_toberendered_ == ORIGINAL) { MeshModel::draw(); } else if (meshtype_toberendered_ == SIMPLIFIED || meshtype_toberendered_ == RESAMPLE_MIDPOINT) { // 第一步, 要是做了参数化的话先显示所有顶点, 包括那些被deleted但是参数化到base complex面上的点. for (TriMesh::VIter v_it(mesh2_.vertices_begin()), v_end(mesh2_.vertices_end()); v_it != v_end; ++v_it) { if ( v_it.handle() == test_vertex_||v_it.handle().idx() == 69000 ) {//|| v_it.handle().idx() == 1493 glColor3f(0, 1, 0); glPointSize(10); glBegin(GL_POINTS); GL::glVertex(mesh2_.point(v_it)); glEnd(); glPointSize(1); } if (v_it.handle() == test_vertex1_ || v_it.handle().idx() == 56656 || v_it.handle().idx() == 66696 ||v_it.handle().idx() == 203340) {// glColor3f(0, 1, 1); glPointSize(10); glBegin(GL_POINTS); GL::glVertex(mesh2_.point(v_it)); glEnd(); glPointSize(1); } } for (TriMesh::VIter v_it(initial_control_mesh_.vertices_begin()), v_end(initial_control_mesh_.vertices_end()); v_it != v_end; ++v_it) { if (v_it.handle() == test_vertex_ ) { //显示新分裂的顶点 glColor3f(0, 1, 0); glPointSize(10); glBegin(GL_POINTS); GL::glVertex(initial_control_mesh_.point(v_it)); glEnd(); glPointSize(1); } } //int fandisk_arr[] = { //这些是一部分特征边 // 9, 269, 265, // 261, 257, 254, // 250, 246, 241, // 237, 233, 229, // 225, 221, 217, // 214, 210, 206, // //202, 995, 9762 // 9922, 9925, 9928, // 9931, 9934, 9939, // 9943, 9947, 9951, // 9954, 9958, 9962, // 9966, 9970, 9974, // 9978, 9982, 9986, // 9990, 9994, 9998, // 10002, 10006, 10011, // 10014, 784, 788 //}; //std::vector<int> fandisk(fandisk_arr, fandisk_arr+18+27); //for (int i = 0; i < 45; ++i) { // glColor3f(1, 0, 1); // 显示特征边 // glLineWidth(3.5); // glBegin(GL_LINES); // GL::glVertex(mesh2_.point(mesh2_.to_vertex_handle(mesh2_.halfedge_handle(mesh2_.edge_handle(fandisk_arr[i]), 0)))); // GL::glVertex(mesh2_.point(mesh2_.to_vertex_handle(mesh2_.halfedge_handle(mesh2_.edge_handle(fandisk_arr[i]), 1)))); // glEnd(); // glLineWidth(1.0); //} if (do_parameterization_) { //(1) 先显示所有顶点, 包括那些被deleted但是参数化到base complex面上的点. // 但是后来我觉得这可以省略, 因为下面显示mesh_collapsed_时候就会显示这些被参数化的点了. glDisable(GL_LIGHTING); for (TriMesh::EIter e_it(mesh_.edges_begin()), e_end(mesh_.edges_end()); e_it != e_end; ++e_it) { if (mesh_.status(e_it).deleted() == false) { if (mesh_.status(e_it).feature()) { glColor3f(1, 0, 1); // 显示特征边 glLineWidth(3.5); glBegin(GL_LINES); GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it.handle(), 0)))); GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it.handle(), 1)))); glEnd(); glLineWidth(1.0);/**/ } if (meshtype_toberendered_ == RESAMPLE_MIDPOINT) { if (mesh_.property(empl_, e_it.handle()) == true) { //已经求出中点的了. glColor3f(0, 1, 0);//黄色 显示那些采样点 glPointSize(4); //glBegin(GL_POINTS); //GL::glVertex(mesh_.property(emp_, e_it.handle())); //glEnd(); glPointSize(1); glPushMatrix(); glTranslatef( mesh_.property(emp_, e_it.handle())[0], mesh_.property(emp_, e_it.handle())[1], mesh_.property(emp_, e_it.handle())[2] ); glutSolidSphere(bb.diagonal_lenght*0.003, 20, 20); glPopMatrix(); } else { // 还没有求出中点的 glColor3f(0.f, 1.f, 0.f);//绿色 显示那些没有对中点采样成功的边 glLineWidth(6.5); glBegin(GL_LINES); GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 0)))); GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 1)))); glEnd(); glLineWidth(1.0); } } // 如果是中点采样的话显示采样点或不成功的边. } } // (4) 显示被参数化的网格, 作为参考.用hiden line线框模式显示 if (mesh_collapsed_render_or_not_) { DGP::hidderline_render(mesh_collapsed_, OpenMesh::Vec3f(0.0, 0.0, 1.0)); } ///////////////////////////// //draw_mode_ = HIDDENLINE;//LINEANDSOLIDFLAT; //NONE; // //这里设置了的话用户就不可以选择了. } //end of if (do_parameterization_). // 第二步, 正常显示. MeshModel::draw(); } else if (meshtype_toberendered_ == REFINED_SIMPLIFIED) { //glBegin(GL_POINTS); //GL::glColor(OpenMesh::Vec3f(1, 0, 0)); //glPointSize(3.0); //for (TriMesh::FIter f_it(mesh_.faces_begin()), f_end(mesh_.faces_end()); f_it != f_end; ++f_it) { // for (std::vector<TriMesh::VHandle>::const_iterator it(mesh_.property(fvset_, f_it.handle()).begin()), it_end(mesh_.property(fvset_, f_it.handle()).end()); // it != it_end; ++it) { // if (32 == mesh_.property(vf_of_rsm_, *it).idx()) // GL::glVertex(refined_simplified_mesh_.point(mesh_.property(vf0_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[0] // + refined_simplified_mesh_.point(mesh_.property(vf1_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[1] // + refined_simplified_mesh_.point(mesh_.property(vf2_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[2]); // } //}glPointSize(1); //glEnd(); MeshModel::draw(); } else if (meshtype_toberendered_ == INITIAL_CONTROL ||meshtype_toberendered_ == LOOP_ONE || meshtype_toberendered_ == LIMIT) { if (upperbounding_mesh_.n_vertices()) { //if (upperbounding_mesh_.empty() == false) {// renc: 20150829 DGP::hidderline_render(upperbounding_mesh_, OpenMesh::Vec3f(0, 0, 1)); DGP::hidderline_render(lowerbounding_mesh_, OpenMesh::Vec3f(0, 1, 0)); } glBegin(GL_LINES); glLineWidth(3); glColor3f(1, 0, 0); for (int i = 0; i < laplacian_.size(); ++i) { TriMesh::VHandle vh = refined_simplified_mesh_.vertex_handle(i); GL::glVertex(refined_simplified_mesh_.point(vh)); GL::glVertex(refined_simplified_mesh_.point(vh) + laplacian_[i]); } glColor3f(0, 1, 0); for (int i = 0; i < laplacian_rcm_.size(); ++i) { TriMesh::VHandle vh = refined_simplified_mesh_.vertex_handle(i); GL::glVertex(refined_simplified_mesh_.point(vh)); GL::glVertex(refined_simplified_mesh_.point(vh) + laplacian_rcm_[i]); } glEnd(); // 下面画出采样点到evaluation坐标的连线, 也画出到closest坐标的连线, 可视化比较是否离采样点近了. glLineWidth(4); glBegin(GL_LINES); GL::glColor(OpenMesh::Vec3f(0, 1, 0)); for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) { if (mesh_.status(v_it).deleted()) { //原始网格的点到其在极限曲面上的位置的连线 if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end()) if (mesh_.property(vp_eval_, v_it)) { GL::glVertex(mesh_.property(vp_eval_pos_, v_it.handle())); GL::glVertex(mesh2_.point(v_it)); } } } GL::glColor(OpenMesh::Vec3f(1, 1, 0));//最近点 for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) { if (mesh_.status(v_it).deleted()) { if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end()) if (mesh_.property(vp_closest_, v_it)) { GL::glVertex(mesh_.property(vp_closest_pos_, v_it)); GL::glVertex(mesh2_.point(v_it)); } } } GL::glColor(OpenMesh::Vec3f(1, 0, 0));//project point for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) { if (mesh_.status(v_it).deleted()) { if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end()) if (mesh_.property(vp_project_, v_it)) { GL::glVertex(mesh_.property(vp_project_pos_, v_it)); GL::glVertex(mesh2_.point(v_it)); } } } glEnd(); glLineWidth(1); if (is_view_fitting_error_of_mesh2_) { glDisable(GL_LIGHTING); glShadeModel(GL_SMOOTH); // 被取代的原因详见MeshViewer::draw(_draw_mode)函数 glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_COLOR_ARRAY); GL::glVertexPointer(mesh2_.points()); GL::glNormalPointer(mesh2_.vertex_normals()); GL::glColorPointer(mesh2_.vertex_colors()); glDrawElements(GL_TRIANGLES, mesh2_indices_for_render_.size(), GL_UNSIGNED_INT, &mesh2_indices_for_render_[0]); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); } if (is_view_fitting_error_of_sm_) { glDisable(GL_LIGHTING); glShadeModel(GL_SMOOTH); glBegin(GL_TRIANGLES); for (TriMesh::FIter f_it(simplified_mesh_.faces_begin()), f_end(simplified_mesh_.faces_end()); f_it!=f_end; ++f_it) { // 这种方式应该学学啊 TriMesh::FVIter fv_it = simplified_mesh_.fv_iter(f_it.handle()); GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it)); GL::glVertex(simplified_mesh_.point(fv_it)); ++fv_it; GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it)); GL::glVertex(simplified_mesh_.point(fv_it)); ++fv_it; GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it)); GL::glVertex(simplified_mesh_.point(fv_it)); } glEnd(); } MeshModel::draw(); } else { std::cout << "Error: there isn't this render type.\n"; } //draw_mesh2_ = true;//false; if (draw_mesh2_ == true) { // 是否显示原始网格, 为了方便比较. DGP::hidderline_render(mesh2_, OpenMesh::Vec3f(1, 0, 0)); } }
void KContainer::BuildKLists(ParticleLayout_t& lattice, bool useSphere) { TinyVector<int,DIM+1> TempActualMax; TinyVector<int,DIM> kvec; TinyVector<RealType,DIM> kvec_cart; RealType modk2; vector<TinyVector<int,DIM> > kpts_tmp; VContainer_t kpts_cart_tmp; SContainer_t ksq_tmp; // reserve the space for memory efficiency #if OHMMS_DIM ==3 int numGuess=(2*mmax[0]+1)*(2*mmax[1]+1)*(2*mmax[2]+1); if(useSphere) { //Loop over guesses for valid k-points. for(int i=-mmax[0]; i<=mmax[0]; i++) { kvec[0] = i; for(int j=-mmax[1]; j<=mmax[1]; j++) { kvec[1] = j; for(int k=-mmax[2]; k<=mmax[2]; k++) { kvec[2] = k; //Do not include k=0 in evaluations. if(i==0 && j==0 && k==0) continue; //Convert kvec to Cartesian kvec_cart = lattice.k_cart(kvec); //Find modk modk2 = dot(kvec_cart,kvec_cart); if(modk2>kcut2) continue; //Inside cutoff? //This k-point should be added to the list kpts_tmp.push_back(kvec); kpts_cart_tmp.push_back(kvec_cart); ksq_tmp.push_back(modk2); //Update record of the allowed maximum translation. for(int idim=0; idim<3; idim++) if(abs(kvec[idim]) > TempActualMax[idim]) TempActualMax[idim] = abs(kvec[idim]); } } } } else { // Loop over all k-points in the parallelpiped and add them to kcontainer // note layout is for interfacing with fft, so for each dimension, the // positive indexes come first then the negative indexes backwards // e.g. 0, 1, .... mmax, -mmax+1, -mmax+2, ... -1 const int idimsize = mmax[0]*2; const int jdimsize = mmax[1]*2; const int kdimsize = mmax[2]*2; for (int i = 0; i < idimsize; i++) { kvec[0] = i; if (kvec[0] > mmax[0]) kvec[0] -= idimsize; for (int j = 0; j < jdimsize; j++) { kvec[1] = j; if (kvec[1] > mmax[1]) kvec[1] -= jdimsize; for (int k = 0; k < kdimsize; k++) { kvec[2] = k; if (kvec[2] > mmax[2]) kvec[2] -= kdimsize; // get cartesian location and modk2 kvec_cart = lattice.k_cart(kvec); modk2 = dot(kvec_cart, kvec_cart); // add k-point to lists kpts_tmp.push_back(kvec); kpts_cart_tmp.push_back(kvec_cart); ksq_tmp.push_back(modk2); } } } // set allowed maximum translation TempActualMax[0] = mmax[0]; TempActualMax[1] = mmax[1]; TempActualMax[2] = mmax[2]; } #elif OHMMS_DIM == 2 int numGuess=(2*mmax[0]+1)*(2*mmax[1]+1); if(useSphere) { //Loop over guesses for valid k-points. for(int i=-mmax[0]; i<=mmax[0]; i++) { kvec[0] = i; for(int j=-mmax[1]; j<=mmax[1]; j++) { kvec[1] = j; //Do not include k=0 in evaluations. if(i==0 && j==0) continue; //Convert kvec to Cartesian kvec_cart = lattice.k_cart(kvec); //Find modk modk2 = dot(kvec_cart,kvec_cart); if(modk2>kcut2) continue; //Inside cutoff? //This k-point should be added to the list kpts_tmp.push_back(kvec); kpts_cart_tmp.push_back(kvec_cart); ksq_tmp.push_back(modk2); //Update record of the allowed maximum translation. for(int idim=0; idim<3; idim++) if(abs(kvec[idim]) > TempActualMax[idim]) TempActualMax[idim] = abs(kvec[idim]); } } } else { // Loop over all k-points in the parallelpiped and add them to kcontainer // note layout is for interfacing with fft, so for each dimension, the // positive indexes come first then the negative indexes backwards // e.g. 0, 1, .... mmax, -mmax+1, -mmax+2, ... -1 const int idimsize = mmax[0]*2; const int jdimsize = mmax[1]*2; for (int i = 0; i < idimsize; i++) { kvec[0] = i; if (kvec[0] > mmax[0]) kvec[0] -= idimsize; for (int j = 0; j < jdimsize; j++) { kvec[1] = j; if (kvec[1] > mmax[1]) kvec[1] -= jdimsize; // get cartesian location and modk2 kvec_cart = lattice.k_cart(kvec); modk2 = dot(kvec_cart, kvec_cart); // add k-point to lists kpts_tmp.push_back(kvec); kpts_cart_tmp.push_back(kvec_cart); ksq_tmp.push_back(modk2); } } // set allowed maximum translation TempActualMax[0] = mmax[0]; TempActualMax[1] = mmax[1]; } //#elif OHMMS_DIM == 1 //add one-dimension #else #error "OHMMS_DIM != 2 || OHMMS_DIM != 3" #endif //Update a record of the number of k vectors numk = kpts_tmp.size(); std::map<int,std::vector<int>*> kpts_sorted; //create the map: use simple integer with resolution of 0.001 in ksq for(int ik=0; ik<numk; ik++) { int k_ind=static_cast<int>(ksq_tmp[ik]*1000); std::map<int,std::vector<int>*>::iterator it(kpts_sorted.find(k_ind)); if(it == kpts_sorted.end()) { std::vector<int>* newSet=new std::vector<int>; kpts_sorted[k_ind]=newSet; newSet->push_back(ik); } else { (*it).second->push_back(ik); } } std::map<int,std::vector<int>*>::iterator it(kpts_sorted.begin()); kpts.resize(numk); kpts_cart.resize(numk); ksq.resize(numk); kshell.resize(kpts_sorted.size()+1,0); int ok=0, ish=0; while(it != kpts_sorted.end()) { std::vector<int>::iterator vit((*it).second->begin()); while(vit != (*it).second->end()) { int ik=(*vit); kpts[ok]=kpts_tmp[ik]; kpts_cart[ok]=kpts_cart_tmp[ik]; ksq[ok]=ksq_tmp[ik]; ++vit; ++ok; } kshell[ish+1]=kshell[ish]+(*it).second->size(); ++it; ++ish; } it=kpts_sorted.begin(); std::map<int,std::vector<int>*>::iterator e_it(kpts_sorted.end()); while(it != e_it) { delete it->second; it++; } //Finished searching k-points. Copy list of maximum translations. mmax[DIM] = 0; for(int idim=0; idim<DIM; idim++) { mmax[idim] = TempActualMax[idim]; mmax[DIM]=std::max(mmax[idim],mmax[DIM]); //if(mmax[idim] > mmax[DIM]) mmax[DIM] = mmax[idim]; } //Now fill the array that returns the index of -k when given the index of k. minusk.resize(numk); // Create a map from the hash value for each k vector to the index std::map<int, int> hashToIndex; for (int ki=0; ki<numk; ki++) { hashToIndex[GetHashOfVec(kpts[ki], numk)] = ki; } // Use the map to find the index of -k from the index of k for(int ki=0; ki<numk; ki++) { minusk[ki] = hashToIndex[ GetHashOfVec(-1 * kpts[ki], numk) ]; } }