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;
}
}
......@@ -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<MapHandler<PFP2>*>(mh)->getMap();
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();
}
}
......
......@@ -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,9 +104,11 @@ 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);
bool importObj(const std::string& filename, std::vector<std::string>& attrNames);
bool importPly(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
......@@ -43,270 +45,270 @@ namespace Import
template<typename PFP>
ImportType MeshTablesSurface<PFP>::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<typename PFP>
bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector<std::string>& 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<typename PFP>
bool MeshTablesSurface<PFP>::importTrian(const std::string& filename, 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>() ;
// 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<unsigned int> 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)