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

update selection plugin

parent 046c3ab1
......@@ -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;
};
......
......@@ -75,25 +75,23 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
if(selector)
{
const std::vector<Dart>& 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<PFP2::VEC3> 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<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;
}
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;
}
}
......@@ -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<MapHandler<PFP2>*>(mh)->getMap();
switch(orbit)
{
case VERTEX : {
Algo::Selection::vertexRaySelection<PFP2>(*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<PFP2> 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;
}
}
......@@ -238,6 +322,10 @@ void Surface_Selection_Plugin::mouseMove(View* view, QMouseEvent* event)
MapHandlerGen* mh = m_schnapps->getSelectedMap();
const MapParameters& p = h_parameterSet[mh];
if(p.positionAttribute.isValid())
{
unsigned int orbit = m_schnapps->getCurrentOrbit();
CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
if(selector)
{
QPoint pixel(event->x(), event->y());
qglviewer::Vec orig;
......@@ -250,12 +338,24 @@ void Surface_Selection_Plugin::mouseMove(View* view, QMouseEvent* event)
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();
Algo::Selection::vertexRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, d);
if(d != NIL)
switch(orbit)
{
m_selectionCenter = p.positionAttribute[d];
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;
}
}
view->updateGL();
}
}
......
......@@ -109,11 +109,10 @@ public:
inline void select(Dart d, bool emitSignal = true)
{
unsigned int v = m_map.getEmbedding<ORBIT>(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<ORBIT>(d);
if(m_cm.isMarked(v))
if(m_cm.isMarked(d))
{
unsigned int v = m_map.getEmbedding<ORBIT>(d);
bool found = false;
unsigned int i;
for(i = 0; i < m_cells.size() && !found; ++i)
......
......@@ -54,6 +54,16 @@ namespace Import
template <typename PFP>
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
......@@ -64,7 +74,6 @@ bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector
template <typename PFP>
bool importChoupi(const std::string& filename, const std::vector<typename PFP::VEC3>& tabV, const std::vector<unsigned int>& tabE);
} // namespace Import
} // Surface
......
......@@ -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,6 +104,8 @@ public:
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 importObj(const std::string& filename, std::vector<std::string>& attrNames);
......
......@@ -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
......@@ -387,6 +389,50 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<
return true;
}
template<typename PFP>
bool MeshTablesSurface<PFP>::importVoxellisation(Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector<std::string>& attrNames)
{
VertexAttribute<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3, VERTEX>("position") ;
if (!positions.isValid())
positions = m_map.template addAttribute<typename PFP::VEC3, VERTEX>("position") ;
attrNames.push_back(positions.name()) ;
AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ;
// lecture des nombres de sommets/faces
m_nbVertices = voxellisation.getNbSommets();
m_nbFaces = voxellisation.getNbFaces();
//lecture sommets
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
for (unsigned int i = 0; i < m_nbVertices;++i)
{
unsigned int id = container.insertLine();
positions[id] = voxellisation.m_sommets[i];
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*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<typename PFP>
bool MeshTablesSurface<PFP>::importMeshBin(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
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>
bool importMeshSAsV(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
......
......@@ -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
{
......
......@@ -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<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);
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,
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
* @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<typename PFP>
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);
/**
* 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
* @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<typename PFP>
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);
/**
* Volume selection, not yet functional
*/
template<typename PFP>
void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position,
const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& 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<typename PFP>
void vertexRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position,
const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, Dart& vertex);
/**
* Volume selection, not yet functional
*/
template<typename PFP>
void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position,
const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVolumes);
template<typename PFP>
void facesPlanSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position,
......
This diff is collapsed.
......@@ -198,6 +198,8 @@ public:
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
if (em == EMBNULL)
return false ;
return m_markVector->operator[](em).testMark(m_mark) ;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment