Commit 54850cac authored by Pierre Kraemer's avatar Pierre Kraemer

update selection plugin

parent 046c3ab1
...@@ -81,12 +81,16 @@ protected: ...@@ -81,12 +81,16 @@ protected:
Utils::PointSprite* m_pointSprite; Utils::PointSprite* m_pointSprite;
Utils::Drawer* m_drawer; Utils::Drawer* m_drawer;
// cell under the mouse when selecting
Dart m_selectingVertex;
Dart m_selectingEdge;
Dart m_selectingFace;
// selected cells drawing // selected cells drawing
Utils::VBO* m_selectedVerticesVBO; Utils::VBO* m_selectedVerticesVBO;
// WithinSphere parameters // WithinSphere parameters
Utils::VBO* m_selectionSphereVBO; Utils::VBO* m_selectionSphereVBO;
PFP2::VEC3 m_selectionCenter;
PFP2::REAL m_selectionRadius; PFP2::REAL m_selectionRadius;
}; };
......
...@@ -75,25 +75,23 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -75,25 +75,23 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
if(selector) if(selector)
{ {
const std::vector<Dart>& selectedCells = selector->getSelectedCells(); const std::vector<Dart>& selectedCells = selector->getSelectedCells();
unsigned int nbCells = map->getGenericMap()->getNbCells(orbit);
switch(orbit) switch(orbit)
{ {
case VERTEX : { case VERTEX : {
m_pointSprite->setAttributePosition(m_selectedVerticesVBO); 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->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->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m_pointSprite->enableVertexAttribs(); m_pointSprite->enableVertexAttribs();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_POINTS, 0, selectedCells.size()); glDrawArrays(GL_POINTS, 0, selectedCells.size());
glDisable(GL_BLEND);
m_pointSprite->disableVertexAttribs(); m_pointSprite->disableVertexAttribs();
if(m_selecting) if(m_selecting && m_selectingVertex != NIL)
{ {
std::vector<PFP2::VEC3> selectionPoint; std::vector<PFP2::VEC3> selectionPoint;
selectionPoint.push_back(m_selectionCenter); selectionPoint.push_back(p.positionAttribute[m_selectingVertex]);
m_selectionSphereVBO->updateData(selectionPoint); m_selectionSphereVBO->updateData(selectionPoint);
m_pointSprite->setAttributePosition(m_selectionSphereVBO); m_pointSprite->setAttributePosition(m_selectionSphereVBO);
...@@ -103,7 +101,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -103,7 +101,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
switch(p.selectionMethod) switch(p.selectionMethod)
{ {
case SingleCell : { case SingleCell : {
m_pointSprite->setSize(map->getBBdiagSize() / 250.0f); m_pointSprite->setSize(30 * map->getBBdiagSize() / nbCells);
break; break;
} }
case WithinSphere : { case WithinSphere : {
...@@ -122,9 +120,77 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -122,9 +120,77 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
break; break;
} }
case EDGE : { case EDGE : {
PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(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<Dart>::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; break;
} }
case FACE : { case FACE : {
PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(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<Dart>::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; break;
} }
} }
...@@ -163,41 +229,27 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) ...@@ -163,41 +229,27 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
{ {
unsigned int orbit = m_schnapps->getCurrentOrbit(); unsigned int orbit = m_schnapps->getCurrentOrbit();
CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit); CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
if(selector) 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<MapHandler<PFP2>*>(mh)->getMap(); PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(mh)->getMap();
switch(orbit) switch(orbit)
{ {
case VERTEX : { case VERTEX : {
Algo::Selection::vertexRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, d); if(m_selectingVertex != NIL)
if(d != NIL)
{ {
switch(p.selectionMethod) switch(p.selectionMethod)
{ {
case SingleCell : { case SingleCell : {
if(event->button() == Qt::LeftButton) if(event->button() == Qt::LeftButton)
selector->select(d); selector->select(m_selectingVertex);
else if(event->button() == Qt::RightButton) else if(event->button() == Qt::RightButton)
selector->unselect(d); selector->unselect(m_selectingVertex);
break; break;
} }
case WithinSphere : { case WithinSphere : {
Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, p.positionAttribute, m_selectionRadius); Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, p.positionAttribute, m_selectionRadius);
neigh.collectAll(d); neigh.collectAll(m_selectingVertex);
if(event->button() == Qt::LeftButton) if(event->button() == Qt::LeftButton)
selector->select(neigh.getInsideVertices()); selector->select(neigh.getInsideVertices());
else if(event->button() == Qt::RightButton) else if(event->button() == Qt::RightButton)
...@@ -215,9 +267,41 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) ...@@ -215,9 +267,41 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
break; break;
} }
case EDGE : { 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; break;
} }
case FACE : { 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; break;
} }
} }
...@@ -239,23 +323,39 @@ void Surface_Selection_Plugin::mouseMove(View* view, QMouseEvent* event) ...@@ -239,23 +323,39 @@ void Surface_Selection_Plugin::mouseMove(View* view, QMouseEvent* event)
const MapParameters& p = h_parameterSet[mh]; const MapParameters& p = h_parameterSet[mh];
if(p.positionAttribute.isValid()) if(p.positionAttribute.isValid())
{ {
QPoint pixel(event->x(), event->y()); unsigned int orbit = m_schnapps->getCurrentOrbit();
qglviewer::Vec orig; CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
qglviewer::Vec dir; if(selector)
view->camera()->convertClickToLine(pixel, orig, dir); {
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); PFP2::VEC3 rayA(orig_inv.x, orig_inv.y, orig_inv.z);
qglviewer::Vec dir_inv = mh->getFrame()->transformOf(dir); 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::MAP* map = static_cast<MapHandler<PFP2>*>(mh)->getMap();
PFP2::VEC3 AB(dir_inv.x, dir_inv.y, dir_inv.z);
switch(orbit)
{
case VERTEX : {
Algo::Selection::vertexRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingVertex);
break;
}
case EDGE : {
Algo::Selection::edgeRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingEdge);
break;
}
case FACE : {
Algo::Selection::faceRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingFace);
break;
}
}
Dart d;
PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(mh)->getMap();
Algo::Selection::vertexRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, d);
if(d != NIL)
{
m_selectionCenter = p.positionAttribute[d];
view->updateGL(); view->updateGL();
} }
} }
......
...@@ -109,11 +109,10 @@ public: ...@@ -109,11 +109,10 @@ public:
inline void select(Dart d, bool emitSignal = true) inline void select(Dart d, bool emitSignal = true)
{ {
unsigned int v = m_map.getEmbedding<ORBIT>(d); if(!m_cm.isMarked(d))
if(!m_cm.isMarked(v))
{ {
m_cells.push_back(d); m_cells.push_back(d);
m_cm.mark(v); m_cm.mark(d);
if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty()) if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty())
{ {
foreach(CellSelectorGen* cs, m_mutuallyExclusive) foreach(CellSelectorGen* cs, m_mutuallyExclusive)
...@@ -128,9 +127,9 @@ public: ...@@ -128,9 +127,9 @@ public:
inline void unselect(Dart d, bool emitSignal = true) inline void unselect(Dart d, bool emitSignal = true)
{ {
unsigned int v = m_map.getEmbedding<ORBIT>(d); if(m_cm.isMarked(d))
if(m_cm.isMarked(v))
{ {
unsigned int v = m_map.getEmbedding<ORBIT>(d);
bool found = false; bool found = false;
unsigned int i; unsigned int i;
for(i = 0; i < m_cells.size() && !found; ++i) for(i = 0; i < m_cells.size() && !found; ++i)
......
...@@ -54,6 +54,16 @@ namespace Import ...@@ -54,6 +54,16 @@ namespace Import
template <typename PFP> template <typename PFP>
bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, bool mergeCloseVertices = false); bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& 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 <typename PFP>
bool importVoxellisation(typename PFP::MAP& map, Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector<std::string>& attrNames, bool mergeCloseVertices=false);
/** /**
* import a Choupi file * import a Choupi file
...@@ -64,7 +74,6 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector ...@@ -64,7 +74,6 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector
template <typename PFP> template <typename PFP>
bool importChoupi(const std::string& filename, const std::vector<typename PFP::VEC3>& tabV, const std::vector<unsigned int>& tabE); bool importChoupi(const std::string& filename, const std::vector<typename PFP::VEC3>& tabV, const std::vector<unsigned int>& tabE);
} // namespace Import } // namespace Import
} // Surface } // Surface
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "Utils/gzstream.h" #include "Utils/gzstream.h"
#include "Algo/Import/importFileTypes.h" #include "Algo/Import/importFileTypes.h"
#include "Algo/Modelisation/voxellisation.h"
#ifdef WITH_ASSIMP #ifdef WITH_ASSIMP
#include "Assimp/assimp.h" #include "Assimp/assimp.h"
...@@ -103,9 +104,11 @@ public: ...@@ -103,9 +104,11 @@ public:
bool importOff(const std::string& filename, std::vector<std::string>& attrNames); bool importOff(const std::string& filename, std::vector<std::string>& attrNames);
bool importVoxellisation(Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector<std::string>& attrNames);
bool importMeshBin(const std::string& filename, std::vector<std::string>& attrNames); bool importMeshBin(const std::string& filename, std::vector<std::string>& attrNames);
bool importObj(const std::string& filename, std::vector<std::string>& attrNames); bool importObj(const std::string& filename, std::vector<std::string>& attrNames);
bool importPly(const std::string& filename, std::vector<std::string>& attrNames); bool importPly(const std::string& filename, std::vector<std::string>& attrNames);
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "Algo/Geometry/boundingbox.h" #include "Algo/Geometry/boundingbox.h"
#include "Topology/generic/autoAttributeHandler.h" #include "Topology/generic/autoAttributeHandler.h"
#include "Algo/Modelisation/voxellisation.h"
#include "Algo/Import/AHEM.h" #include "Algo/Import/AHEM.h"
namespace CGoGN namespace CGoGN
...@@ -43,270 +45,270 @@ namespace Import ...@@ -43,270 +45,270 @@ namespace Import
template<typename PFP> template<typename PFP>
ImportType MeshTablesSurface<PFP>::getFileType(const std::string& filename) ImportType MeshTablesSurface<PFP>::getFileType(const std::string& filename)
{ {
if ((filename.rfind(".trianbgz")!=std::string::npos) || (filename.rfind(".TRIANBGZ")!=std::string::npos)) if ((filename.rfind(".trianbgz")!=std::string::npos) || (filename.rfind(".TRIANBGZ")!=std::string::npos))
return TRIANBGZ; return TRIANBGZ;
if ((filename.rfind(".trian")!=std::string::npos) || (filename.rfind(".TRIAN")!=std::string::npos)) if ((filename.rfind(".trian")!=std::string::npos) || (filename.rfind(".TRIAN")!=std::string::npos))
return TRIAN; return TRIAN;
if ((filename.rfind(".meshbin")!=std::string::npos) || (filename.rfind(".MESHBIN")!=std::string::npos)) if ((filename.rfind(".meshbin")!=std::string::npos) || (filename.rfind(".MESHBIN")!=std::string::npos))
return MESHBIN; return MESHBIN;
/* if ((filename.rfind(".plyptm")!=std::string::npos) || (filename.rfind(".PLYGEN")!=std::string::npos)) /* 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)) if ((filename.rfind(".plyPTMextBin")!=std::string::npos) || (filename.rfind(".plySHrealBin")!=std::string::npos))
return PLYSLFgenericBin; return PLYSLFgenericBin;
if ((filename.rfind(".plyPTMext")!=std::string::npos) || (filename.rfind(".plySHreal")!=std::string::npos)) if ((filename.rfind(".plyPTMext")!=std::string::npos) || (filename.rfind(".plySHreal")!=std::string::npos))
return PLYSLFgeneric; return PLYSLFgeneric;
if ((filename.rfind(".ply")!=std::string::npos) || (filename.rfind(".PLY")!=std::string::npos)) if ((filename.rfind(".ply")!=std::string::npos) || (filename.rfind(".PLY")!=std::string::npos))
return PLY; return PLY;
if ((filename.rfind(".off")!=std::string::npos) || (filename.rfind(".OFF")!=std::string::npos)) if ((filename.rfind(".off")!=std::string::npos) || (filename.rfind(".OFF")!=std::string::npos))
return OFF; return OFF;
if ((filename.rfind(".obj")!=std::string::npos) || (filename.rfind(".OBJ")!=std::string::npos)) if ((filename.rfind(".obj")!=std::string::npos) || (filename.rfind(".OBJ")!=std::string::npos))
return OBJ; return OBJ;
if ((filename.rfind(".ahem")!=std::string::npos) || (filename.rfind(".AHEM")!=std::string::npos)) if ((filename.rfind(".ahem")!=std::string::npos) || (filename.rfind(".AHEM")!=std::string::npos))
return AHEM; return AHEM;
if ((filename.rfind(".stlb")!=std::string::npos) || (filename.rfind(".STLB")!=std::string::npos)) if ((filename.rfind(".stlb")!=std::string::npos) || (filename.rfind(".STLB")!=std::string::npos))
return STLB; return STLB;
if ((filename.rfind(".stl")!=std::string::npos) || (filename.rfind(".STL")!=std::string::npos)) if ((filename.rfind(".stl")!=std::string::npos) || (filename.rfind(".STL")!=std::string::npos))
return STL; return STL;
return UNKNOWNSURFACE; return UNKNOWNSURFACE;
} }
template<typename PFP> template<typename PFP>
bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector<std::string>& attrNames) bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector<std::string>& attrNames)
{ {
ImportType kind = getFileType(filename); ImportType kind = getFileType(filename);
attrNames.clear() ; attrNames.clear() ;
switch (kind) switch (kind)
{ {
case TRIAN: case TRIAN:
CGoGNout << "TYPE: TRIAN" << CGoGNendl; CGoGNout << "TYPE: TRIAN" << CGoGNendl;
return importTrian(filename, attrNames); return importTrian(filename, attrNames);
break; break;
case TRIANBGZ: case TRIANBGZ:
CGoGNout << "TYPE: TRIANBGZ" << CGoGNendl; CGoGNout << "TYPE: TRIANBGZ" << CGoGNendl;
return importTrianBinGz(filename, attrNames); return importTrianBinGz(filename, attrNames);
break; break;
case OFF: case OFF:
CGoGNout << "TYPE: OFF" << CGoGNendl; CGoGNout << "TYPE: OFF" << CGoGNendl;
return importOff(filename, attrNames); return importOff(filename, attrNames);
break; break;
case MESHBIN: case MESHBIN:
CGoGNout << "TYPE: MESHBIN" << CGoGNendl; CGoGNout << "TYPE: MESHBIN" << CGoGNendl;
return importMeshBin(filename, attrNames); return importMeshBin(filename, attrNames);
break; break;
case PLY: case PLY:
CGoGNout << "TYPE: PLY" << CGoGNendl; CGoGNout << "TYPE: PLY" << CGoGNendl;
return importPly(filename, attrNames); return importPly(filename, attrNames);
break; break;
/* case PLYPTM: /* case PLYPTM:
CGoGNout << "TYPE: PLYPTM" << CGoGNendl; CGoGNout << "TYPE: PLYPTM" << CGoGNendl;
return importPlyPTM(filename, attrNames); return importPlyPTM(filename, attrNames);
break; break;
*/ case PLYSLFgeneric: */ case PLYSLFgeneric:
CGoGNout << "TYPE: PLYSLFgeneric" << CGoGNendl;