diff --git a/SCHNApps/Plugins/surface_selection/include/surface_selection.h b/SCHNApps/Plugins/surface_selection/include/surface_selection.h index 7fa3309a5101553f460868d641ab77d4aa17e8f0..9b2bc93daba778aec74960bd19557a5435307f3c 100644 --- a/SCHNApps/Plugins/surface_selection/include/surface_selection.h +++ b/SCHNApps/Plugins/surface_selection/include/surface_selection.h @@ -81,12 +81,16 @@ protected: Utils::PointSprite* m_pointSprite; Utils::Drawer* m_drawer; + // cell under the mouse when selecting + Dart m_selectingVertex; + Dart m_selectingEdge; + Dart m_selectingFace; + // selected cells drawing Utils::VBO* m_selectedVerticesVBO; // WithinSphere parameters Utils::VBO* m_selectionSphereVBO; - PFP2::VEC3 m_selectionCenter; PFP2::REAL m_selectionRadius; }; diff --git a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp index fe70e9e1b975a6e0bbebd442fb36223e07d07c89..db8f23346751be9d426512cd17055d5a28da4fda 100644 --- a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp +++ b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp @@ -75,25 +75,23 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) if(selector) { const std::vector& selectedCells = selector->getSelectedCells(); + unsigned int nbCells = map->getGenericMap()->getNbCells(orbit); switch(orbit) { case VERTEX : { m_pointSprite->setAttributePosition(m_selectedVerticesVBO); - m_pointSprite->setSize(map->getBBdiagSize() / 500.0f); + m_pointSprite->setSize(20 * map->getBBdiagSize() / nbCells); m_pointSprite->setColor(CGoGN::Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f)); m_pointSprite->enableVertexAttribs(); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDrawArrays(GL_POINTS, 0, selectedCells.size()); - glDisable(GL_BLEND); m_pointSprite->disableVertexAttribs(); - if(m_selecting) + if(m_selecting && m_selectingVertex != NIL) { std::vector selectionPoint; - selectionPoint.push_back(m_selectionCenter); + selectionPoint.push_back(p.positionAttribute[m_selectingVertex]); m_selectionSphereVBO->updateData(selectionPoint); m_pointSprite->setAttributePosition(m_selectionSphereVBO); @@ -103,7 +101,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) switch(p.selectionMethod) { case SingleCell : { - m_pointSprite->setSize(map->getBBdiagSize() / 250.0f); + m_pointSprite->setSize(30 * map->getBBdiagSize() / nbCells); break; } case WithinSphere : { @@ -122,9 +120,77 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) break; } case EDGE : { + PFP2::MAP* m = static_cast*>(map)->getMap(); + + m_drawer->newList(GL_COMPILE_AND_EXECUTE); + m_drawer->lineWidth(3.0f); + m_drawer->color3f(1.0f, 0.0f, 0.0f); + m_drawer->begin(GL_LINES); + for(std::vector::const_iterator it = selectedCells.begin(); it != selectedCells.end(); ++it) + { + m_drawer->vertex(p.positionAttribute[*it]); + m_drawer->vertex(p.positionAttribute[m->phi1(*it)]); + } + m_drawer->end(); + m_drawer->endList(); + + if(m_selecting && m_selectingEdge != NIL) + { + switch(p.selectionMethod) + { + case SingleCell : { + m_drawer->newList(GL_COMPILE_AND_EXECUTE); + m_drawer->lineWidth(6.0f); + m_drawer->color3f(0.0f, 0.0f, 1.0f); + m_drawer->begin(GL_LINES); + m_drawer->vertex(p.positionAttribute[m_selectingEdge]); + m_drawer->vertex(p.positionAttribute[m->phi1(m_selectingEdge)]); + m_drawer->end(); + m_drawer->endList(); + break; + } + case WithinSphere : { + break; + } + } + } break; } case FACE : { + PFP2::MAP* m = static_cast*>(map)->getMap(); + + m_drawer->newList(GL_COMPILE_AND_EXECUTE); + m_drawer->color3f(1.0f, 0.0f, 0.0f); + m_drawer->begin(GL_TRIANGLES); + for(std::vector::const_iterator it = selectedCells.begin(); it != selectedCells.end(); ++it) + { + m_drawer->vertex(p.positionAttribute[*it]); + m_drawer->vertex(p.positionAttribute[m->phi1(*it)]); + m_drawer->vertex(p.positionAttribute[m->phi_1(*it)]); + } + m_drawer->end(); + m_drawer->endList(); + + if(m_selecting && m_selectingFace != NIL) + { + switch(p.selectionMethod) + { + case SingleCell : { + m_drawer->newList(GL_COMPILE_AND_EXECUTE); + m_drawer->color3f(0.0f, 0.0f, 1.0f); + m_drawer->begin(GL_TRIANGLES); + m_drawer->vertex(p.positionAttribute[m_selectingFace]); + m_drawer->vertex(p.positionAttribute[m->phi1(m_selectingFace)]); + m_drawer->vertex(p.positionAttribute[m->phi_1(m_selectingFace)]); + m_drawer->end(); + m_drawer->endList(); + break; + } + case WithinSphere : { + break; + } + } + } break; } } @@ -163,41 +229,27 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) { unsigned int orbit = m_schnapps->getCurrentOrbit(); CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit); - if(selector) { - QPoint pixel(event->x(), event->y()); - qglviewer::Vec orig; - qglviewer::Vec dir; - view->camera()->convertClickToLine(pixel, orig, dir); - - qglviewer::Vec orig_inv = mh->getFrame()->coordinatesOf(orig); - qglviewer::Vec dir_inv = mh->getFrame()->transformOf(dir); - - PFP2::VEC3 rayA(orig_inv.x, orig_inv.y, orig_inv.z); - PFP2::VEC3 AB(dir_inv.x, dir_inv.y, dir_inv.z); - - Dart d; PFP2::MAP* map = static_cast*>(mh)->getMap(); switch(orbit) { case VERTEX : { - Algo::Selection::vertexRaySelection(*map, p.positionAttribute, rayA, AB, d); - if(d != NIL) + if(m_selectingVertex != NIL) { switch(p.selectionMethod) { case SingleCell : { if(event->button() == Qt::LeftButton) - selector->select(d); + selector->select(m_selectingVertex); else if(event->button() == Qt::RightButton) - selector->unselect(d); + selector->unselect(m_selectingVertex); break; } case WithinSphere : { Algo::Surface::Selection::Collector_WithinSphere neigh(*map, p.positionAttribute, m_selectionRadius); - neigh.collectAll(d); + neigh.collectAll(m_selectingVertex); if(event->button() == Qt::LeftButton) selector->select(neigh.getInsideVertices()); else if(event->button() == Qt::RightButton) @@ -215,9 +267,41 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) break; } case EDGE : { + if(m_selectingEdge != NIL) + { + switch(p.selectionMethod) + { + case SingleCell : { + if(event->button() == Qt::LeftButton) + selector->select(m_selectingEdge); + else if(event->button() == Qt::RightButton) + selector->unselect(m_selectingEdge); + break; + } + case WithinSphere : { + break; + } + } + } break; } case FACE : { + if(m_selectingFace != NIL) + { + switch(p.selectionMethod) + { + case SingleCell : { + if(event->button() == Qt::LeftButton) + selector->select(m_selectingFace); + else if(event->button() == Qt::RightButton) + selector->unselect(m_selectingFace); + break; + } + case WithinSphere : { + break; + } + } + } break; } } @@ -239,23 +323,39 @@ void Surface_Selection_Plugin::mouseMove(View* view, QMouseEvent* event) const MapParameters& p = h_parameterSet[mh]; if(p.positionAttribute.isValid()) { - QPoint pixel(event->x(), event->y()); - qglviewer::Vec orig; - qglviewer::Vec dir; - view->camera()->convertClickToLine(pixel, orig, dir); + unsigned int orbit = m_schnapps->getCurrentOrbit(); + CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit); + if(selector) + { + QPoint pixel(event->x(), event->y()); + qglviewer::Vec orig; + qglviewer::Vec dir; + view->camera()->convertClickToLine(pixel, orig, dir); + + qglviewer::Vec orig_inv = mh->getFrame()->coordinatesOf(orig); + qglviewer::Vec dir_inv = mh->getFrame()->transformOf(dir); - qglviewer::Vec orig_inv = mh->getFrame()->coordinatesOf(orig); - qglviewer::Vec dir_inv = mh->getFrame()->transformOf(dir); + PFP2::VEC3 rayA(orig_inv.x, orig_inv.y, orig_inv.z); + PFP2::VEC3 AB(dir_inv.x, dir_inv.y, dir_inv.z); - PFP2::VEC3 rayA(orig_inv.x, orig_inv.y, orig_inv.z); - PFP2::VEC3 AB(dir_inv.x, dir_inv.y, dir_inv.z); + PFP2::MAP* map = static_cast*>(mh)->getMap(); + + switch(orbit) + { + case VERTEX : { + Algo::Selection::vertexRaySelection(*map, p.positionAttribute, rayA, AB, m_selectingVertex); + break; + } + case EDGE : { + Algo::Selection::edgeRaySelection(*map, p.positionAttribute, rayA, AB, m_selectingEdge); + break; + } + case FACE : { + Algo::Selection::faceRaySelection(*map, p.positionAttribute, rayA, AB, m_selectingFace); + break; + } + } - Dart d; - PFP2::MAP* map = static_cast*>(mh)->getMap(); - Algo::Selection::vertexRaySelection(*map, p.positionAttribute, rayA, AB, d); - if(d != NIL) - { - m_selectionCenter = p.positionAttribute[d]; view->updateGL(); } } diff --git a/SCHNApps/include/cellSelector.h b/SCHNApps/include/cellSelector.h index 4475eec42f3bdf1b3f85f468e35e900971c5d77d..8689a861ca1d2c431d023841a8a34748e66a7844 100644 --- a/SCHNApps/include/cellSelector.h +++ b/SCHNApps/include/cellSelector.h @@ -109,11 +109,10 @@ public: inline void select(Dart d, bool emitSignal = true) { - unsigned int v = m_map.getEmbedding(d); - if(!m_cm.isMarked(v)) + if(!m_cm.isMarked(d)) { m_cells.push_back(d); - m_cm.mark(v); + m_cm.mark(d); if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty()) { foreach(CellSelectorGen* cs, m_mutuallyExclusive) @@ -128,9 +127,9 @@ public: inline void unselect(Dart d, bool emitSignal = true) { - unsigned int v = m_map.getEmbedding(d); - if(m_cm.isMarked(v)) + if(m_cm.isMarked(d)) { + unsigned int v = m_map.getEmbedding(d); bool found = false; unsigned int i; for(i = 0; i < m_cells.size() && !found; ++i) diff --git a/include/Algo/Import/import.h b/include/Algo/Import/import.h index 682cf6e50e9af39fb11fb64df3893312fc9c9a54..360cfbeb5681c4fb08b27542f85e5a1309d8fb77 100644 --- a/include/Algo/Import/import.h +++ b/include/Algo/Import/import.h @@ -54,6 +54,16 @@ namespace Import template bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector& attrNames, bool mergeCloseVertices = false); +/** +* import a voxellisation +* @param map the map in which the function imports the mesh +* @param voxellisation +* @param attrNames attribute names +* @param mergeCloseVertices a boolean indicating if close vertices should be merged during import +* @return a boolean indicating if import was successful +*/ +template +bool importVoxellisation(typename PFP::MAP& map, Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector& attrNames, bool mergeCloseVertices=false); /** * import a Choupi file @@ -64,7 +74,6 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector template bool importChoupi(const std::string& filename, const std::vector& tabV, const std::vector& tabE); - } // namespace Import } // Surface diff --git a/include/Algo/Import/import2tables.h b/include/Algo/Import/import2tables.h index 331963864a0c35c6150447eb4a129d2405b9844c..ffaec2b5b9218e0509ec9bcab8ae0a6050bf3c9d 100644 --- a/include/Algo/Import/import2tables.h +++ b/include/Algo/Import/import2tables.h @@ -36,6 +36,7 @@ #include "Utils/gzstream.h" #include "Algo/Import/importFileTypes.h" +#include "Algo/Modelisation/voxellisation.h" #ifdef WITH_ASSIMP #include "Assimp/assimp.h" @@ -103,9 +104,11 @@ public: bool importOff(const std::string& filename, std::vector& attrNames); + bool importVoxellisation(Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector& attrNames); + bool importMeshBin(const std::string& filename, std::vector& attrNames); - bool importObj(const std::string& filename, std::vector& attrNames); + bool importObj(const std::string& filename, std::vector& attrNames); bool importPly(const std::string& filename, std::vector& attrNames); diff --git a/include/Algo/Import/import2tablesSurface.hpp b/include/Algo/Import/import2tablesSurface.hpp index fece4afaafdaf0c75441fb877800cdb13fad5f2b..c4bc4bb8ec209e71a723c6b4f68b00ef13f2d5cc 100644 --- a/include/Algo/Import/import2tablesSurface.hpp +++ b/include/Algo/Import/import2tablesSurface.hpp @@ -26,6 +26,8 @@ #include "Algo/Geometry/boundingbox.h" #include "Topology/generic/autoAttributeHandler.h" +#include "Algo/Modelisation/voxellisation.h" + #include "Algo/Import/AHEM.h" namespace CGoGN @@ -43,270 +45,270 @@ namespace Import template ImportType MeshTablesSurface::getFileType(const std::string& filename) { - if ((filename.rfind(".trianbgz")!=std::string::npos) || (filename.rfind(".TRIANBGZ")!=std::string::npos)) - return TRIANBGZ; + if ((filename.rfind(".trianbgz")!=std::string::npos) || (filename.rfind(".TRIANBGZ")!=std::string::npos)) + return TRIANBGZ; - if ((filename.rfind(".trian")!=std::string::npos) || (filename.rfind(".TRIAN")!=std::string::npos)) - return TRIAN; + if ((filename.rfind(".trian")!=std::string::npos) || (filename.rfind(".TRIAN")!=std::string::npos)) + return TRIAN; - if ((filename.rfind(".meshbin")!=std::string::npos) || (filename.rfind(".MESHBIN")!=std::string::npos)) - return MESHBIN; + if ((filename.rfind(".meshbin")!=std::string::npos) || (filename.rfind(".MESHBIN")!=std::string::npos)) + return MESHBIN; /* if ((filename.rfind(".plyptm")!=std::string::npos) || (filename.rfind(".PLYGEN")!=std::string::npos)) - return PLYPTM; + return PLYPTM; */ - if ((filename.rfind(".plyPTMextBin")!=std::string::npos) || (filename.rfind(".plySHrealBin")!=std::string::npos)) - return PLYSLFgenericBin; + if ((filename.rfind(".plyPTMextBin")!=std::string::npos) || (filename.rfind(".plySHrealBin")!=std::string::npos)) + return PLYSLFgenericBin; - if ((filename.rfind(".plyPTMext")!=std::string::npos) || (filename.rfind(".plySHreal")!=std::string::npos)) - return PLYSLFgeneric; + if ((filename.rfind(".plyPTMext")!=std::string::npos) || (filename.rfind(".plySHreal")!=std::string::npos)) + return PLYSLFgeneric; - if ((filename.rfind(".ply")!=std::string::npos) || (filename.rfind(".PLY")!=std::string::npos)) - return PLY; + if ((filename.rfind(".ply")!=std::string::npos) || (filename.rfind(".PLY")!=std::string::npos)) + return PLY; - if ((filename.rfind(".off")!=std::string::npos) || (filename.rfind(".OFF")!=std::string::npos)) - return OFF; + if ((filename.rfind(".off")!=std::string::npos) || (filename.rfind(".OFF")!=std::string::npos)) + return OFF; - if ((filename.rfind(".obj")!=std::string::npos) || (filename.rfind(".OBJ")!=std::string::npos)) - return OBJ; + if ((filename.rfind(".obj")!=std::string::npos) || (filename.rfind(".OBJ")!=std::string::npos)) + return OBJ; - if ((filename.rfind(".ahem")!=std::string::npos) || (filename.rfind(".AHEM")!=std::string::npos)) - return AHEM; + if ((filename.rfind(".ahem")!=std::string::npos) || (filename.rfind(".AHEM")!=std::string::npos)) + return AHEM; - if ((filename.rfind(".stlb")!=std::string::npos) || (filename.rfind(".STLB")!=std::string::npos)) - return STLB; + if ((filename.rfind(".stlb")!=std::string::npos) || (filename.rfind(".STLB")!=std::string::npos)) + return STLB; - if ((filename.rfind(".stl")!=std::string::npos) || (filename.rfind(".STL")!=std::string::npos)) - return STL; + if ((filename.rfind(".stl")!=std::string::npos) || (filename.rfind(".STL")!=std::string::npos)) + return STL; - return UNKNOWNSURFACE; + return UNKNOWNSURFACE; } template bool MeshTablesSurface::importMesh(const std::string& filename, std::vector& attrNames) { - ImportType kind = getFileType(filename); - - attrNames.clear() ; - - switch (kind) - { - case TRIAN: - CGoGNout << "TYPE: TRIAN" << CGoGNendl; - return importTrian(filename, attrNames); - break; - case TRIANBGZ: - CGoGNout << "TYPE: TRIANBGZ" << CGoGNendl; - return importTrianBinGz(filename, attrNames); - break; - case OFF: - CGoGNout << "TYPE: OFF" << CGoGNendl; - return importOff(filename, attrNames); - break; - case MESHBIN: - CGoGNout << "TYPE: MESHBIN" << CGoGNendl; - return importMeshBin(filename, attrNames); - break; - case PLY: - CGoGNout << "TYPE: PLY" << CGoGNendl; - return importPly(filename, attrNames); - break; + ImportType kind = getFileType(filename); + + attrNames.clear() ; + + switch (kind) + { + case TRIAN: + CGoGNout << "TYPE: TRIAN" << CGoGNendl; + return importTrian(filename, attrNames); + break; + case TRIANBGZ: + CGoGNout << "TYPE: TRIANBGZ" << CGoGNendl; + return importTrianBinGz(filename, attrNames); + break; + case OFF: + CGoGNout << "TYPE: OFF" << CGoGNendl; + return importOff(filename, attrNames); + break; + case MESHBIN: + CGoGNout << "TYPE: MESHBIN" << CGoGNendl; + return importMeshBin(filename, attrNames); + break; + case PLY: + CGoGNout << "TYPE: PLY" << CGoGNendl; + return importPly(filename, attrNames); + break; /* case PLYPTM: - CGoGNout << "TYPE: PLYPTM" << CGoGNendl; - return importPlyPTM(filename, attrNames); - break; + CGoGNout << "TYPE: PLYPTM" << CGoGNendl; + return importPlyPTM(filename, attrNames); + break; */ case PLYSLFgeneric: - CGoGNout << "TYPE: PLYSLFgeneric" << CGoGNendl; - return importPlySLFgeneric(filename, attrNames); - break; - case PLYSLFgenericBin: - CGoGNout << "TYPE: PLYSLFgenericBin" << CGoGNendl; - return importPlySLFgenericBin(filename, attrNames); - break; - case OBJ: - CGoGNout << "TYPE: OBJ" << CGoGNendl; - return importObj(filename, attrNames); - break; - case AHEM: - CGoGNout << "TYPE: AHEM" << CGoGNendl; - return importAHEM(filename, attrNames); - break; - case STLB: - CGoGNout << "TYPE: STLB" << CGoGNendl; - return importSTLBin(filename, attrNames); - break; - case STL: - CGoGNout << "TYPE: STL" << CGoGNendl; - return importSTLAscii(filename, attrNames); - break; - default: - #ifdef WITH_ASSIMP - CGoGNout << "TYPE: ASSIMP" << CGoGNendl; - return importASSIMP(filename, attrNames); - #else - CGoGNout << "unsupported file type"<< CGoGNendl; - #endif - break; - } - return false; + CGoGNout << "TYPE: PLYSLFgeneric" << CGoGNendl; + return importPlySLFgeneric(filename, attrNames); + break; + case PLYSLFgenericBin: + CGoGNout << "TYPE: PLYSLFgenericBin" << CGoGNendl; + return importPlySLFgenericBin(filename, attrNames); + break; + case OBJ: + CGoGNout << "TYPE: OBJ" << CGoGNendl; + return importObj(filename, attrNames); + break; + case AHEM: + CGoGNout << "TYPE: AHEM" << CGoGNendl; + return importAHEM(filename, attrNames); + break; + case STLB: + CGoGNout << "TYPE: STLB" << CGoGNendl; + return importSTLBin(filename, attrNames); + break; + case STL: + CGoGNout << "TYPE: STL" << CGoGNendl; + return importSTLAscii(filename, attrNames); + break; + default: + #ifdef WITH_ASSIMP + CGoGNout << "TYPE: ASSIMP" << CGoGNendl; + return importASSIMP(filename, attrNames); + #else + CGoGNout << "unsupported file type"<< CGoGNendl; + #endif + break; + } + return false; } template bool MeshTablesSurface::importTrian(const std::string& filename, std::vector& attrNames) { - VertexAttribute positions = m_map.template getAttribute("position") ; - - if (!positions.isValid()) - positions = m_map.template addAttribute("position") ; - - attrNames.push_back(positions.name()) ; - - AttributeContainer& container = m_map.template getAttributeContainer() ; - - // open file - std::ifstream fp(filename.c_str(), std::ios::in); - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } - - // read nb of points - fp >> m_nbVertices; - - // read points - std::vector verticesID; - verticesID.reserve(m_nbVertices); - - for (unsigned int i = 0; i < m_nbVertices; ++i) - { - VEC3 pos; - fp >> pos[0]; - fp >> pos[1]; - fp >> pos[2]; - unsigned int id = container.insertLine(); - positions[id] = pos; - verticesID.push_back(id); - } - - // read nb of faces - fp >> m_nbFaces; - m_nbEdges.reserve(m_nbFaces); - m_emb.reserve(3*m_nbFaces); - - // read indices of faces - for (unsigned int i = 0; i < m_nbFaces; ++i) - { - m_nbEdges.push_back(3); - // read the three vertices of triangle - int pt; - fp >> pt; - m_emb.push_back(verticesID[pt]); - fp >> pt; - m_emb.push_back(verticesID[pt]); - fp >> pt; - m_emb.push_back(verticesID[pt]); - - // neighbour not always good in files !! - int neigh; - fp >> neigh; - fp >> neigh; - fp >> neigh; - } - - fp.close(); - return true; + VertexAttribute positions = m_map.template getAttribute("position") ; + + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; + + attrNames.push_back(positions.name()) ; + + AttributeContainer& container = m_map.template getAttributeContainer() ; + + // open file + std::ifstream fp(filename.c_str(), std::ios::in); + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } + + // read nb of points + fp >> m_nbVertices; + + // read points + std::vector verticesID; + verticesID.reserve(m_nbVertices); + + for (unsigned int i = 0; i < m_nbVertices; ++i) + { + VEC3 pos; + fp >> pos[0]; + fp >> pos[1]; + fp >> pos[2]; + unsigned int id = container.insertLine(); + positions[id] = pos; + verticesID.push_back(id); + } + + // read nb of faces + fp >> m_nbFaces; + m_nbEdges.reserve(m_nbFaces); + m_emb.reserve(3*m_nbFaces); + + // read indices of faces + for (unsigned int i = 0; i < m_nbFaces; ++i) + { + m_nbEdges.push_back(3); + // read the three vertices of triangle + int pt; + fp >> pt; + m_emb.push_back(verticesID[pt]); + fp >> pt; + m_emb.push_back(verticesID[pt]); + fp >> pt; + m_emb.push_back(verticesID[pt]); + + // neighbour not always good in files !! + int neigh; + fp >> neigh; + fp >> neigh; + fp >> neigh; + } + + fp.close(); + return true; } template bool MeshTablesSurface::importTrianBinGz(const std::string& filename, std::vector& attrNames) { - VertexAttribute positions = m_map.template getAttribute("position") ; - - if (!positions.isValid()) - positions = m_map.template addAttribute("position") ; - - attrNames.push_back(positions.name()) ; - - AttributeContainer& container = m_map.template getAttributeContainer() ; - - // open file - igzstream fs(filename.c_str(), std::ios::in|std::ios::binary); - - if (!fs.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } - - // read nb of points - fs.read(reinterpret_cast(&m_nbVertices), sizeof(int)); - - // read points - std::vector verticesID; - { // juste pour limiter la portee des variables - verticesID.reserve(m_nbVertices); - float* buffer = new float[m_nbVertices*3]; - fs.read(reinterpret_cast(buffer), 3*m_nbVertices*sizeof(float)); - float *ptr = buffer; - for (unsigned int i = 0; i < m_nbVertices; ++i) - { - VEC3 pos; - pos[0]= *ptr++; - pos[1]= *ptr++; - pos[2]= *ptr++; - - unsigned int id = container.insertLine(); - positions[id] = pos; - - verticesID.push_back(id); - } - delete[] buffer; - } - - // read nb of faces - fs.read(reinterpret_cast(&m_nbFaces), sizeof(int)); - m_nbEdges.reserve(m_nbFaces); - m_emb.reserve(3*m_nbFaces); - - // read indices of faces - { // juste pour limiter la portee des variables - int* buffer = new int[m_nbFaces*6]; - fs.read(reinterpret_cast(buffer),6*m_nbFaces*sizeof(float)); - int *ptr = buffer; - - for (unsigned int i = 0; i < m_nbFaces; i++) - { - m_nbEdges.push_back(3); - m_emb.push_back(verticesID[*ptr++]); - m_emb.push_back(verticesID[*ptr++]); - m_emb.push_back(verticesID[*ptr++]); - } - } - - fs.close(); - return true; + VertexAttribute positions = m_map.template getAttribute("position") ; + + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; + + attrNames.push_back(positions.name()) ; + + AttributeContainer& container = m_map.template getAttributeContainer() ; + + // open file + igzstream fs(filename.c_str(), std::ios::in|std::ios::binary); + + if (!fs.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } + + // read nb of points + fs.read(reinterpret_cast(&m_nbVertices), sizeof(int)); + + // read points + std::vector verticesID; + { // juste pour limiter la portee des variables + verticesID.reserve(m_nbVertices); + float* buffer = new float[m_nbVertices*3]; + fs.read(reinterpret_cast(buffer), 3*m_nbVertices*sizeof(float)); + float *ptr = buffer; + for (unsigned int i = 0; i < m_nbVertices; ++i) + { + VEC3 pos; + pos[0]= *ptr++; + pos[1]= *ptr++; + pos[2]= *ptr++; + + unsigned int id = container.insertLine(); + positions[id] = pos; + + verticesID.push_back(id); + } + delete[] buffer; + } + + // read nb of faces + fs.read(reinterpret_cast(&m_nbFaces), sizeof(int)); + m_nbEdges.reserve(m_nbFaces); + m_emb.reserve(3*m_nbFaces); + + // read indices of faces + { // juste pour limiter la portee des variables + int* buffer = new int[m_nbFaces*6]; + fs.read(reinterpret_cast(buffer),6*m_nbFaces*sizeof(float)); + int *ptr = buffer; + + for (unsigned int i = 0; i < m_nbFaces; i++) + { + m_nbEdges.push_back(3); + m_emb.push_back(verticesID[*ptr++]); + m_emb.push_back(verticesID[*ptr++]); + m_emb.push_back(verticesID[*ptr++]); + } + } + + fs.close(); + return true; } template bool MeshTablesSurface::importOff(const std::string& filename, std::vector& attrNames) { - VertexAttribute positions = m_map.template getAttribute("position") ; + VertexAttribute positions = m_map.template getAttribute("position") ; - if (!positions.isValid()) - positions = m_map.template addAttribute("position") ; + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; - attrNames.push_back(positions.name()) ; + attrNames.push_back(positions.name()) ; - AttributeContainer& container = m_map.template getAttributeContainer() ; + AttributeContainer& container = m_map.template getAttributeContainer() ; - // open file - std::ifstream fp(filename.c_str(), std::ios::in); - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } + // open file + std::ifstream fp(filename.c_str(), std::ios::in); + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } std::string ligne; @@ -314,102 +316,146 @@ bool MeshTablesSurface::importOff(const std::string& filename, std::vector< std::getline (fp, ligne); if (ligne.rfind("OFF") == std::string::npos) { - CGoGNerr << "Problem reading off file: not an off file" << CGoGNendl; - CGoGNerr << ligne << CGoGNendl; - return false; + CGoGNerr << "Problem reading off file: not an off file" << CGoGNendl; + CGoGNerr << ligne << CGoGNendl; + return false; } // lecture des nombres de sommets/faces/aretes - int nbe; + int nbe; + { + do + { + std::getline (fp, ligne); + } while (ligne.size() == 0); + + std::stringstream oss(ligne); + oss >> m_nbVertices; + oss >> m_nbFaces; + oss >> nbe; + } + + //lecture sommets + std::vector verticesID; + verticesID.reserve(m_nbVertices); + for (unsigned int i = 0; i < m_nbVertices;++i) + { + do + { + std::getline (fp, ligne); + } while (ligne.size() == 0); + + std::stringstream oss(ligne); + + float x,y,z; + oss >> x; + oss >> y; + oss >> z; + // on peut ajouter ici la lecture de couleur si elle existe + VEC3 pos(x,y,z); + + unsigned int id = container.insertLine(); + positions[id] = pos; + + verticesID.push_back(id); + } + + // lecture faces + // normalement nbVertices*8 devrait suffire largement + m_nbEdges.reserve(m_nbFaces); + m_emb.reserve(m_nbVertices*8); + + for (unsigned int i = 0; i < m_nbFaces; ++i) + { + do + { + std::getline (fp, ligne); + } while (ligne.size() == 0); + + std::stringstream oss(ligne); + unsigned int n; + oss >> n; + m_nbEdges.push_back(n); + for (unsigned int j = 0; j < n; ++j) + { + int index; // index du plongement + oss >> index; + m_emb.push_back(verticesID[index]); + } + // on peut ajouter ici la lecture de couleur si elle existe + } + + fp.close(); + return true; +} + +template +bool MeshTablesSurface::importVoxellisation(Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector& attrNames) +{ + VertexAttribute positions = m_map.template getAttribute("position") ; + + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; + + attrNames.push_back(positions.name()) ; + + AttributeContainer& container = m_map.template getAttributeContainer() ; + + // lecture des nombres de sommets/faces + m_nbVertices = voxellisation.getNbSommets(); + m_nbFaces = voxellisation.getNbFaces(); + + //lecture sommets + std::vector verticesID; + verticesID.reserve(m_nbVertices); + for (unsigned int i = 0; i < m_nbVertices;++i) { - do - { - std::getline (fp, ligne); - } while (ligne.size() == 0); + unsigned int id = container.insertLine(); + positions[id] = voxellisation.m_sommets[i]; - std::stringstream oss(ligne); - oss >> m_nbVertices; - oss >> m_nbFaces; - oss >> nbe; + verticesID.push_back(id); } - //lecture sommets - std::vector verticesID; - verticesID.reserve(m_nbVertices); - for (unsigned int i = 0; i < m_nbVertices;++i) - { - do - { - std::getline (fp, ligne); - } while (ligne.size() == 0); - - std::stringstream oss(ligne); - - float x,y,z; - oss >> x; - oss >> y; - oss >> z; - // on peut ajouter ici la lecture de couleur si elle existe - VEC3 pos(x,y,z); - - unsigned int id = container.insertLine(); - positions[id] = pos; - - verticesID.push_back(id); - } - - // lecture faces - // normalement nbVertices*8 devrait suffire largement - m_nbEdges.reserve(m_nbFaces); - m_emb.reserve(m_nbVertices*8); - - for (unsigned int i = 0; i < m_nbFaces; ++i) - { - do - { - std::getline (fp, ligne); - } while (ligne.size() == 0); - - std::stringstream oss(ligne); - unsigned int n; - oss >> n; - m_nbEdges.push_back(n); - for (unsigned int j = 0; j < n; ++j) - { - int index; // index du plongement - oss >> index; - m_emb.push_back(verticesID[index]); - } - // on peut ajouter ici la lecture de couleur si elle existe - } - - fp.close(); - return true; + // lecture faces + // normalement nbVertices*8 devrait suffire largement + m_nbEdges.reserve(m_nbFaces); + m_emb.reserve(m_nbVertices*8); + + for (unsigned int i = 0; i < m_nbFaces*4-3; i=i+4) + { + m_nbEdges.push_back(4); //Toutes les faces ont 4 côtés (de par leur construction) + for (unsigned int j = 0; j < 4; ++j) + { + m_emb.push_back(verticesID[voxellisation.m_faces[i+j]]); + } + } + + return true; } template bool MeshTablesSurface::importMeshBin(const std::string& filename, std::vector& attrNames) { - VertexAttribute positions = m_map.template getAttribute("position") ; + VertexAttribute positions = m_map.template getAttribute("position") ; - if (!positions.isValid()) - { - positions = m_map.template addAttribute("position") ; - } + if (!positions.isValid()) + { + positions = m_map.template addAttribute("position") ; + } - attrNames.push_back(positions.name()) ; + attrNames.push_back(positions.name()) ; - AttributeContainer& container = m_map.template getAttributeContainer() ; + AttributeContainer& container = m_map.template getAttributeContainer() ; - // open file - std::ifstream fp(filename.c_str(), std::ios::in | std::ios::binary); - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } + // open file + std::ifstream fp(filename.c_str(), std::ios::in | std::ios::binary); + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } - // Read header + // Read header unsigned int Fmin, Fmax ; fp.read((char*)&m_nbVertices, sizeof(unsigned int)) ; fp.read((char*)&m_nbFaces, sizeof(unsigned int)) ; @@ -419,64 +465,64 @@ bool MeshTablesSurface::importMeshBin(const std::string& filename, std::vec assert((Fmin == 3 && Fmax == 3) || !"Only triangular faces are handled yet") ; // Read foreach vertex - std::vector verticesID ; - verticesID.reserve(m_nbVertices) ; + std::vector verticesID ; + verticesID.reserve(m_nbVertices) ; for (unsigned int vxNum = 0 ; vxNum < m_nbVertices ; ++vxNum) { - Geom::Vec3f pos ; - fp.read((char*) &pos[0], sizeof(float)) ; - fp.read((char*) &pos[1], sizeof(float)) ; - fp.read((char*) &pos[2], sizeof(float)) ; + Geom::Vec3f pos ; + fp.read((char*) &pos[0], sizeof(float)) ; + fp.read((char*) &pos[1], sizeof(float)) ; + fp.read((char*) &pos[2], sizeof(float)) ; - unsigned int id = container.insertLine() ; - positions[id] = pos ; + unsigned int id = container.insertLine() ; + positions[id] = pos ; - verticesID.push_back(id) ; + verticesID.push_back(id) ; } // Read foreach face - m_nbEdges.reserve(m_nbFaces) ; - m_emb.reserve(m_nbVertices * 8) ; - - for (unsigned int fNum = 0; fNum < m_nbFaces; ++fNum) - { - const unsigned int faceSize = 3 ; - fp.read((char*) &faceSize, sizeof(float)) ; - m_nbEdges.push_back(faceSize) ; - - for (unsigned int i = 0 ; i < faceSize; ++i) - { - unsigned int index ; // index of embedding - fp.read((char*) &index, sizeof(unsigned int)) ; - m_emb.push_back(verticesID[index]) ; - } - } - - fp.close() ; - return true ; + m_nbEdges.reserve(m_nbFaces) ; + m_emb.reserve(m_nbVertices * 8) ; + + for (unsigned int fNum = 0; fNum < m_nbFaces; ++fNum) + { + const unsigned int faceSize = 3 ; + fp.read((char*) &faceSize, sizeof(float)) ; + m_nbEdges.push_back(faceSize) ; + + for (unsigned int i = 0 ; i < faceSize; ++i) + { + unsigned int index ; // index of embedding + fp.read((char*) &index, sizeof(unsigned int)) ; + m_emb.push_back(verticesID[index]) ; + } + } + + fp.close() ; + return true ; } template bool MeshTablesSurface::importObj(const std::string& filename, std::vector& attrNames) { - VertexAttribute positions = m_map.template getAttribute("position") ; + VertexAttribute positions = m_map.template getAttribute("position") ; - if (!positions.isValid()) - positions = m_map.template addAttribute("position") ; + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; - attrNames.push_back(positions.name()) ; + attrNames.push_back(positions.name()) ; - AttributeContainer& container = m_map.template getAttributeContainer() ; + AttributeContainer& container = m_map.template getAttributeContainer() ; - // open file - std::ifstream fp(filename.c_str(), std::ios::binary); - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } + // open file + std::ifstream fp(filename.c_str(), std::ios::binary); + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } // fp.seekg(0, std::ios::end); // int ab = fp.tellg(); @@ -488,181 +534,181 @@ bool MeshTablesSurface::importObj(const std::string& filename, std::vector< do { - fp >> tag; - std::getline (fp, ligne); + fp >> tag; + std::getline (fp, ligne); }while (tag != std::string("v")); // lecture des sommets - std::vector verticesID; - verticesID.reserve(102400); // on tape large (400Ko wahouuuuu !!) + std::vector verticesID; + verticesID.reserve(102400); // on tape large (400Ko wahouuuuu !!) - unsigned int i = 0; + unsigned int i = 0; do { - if (tag == std::string("v")) - { - std::stringstream oss(ligne); - - float x,y,z; - oss >> x; - oss >> y; - oss >> z; + if (tag == std::string("v")) + { + std::stringstream oss(ligne); + + float x,y,z; + oss >> x; + oss >> y; + oss >> z; - VEC3 pos(x,y,z); + VEC3 pos(x,y,z); - unsigned int id = container.insertLine(); - positions[id] = pos; + unsigned int id = container.insertLine(); + positions[id] = pos; - verticesID.push_back(id); - i++; - } + verticesID.push_back(id); + i++; + } - fp >> tag; - std::getline(fp, ligne); + fp >> tag; + std::getline(fp, ligne); } while (!fp.eof()); - m_nbVertices = verticesID.size(); + m_nbVertices = verticesID.size(); - // close/clear/open only way to go back to beginning of file - fp.close(); - fp.clear(); - fp.open(filename.c_str()); + // close/clear/open only way to go back to beginning of file + fp.close(); + fp.clear(); + fp.open(filename.c_str()); - do + do { - fp >> tag; - std::getline (fp, ligne); + fp >> tag; + std::getline (fp, ligne); } while (tag != std::string("f")); - m_nbEdges.reserve(verticesID.size()*2); - m_emb.reserve(verticesID.size()*8); + m_nbEdges.reserve(verticesID.size()*2); + m_emb.reserve(verticesID.size()*8); - std::vector table; - table.reserve(64); // NBV cotes pour une face devrait suffire - m_nbFaces = 0; + std::vector table; + table.reserve(64); // NBV cotes pour une face devrait suffire + m_nbFaces = 0; do { - if (tag == std::string("f")) // lecture d'une face - { - std::stringstream oss(ligne); - table.clear(); - while (!oss.eof()) // lecture de tous les indices - { - std::string str; - oss >> str; - - unsigned int ind = 0; - - while ((ind 0) - { - long index; - std::stringstream iss(str.substr(0, ind)); - iss >> index; - table.push_back(index); - } - } - - unsigned int n = table.size(); - m_nbEdges.push_back(short(n)); - for (unsigned int j = 0; j < n; ++j) - { - int index = table[j] - 1; // les index commencent a 1 (boufonnerie d'obj ;) - m_emb.push_back(verticesID[index]); - } - m_nbFaces++; - } - fp >> tag; - std::getline(fp, ligne); + if (tag == std::string("f")) // lecture d'une face + { + std::stringstream oss(ligne); + table.clear(); + while (!oss.eof()) // lecture de tous les indices + { + std::string str; + oss >> str; + + unsigned int ind = 0; + + while ((ind 0) + { + long index; + std::stringstream iss(str.substr(0, ind)); + iss >> index; + table.push_back(index); + } + } + + unsigned int n = table.size(); + m_nbEdges.push_back(short(n)); + for (unsigned int j = 0; j < n; ++j) + { + int index = table[j] - 1; // les index commencent a 1 (boufonnerie d'obj ;) + m_emb.push_back(verticesID[index]); + } + m_nbFaces++; + } + fp >> tag; + std::getline(fp, ligne); } while (!fp.eof()); - fp.close (); - return true; + fp.close (); + return true; } template bool MeshTablesSurface::importPly(const std::string& filename, std::vector& attrNames) { - VertexAttribute positions = m_map.template getAttribute("position") ; + VertexAttribute positions = m_map.template getAttribute("position") ; - if (!positions.isValid()) - positions = m_map.template addAttribute("position") ; + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; - attrNames.push_back(positions.name()) ; + attrNames.push_back(positions.name()) ; - AttributeContainer& container = m_map.template getAttributeContainer() ; + AttributeContainer& container = m_map.template getAttributeContainer() ; - PlyImportData pid; + PlyImportData pid; - if (! pid.read_file(filename) ) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } + if (! pid.read_file(filename) ) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } - VertexAttribute colors = m_map.template getAttribute("color") ; - if (pid.hasColors()) - { - if(!colors.isValid()) - colors = m_map.template addAttribute("color") ; - attrNames.push_back(colors.name()) ; - } + VertexAttribute colors = m_map.template getAttribute("color") ; + if (pid.hasColors()) + { + if(!colors.isValid()) + colors = m_map.template addAttribute("color") ; + attrNames.push_back(colors.name()) ; + } // lecture des nombres de sommets/aretes/faces - m_nbVertices = pid.nbVertices(); - m_nbFaces = pid.nbFaces(); - - //lecture sommets - std::vector verticesID; - verticesID.reserve(m_nbVertices); - for (unsigned int i = 0; i < m_nbVertices; ++i) - { - VEC3 pos; - pid.vertexPosition(i, pos); - - unsigned int id = container.insertLine(); - positions[id] = pos; - - if (pid.hasColorsUint8()) - { - Geom::Vector<3, unsigned char> col ; - pid.vertexColorUint8(i, col) ; - colors[id][0] = col[0] ; - colors[id][1] = col[1] ; - colors[id][2] = col[2] ; - colors[id] /= 255.0 ; - } - - if (pid.hasColorsFloat32()) - { - Geom::Vector<3, float> col ; - pid.vertexColorFloat32(i, col) ; - colors[id][0] = col[0] ; - colors[id][1] = col[1] ; - colors[id][2] = col[2] ; - } - - - verticesID.push_back(id); - } - - m_nbEdges.reserve(m_nbFaces); - m_emb.reserve(m_nbVertices*8); - - for (unsigned int i = 0 ; i < m_nbFaces ; ++i) - { - unsigned int n = pid.getFaceValence(i); - m_nbEdges.push_back(n); - int* indices = pid.getFaceIndices(i); - for (unsigned int j = 0; j < n; ++j) - { - m_emb.push_back(verticesID[indices[j]]); - } - } - - return true; + m_nbVertices = pid.nbVertices(); + m_nbFaces = pid.nbFaces(); + + //lecture sommets + std::vector verticesID; + verticesID.reserve(m_nbVertices); + for (unsigned int i = 0; i < m_nbVertices; ++i) + { + VEC3 pos; + pid.vertexPosition(i, pos); + + unsigned int id = container.insertLine(); + positions[id] = pos; + + if (pid.hasColorsUint8()) + { + Geom::Vector<3, unsigned char> col ; + pid.vertexColorUint8(i, col) ; + colors[id][0] = col[0] ; + colors[id][1] = col[1] ; + colors[id][2] = col[2] ; + colors[id] /= 255.0 ; + } + + if (pid.hasColorsFloat32()) + { + Geom::Vector<3, float> col ; + pid.vertexColorFloat32(i, col) ; + colors[id][0] = col[0] ; + colors[id][1] = col[1] ; + colors[id][2] = col[2] ; + } + + + verticesID.push_back(id); + } + + m_nbEdges.reserve(m_nbFaces); + m_emb.reserve(m_nbVertices*8); + + for (unsigned int i = 0 ; i < m_nbFaces ; ++i) + { + unsigned int n = pid.getFaceValence(i); + m_nbEdges.push_back(n); + int* indices = pid.getFaceIndices(i); + for (unsigned int j = 0; j < n; ++j) + { + m_emb.push_back(verticesID[indices[j]]); + } + } + + return true; } /** @@ -689,461 +735,461 @@ bool MeshTablesSurface::importPly(const std::string& filename, std::vector< template bool MeshTablesSurface::importPlySLFgeneric(const std::string& filename, std::vector& attrNames) { - // Open file - std::ifstream fp(filename.c_str(), std::ios::in) ; - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl ; - return false ; - } - - // Read quantities : #vertices, #faces, #properties, degree of polynomials + // Open file + std::ifstream fp(filename.c_str(), std::ios::in) ; + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl ; + return false ; + } + + // Read quantities : #vertices, #faces, #properties, degree of polynomials std::string tag ; fp >> tag; - if (tag != std::string("ply")) // verify file type - { - CGoGNerr << filename << " is not a ply file !" << CGoGNout ; - return false ; - } - - do // go to #vertices - { - fp >> tag ; - } while (tag != std::string("vertex")) ; - unsigned int nbVertices ; - fp >> nbVertices ; // Read #vertices - - bool position = false ; - bool tangent = false ; - bool binormal = false ; - bool normal = false ; - bool PTM = false ; - bool SH = false ; - unsigned int nbProps = 0 ; // # properties - unsigned int nbCoefs = 0 ; // # coefficients - do // go to #faces and count #properties - { - fp >> tag ; - if (tag == std::string("property")) - ++nbProps ; - else if (tag == std::string("x") || tag == std::string("y") || tag == std::string("z")) - position = true ; - //else if (tag == std::string("tx") || tag == std::string("ty") || tag == std::string("tz")) - else if (tag == std::string("frameT_0") || tag == std::string("frameT_1") || tag == std::string("frameT_2")) - tangent = true ; - //else if (tag == std::string("bx") || tag == std::string("by") || tag == std::string("bz")) - else if (tag == std::string("frameB_0") || tag == std::string("frameB_1") || tag == std::string("frameB_2")) - binormal = true ; - //else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz")) - else if (tag == std::string("frameN_0") || tag == std::string("frameN_1") || tag == std::string("frameN_2")) - normal = true ; - // else if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_")) - else if ((tag.length() > 8) && tag.find("_") != std::string::npos) - { - if (tag.substr(0,7) == std::string("PBcoefs")) - { - PTM = true ; - ++nbCoefs ; - } - else if (tag.substr(0,7) == std::string("SHcoefs")) - { - SH = true ; - ++nbCoefs ; - } - } - } while (tag != std::string("face")) ; - unsigned int nbRemainders = nbProps ; // # remaining properties - nbRemainders -= nbCoefs + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ; - nbCoefs /= 3 ; - - fp >> m_nbFaces ; // Read #vertices - - do // go to end of header - { - fp >> tag ; - } while (tag != std::string("end_header")) ; - - // Define containers - VertexAttribute positions = m_map.template getAttribute("position") ; + if (tag != std::string("ply")) // verify file type + { + CGoGNerr << filename << " is not a ply file !" << CGoGNout ; + return false ; + } + + do // go to #vertices + { + fp >> tag ; + } while (tag != std::string("vertex")) ; + unsigned int nbVertices ; + fp >> nbVertices ; // Read #vertices + + bool position = false ; + bool tangent = false ; + bool binormal = false ; + bool normal = false ; + bool PTM = false ; + bool SH = false ; + unsigned int nbProps = 0 ; // # properties + unsigned int nbCoefs = 0 ; // # coefficients + do // go to #faces and count #properties + { + fp >> tag ; + if (tag == std::string("property")) + ++nbProps ; + else if (tag == std::string("x") || tag == std::string("y") || tag == std::string("z")) + position = true ; + //else if (tag == std::string("tx") || tag == std::string("ty") || tag == std::string("tz")) + else if (tag == std::string("frameT_0") || tag == std::string("frameT_1") || tag == std::string("frameT_2")) + tangent = true ; + //else if (tag == std::string("bx") || tag == std::string("by") || tag == std::string("bz")) + else if (tag == std::string("frameB_0") || tag == std::string("frameB_1") || tag == std::string("frameB_2")) + binormal = true ; + //else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz")) + else if (tag == std::string("frameN_0") || tag == std::string("frameN_1") || tag == std::string("frameN_2")) + normal = true ; + // else if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_")) + else if ((tag.length() > 8) && tag.find("_") != std::string::npos) + { + if (tag.substr(0,7) == std::string("PBcoefs")) + { + PTM = true ; + ++nbCoefs ; + } + else if (tag.substr(0,7) == std::string("SHcoefs")) + { + SH = true ; + ++nbCoefs ; + } + } + } while (tag != std::string("face")) ; + unsigned int nbRemainders = nbProps ; // # remaining properties + nbRemainders -= nbCoefs + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ; + nbCoefs /= 3 ; + + fp >> m_nbFaces ; // Read #vertices + + do // go to end of header + { + fp >> tag ; + } while (tag != std::string("end_header")) ; + + // Define containers + VertexAttribute positions = m_map.template getAttribute("position") ; ; - if (!positions.isValid()) - positions = m_map.template addAttribute("position") ; - attrNames.push_back(positions.name()) ; - - VertexAttribute *frame = new VertexAttribute[3] ; - frame[0] = m_map.template addAttribute("frameT") ; // Tangent - frame[0] = m_map.template addAttribute("frameB") ; // Binormal - frame[0] = m_map.template addAttribute("frameN") ; // Normal - attrNames.push_back(frame[0].name()) ; - attrNames.push_back(frame[1].name()) ; - attrNames.push_back(frame[2].name()) ; - - VertexAttribute *PBcoefs = NULL, *SHcoefs = NULL ; - if (PTM) - { - PBcoefs = new VertexAttribute[nbCoefs] ; - for (unsigned int i = 0 ; i < nbCoefs ; ++i) - { - std::stringstream name ; - name << "PBcoefs" << i ; - PBcoefs[i] = m_map.template addAttribute(name.str()) ; - attrNames.push_back(PBcoefs[i].name()) ; - } - } - - if (SH) - { - SHcoefs = new VertexAttribute[nbCoefs] ; - for (unsigned int i = 0 ; i < nbCoefs ; ++i) - { - std::stringstream name ; - name << "SHcoefs" << i ; - SHcoefs[i] = m_map.template addAttribute(name.str()) ; - attrNames.push_back(SHcoefs[i].name()) ; - } - } - - VertexAttribute *remainders = new VertexAttribute[nbRemainders] ; - for (unsigned int i = 0 ; i < nbRemainders ; ++i) - { - std::stringstream name ; - name << "remainderNo" << i ; - remainders[i] = m_map.template addAttribute(name.str()) ; - attrNames.push_back(remainders[i].name()) ; - } - - // Read vertices - std::vector verticesID ; - verticesID.reserve(nbVertices) ; - - float* properties = new float[nbProps] ; - AttributeContainer& container = m_map.template getAttributeContainer() ; - for (unsigned int i = 0 ; i < nbVertices ; ++i) // Read and store properties for current vertex - { - unsigned int id = container.insertLine() ; - verticesID.push_back(id) ; - - for (unsigned int j = 0 ; j < nbProps ; ++j) // get all properties - fp >> properties[j] ; - - positions[id] = VEC3(properties[0],properties[1],properties[2]) ; // position - for (unsigned int k = 0 ; k < 3 ; ++k) // frame - for (unsigned int l = 0 ; l < 3 ; ++l) - frame[k][id][l] = properties[3+(3*k+l)] ; - for (unsigned int l = 0 ; l < nbCoefs ; ++l) // coefficients - for (unsigned int k = 0 ; k < 3 ; ++k) - { - if (PTM) - PBcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(3*l+k)]) ; - else /* if SH */ - SHcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(3*l+k)]) ; - } - unsigned int cur = 12+3*nbCoefs ; - for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data - remainders[k][id] = properties[cur + k] ; - } - m_nbVertices = verticesID.size() ; - delete[] properties ; - - // Read faces index - m_nbEdges.reserve(m_nbFaces) ; - m_emb.reserve(3 * m_nbFaces) ; - for (unsigned int i = 0 ; i < m_nbFaces ; ++i) - { - // read the indices of vertices for current face - unsigned int nbEdgesForFace ; - fp >> nbEdgesForFace ; - m_nbEdges.push_back(nbEdgesForFace); - - unsigned int vertexID ; - for (unsigned int j=0 ; j < nbEdgesForFace ; ++j) - { - fp >> vertexID ; - m_emb.push_back(verticesID[vertexID]); - } - } - - // Close file - fp.close() ; - - return true ; + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; + attrNames.push_back(positions.name()) ; + + VertexAttribute *frame = new VertexAttribute[3] ; + frame[0] = m_map.template addAttribute("frameT") ; // Tangent + frame[0] = m_map.template addAttribute("frameB") ; // Binormal + frame[0] = m_map.template addAttribute("frameN") ; // Normal + attrNames.push_back(frame[0].name()) ; + attrNames.push_back(frame[1].name()) ; + attrNames.push_back(frame[2].name()) ; + + VertexAttribute *PBcoefs = NULL, *SHcoefs = NULL ; + if (PTM) + { + PBcoefs = new VertexAttribute[nbCoefs] ; + for (unsigned int i = 0 ; i < nbCoefs ; ++i) + { + std::stringstream name ; + name << "PBcoefs" << i ; + PBcoefs[i] = m_map.template addAttribute(name.str()) ; + attrNames.push_back(PBcoefs[i].name()) ; + } + } + + if (SH) + { + SHcoefs = new VertexAttribute[nbCoefs] ; + for (unsigned int i = 0 ; i < nbCoefs ; ++i) + { + std::stringstream name ; + name << "SHcoefs" << i ; + SHcoefs[i] = m_map.template addAttribute(name.str()) ; + attrNames.push_back(SHcoefs[i].name()) ; + } + } + + VertexAttribute *remainders = new VertexAttribute[nbRemainders] ; + for (unsigned int i = 0 ; i < nbRemainders ; ++i) + { + std::stringstream name ; + name << "remainderNo" << i ; + remainders[i] = m_map.template addAttribute(name.str()) ; + attrNames.push_back(remainders[i].name()) ; + } + + // Read vertices + std::vector verticesID ; + verticesID.reserve(nbVertices) ; + + float* properties = new float[nbProps] ; + AttributeContainer& container = m_map.template getAttributeContainer() ; + for (unsigned int i = 0 ; i < nbVertices ; ++i) // Read and store properties for current vertex + { + unsigned int id = container.insertLine() ; + verticesID.push_back(id) ; + + for (unsigned int j = 0 ; j < nbProps ; ++j) // get all properties + fp >> properties[j] ; + + positions[id] = VEC3(properties[0],properties[1],properties[2]) ; // position + for (unsigned int k = 0 ; k < 3 ; ++k) // frame + for (unsigned int l = 0 ; l < 3 ; ++l) + frame[k][id][l] = properties[3+(3*k+l)] ; + for (unsigned int l = 0 ; l < nbCoefs ; ++l) // coefficients + for (unsigned int k = 0 ; k < 3 ; ++k) + { + if (PTM) + PBcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(3*l+k)]) ; + else /* if SH */ + SHcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(3*l+k)]) ; + } + unsigned int cur = 12+3*nbCoefs ; + for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data + remainders[k][id] = properties[cur + k] ; + } + m_nbVertices = verticesID.size() ; + delete[] properties ; + + // Read faces index + m_nbEdges.reserve(m_nbFaces) ; + m_emb.reserve(3 * m_nbFaces) ; + for (unsigned int i = 0 ; i < m_nbFaces ; ++i) + { + // read the indices of vertices for current face + unsigned int nbEdgesForFace ; + fp >> nbEdgesForFace ; + m_nbEdges.push_back(nbEdgesForFace); + + unsigned int vertexID ; + for (unsigned int j=0 ; j < nbEdgesForFace ; ++j) + { + fp >> vertexID ; + m_emb.push_back(verticesID[vertexID]); + } + } + + // Close file + fp.close() ; + + return true ; } template bool MeshTablesSurface::importPlySLFgenericBin(const std::string& filename, std::vector& attrNames) { - // Open file - std::ifstream fp(filename.c_str(), std::ios::in | std::ios::binary) ; - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl ; - return false ; - } - - // Read quantities : #vertices, #faces, #properties, degree of polynomials + // Open file + std::ifstream fp(filename.c_str(), std::ios::in | std::ios::binary) ; + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl ; + return false ; + } + + // Read quantities : #vertices, #faces, #properties, degree of polynomials std::string tag ; fp >> tag; - if (tag != std::string("ply")) // verify file type - { - CGoGNerr << filename << " is not a ply file !" << CGoGNout ; - return false ; - } - - do // go to #vertices - { - fp >> tag ; - } while (tag != std::string("vertex")) ; - unsigned int nbVertices ; - fp >> nbVertices ; // Read #vertices - - bool position = false ; - bool tangent = false ; - bool binormal = false ; - bool normal = false ; - bool PTM = false ; - bool SH = false ; - unsigned int propSize = 0 ; - unsigned int nbProps = 0 ; // # properties - unsigned int nbCoefs = 0 ; // # coefficients - do // go to #faces and count #properties - { - fp >> tag ; - if (tag == std::string("property")) - ++nbProps ; - else if (tag == std::string("int8") || tag == std::string("uint8")) - { - if (propSize < 2) - { - propSize = 1 ; - std::cerr << "MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled" << std::endl ; - assert(!"MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled") ; } - else - { - std::cerr << "MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled" << std::endl ; - assert(!"MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled") ; - } - } - else if (tag == std::string("int16") || tag == std::string("uint16")) - { - if (propSize == 0 || propSize == 2) - { - propSize = 2 ; - std::cerr << "MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled" << std::endl ; - assert(!"MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled") ; } - else - { - std::cerr << "MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled" << std::endl ; - assert(!"MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled") ; - } - } - else if (tag == std::string("int32") || tag == std::string("float32") || tag == std::string("uint32")) - { - if (propSize == 0 || propSize == 4) - { - propSize = 4 ; - std::cerr << "MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled" << std::endl ; - assert(!"MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled") ; - } - else - { - std::cerr << "MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled" << std::endl ; - assert(!"MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled") ; - } - } - else if (tag == std::string("int64") || tag == std::string("float64")) - { - if (propSize == 0 || propSize == 8) - { - propSize = 8 ; - //std::cerr << "MeshTablesSurface::importPlySLFgenericBin: only float32 is yet handled" << std::endl ; - //assert(!"MeshTablesSurface::importPlySLFgenericBin: only float32 is yet handled") ; - } - else - { - std::cerr << "MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled" << std::endl ; - assert(!"MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled") ; - } - } - else if (tag == std::string("x") || tag == std::string("y") || tag == std::string("z")) - position = true ; - //else if (tag == std::string("tx") || tag == std::string("ty") || tag == std::string("tz")) - else if (tag == std::string("frameT_0") || tag == std::string("frameT_1") || tag == std::string("frameT_2")) - tangent = true ; - //else if (tag == std::string("bx") || tag == std::string("by") || tag == std::string("bz")) - else if (tag == std::string("frameB_0") || tag == std::string("frameB_1") || tag == std::string("frameB_2")) - binormal = true ; - //else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz")) - else if (tag == std::string("frameN_0") || tag == std::string("frameN_1") || tag == std::string("frameN_2")) - normal = true ; - // else if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_")) - else if ((tag.length() > 8) && tag.find("_") != std::string::npos) - { - if (tag.substr(0,7) == std::string("PBcoefs")) - { - PTM = true ; - ++nbCoefs ; - } - else if (tag.substr(0,7) == std::string("SHcoefs")) - { - SH = true ; - ++nbCoefs ; - } - } - } while (tag != std::string("face")) ; - unsigned int nbRemainders = nbProps ; // # remaining properties - nbRemainders -= nbCoefs + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ; - nbCoefs /= 3 ; - - assert(!(SH && PTM) || !"MeshTablesSurface::importPlySLFgenericBin: Confusing functional colors since both SLF and RF are defined.") ; - if (SH && PTM) - std::cerr << "MeshTablesSurface::importPlySLFgenericBin: Confusing functional colors since both SLF and RF are defined." << std::endl ; - - fp >> m_nbFaces ; // Read #vertices - - do // go to end of header - { - fp >> tag ; - } while (tag != std::string("end_header")) ; - - char* endline = new char[1] ; - fp.read(endline, sizeof(char)) ; - if (*endline == '\r') // for windows - fp.read(endline, sizeof(char)) ; - assert(*endline == '\n') ; - delete[] endline ; - - // Define containers - VertexAttribute positions = m_map.template getAttribute("position") ; - if (!positions.isValid()) - positions = m_map.template addAttribute("position") ; - attrNames.push_back(positions.name()) ; - - VertexAttribute *frame = new VertexAttribute[3] ; - if (tangent) - { - frame[0] = m_map.template addAttribute("frameT") ; // Tangent - attrNames.push_back(frame[0].name()) ; - } - if (binormal) - { - frame[1] = m_map.template addAttribute("frameB") ; // Bitangent - attrNames.push_back(frame[0].name()) ; - } - if (normal) - { - frame[2] = m_map.template addAttribute("frameN") ; // Normal - attrNames.push_back(frame[0].name()) ; - } - - VertexAttribute *PBcoefs = NULL, *SHcoefs = NULL ; - if (PTM) - { - PBcoefs = new VertexAttribute[nbCoefs] ; - for (unsigned int i = 0 ; i < nbCoefs ; ++i) - { - std::stringstream name ; - name << "PBcoefs" << i ; - PBcoefs[i] = m_map.template addAttribute(name.str()) ; - attrNames.push_back(PBcoefs[i].name()) ; - } - } - - if (SH) - { - SHcoefs = new VertexAttribute[nbCoefs] ; - for (unsigned int i = 0 ; i < nbCoefs ; ++i) - { - std::stringstream name ; - name << "SHcoefs" << i ; - SHcoefs[i] = m_map.template addAttribute(name.str()) ; - attrNames.push_back(SHcoefs[i].name()) ; - } - } - - VertexAttribute *remainders = new VertexAttribute[nbRemainders] ; - for (unsigned int i = 0 ; i < nbRemainders ; ++i) - { - std::stringstream name ; - name << "remainderNo" << i ; - remainders[i] = m_map.template addAttribute(name.str()) ; - attrNames.push_back(remainders[i].name()) ; - } - - // Read vertices - std::vector verticesID ; - verticesID.reserve(nbVertices) ; - - double* properties = new double[nbProps] ; - AttributeContainer& container = m_map.template getAttributeContainer() ; - for (unsigned int i = 0 ; i < nbVertices ; ++i) // Read and store properties for current vertex - { - unsigned int id = container.insertLine() ; - verticesID.push_back(id) ; - - fp.read((char*)properties,nbProps * propSize) ; - - // positions - if (nbProps > 2) - positions[id] = VEC3(properties[0],properties[1],properties[2]) ; // position - - if (tangent && binormal && normal) // == if (nbprops > 11) - for (unsigned int k = 0 ; k < 3 ; ++k) // frame - for (unsigned int l = 0 ; l < 3 ; ++l) - frame[k][id][l] = (typename PFP::REAL)(properties[3+(3*k+l)]) ; - - for (unsigned int l = 0 ; l < nbCoefs ; ++l) // coefficients - for (unsigned int k = 0 ; k < 3 ; ++k) - { - if (PTM) - PBcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(3*l+k)]) ; - else /* if SH */ - SHcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(3*l+k)]) ; - } - - unsigned int cur = 12+3*nbCoefs ; - for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data - remainders[k][id] = (typename PFP::REAL)(properties[cur + k]) ; - } - m_nbVertices = verticesID.size() ; - delete[] properties ; - - // Read faces index - m_nbEdges.reserve(m_nbFaces) ; - m_emb.reserve(3 * m_nbFaces) ; - for (unsigned int i = 0 ; i < m_nbFaces ; ++i) - { - // read the indices of vertices for current face - unsigned int nbEdgesForFace ; - unsigned char tmp ; - fp.read((char*)&(tmp), sizeof(unsigned char)) ; - nbEdgesForFace = tmp ; - m_nbEdges.push_back(nbEdgesForFace); - - unsigned int vertexID ; - for (unsigned int j=0 ; j < nbEdgesForFace ; ++j) - { - fp.read((char*)&vertexID, sizeof(unsigned int)) ; - m_emb.push_back(verticesID[vertexID]); - } - /*// read the indices of vertices for current face - unsigned int nbEdgesForFace ; - fp.read((char*)&(nbEdgesForFace), sizeof(unsigned int)) ; - m_nbEdges.push_back(nbEdgesForFace); - - unsigned int vertexID ; - for (unsigned int j=0 ; j < nbEdgesForFace ; ++j) - { - fp.read((char*)&vertexID, sizeof(unsigned int)) ; - m_emb.push_back(verticesID[vertexID]); - }*/ - } - - // Close file - fp.close() ; - - return true ; + if (tag != std::string("ply")) // verify file type + { + CGoGNerr << filename << " is not a ply file !" << CGoGNout ; + return false ; + } + + do // go to #vertices + { + fp >> tag ; + } while (tag != std::string("vertex")) ; + unsigned int nbVertices ; + fp >> nbVertices ; // Read #vertices + + bool position = false ; + bool tangent = false ; + bool binormal = false ; + bool normal = false ; + bool PTM = false ; + bool SH = false ; + unsigned int propSize = 0 ; + unsigned int nbProps = 0 ; // # properties + unsigned int nbCoefs = 0 ; // # coefficients + do // go to #faces and count #properties + { + fp >> tag ; + if (tag == std::string("property")) + ++nbProps ; + else if (tag == std::string("int8") || tag == std::string("uint8")) + { + if (propSize < 2) + { + propSize = 1 ; + std::cerr << "MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled" << std::endl ; + assert(!"MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled") ; } + else + { + std::cerr << "MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled" << std::endl ; + assert(!"MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled") ; + } + } + else if (tag == std::string("int16") || tag == std::string("uint16")) + { + if (propSize == 0 || propSize == 2) + { + propSize = 2 ; + std::cerr << "MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled" << std::endl ; + assert(!"MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled") ; } + else + { + std::cerr << "MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled" << std::endl ; + assert(!"MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled") ; + } + } + else if (tag == std::string("int32") || tag == std::string("float32") || tag == std::string("uint32")) + { + if (propSize == 0 || propSize == 4) + { + propSize = 4 ; + std::cerr << "MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled" << std::endl ; + assert(!"MeshTablesSurface::importPlySLFgenericBin: only float64 is yet handled") ; + } + else + { + std::cerr << "MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled" << std::endl ; + assert(!"MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled") ; + } + } + else if (tag == std::string("int64") || tag == std::string("float64")) + { + if (propSize == 0 || propSize == 8) + { + propSize = 8 ; + //std::cerr << "MeshTablesSurface::importPlySLFgenericBin: only float32 is yet handled" << std::endl ; + //assert(!"MeshTablesSurface::importPlySLFgenericBin: only float32 is yet handled") ; + } + else + { + std::cerr << "MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled" << std::endl ; + assert(!"MeshTablesSurface::importPlySLFgenericBin: all properties should be same size: otherwise not handled") ; + } + } + else if (tag == std::string("x") || tag == std::string("y") || tag == std::string("z")) + position = true ; + //else if (tag == std::string("tx") || tag == std::string("ty") || tag == std::string("tz")) + else if (tag == std::string("frameT_0") || tag == std::string("frameT_1") || tag == std::string("frameT_2")) + tangent = true ; + //else if (tag == std::string("bx") || tag == std::string("by") || tag == std::string("bz")) + else if (tag == std::string("frameB_0") || tag == std::string("frameB_1") || tag == std::string("frameB_2")) + binormal = true ; + //else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz")) + else if (tag == std::string("frameN_0") || tag == std::string("frameN_1") || tag == std::string("frameN_2")) + normal = true ; + // else if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_")) + else if ((tag.length() > 8) && tag.find("_") != std::string::npos) + { + if (tag.substr(0,7) == std::string("PBcoefs")) + { + PTM = true ; + ++nbCoefs ; + } + else if (tag.substr(0,7) == std::string("SHcoefs")) + { + SH = true ; + ++nbCoefs ; + } + } + } while (tag != std::string("face")) ; + unsigned int nbRemainders = nbProps ; // # remaining properties + nbRemainders -= nbCoefs + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ; + nbCoefs /= 3 ; + + assert(!(SH && PTM) || !"MeshTablesSurface::importPlySLFgenericBin: Confusing functional colors since both SLF and RF are defined.") ; + if (SH && PTM) + std::cerr << "MeshTablesSurface::importPlySLFgenericBin: Confusing functional colors since both SLF and RF are defined." << std::endl ; + + fp >> m_nbFaces ; // Read #vertices + + do // go to end of header + { + fp >> tag ; + } while (tag != std::string("end_header")) ; + + char* endline = new char[1] ; + fp.read(endline, sizeof(char)) ; + if (*endline == '\r') // for windows + fp.read(endline, sizeof(char)) ; + assert(*endline == '\n') ; + delete[] endline ; + + // Define containers + VertexAttribute positions = m_map.template getAttribute("position") ; + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; + attrNames.push_back(positions.name()) ; + + VertexAttribute *frame = new VertexAttribute[3] ; + if (tangent) + { + frame[0] = m_map.template addAttribute("frameT") ; // Tangent + attrNames.push_back(frame[0].name()) ; + } + if (binormal) + { + frame[1] = m_map.template addAttribute("frameB") ; // Bitangent + attrNames.push_back(frame[0].name()) ; + } + if (normal) + { + frame[2] = m_map.template addAttribute("frameN") ; // Normal + attrNames.push_back(frame[0].name()) ; + } + + VertexAttribute *PBcoefs = NULL, *SHcoefs = NULL ; + if (PTM) + { + PBcoefs = new VertexAttribute[nbCoefs] ; + for (unsigned int i = 0 ; i < nbCoefs ; ++i) + { + std::stringstream name ; + name << "PBcoefs" << i ; + PBcoefs[i] = m_map.template addAttribute(name.str()) ; + attrNames.push_back(PBcoefs[i].name()) ; + } + } + + if (SH) + { + SHcoefs = new VertexAttribute[nbCoefs] ; + for (unsigned int i = 0 ; i < nbCoefs ; ++i) + { + std::stringstream name ; + name << "SHcoefs" << i ; + SHcoefs[i] = m_map.template addAttribute(name.str()) ; + attrNames.push_back(SHcoefs[i].name()) ; + } + } + + VertexAttribute *remainders = new VertexAttribute[nbRemainders] ; + for (unsigned int i = 0 ; i < nbRemainders ; ++i) + { + std::stringstream name ; + name << "remainderNo" << i ; + remainders[i] = m_map.template addAttribute(name.str()) ; + attrNames.push_back(remainders[i].name()) ; + } + + // Read vertices + std::vector verticesID ; + verticesID.reserve(nbVertices) ; + + double* properties = new double[nbProps] ; + AttributeContainer& container = m_map.template getAttributeContainer() ; + for (unsigned int i = 0 ; i < nbVertices ; ++i) // Read and store properties for current vertex + { + unsigned int id = container.insertLine() ; + verticesID.push_back(id) ; + + fp.read((char*)properties,nbProps * propSize) ; + + // positions + if (nbProps > 2) + positions[id] = VEC3(properties[0],properties[1],properties[2]) ; // position + + if (tangent && binormal && normal) // == if (nbprops > 11) + for (unsigned int k = 0 ; k < 3 ; ++k) // frame + for (unsigned int l = 0 ; l < 3 ; ++l) + frame[k][id][l] = (typename PFP::REAL)(properties[3+(3*k+l)]) ; + + for (unsigned int l = 0 ; l < nbCoefs ; ++l) // coefficients + for (unsigned int k = 0 ; k < 3 ; ++k) + { + if (PTM) + PBcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(3*l+k)]) ; + else /* if SH */ + SHcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(3*l+k)]) ; + } + + unsigned int cur = 12+3*nbCoefs ; + for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data + remainders[k][id] = (typename PFP::REAL)(properties[cur + k]) ; + } + m_nbVertices = verticesID.size() ; + delete[] properties ; + + // Read faces index + m_nbEdges.reserve(m_nbFaces) ; + m_emb.reserve(3 * m_nbFaces) ; + for (unsigned int i = 0 ; i < m_nbFaces ; ++i) + { + // read the indices of vertices for current face + unsigned int nbEdgesForFace ; + unsigned char tmp ; + fp.read((char*)&(tmp), sizeof(unsigned char)) ; + nbEdgesForFace = tmp ; + m_nbEdges.push_back(nbEdgesForFace); + + unsigned int vertexID ; + for (unsigned int j=0 ; j < nbEdgesForFace ; ++j) + { + fp.read((char*)&vertexID, sizeof(unsigned int)) ; + m_emb.push_back(verticesID[vertexID]); + } + /*// read the indices of vertices for current face + unsigned int nbEdgesForFace ; + fp.read((char*)&(nbEdgesForFace), sizeof(unsigned int)) ; + m_nbEdges.push_back(nbEdgesForFace); + + unsigned int vertexID ; + for (unsigned int j=0 ; j < nbEdgesForFace ; ++j) + { + fp.read((char*)&vertexID, sizeof(unsigned int)) ; + m_emb.push_back(verticesID[vertexID]); + }*/ + } + + // Close file + fp.close() ; + + return true ; } /** @@ -1285,362 +1331,362 @@ bool MeshTablesSurface::importPlySLFgenericBin(const std::string& filename, template bool MeshTablesSurface::importAHEM(const std::string& filename, std::vector& attrNames) { - // Open file + // Open file + + std::ifstream fp(filename.c_str(), std::ios::binary); - std::ifstream fp(filename.c_str(), std::ios::binary); + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } + // Read header - // Read header + AHEMHeader hdr; - AHEMHeader hdr; + fp.read((char*)&hdr, sizeof(AHEMHeader)); - fp.read((char*)&hdr, sizeof(AHEMHeader)); + if(hdr.magic != AHEM_MAGIC) + CGoGNerr << "Warning: " << filename << " invalid magic" << CGoGNendl; - if(hdr.magic != AHEM_MAGIC) - CGoGNerr << "Warning: " << filename << " invalid magic" << CGoGNendl; + m_nbVertices = hdr.meshHdr.vxCount; + m_nbFaces = hdr.meshHdr.faceCount; - m_nbVertices = hdr.meshHdr.vxCount; - m_nbFaces = hdr.meshHdr.faceCount; + // Read attributes - // Read attributes + AHEMAttributeDescriptor* ahemAttrDesc = new AHEMAttributeDescriptor[hdr.attributesChunkNumber]; + char** ahemAttrNames = new char*[hdr.attributesChunkNumber]; - AHEMAttributeDescriptor* ahemAttrDesc = new AHEMAttributeDescriptor[hdr.attributesChunkNumber]; - char** ahemAttrNames = new char*[hdr.attributesChunkNumber]; + for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) + { + fp.read((char*)(ahemAttrDesc + i), sizeof(AHEMAttributeDescriptor)); - for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) - { - fp.read((char*)(ahemAttrDesc + i), sizeof(AHEMAttributeDescriptor)); - - ahemAttrNames[i] = new char[ahemAttrDesc[i].nameSize + 1]; - fp.read(ahemAttrNames[i], ahemAttrDesc[i].nameSize); - ahemAttrNames[i][ahemAttrDesc[i].nameSize] = '\0'; - } + ahemAttrNames[i] = new char[ahemAttrDesc[i].nameSize + 1]; + fp.read(ahemAttrNames[i], ahemAttrDesc[i].nameSize); + ahemAttrNames[i][ahemAttrDesc[i].nameSize] = '\0'; + } - // Compute buffer size for largest chunk and allocate + // Compute buffer size for largest chunk and allocate - unsigned int bufferSize = hdr.meshHdr.meshChunkSize; + unsigned int bufferSize = hdr.meshHdr.meshChunkSize; - for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) - if(ahemAttrDesc[i].attributeChunkSize > bufferSize) - bufferSize = ahemAttrDesc[i].attributeChunkSize; + for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) + if(ahemAttrDesc[i].attributeChunkSize > bufferSize) + bufferSize = ahemAttrDesc[i].attributeChunkSize; - char* buffer = new char[bufferSize]; + char* buffer = new char[bufferSize]; // Allocate vertices - AttributeContainer& vxContainer = m_map.template getAttributeContainer(); + AttributeContainer& vxContainer = m_map.template getAttributeContainer(); - std::vector verticesId; - verticesId.resize(hdr.meshHdr.vxCount); + std::vector verticesId; + verticesId.resize(hdr.meshHdr.vxCount); - for(unsigned int i = 0 ; i < hdr.meshHdr.vxCount ; i++) - verticesId[i] = vxContainer.insertLine(); + for(unsigned int i = 0 ; i < hdr.meshHdr.vxCount ; i++) + verticesId[i] = vxContainer.insertLine(); - // Read faces stream + // Read faces stream - m_nbEdges.resize(hdr.meshHdr.faceCount); - m_emb.resize(hdr.meshHdr.heCount); + m_nbEdges.resize(hdr.meshHdr.faceCount); + m_emb.resize(hdr.meshHdr.heCount); - fp.read(buffer, hdr.meshHdr.meshChunkSize); - char* batch = buffer; + fp.read(buffer, hdr.meshHdr.meshChunkSize); + char* batch = buffer; - unsigned int fCount = 0; + unsigned int fCount = 0; - unsigned int fId = 0; - unsigned int j = 0; + unsigned int fId = 0; + unsigned int j = 0; - while(fCount < hdr.meshHdr.faceCount) - { - AHEMFaceBatchDescriptor* fbd = (AHEMFaceBatchDescriptor*)batch; - stUInt32* ix = (stUInt32*)(batch + sizeof(AHEMFaceBatchDescriptor)); + while(fCount < hdr.meshHdr.faceCount) + { + AHEMFaceBatchDescriptor* fbd = (AHEMFaceBatchDescriptor*)batch; + stUInt32* ix = (stUInt32*)(batch + sizeof(AHEMFaceBatchDescriptor)); - for(unsigned int i = 0 ; i < fbd->batchLength ; i++) - { - m_nbEdges[fId++] = fbd->batchFaceSize; + for(unsigned int i = 0 ; i < fbd->batchLength ; i++) + { + m_nbEdges[fId++] = fbd->batchFaceSize; - for(unsigned int k = 0 ; k < fbd->batchFaceSize ; k++) - m_emb[j++] = *ix++; - } + for(unsigned int k = 0 ; k < fbd->batchFaceSize ; k++) + m_emb[j++] = *ix++; + } - fCount += fbd->batchLength; - batch = (char*)ix; - } + fCount += fbd->batchLength; + batch = (char*)ix; + } - // Read positions + // Read positions - VertexAttribute position = m_map.template getAttribute("position") ; + VertexAttribute position = m_map.template getAttribute("position") ; - if (!position.isValid()) - position = m_map.template addAttribute("position") ; + if (!position.isValid()) + position = m_map.template addAttribute("position") ; - attrNames.push_back(position.name()) ; + attrNames.push_back(position.name()) ; - AHEMAttributeDescriptor* posDesc = NULL; - - for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) - { - if(IsEqualGUID(ahemAttrDesc[i].semantic, AHEMATTRIBUTE_POSITION)) - { - posDesc = ahemAttrDesc + i; - break; - } - } + AHEMAttributeDescriptor* posDesc = NULL; - fp.seekg(posDesc->fileStartOffset, std::ios_base::beg); - fp.read(buffer, posDesc->attributeChunkSize); + for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) + { + if(IsEqualGUID(ahemAttrDesc[i].semantic, AHEMATTRIBUTE_POSITION)) + { + posDesc = ahemAttrDesc + i; + break; + } + } - float* q = (float*)buffer; + fp.seekg(posDesc->fileStartOffset, std::ios_base::beg); + fp.read(buffer, posDesc->attributeChunkSize); - for(unsigned int i = 0 ; i < hdr.meshHdr.vxCount ; i++) - { - position[verticesId[i]] = VEC3(q[0], q[1], q[2]); - q += 3; - } + float* q = (float*)buffer; - // Close file and release allocated stuff + for(unsigned int i = 0 ; i < hdr.meshHdr.vxCount ; i++) + { + position[verticesId[i]] = VEC3(q[0], q[1], q[2]); + q += 3; + } - fp.close(); + // Close file and release allocated stuff - for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) - delete[] ahemAttrNames[i]; + fp.close(); - delete[] ahemAttrNames; - delete[] ahemAttrDesc; - delete[] buffer; + for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) + delete[] ahemAttrNames[i]; - return true; + delete[] ahemAttrNames; + delete[] ahemAttrDesc; + delete[] buffer; + + return true; } #ifdef WITH_ASSIMP template void MeshTablesSurface::extractMeshRec(AttributeContainer& container, VertexAttribute& positions, const struct aiScene* scene, const struct aiNode* nd, struct aiMatrix4x4* trafo) { - struct aiMatrix4x4 prev; - - prev = *trafo; - aiMultiplyMatrix4(trafo,&nd->mTransformation); - - std::vector verticesID; - - // foreach mesh of node - for (unsigned int n = 0; n < nd->mNumMeshes; ++n) - { - const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]]; - - verticesID.clear(); - verticesID.reserve(mesh->mNumVertices); - //read positions - for (unsigned int t = 0; t < mesh->mNumVertices; ++t) - { - // transform position - struct aiVector3D tmp = mesh->mVertices[t]; - aiTransformVecByMatrix4(&tmp, trafo); - // now store it - unsigned int id = container.insertLine(); - positions[id] = VEC3(tmp[0], tmp[1], tmp[2]); - verticesID.push_back(id); - } - m_nbVertices += mesh->mNumVertices; - - // read faces indices - for (unsigned int t = 0; t < mesh->mNumFaces; ++t) - { - const struct aiFace* face = &mesh->mFaces[t]; - m_nbEdges.push_back(face->mNumIndices); - for(unsigned int i = 0; i < face->mNumIndices; i++) - { - unsigned int pt = face->mIndices[i]; - m_emb.push_back(verticesID[pt]); - } - } - m_nbFaces += mesh->mNumFaces; - } - - // recurse on all children of node - for (unsigned int n = 0; n < nd->mNumChildren; ++n) - { + struct aiMatrix4x4 prev; + + prev = *trafo; + aiMultiplyMatrix4(trafo,&nd->mTransformation); + + std::vector verticesID; + + // foreach mesh of node + for (unsigned int n = 0; n < nd->mNumMeshes; ++n) + { + const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]]; + + verticesID.clear(); + verticesID.reserve(mesh->mNumVertices); + //read positions + for (unsigned int t = 0; t < mesh->mNumVertices; ++t) + { + // transform position + struct aiVector3D tmp = mesh->mVertices[t]; + aiTransformVecByMatrix4(&tmp, trafo); + // now store it + unsigned int id = container.insertLine(); + positions[id] = VEC3(tmp[0], tmp[1], tmp[2]); + verticesID.push_back(id); + } + m_nbVertices += mesh->mNumVertices; + + // read faces indices + for (unsigned int t = 0; t < mesh->mNumFaces; ++t) + { + const struct aiFace* face = &mesh->mFaces[t]; + m_nbEdges.push_back(face->mNumIndices); + for(unsigned int i = 0; i < face->mNumIndices; i++) + { + unsigned int pt = face->mIndices[i]; + m_emb.push_back(verticesID[pt]); + } + } + m_nbFaces += mesh->mNumFaces; + } + + // recurse on all children of node + for (unsigned int n = 0; n < nd->mNumChildren; ++n) + { // CGoGNout << "Children "<mChildren[n], trafo); - } - *trafo = prev; + extractMeshRec(container, positions, scene, nd->mChildren[n], trafo); + } + *trafo = prev; } template bool MeshTablesSurface::importASSIMP(const std::string& filename, std::vector& attrNames) { - AttributeContainer& container = m_map.template getAttributeContainer() ; - VertexAttribute positions = m_map.template addAttribute("position") ; - attrNames.push_back(positions.name()) ; + AttributeContainer& container = m_map.template getAttributeContainer() ; + VertexAttribute positions = m_map.template addAttribute("position") ; + attrNames.push_back(positions.name()) ; - m_nbVertices = 0; - m_nbFaces = 0; + m_nbVertices = 0; + m_nbFaces = 0; - m_nbEdges.reserve(5000); - m_emb.reserve(15000); + m_nbEdges.reserve(5000); + m_emb.reserve(15000); - struct aiMatrix4x4 trafo; - aiIdentityMatrix4(&trafo); + struct aiMatrix4x4 trafo; + aiIdentityMatrix4(&trafo); - m_lab = 0; - const struct aiScene* scene = aiImportFile(filename.c_str(), aiProcess_FindDegenerates | aiProcess_JoinIdenticalVertices); - extractMeshRec(container, positions, scene, scene->mRootNode, &trafo); + m_lab = 0; + const struct aiScene* scene = aiImportFile(filename.c_str(), aiProcess_FindDegenerates | aiProcess_JoinIdenticalVertices); + extractMeshRec(container, positions, scene, scene->mRootNode, &trafo); - return true; + return true; } #endif template bool MeshTablesSurface::mergeCloseVertices() { - const int NBV = 64; // seems to be good - - const int NEIGH[27] = { - -NBV*NBV - NBV - 1, -NBV*NBV - NBV, -NBV*NBV - NBV + 1, - -NBV*NBV - 1, -NBV*NBV, -NBV*NBV + 1, - -NBV*NBV + NBV - 1, -NBV*NBV + NBV, - NBV*NBV + NBV + 1, - -NBV - 1, - NBV, -NBV + 1, - -1, 0, 1, - NBV - 1, NBV, NBV + 1, - NBV*NBV - NBV - 1, NBV*NBV - NBV, NBV*NBV - NBV + 1, - NBV*NBV - 1, NBV*NBV, NBV*NBV + 1, - NBV*NBV + NBV - 1, NBV*NBV + NBV, NBV*NBV + NBV + 1}; - - std::vector** grid; - grid = new std::vector*[NBV*NBV*NBV]; - - // init grid with null ptrs - for (unsigned int i=0; i positions = m_map.template getAttribute("position"); - - // compute BB - Geom::BoundingBox bb(positions[ positions.begin() ]) ; - for (unsigned int i = positions.begin(); i != positions.end(); positions.next(i)) - { - bb.addPoint(positions[i]) ; - } - - // add one voxel around to avoid testing - typename PFP::VEC3 bbsize = (bb.max() - bb.min()); - typename PFP::VEC3 one = bbsize/(NBV-2); - one*= 1.001f; - bb.addPoint( bb.min() - one); - bb.addPoint( bb.max() + one); - bbsize = (bb.max() - bb.min()); - - VertexAutoAttribute gridIndex(m_map, "gridIndex"); - VertexAutoAttribute newIndices(m_map, "newIndices"); - - // Store each vertex in the grid and store voxel index in vertex attribute - for (unsigned int i = positions.begin(); i != positions.end(); positions.next(i)) - { - typename PFP::VEC3 P = positions[i]; - P -= bb.min(); - float pz = floor((P[2]/bbsize[2])*NBV); - float py = floor((P[1]/bbsize[1])*NBV); - float px = floor((P[0]/bbsize[0])*NBV); - - unsigned int index = NBV*NBV*pz + NBV*py + px; - - if (pz==63) - std::cout << "z 63 bb:"< bb(positions[ positions.begin() ]) ; + for (unsigned int i = positions.begin(); i != positions.end(); positions.next(i)) + { + bb.addPoint(positions[i]) ; + } + + // add one voxel around to avoid testing + typename PFP::VEC3 bbsize = (bb.max() - bb.min()); + typename PFP::VEC3 one = bbsize/(NBV-2); + one*= 1.001f; + bb.addPoint( bb.min() - one); + bb.addPoint( bb.max() + one); + bbsize = (bb.max() - bb.min()); + + VertexAutoAttribute gridIndex(m_map, "gridIndex"); + VertexAutoAttribute newIndices(m_map, "newIndices"); + + // Store each vertex in the grid and store voxel index in vertex attribute + for (unsigned int i = positions.begin(); i != positions.end(); positions.next(i)) + { + typename PFP::VEC3 P = positions[i]; + P -= bb.min(); + float pz = floor((P[2]/bbsize[2])*NBV); + float py = floor((P[1]/bbsize[1])*NBV); + float px = floor((P[0]/bbsize[0])*NBV); + + unsigned int index = NBV*NBV*pz + NBV*py + px; + + if (pz==63) + std::cout << "z 63 bb:"<("position") ; - - attrNames.push_back(positions.name()) ; - - AttributeContainer& container = m_map.template getAttributeContainer() ; - - // open file - std::ifstream fp(filename.c_str(), std::ios::in); - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } - - - std::vector verticesID; - verticesID.reserve(1000); - std::vector m_points; - - m_nbFaces = 0; - m_nbVertices = 0; - - m_nbEdges.reserve(1000); - m_emb.reserve(3000); - - std::string ligne; - std::string tag; - - do - { - fp >> tag; - std::getline (fp, ligne); - }while (tag != std::string("vertex")); - - do - { - for (int i=0; i<3; ++i) - { - std::stringstream oss(ligne); - float x,y,z; - oss >> x; - oss >> y; - oss >> z; - - VEC3 pos(x,y,z); - - typename std::vector::iterator it = find (m_points.begin(), m_points.end(), pos); - if (it != m_points.end()) - { - unsigned int idP = it - m_points.begin(); - m_emb.push_back(verticesID[idP]); - } - else - { - unsigned int id = container.insertLine(); - positions[id] = pos; - verticesID.push_back(id); - m_points.push_back(pos); - m_emb.push_back(id); - } - fp >> tag; - std::getline (fp, ligne); - } - m_nbEdges.push_back(3); - - do - { - fp >> tag; - std::getline (fp, ligne); - }while (!fp.eof() && (tag != std::string("vertex"))); - - }while (!fp.eof()); - - m_nbVertices = m_points.size(); - m_nbFaces = m_nbEdges.size(); - - fp.close(); - return true; + VertexAttribute positions = m_map.template getAttribute("position") ; + + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; + + attrNames.push_back(positions.name()) ; + + AttributeContainer& container = m_map.template getAttributeContainer() ; + + // open file + std::ifstream fp(filename.c_str(), std::ios::in); + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } + + + std::vector verticesID; + verticesID.reserve(1000); + std::vector m_points; + + m_nbFaces = 0; + m_nbVertices = 0; + + m_nbEdges.reserve(1000); + m_emb.reserve(3000); + + std::string ligne; + std::string tag; + + do + { + fp >> tag; + std::getline (fp, ligne); + }while (tag != std::string("vertex")); + + do + { + for (int i=0; i<3; ++i) + { + std::stringstream oss(ligne); + float x,y,z; + oss >> x; + oss >> y; + oss >> z; + + VEC3 pos(x,y,z); + + typename std::vector::iterator it = find (m_points.begin(), m_points.end(), pos); + if (it != m_points.end()) + { + unsigned int idP = it - m_points.begin(); + m_emb.push_back(verticesID[idP]); + } + else + { + unsigned int id = container.insertLine(); + positions[id] = pos; + verticesID.push_back(id); + m_points.push_back(pos); + m_emb.push_back(id); + } + fp >> tag; + std::getline (fp, ligne); + } + m_nbEdges.push_back(3); + + do + { + fp >> tag; + std::getline (fp, ligne); + }while (!fp.eof() && (tag != std::string("vertex"))); + + }while (!fp.eof()); + + m_nbVertices = m_points.size(); + m_nbFaces = m_nbEdges.size(); + + fp.close(); + return true; } @@ -1736,75 +1782,75 @@ bool MeshTablesSurface::importSTLAscii(const std::string& filename, std::ve template bool MeshTablesSurface::importSTLBin(const std::string& filename, std::vector& attrNames) { - VertexAttribute positions = m_map.template getAttribute("position") ; - - if (!positions.isValid()) - positions = m_map.template addAttribute("position") ; - - attrNames.push_back(positions.name()) ; - - AttributeContainer& container = m_map.template getAttributeContainer() ; - - // open file - std::ifstream fp(filename.c_str(), std::ios::in|std::ios::binary); - if (!fp.good()) - { - CGoGNerr << "Unable to open file " << filename << CGoGNendl; - return false; - } - - - std::vector verticesID; - verticesID.reserve(1000); - std::vector m_points; - - m_nbVertices = 0; - - - std::string ligne; - std::string tag; - - fp.ignore(80); - fp.read(reinterpret_cast(&m_nbFaces), sizeof(int)); - - m_nbEdges.reserve(m_nbFaces); - m_emb.reserve(m_nbFaces*3); - - - for (unsigned int j=0;j(&pos[0]), sizeof(float)); - fp.read(reinterpret_cast(&pos[1]), sizeof(float)); - fp.read(reinterpret_cast(&pos[2]), sizeof(float)); - - typename std::vector::iterator it = find (m_points.begin(), m_points.end(), pos); - if (it != m_points.end()) - { - unsigned int idP = it - m_points.begin(); - m_emb.push_back(verticesID[idP]); - } - else - { - unsigned int id = container.insertLine(); - positions[id] = pos; - verticesID.push_back(id); - m_points.push_back(pos); - m_emb.push_back(id); - } - } - fp.ignore(2); - m_nbEdges.push_back(3); - } - - m_nbVertices = m_points.size(); - m_nbFaces = m_nbEdges.size(); - - fp.close(); - return true; + VertexAttribute positions = m_map.template getAttribute("position") ; + + if (!positions.isValid()) + positions = m_map.template addAttribute("position") ; + + attrNames.push_back(positions.name()) ; + + AttributeContainer& container = m_map.template getAttributeContainer() ; + + // open file + std::ifstream fp(filename.c_str(), std::ios::in|std::ios::binary); + if (!fp.good()) + { + CGoGNerr << "Unable to open file " << filename << CGoGNendl; + return false; + } + + + std::vector verticesID; + verticesID.reserve(1000); + std::vector m_points; + + m_nbVertices = 0; + + + std::string ligne; + std::string tag; + + fp.ignore(80); + fp.read(reinterpret_cast(&m_nbFaces), sizeof(int)); + + m_nbEdges.reserve(m_nbFaces); + m_emb.reserve(m_nbFaces*3); + + + for (unsigned int j=0;j(&pos[0]), sizeof(float)); + fp.read(reinterpret_cast(&pos[1]), sizeof(float)); + fp.read(reinterpret_cast(&pos[2]), sizeof(float)); + + typename std::vector::iterator it = find (m_points.begin(), m_points.end(), pos); + if (it != m_points.end()) + { + unsigned int idP = it - m_points.begin(); + m_emb.push_back(verticesID[idP]); + } + else + { + unsigned int id = container.insertLine(); + positions[id] = pos; + verticesID.push_back(id); + m_points.push_back(pos); + m_emb.push_back(id); + } + } + fp.ignore(2); + m_nbEdges.push_back(3); + } + + m_nbVertices = m_points.size(); + m_nbFaces = m_nbEdges.size(); + + fp.close(); + return true; } diff --git a/include/Algo/Import/importMesh.hpp b/include/Algo/Import/importMesh.hpp index 7127d7443b5c6d1e57aaa29c77c4f1133da37a40..b4df63213ddec595ff908908f9d24ce891517cc0 100644 --- a/include/Algo/Import/importMesh.hpp +++ b/include/Algo/Import/importMesh.hpp @@ -155,6 +155,20 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector return importMesh(map, mts); } +template +bool importVoxellisation(typename PFP::MAP& map, Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector& attrNames, bool mergeCloseVertices) +{ + MeshTablesSurface mts(map); + + if(!mts.importVoxellisation(voxellisation, attrNames)) + return false; + + if (mergeCloseVertices) + mts.mergeCloseVertices(); + + return importMesh(map, mts); +} + template bool importMeshSAsV(typename PFP::MAP& map, MeshTablesSurface& mts) diff --git a/include/Algo/Selection/raySelectFunctor.hpp b/include/Algo/Selection/raySelectFunctor.hpp index f1b6252a7287df7cbc96a491b135853e9c018265..bfc4ad122e8eab4fee5ea24b505f590204e3eeb7 100644 --- a/include/Algo/Selection/raySelectFunctor.hpp +++ b/include/Algo/Selection/raySelectFunctor.hpp @@ -224,21 +224,6 @@ public: -template -bool distndartOrdering(const std::pair& e1, const std::pair& e2) -{ - return (e1.first < e2.first); -} - -template -bool distnintOrdering(const std::pair& e1, const std::pair& e2) -{ - return (e1.first < e2.first); -} - - - - namespace Parallel { diff --git a/include/Algo/Selection/raySelector.h b/include/Algo/Selection/raySelector.h index f8fd6f134592501ff6adf9527bce60c41dfe0770..26df5c3d931dac4c144e3a7038e29098e6dbecd6 100644 --- a/include/Algo/Selection/raySelector.h +++ b/include/Algo/Selection/raySelector.h @@ -41,17 +41,53 @@ namespace Selection /** * Function that does the selection of faces, returned darts are sorted from closest to farthest * @param map the map we want to test + * @param position the vertex attribute storing positions * @param rayA first point of ray (user side) * @param rayAB direction of ray (directed to the scene) * @param vecFaces (out) vector to store the darts of intersected faces + * @param iPoints (out) vector to store the intersection points */ template -void facesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, - const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecFaces); +void facesRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + std::vector& vecFaces, + std::vector& iPoints); + +/** + * Function that does the selection of faces, returned darts are sorted from closest to farthest + * @param map the map we want to test + * @param position the vertex attribute storing positions + * @param rayA first point of ray (user side) + * @param rayAB direction of ray (directed to the scene) + * @param vecFaces (out) vector to store the darts of intersected faces + */ +template +void facesRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + std::vector& vecFaces); + +/** + * Function that does the selection of one face + * @param map the map we want to test + * @param position the vertex attribute storing positions + * @param rayA first point of ray (user side) + * @param rayAB vector of ray (directed ot the scene) + * @param face (out) dart of selected vertex (set to NIL if no face selected) + */ +template +void faceRaySelection(typename PFP::MAP& map, const VertexAttribute& position, + const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, Dart& face); /** * Function that does the selection of edges, returned darts are sorted from closest to farthest * @param map the map we want to test + * @param position the vertex attribute storing positions * @param rayA first point of ray (user side) * @param rayAB vector of ray (directed ot the scene) * @param vecEdges (out) vector to store dart of intersected edges @@ -61,9 +97,22 @@ template void edgesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecEdges, float distMax); +/** + * Function that does the selection of one vertex + * @param map the map we want to test + * @param position the vertex attribute storing positions + * @param rayA first point of ray (user side) + * @param rayAB vector of ray (directed ot the scene) + * @param edge (out) dart of selected vertex (set to NIL if no edge selected) + */ +template +void edgeRaySelection(typename PFP::MAP& map, const VertexAttribute& position, + const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, Dart& edge); + /** * Function that does the selection of vertices, returned darts are sorted from closest to farthest * @param map the map we want to test + * @param position the vertex attribute storing positions * @param rayA first point of ray (user side) * @param rayAB vector of ray (directed ot the scene) * @param vecVertices (out) vector to store dart of intersected vertices @@ -73,20 +122,10 @@ template void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecVertices); - -/** - * Volume selection, not yet functional - */ -template -void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, - const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecVolumes); - - - - /** * Function that does the selection of one vertex * @param map the map we want to test + * @param position the vertex attribute storing positions * @param rayA first point of ray (user side) * @param rayAB vector of ray (directed ot the scene) * @param vertex (out) dart of selected vertex (set to NIL if no vertex selected) @@ -95,6 +134,14 @@ template void vertexRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, Dart& vertex); +/** + * Volume selection, not yet functional + */ +template +void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, + const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecVolumes); + + template void facesPlanSelection(typename PFP::MAP& map, const VertexAttribute& position, diff --git a/include/Algo/Selection/raySelector.hpp b/include/Algo/Selection/raySelector.hpp index e3f256b1c1e7583158c065d2139c45ba749227a4..abb804310df779536f348e09013a87c1aa33e89b 100644 --- a/include/Algo/Selection/raySelector.hpp +++ b/include/Algo/Selection/raySelector.hpp @@ -37,22 +37,44 @@ namespace Algo namespace Selection { +template +bool distOrdering(const std::pair& e1, const std::pair& e2) +{ + return (e1.first < e2.first); +} + +template +struct FaceInter +{ + Dart f; + typename PFP::VEC3 i; + FaceInter(Dart d, const typename PFP::VEC3& v) : f(d), i(v) {} + FaceInter() {} +}; + /** - * Function that does the selection of faces, returned darts are sorted from closest to farthest + * Function that does the selection of faces, returned darts and intersection points are sorted from closest to farthest * @param map the map we want to test + * @param position the vertex attribute storing positions * @param rayA first point of ray (user side) * @param rayAB direction of ray (directed to the scene) * @param vecFaces (out) vector to store the darts of intersected faces + * @param iPoints (out) vector to store the intersection points */ template -void facesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecFaces) +void facesRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + std::vector& vecFaces, + std::vector& iPoints) { - std::vector iPoints; - - // get back intersected faces vecFaces.reserve(256); iPoints.reserve(256); vecFaces.clear(); + iPoints.clear(); + TraversorF trav(map); for(Dart d = trav.begin(); d!=trav.end(); d = trav.next()) { @@ -62,7 +84,7 @@ void facesRaySelection(typename PFP::MAP& map, const VertexAttribute DartDist; - std::vector distndart; - - unsigned int nbi = vecFaces.size(); - distndart.resize(nbi); - for (unsigned int i = 0; i < nbi; ++i) + if(vecFaces.size() > 0) { - distndart[i].second = vecFaces[i]; - typename PFP::VEC3 V = iPoints[i] - rayA; - distndart[i].first = V.norm2(); + // compute all distances to observer for each intersected face + // and put them in a vector for sorting + typedef std::pair > faceInterDist; + std::vector dist; + + unsigned int nbi = vecFaces.size(); + dist.resize(nbi); + for (unsigned int i = 0; i < nbi; ++i) + { + dist[i].first = (iPoints[i] - rayA).norm2(); + dist[i].second = FaceInter(vecFaces[i], iPoints[i]); + } + + // sort the vector of pair dist/dart + std::sort(dist.begin(), dist.end(), distOrdering >); + + // store result in returned vectors + for (unsigned int i = 0; i < nbi; ++i) + { + vecFaces[i] = dist[i].second.f; + iPoints[i] = dist[i].second.i; + } } +} - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); +/** + * Function that does the selection of faces, returned darts are sorted from closest to farthest + * @param map the map we want to test + * @param position the vertex attribute storing positions + * @param rayA first point of ray (user side) + * @param rayAB direction of ray (directed to the scene) + * @param vecFaces (out) vector to store the darts of intersected faces + */ +template +void facesRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + std::vector& vecFaces) +{ + std::vector iPoints; + facesRaySelection(map, position, rayA, rayAB, vecFaces, iPoints); +} - // store sorted darts in returned vector - for (unsigned int i = 0; i < nbi; ++i) - vecFaces[i] = distndart[i].second; +/** + * Function that does the selection of one face + * @param map the map we want to test + * @param rayA first point of ray (user side) + * @param rayAB vector of ray (directed ot the scene) + * @param face (out) dart of intersected edge (set to NIL if no face selected) + */ +template +void faceRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + Dart& face) +{ + if (map.dimension() > 2) + CGoGNerr << "faceRaySelection only on map of dimension 2" << CGoGNendl; + + std::vector vecFaces; + std::vector iPoints; + + facesRaySelection(map, position, rayA, rayAB, vecFaces, iPoints); + + if(vecFaces.size() > 0) + face = vecFaces[0]; + else + face = NIL; } /** @@ -109,7 +185,13 @@ void facesRaySelection(typename PFP::MAP& map, const VertexAttribute -void edgesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecEdges, float distMax) +void edgesRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + std::vector& vecEdges, + float distMax) { typename PFP::REAL dist2 = distMax * distMax; typename PFP::REAL AB2 = rayAB * rayAB; @@ -130,29 +212,81 @@ void edgesRaySelection(typename PFP::MAP& map, const VertexAttribute DartDist; - std::vector distndart; + if(vecEdges.size() > 0) + { + typedef std::pair DartDist; + std::vector distndart; - unsigned int nbi = vecEdges.size(); - distndart.resize(nbi); + unsigned int nbi = vecEdges.size(); + distndart.resize(nbi); - // compute all distances to observer for each middle of intersected edge - // and put them in a vector for sorting - for (unsigned int i = 0; i < nbi; ++i) - { - Dart d = vecEdges[i]; - distndart[i].second = d; - typename PFP::VEC3 V = (position[d] + position[map.phi1(d)]) / typename PFP::REAL(2); - V -= rayA; - distndart[i].first = V.norm2(); + // compute all distances to observer for each middle of intersected edge + // and put them in a vector for sorting + for (unsigned int i = 0; i < nbi; ++i) + { + Dart d = vecEdges[i]; + distndart[i].second = d; + typename PFP::VEC3 V = (position[d] + position[map.phi1(d)]) / typename PFP::REAL(2); + V -= rayA; + distndart[i].first = V.norm2(); + } + + // sort the vector of pair dist/dart + std::sort(distndart.begin(), distndart.end(), distOrdering); + + // store sorted darts in returned vector + for (unsigned int i = 0; i < nbi; ++i) + vecEdges[i] = distndart[i].second; } +} - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); +/** + * Function that does the selection of one edge + * @param map the map we want to test + * @param rayA first point of ray (user side) + * @param rayAB vector of ray (directed ot the scene) + * @param edge (out) dart of intersected edge (set to NIL if no edge selected) + */ +template +void edgeRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + Dart& edge) +{ + if (map.dimension() > 2) + CGoGNerr << "edgeRaySelection only on map of dimension 2" << CGoGNendl; - // store sorted darts in returned vector - for (unsigned int i = 0; i < nbi; ++i) - vecEdges[i] = distndart[i].second; + std::vector vecFaces; + std::vector iPoints; + + facesRaySelection(map, position, rayA, rayAB, vecFaces, iPoints); + + if(vecFaces.size() > 0) + { + // recuperation du point d'intersection sur la face la plus proche + typename PFP::VEC3 ip = iPoints[0]; + + // recuperation de l'arete la plus proche du point d'intersection + Dart d = vecFaces[0]; + Dart it = d; + typename PFP::REAL minDist = squaredDistanceLine2Point(position[it], position[map.phi1(it)], ip); + edge = it; + it = map.phi1(it); + while(it != d) + { + typename PFP::REAL dist = squaredDistanceLine2Point(position[it], position[map.phi1(it)], ip); + if(dist < minDist) + { + minDist = dist; + edge = it; + } + it = map.phi1(it); + } + } + else + edge = NIL; } /** @@ -164,7 +298,13 @@ void edgesRaySelection(typename PFP::MAP& map, const VertexAttribute -void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecVertices, float dist) +void verticesRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + std::vector& vecVertices, + float dist) { typename PFP::REAL dist2 = dist * dist; typename PFP::REAL AB2 = rayAB * rayAB; @@ -182,34 +322,89 @@ void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute DartDist; - std::vector distndart; + if(vecVertices.size() > 0) + { + typedef std::pair DartDist; + std::vector distndart; - unsigned int nbi = vecVertices.size(); - distndart.resize(nbi); + unsigned int nbi = vecVertices.size(); + distndart.resize(nbi); - // compute all distances to observer for each intersected vertex - // and put them in a vector for sorting - for (unsigned int i = 0; i < nbi; ++i) - { - Dart d = vecVertices[i]; - distndart[i].second = d; - typename PFP::VEC3 V = position[d] - rayA; - distndart[i].first = V.norm2(); - } + // compute all distances to observer for each intersected vertex + // and put them in a vector for sorting + for (unsigned int i = 0; i < nbi; ++i) + { + Dart d = vecVertices[i]; + distndart[i].second = d; + typename PFP::VEC3 V = position[d] - rayA; + distndart[i].first = V.norm2(); + } - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); + // sort the vector of pair dist/dart + std::sort(distndart.begin(), distndart.end(), distOrdering); - // store sorted darts in returned vector - for (unsigned int i = 0; i < nbi; ++i) - vecVertices[i] = distndart[i].second; + // store sorted darts in returned vector + for (unsigned int i = 0; i < nbi; ++i) + vecVertices[i] = distndart[i].second; + } } +/** + * Function that does the selection of one vertex + * @param map the map we want to test + * @param rayA first point of ray (user side) + * @param rayAB vector of ray (directed ot the scene) + * @param vertex (out) dart of selected vertex (set to NIL if no vertex selected) + */ +template +void vertexRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + Dart& vertex) +{ + if (map.dimension() > 2) + CGoGNerr << "vertexRaySelection only on map of dimension 2" << CGoGNendl; + + std::vector vecFaces; + std::vector iPoints; + + facesRaySelection(map, position, rayA, rayAB, vecFaces, iPoints); + if(vecFaces.size() > 0) + { + // recuperation du point d'intersection sur la face la plus proche + typename PFP::VEC3 ip = iPoints[0]; + + // recuperation du sommet le plus proche du point d'intersection + Dart d = vecFaces[0]; + Dart it = d; + typename PFP::REAL minDist = (ip - position[it]).norm2(); + vertex = it; + it = map.phi1(it); + while(it != d) + { + typename PFP::REAL dist = (ip - position[it]).norm2(); + if(dist < minDist) + { + minDist = dist; + vertex = it; + } + it = map.phi1(it); + } + } + else + vertex = NIL; +} template -void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecVolumes) +void volumesRaySelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + std::vector& vecVolumes) { std::vector vecFaces; std::vector iPoints; @@ -219,7 +414,7 @@ void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute trav(map); - for(Dart d = trav.begin(); d!=trav.end(); d = trav.next()) + for(Dart d = trav.begin(); d != trav.end(); d = trav.next()) { const typename PFP::VEC3& Ta = position[d]; Dart dd = map.phi1(d); @@ -258,7 +453,7 @@ void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute); + std::sort(distndart.begin(), distndart.end(), distOrdering); //TODO // think of how sort volumes from faces order @@ -266,96 +461,8 @@ void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute -void vertexRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, Dart& vertex) -{ - if (map.dimension() >2) - { - CGoGNerr << "vertexOfSurfaceRaySelection only on map of dimension 2" << CGoGNendl; - } - - std::vector vecFaces; - std::vector iPoints; - - // recuperation des faces intersectes - TraversorF trav(map); - for(Dart d = trav.begin(); d!=trav.end(); d = trav.next()) - { - const typename PFP::VEC3& Ta = position[d]; - Dart dd = map.phi1(d); - Dart ddd = map.phi1(dd); - bool notfound = true; - do - { - // get back position of triangle Ta,Tb,Tc - const typename PFP::VEC3& Tb = position[dd]; - const typename PFP::VEC3& Tc = position[ddd]; - typename PFP::VEC3 I; - if (Geom::intersectionRayTriangleOpt(rayA, rayAB, Ta, Tb, Tc, I)) - { - vecFaces.push_back(d); - iPoints.push_back(I); - notfound = false; - } - // next triangle if we are in polygon - dd = ddd; - ddd = map.phi1(dd); - } while ((ddd != d) && notfound); - } - - if(vecFaces.size() > 0) - { - typedef std::pair IndexedDist; - std::vector distnint; - - unsigned int nbi = vecFaces.size(); - distnint.resize(nbi); - for (unsigned int i = 0; i < nbi; ++i) - { - distnint[i].first = (iPoints[i] - rayA).norm2(); - distnint[i].second = i; - } - - // sort the vector of pair dist/dart - std::sort(distnint.begin(), distnint.end(), distnintOrdering); - - // recuperation du point d'intersection sur la face la plus proche - unsigned int first = distnint[0].second; - typename PFP::VEC3 ip = iPoints[first]; - - // recuperation du sommet le plus proche du point d'intersection - Dart d = vecFaces[first]; - Dart it = d; - typename PFP::REAL minDist = (ip - position[it]).norm2(); - vertex = it; - it = map.phi1(it); - while(it != d) - { - typename PFP::REAL dist = (ip - position[it]).norm2(); - if(dist < minDist) - { - minDist = dist; - vertex = it; - } - it = map.phi1(it); - } - } - else - vertex = NIL; -} - /** - * Fonction that do the selection of darts, returned darts are sorted from closest to farthest + * Fonction that does the selection of darts, returned darts are sorted from closest to farthest * Dart is here considered as a triangle formed by the 2 end vertices of the edge and the face centroid * @param map the map we want to test * @param rayA first point of ray (user side) @@ -396,8 +503,11 @@ void vertexRaySelection(typename PFP::MAP& map, const VertexAttribute -void facesPlanSelection(typename PFP::MAP& map, const VertexAttribute& position, - const typename Geom::Plane3D& plan, std::vector& vecDarts) +void facesPlanSelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename Geom::Plane3D& plan, + std::vector& vecDarts) { TraversorF travF(map); @@ -423,7 +533,13 @@ void facesPlanSelection(typename PFP::MAP& map, const VertexAttribute -void verticesConeSelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, float angle, std::vector& vecVertices) +void verticesConeSelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + float angle, + std::vector& vecVertices) { typename PFP::REAL AB2 = rayAB * rayAB; @@ -462,7 +578,7 @@ void verticesConeSelection(typename PFP::MAP& map, const VertexAttribute); + std::sort(distndart.begin(), distndart.end(), distOrdering); // store sorted darts in returned vector for (unsigned int i = 0; i < nbi; ++i) @@ -478,7 +594,13 @@ void verticesConeSelection(typename PFP::MAP& map, const VertexAttribute -void edgesConeSelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, float angle, std::vector& vecEdges) +void edgesConeSelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& rayA, + const typename PFP::VEC3& rayAB, + float angle, + std::vector& vecEdges) { typename PFP::REAL AB2 = rayAB * rayAB; @@ -521,7 +643,7 @@ void edgesConeSelection(typename PFP::MAP& map, const VertexAttribute); + std::sort(distndart.begin(), distndart.end(), distOrdering); // store sorted darts in returned vector for (unsigned int i = 0; i < nbi; ++i) @@ -531,7 +653,11 @@ void edgesConeSelection(typename PFP::MAP& map, const VertexAttribute -Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax) +Dart verticesBubbleSelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& cursor, + typename PFP::REAL radiusMax) { typename PFP::REAL l2max = radiusMax*radiusMax; typename PFP::REAL l2min(std::numeric_limits::max()); @@ -551,9 +677,12 @@ Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute -Dart edgesBubbleSelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax) +Dart edgesBubbleSelection( + typename PFP::MAP& map, + const VertexAttribute& position, + const typename PFP::VEC3& cursor, + typename PFP::REAL radiusMax) { typename PFP::REAL l2max = radiusMax*radiusMax; typename PFP::REAL l2min(std::numeric_limits::max()); diff --git a/include/Topology/generic/cellmarker.h b/include/Topology/generic/cellmarker.h index 1c003cd6a77267fe2f62f3e9dc0bd4d5ea239327..436cadaaabbb91a53ee5603d69074f9afe8bc41a 100644 --- a/include/Topology/generic/cellmarker.h +++ b/include/Topology/generic/cellmarker.h @@ -198,6 +198,8 @@ public: assert(m_map.getMarkerSet(m_thread).testMark(m_mark)); assert(m_markVector != NULL); + if (em == EMBNULL) + return false ; return m_markVector->operator[](em).testMark(m_mark) ; }