void Viewer::importMesh(std::string& filename) { myMap.clear(true) ; size_t pos = filename.rfind("."); // position of "." in filename std::string extension = filename.substr(pos); if (extension == std::string(".map")) { myMap.loadMapBin(filename); position = myMap.getAttribute<VEC3, VERTEX, MAP>("position") ; } else { std::vector<std::string> attrNames ; if(!Algo::Surface::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames)) { CGoGNerr << "could not import " << filename << CGoGNendl ; return; } position = myMap.getAttribute<PFP::VEC3, VERTEX, MAP>(attrNames[0]) ; } // myMap.enableQuickTraversal<VERTEX>() ; m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ; m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES) ; m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES) ; m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ; normalBaseSize = bb.diagSize() / 100.0f ; // vertexBaseSize = normalBaseSize / 5.0f ; normal = myMap.getAttribute<VEC3, VERTEX, MAP>("normal") ; if(!normal.isValid()) normal = myMap.addAttribute<VEC3, VERTEX, MAP>("normal") ; Utils::Chrono c; c.start(); Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ; std::cout << "compute normals -> " << c.elapsed() << std::endl; m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; setParamObject(bb.maxSize(), bb.center().data()) ; updateGLMatrices() ; std::cout << "#vertices -> " << Algo::Topo::getNbOrbits<VERTEX>(myMap) << std::endl; }
int main() { // declare a map to handle the mesh MAP myMap; Utils::Chrono ch; ch.start(); // add position attribute on vertices and get handler on it VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position"); const int nb = 100; Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, nb, nb, nb); cubic.embedIntoGrid(position, 10.0f, 10.0f, 10.0f); std::cout<< "construct grid in " << ch.elapsed()<< " ms"<< std::endl; ch.start(); VEC3 centerMesh(0,0,0); int nbVols=0; foreach_cell<VOLUME>(myMap, [&](Vol w) // foreach volume { VEC3 centerVol(0,0,0); int nbFaces=0; foreach_incident3<FACE>(myMap, w, [&](Face f) // foreach face of each volume { VEC3 centerFace(0,0,0); int nbVert=0; foreach_incident3<VERTEX>(myMap, f, [&](Vertex v) // foreach vertex of each face of each volume { centerFace += position[v]; nbVert++; }); centerFace /=nbVert; centerVol += centerFace; nbFaces++; }); centerVol /= nbFaces; centerMesh += centerVol; nbVols++; }); centerMesh /= nbVols; CGoGNout<< "Traverse with foreach in " << ch.elapsed()<< " ms"<< CGoGNendl; ch.start(); centerMesh=VEC3(0,0,0); nbVols=0; TraversorW<MAP> tw(myMap); // alias for Traversor<MAP,VERTEX> for (Dart dw=tw.begin(); dw!=tw.end(); dw=tw.next()) { VEC3 centerVol(0,0,0); int nbFaces=0; Traversor3WF<MAP> trwf(myMap, dw); for (Dart df = trwf.begin(); df != trwf.end(); df = trwf.next()) { VEC3 centerFace(0,0,0); int nbVert=0; Traversor3FV<MAP> trfv(myMap, df); for (Dart dv = trfv.begin(); dv != trfv.end(); dv = trfv.next()) { centerFace += position[dv]; nbVert++; } centerFace /=nbVert; centerVol += centerFace; nbFaces++; } centerVol /= nbFaces; centerMesh += centerVol; nbVols++; } CGoGNout<< "Traverse with traversor in " << ch.elapsed()<< " ms"<< CGoGNendl; ch.start(); PFP::REAL vol = Algo::Geometry::totalVolume<PFP>(myMap, position); CGoGNout<< "Parallel volume:" << ch.elapsed()<< " ms val="<<vol<< CGoGNendl; vol = 0; foreach_cell<VOLUME>(myMap, [&](Vol w) // foreach volume { vol += Algo::Geometry::convexPolyhedronVolume<PFP>(myMap, w, position) ; }); CGoGNout<< "Linear volume:" << ch.elapsed()<< " ms val="<<vol<< CGoGNendl; return 0; }
int main() { // declare a map to handle the mesh MAP myMap; // add position attribute on vertices and get handler on it VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position"); // create a topo grid of 4x4x4 squares Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, 20, 20, 20); cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f); // easy way to find the central vertex of the grid Vertex v; foreach_cell_until<VERTEX>(myMap, [&] (Vertex it) { if (position[it] == VEC3(0,0,0)) { v = it; std::cout << "Trouve"<< std::endl; return false; } return true; }); // must test of find ok (if not v.dart is NIL) if (! v.valid()) std::cerr << "could not find a vertex with position (0,0,0)" << std::endl; // WITH TRAVERSORS: // find incident faces to vertex Traversor3VF<MAP> trvf(myMap, v.dart); for (Dart e = trvf.begin(); e != trvf.end(); e = trvf.next()) { std::cout << "Face of dart "<<e<< " incident to vertex of dart " << v.dart<< std::endl; } // find adjacent vertices thru a face Traversor3VVaF<MAP> trvvaf(myMap, v.dart); for (Dart e = trvvaf.begin(); e != trvvaf.end(); e = trvvaf.next()) { std::cout << "vertex of dart "<<e<< " adjacent to vertex of dart " << v.dart<< " by a face" << std::endl; } // WITH FOREACH FUNCTION (C++11 lambda expression) // find faces incident to vertex v foreach_incident3<FACE>(myMap, v, [&](Face f) { std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl; }); // find vertices adjacent to vertex v thru a face foreach_adjacent3<FACE>(myMap, v, [&](Vertex x) { std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl; }); // WITH FOR C++11 SYNTAX for(Face f : facesIncidentToVertex3(myMap,v)) std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl; for (Vertex x : verticesAdjacentByFace3(myMap,v)) std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl; for(Vertex v1 : allVerticesOf(myMap)) { for (Vertex v2 : verticesAdjacentByEdge3(myMap,v1)) { for (Face f : facesIncidentToVertex3(myMap,v2)) if ((f.dart.index)%1000 == 1 ) std::cout << "juste for fun face " << f << std::endl; } } Utils::Chrono ch; VertexAttribute<VEC3,MAP> pos2 = myMap.getAttribute<VEC3, VERTEX, MAP>("pos2") ; if(!pos2.isValid()) pos2 = myMap.addAttribute<VEC3, VERTEX, MAP>("pos2") ; ch.start(); for (int i=0; i< 20; ++i) { VEC3 xx(0,0,0); int nb=0; for(Vol d : allVolumesOf(myMap)) { VEC3 vCentroid = localvolumeCentroidELW<PFP>(myMap, d, position) ; xx += vCentroid; nb++; } xx /= nb; std::cout << xx << std::endl; } std::cout << "for "<< ch.elapsed()<< " ms "<< std::endl; ch.start(); for (int i=0; i< 20; ++i) { VEC3 xx(0,0,0); int nb=0; foreach_cell<VOLUME>(myMap, [&] (Vol d) { VEC3 vCentroid = Algo::Surface::Geometry::volumeCentroidELW<PFP>(myMap, d, position) ; xx += vCentroid; nb++; }); xx /= nb; std::cout << xx << std::endl; } std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl; return 0; }
void Viewer::cb_keyPress(int keycode) { switch(keycode) { case 'c' : myMap.check(); break; case 'a': { Utils::Chrono ch; ch.start(); VertexAttribute<VEC3, MAP> pos2 = myMap.getAttribute<VEC3, VERTEX, MAP>("pos2") ; if(!pos2.isValid()) pos2 = myMap.addAttribute<VEC3, VERTEX, MAP>("pos2") ; for (int i=0; i< 10; ++i) { TraversorV<MAP> trav(myMap); for (Dart d=trav.begin(), d_end = trav.end(); d!=d_end ; d = trav.next()) { pos2[d] = VEC3(0,0,0); int nb=0; Traversor2VVaF<MAP> trf(myMap,d); for (Dart e = trf.begin(),e_end =trf.end() ; e != e_end; e = trf.next()) { pos2[d] += position[e]; nb++; } pos2[d]/=nb; } myMap.swapAttributes(position, pos2); } std::cout << "Traversor "<< ch.elapsed()<< " ms "<< std::endl; Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ; m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; updateGL(); } break; case 'b': { Utils::Chrono ch; ch.start(); VertexAttribute<VEC3,MAP> pos2 = myMap.getAttribute<VEC3, VERTEX, MAP>("pos2") ; if(!pos2.isValid()) pos2 = myMap.addAttribute<VEC3, VERTEX, MAP>("pos2") ; for (int i=0; i< 6; ++i) { foreach_cell<VERTEX>(myMap, [&] (Vertex d) { pos2[d] = VEC3(0,0,0); int nb=0; foreach_adjacent2<FACE>(myMap,d,[&](Vertex e) { pos2[d] += position[e]; nb++; }); pos2[d]/=nb; }); myMap.swapAttributes(position,pos2); } std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl; Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ; m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; updateGL(); } break; case 'B': { Utils::Chrono ch; ch.start(); VertexAttribute<VEC3,MAP> pos2 = myMap.getAttribute<VEC3, VERTEX, MAP>("pos2") ; if(!pos2.isValid()) pos2 = myMap.addAttribute<VEC3, VERTEX, MAP>("pos2") ; // foreach_cell_EvenOddd<VERTEX>(myMap, [&] (Vertex d) // { // pos2[d] = VEC3(0,0,0); // int nb=0; // foreach_adjacent2<FACE>(myMap,d,[&](Vertex e) // { // pos2[d] += position[e]; // nb++; // }); // pos2[d]/=nb; // }, // [&] (Vertex d) // { // position[d] = VEC3(0,0,0); // int nb=0; // foreach_adjacent2<FACE>(myMap,d,[&](Vertex e) // { // position[d] += pos2[e]; // nb++; // }); // position[d]/=nb; // }, // 3); // std::cout << "Even/Odd "<< ch.elapsed()<< " ms "<< std::endl; Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ; m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; updateGL(); } break; case 'e': { Utils::Chrono ch; ch.start(); VertexAttribute<VEC3,MAP> pos2 = myMap.getAttribute<VEC3, VERTEX, MAP>("pos2") ; if(!pos2.isValid()) pos2 = myMap.addAttribute<VEC3, VERTEX, MAP>("pos2") ; for (int i=0; i< 10; ++i) { TraversorV<MAP> trav(myMap); for (Dart d=trav.begin(), d_end = trav.end(); d!=d_end ; d = trav.next()) { pos2[d] = VEC3(0,0,0); int nb=0; Traversor2VE<MAP> trf(myMap,d); for (Dart e = trf.begin(),e_end =trf.end() ; e != e_end; e = trf.next()) { pos2[d] += position[myMap.phi1(e)]; nb++; } pos2[d]/=nb; } myMap.swapAttributes(position,pos2); } std::cout << "Traversor "<< ch.elapsed()<< " ms "<< std::endl; Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ; m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; updateGL(); } break; case 'f': { Utils::Chrono ch; ch.start(); VertexAttribute<VEC3,MAP> pos2 = myMap.getAttribute<VEC3, VERTEX, MAP>("pos2") ; if(!pos2.isValid()) pos2 = myMap.addAttribute<VEC3, VERTEX, MAP>("pos2") ; for (int i=0; i< 10; ++i) { foreach_cell<VERTEX>(myMap, [&] (Vertex d) { pos2[d] = VEC3(0,0,0); int nb=0; foreach_incident2<EDGE>(myMap,d,[&](Edge e) { pos2[d] += position[myMap.phi1(e)]; nb++; }); pos2[d]/=nb; }); myMap.swapAttributes(position,pos2); } std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl; Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ; m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; updateGL(); } break; case'A': { myMap.disableQuickTraversal<VERTEX>() ; #define NBLOOP 5 Utils::Chrono ch; ch.start(); { TraversorCell<MAP, VERTEX, FORCE_CELL_MARKING> trav(myMap,true); for(unsigned int i=0; i<NBLOOP; ++i) { for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next()) { normal[v][0] = 0.0f; } } std::cout << "FORCE_CELL_MARKING "<< ch.elapsed()<< " ms "<< std::endl; } ch.start(); { TraversorCell<MAP, VERTEX> trav(myMap); for(unsigned int i=0; i<NBLOOP; ++i) { for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next()) { normal[v][0] = 0.0f; } } std::cout << "auto "<< ch.elapsed()<< " ms "<< std::endl; } ch.start(); { TraversorCell<MAP, VERTEX> trav(myMap,true); for(unsigned int i=0; i<NBLOOP; ++i) { for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next()) { normal[v][0] = 0.0f; } } std::cout << "auto forcedart "<< ch.elapsed()<< " ms "<< std::endl; } ch.start(); { TraversorCell<MAP, VERTEX, FORCE_DART_MARKING> trav(myMap,true); for(unsigned int i=0; i<NBLOOP; ++i) { for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next()) { normal[v][0] = 0.0f; } } std::cout << "FORCE_DART_MARKING "<< ch.elapsed()<< " ms "<< std::endl; } myMap.enableQuickTraversal<MAP, VERTEX>() ; ch.start(); { TraversorCell<MAP, VERTEX> trav(myMap); for(unsigned int i=0; i<NBLOOP; ++i) { for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next()) { normal[v][0] = 0.0f; } } std::cout << "auto (quick) "<< ch.elapsed()<< " ms "<< std::endl; } ch.start(); { TraversorCell<MAP, VERTEX, FORCE_QUICK_TRAVERSAL> trav(myMap); for(unsigned int i=0; i<NBLOOP; ++i) { for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next()) { normal[v][0] = 0.0f; } } std::cout << "FORCE_QUICK_TRAVERSAL "<< ch.elapsed()<< " ms "<< std::endl; } } break; case'Z': { Utils::Chrono ch; ch.start(); CGoGN::Parallel::NumberOfThreads = 1; for (unsigned int i=0; i<4; ++i) Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ; std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices1 "<< ch.elapsed()<< " ms "<< std::endl; ch.start(); CGoGN::Parallel::NumberOfThreads = 2; for (unsigned int i=0; i<4; ++i) Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ; std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices2 "<< ch.elapsed()<< " ms "<< std::endl; ch.start(); CGoGN::Parallel::NumberOfThreads = 3; for (unsigned int i=0; i<4; ++i) Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ; std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices3 "<< ch.elapsed()<< " ms "<< std::endl; ch.start(); CGoGN::Parallel::NumberOfThreads = 4; for (unsigned int i=0; i<4; ++i) Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ; std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices4 "<< ch.elapsed()<< " ms "<< std::endl; ch.start(); CGoGN::Parallel::NumberOfThreads = 8; for (unsigned int i=0; i<4; ++i) Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ; std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices8 "<< ch.elapsed()<< " ms "<< std::endl; // ch.start(); // Parallel::foreach_cell_EO<VERTEX>(myMap,[&](Vertex v, unsigned int thr) // { // normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap,v,position); // }, // [&](Vertex v, unsigned int th) // { // normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap,v,position); // },2,4,false,FORCE_CELL_MARKING); // std::cout << "Parallel::foreach_cell_EO "<< ch.elapsed()<< " ms "<< std::endl; } break; default: break; } }