bool MeshTablesVolume<PFP>::importOFFWithELERegions(const std::string& filenameOFF, const std::string& filenameELE, std::vector<std::string>& attrNames) { VertexAttribute<VEC3> position = m_map.template getAttribute<VEC3, VERTEX>("position") ; if (!position.isValid()) position = m_map.template addAttribute<VEC3, VERTEX>("position") ; attrNames.push_back(position.name()) ; AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ; // open files std::ifstream foff(filenameOFF.c_str(), std::ios::in); if (!foff.good()) { CGoGNerr << "Unable to open OFF file " << CGoGNendl; return false; } std::ifstream fele(filenameELE.c_str(), std::ios::in); if (!fele.good()) { CGoGNerr << "Unable to open ELE file " << CGoGNendl; return false; } std::string line; //OFF reading std::getline(foff, line); if(line.rfind("OFF") == std::string::npos) { CGoGNerr << "Problem reading off file: not an off file"<<CGoGNendl; CGoGNerr << line << CGoGNendl; return false; } //Reading number of vertex/faces/edges in OFF file unsigned int nbe; { do { std::getline(foff,line); }while(line.size() == 0); std::stringstream oss(line); oss >> m_nbVertices; oss >> nbe; oss >> nbe; oss >> nbe; } //Reading number of tetrahedra in ELE file unsigned int nbv; { do { std::getline(fele,line); }while(line.size() == 0); std::stringstream oss(line); oss >> m_nbVolumes; oss >> nbv ; oss >> nbv; } //Reading vertices std::vector<unsigned int> verticesID; verticesID.reserve(m_nbVertices); for(unsigned int i = 0 ; i < m_nbVertices ; ++i) { do { std::getline(foff,line); }while(line.size() == 0); std::stringstream oss(line); float x,y,z; oss >> x; oss >> y; oss >> z; //we can read colors informations if exists VEC3 pos(x,y,z); unsigned int id = container.insertLine(); position[id] = pos; verticesID.push_back(id); } // reading tetrahedra m_nbFaces.reserve(m_nbVolumes*4); m_emb.reserve(m_nbVolumes*12); for(unsigned i = 0; i < m_nbVolumes ; ++i) { do { std::getline(fele,line); } while(line.size() == 0); std::stringstream oss(line); oss >> nbe; m_nbFaces.push_back(4); int s0,s1,s2,s3; oss >> s0; oss >> s1; oss >> s2; oss >> s3; typename PFP::VEC3 P = position[verticesID[s0]]; typename PFP::VEC3 A = position[verticesID[s1]]; typename PFP::VEC3 B = position[verticesID[s2]]; typename PFP::VEC3 C = position[verticesID[s3]]; if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::UNDER) { int ui= s0; s0 = s3; s3 = s2; s2 = s1; s1 = ui; } m_emb.push_back(verticesID[s0]); m_emb.push_back(verticesID[s1]); m_emb.push_back(verticesID[s2]); m_emb.push_back(verticesID[s3]); } foff.close(); fele.close(); return true; }
bool importOFFWithELERegions(typename PFP::MAP& map, const std::string& filenameOFF, const std::string& filenameELE, std::vector<std::string>& attrNames) { typedef typename PFP::VEC3 VEC3; VertexAttribute<VEC3> position = map.template addAttribute<VEC3, VERTEX>("position") ; attrNames.push_back(position.name()) ; AttributeContainer& container = map.template getAttributeContainer<VERTEX>() ; unsigned int m_nbVertices = 0, m_nbFaces = 0, m_nbEdges = 0, m_nbVolumes = 0; VertexAutoAttribute< NoMathIONameAttribute< std::vector<Dart> > > vecDartsPerVertex(map, "incidents"); // open files std::ifstream foff(filenameOFF.c_str(), std::ios::in); if (!foff.good()) { CGoGNerr << "Unable to open OFF file " << CGoGNendl; return false; } std::ifstream fele(filenameELE.c_str(), std::ios::in); if (!fele.good()) { CGoGNerr << "Unable to open ELE file " << CGoGNendl; return false; } std::string line; //OFF reading std::getline(foff, line); if(line.rfind("OFF") == std::string::npos) { CGoGNerr << "Problem reading off file: not an off file"<<CGoGNendl; CGoGNerr << line << CGoGNendl; return false; } //Reading number of vertex/faces/edges in OFF file unsigned int nbe; { do { std::getline(foff,line); }while(line.size() == 0); std::stringstream oss(line); oss >> m_nbVertices; oss >> m_nbFaces; oss >> m_nbEdges; oss >> nbe; } //Reading number of tetrahedra in ELE file unsigned int nbv; { do { std::getline(fele,line); }while(line.size() == 0); std::stringstream oss(line); oss >> m_nbVolumes; oss >> nbv ; oss >> nbv; } CGoGNout << "nb points = " << m_nbVertices << " / nb faces = " << m_nbFaces << " / nb edges = " << m_nbEdges << " / nb tet = " << m_nbVolumes << CGoGNendl; //Reading vertices std::vector<unsigned int> verticesID; verticesID.reserve(m_nbVertices); for(unsigned int i = 0 ; i < m_nbVertices ; ++i) { do { std::getline(foff,line); }while(line.size() == 0); std::stringstream oss(line); float x,y,z; oss >> x; oss >> y; oss >> z; //we can read colors informations if exists VEC3 pos(x,y,z); unsigned int id = container.insertLine(); position[id] = pos; verticesID.push_back(id); } std::vector<std::vector<Dart> > vecDartPtrEmb; vecDartPtrEmb.reserve(m_nbVertices); DartMarkerNoUnmark m(map) ; //Read and embed tetrahedra TODO for(unsigned i = 0; i < m_nbVolumes ; ++i) { do { std::getline(fele,line); } while(line.size() == 0); std::stringstream oss(line); oss >> nbe; Dart d = Algo::Modelisation::createTetrahedron<PFP>(map); Geom::Vec4ui pt; oss >> pt[0]; oss >> pt[1]; oss >> pt[2]; oss >> pt[3]; //regions ? oss >> nbe; // Embed three vertices for(unsigned int j = 0 ; j < 3 ; ++j) { FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesID[pt[2-j]]); map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb); //store darts per vertices to optimize reconstruction Dart dd = d; do { m.mark(dd) ; vecDartsPerVertex[pt[2-j]].push_back(dd); dd = map.phi1(map.phi2(dd)); } while(dd != d); d = map.phi1(d); } //Embed the last vertex d = map.phi_1(map.phi2(d)); FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesID[pt[3]]); map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb); //store darts per vertices to optimize reconstruction Dart dd = d; do { m.mark(dd) ; vecDartsPerVertex[pt[3]].push_back(dd); dd = map.phi1(map.phi2(dd)); } while(dd != d); } foff.close(); fele.close(); //Association des phi3 unsigned int nbBoundaryFaces = 0 ; for (Dart d = map.begin(); d != map.end(); map.next(d)) { if (m.isMarked(d)) { std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)]; Dart good_dart = NIL; for(typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it) { if(map.template getEmbedding<VERTEX>(map.phi1(*it)) == map.template getEmbedding<VERTEX>(d) && map.template getEmbedding<VERTEX>(map.phi_1(*it)) == map.template getEmbedding<VERTEX>(map.phi_1(d)) /*&& map.template getEmbedding<VERTEX>(*it) == map.template getEmbedding<VERTEX>(map.phi1(d)) */) { good_dart = *it ; } } if (good_dart != NIL) { map.sewVolumes(d, good_dart, false); m.template unmarkOrbit<FACE>(d); } else { m.template unmarkOrbit<PFP::MAP::FACE_OF_PARENT>(d); ++nbBoundaryFaces; } } } if (nbBoundaryFaces > 0) { std::cout << "closing" << std::endl ; map.closeMap(); CGoGNout << "Map closed (" << nbBoundaryFaces << " boundary faces)" << CGoGNendl; } return true; }