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);
......
...@@ -155,6 +155,20 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector ...@@ -155,6 +155,20 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector
return importMesh<PFP>(map, mts); return importMesh<PFP>(map, mts);
} }
template <typename PFP>
bool importVoxellisation(typename PFP::MAP& map, Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector<std::string>& attrNames, bool mergeCloseVertices)
{
MeshTablesSurface<PFP> mts(map);
if(!mts.importVoxellisation(voxellisation, attrNames))
return false;
if (mergeCloseVertices)
mts.mergeCloseVertices();
return importMesh<PFP>(map, mts);
}
template <typename PFP> template <typename PFP>
bool importMeshSAsV(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts) bool importMeshSAsV(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
......
...@@ -224,21 +224,6 @@ public: ...@@ -224,21 +224,6 @@ public:
template <typename PFP>
bool distndartOrdering(const std::pair<typename PFP::REAL, Dart>& e1, const std::pair<typename PFP::REAL, Dart>& e2)
{
return (e1.first < e2.first);
}
template <typename PFP>
bool distnintOrdering(const std::pair<typename PFP::REAL, unsigned int>& e1, const std::pair<typename PFP::REAL, unsigned int>& e2)
{
return (e1.first < e2.first);
}
namespace Parallel namespace Parallel
{ {
......
...@@ -41,17 +41,53 @@ namespace Selection ...@@ -41,17 +41,53 @@ namespace Selection
/** /**
* Function that does the selection of faces, returned darts are sorted from closest to farthest * Function that does the selection of faces, returned darts are sorted from closest to farthest
* @param map the map we want to test * @param map the map we want to test
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side) * @param rayA first point of ray (user side)
* @param rayAB direction of ray (directed to the scene) * @param rayAB direction of ray (directed to the scene)
* @param vecFaces (out) vector to store the darts of intersected faces * @param vecFaces (out) vector to store the darts of intersected faces
* @param iPoints (out) vector to store the intersection points
*/ */
template<typename PFP> template<typename PFP>
void facesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, void facesRaySelection(
const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecFaces); typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
std::vector<Dart>& vecFaces,
std::vector<typename PFP::VEC3>& 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<typename PFP>
void facesRaySelection(
typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
std::vector<Dart>& 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<typename PFP>
void faceRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& 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 * Function that does the selection of edges, returned darts are sorted from closest to farthest
* @param map the map we want to test * @param map the map we want to test
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side) * @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene) * @param rayAB vector of ray (directed ot the scene)
* @param vecEdges (out) vector to store dart of intersected edges * @param vecEdges (out) vector to store dart of intersected edges
...@@ -61,9 +97,22 @@ template<typename PFP> ...@@ -61,9 +97,22 @@ template<typename PFP>
void edgesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, void edgesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position,
const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecEdges, float distMax); const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& 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<typename PFP>
void edgeRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& 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 * Function that does the selection of vertices, returned darts are sorted from closest to farthest
* @param map the map we want to test * @param map the map we want to test
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side) * @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene) * @param rayAB vector of ray (directed ot the scene)
* @param vecVertices (out) vector to store dart of intersected vertices * @param vecVertices (out) vector to store dart of intersected vertices
...@@ -73,20 +122,10 @@ template<typename PFP> ...@@ -73,20 +122,10 @@ template<typename PFP>
void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position,
const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVertices); const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVertices);
/**
* Volume selection, not yet functional