Commit 1e04a087 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

surface selection plugin ok

parent 5b65878e
...@@ -61,12 +61,11 @@ public: ...@@ -61,12 +61,11 @@ public:
private slots: private slots:
// slots called from SCHNApps signals // slots called from SCHNApps signals
void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur); void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
void mapAdded(MapHandlerGen* map);
void mapRemoved(MapHandlerGen* map);
void updateSelectedCellsRendering(); void updateSelectedCellsRendering();
// slots called from MapHandler signals // slots called from MapHandler signals
void attributeAdded(unsigned int orbit, const QString& name); void selectedMapAttributeAdded(unsigned int orbit, const QString& name);
void selectedMapAttributeModified(unsigned int orbit, const QString& name);
public slots: public slots:
// slots for Python calls // slots for Python calls
...@@ -79,17 +78,20 @@ protected: ...@@ -79,17 +78,20 @@ protected:
bool m_selecting; bool m_selecting;
Utils::PointSprite* m_pointSprite;
Utils::Drawer* m_drawer;
// cell under the mouse when selecting // cell under the mouse when selecting
Dart m_selectingVertex; Dart m_selectingVertex;
Dart m_selectingEdge; Dart m_selectingEdge;
Dart m_selectingFace; Dart m_selectingFace;
// selected cells drawing // selecting & selected cells drawing
Utils::PointSprite* m_pointSprite;
Utils::VBO* m_selectedVerticesVBO; Utils::VBO* m_selectedVerticesVBO;
Utils::Drawer* m_selectedEdgesDrawer;
Utils::Drawer* m_selectedFacesDrawer;
Utils::Drawer* m_selectingCellDrawer;
// WithinSphere parameters // WithinSphere parameters
Utils::VBO* m_selectionSphereVBO; Utils::VBO* m_selectionSphereVBO;
PFP2::REAL m_selectionRadius; PFP2::REAL m_selectionRadius;
......
...@@ -26,22 +26,30 @@ bool Surface_Selection_Plugin::enable() ...@@ -26,22 +26,30 @@ bool Surface_Selection_Plugin::enable()
m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Selection"); m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Selection");
m_pointSprite = new CGoGN::Utils::PointSprite(); m_pointSprite = new CGoGN::Utils::PointSprite();
m_drawer = new Utils::Drawer();
m_selectedVerticesVBO = new Utils::VBO(); m_selectedVerticesVBO = new Utils::VBO();
m_selectedEdgesDrawer = new Utils::Drawer();
m_selectedFacesDrawer = new Utils::Drawer();
m_selectingCellDrawer = new Utils::Drawer();
m_selectionSphereVBO = new Utils::VBO(); m_selectionSphereVBO = new Utils::VBO();
registerShader(m_drawer->getShader());
registerShader(m_pointSprite); registerShader(m_pointSprite);
registerShader(m_selectedEdgesDrawer->getShader());
registerShader(m_selectedFacesDrawer->getShader());
registerShader(m_selectingCellDrawer->getShader());
connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*))); connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
connect(m_schnapps, SIGNAL(selectedCellSelectorChanged(CellSelectorGen*)), this, SLOT(updateSelectedCellsRendering())); connect(m_schnapps, SIGNAL(selectedCellSelectorChanged(CellSelectorGen*)), this, SLOT(updateSelectedCellsRendering()));
foreach(MapHandlerGen* map, m_schnapps->getMapSet().values()) MapHandlerGen* cur = m_schnapps->getSelectedMap();
mapAdded(map); if(cur)
{
connect(cur, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&)));
connect(cur, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&)));
m_selectionRadius = cur->getBBdiagSize() / 50.0f;
}
m_dockTab->updateMapParameters(); m_dockTab->updateMapParameters();
...@@ -52,12 +60,15 @@ void Surface_Selection_Plugin::disable() ...@@ -52,12 +60,15 @@ void Surface_Selection_Plugin::disable()
{ {
delete m_pointSprite; delete m_pointSprite;
delete m_selectedVerticesVBO; delete m_selectedVerticesVBO;
delete m_selectedEdgesDrawer;
delete m_selectedFacesDrawer;
delete m_selectingCellDrawer;
delete m_selectionSphereVBO; delete m_selectionSphereVBO;
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*))); disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*))); disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(selectedCellSelectorChanged(CellSelectorGen*)), this, SLOT(updateSelectedCellsRendering()));
} }
void Surface_Selection_Plugin::draw(View *view) void Surface_Selection_Plugin::draw(View *view)
...@@ -121,33 +132,22 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -121,33 +132,22 @@ 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_selectedEdgesDrawer->callList();
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) if(m_selecting && m_selectingEdge != NIL)
{ {
switch(p.selectionMethod) switch(p.selectionMethod)
{ {
case SingleCell : { case SingleCell : {
m_drawer->newList(GL_COMPILE_AND_EXECUTE); PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();
m_drawer->lineWidth(6.0f); m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE);
m_drawer->color3f(0.0f, 0.0f, 1.0f); m_selectingCellDrawer->lineWidth(6.0f);
m_drawer->begin(GL_LINES); m_selectingCellDrawer->color3f(0.0f, 0.0f, 1.0f);
m_drawer->vertex(p.positionAttribute[m_selectingEdge]); m_selectingCellDrawer->begin(GL_LINES);
m_drawer->vertex(p.positionAttribute[m->phi1(m_selectingEdge)]); m_selectingCellDrawer->vertex(p.positionAttribute[m_selectingEdge]);
m_drawer->end(); m_selectingCellDrawer->vertex(p.positionAttribute[m->phi1(m_selectingEdge)]);
m_drawer->endList(); m_selectingCellDrawer->end();
m_selectingCellDrawer->endList();
break; break;
} }
case WithinSphere : { case WithinSphere : {
...@@ -158,33 +158,22 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -158,33 +158,22 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
break; break;
} }
case FACE : { case FACE : {
PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap(); m_selectedFacesDrawer->callList();
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) if(m_selecting && m_selectingFace != NIL)
{ {
switch(p.selectionMethod) switch(p.selectionMethod)
{ {
case SingleCell : { case SingleCell : {
m_drawer->newList(GL_COMPILE_AND_EXECUTE); PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();
m_drawer->color3f(0.0f, 0.0f, 1.0f); m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE);
m_drawer->begin(GL_TRIANGLES); m_selectingCellDrawer->color3f(0.0f, 0.0f, 1.0f);
m_drawer->vertex(p.positionAttribute[m_selectingFace]); m_selectingCellDrawer->begin(GL_TRIANGLES);
m_drawer->vertex(p.positionAttribute[m->phi1(m_selectingFace)]); m_selectingCellDrawer->vertex(p.positionAttribute[m_selectingFace]);
m_drawer->vertex(p.positionAttribute[m->phi_1(m_selectingFace)]); m_selectingCellDrawer->vertex(p.positionAttribute[m->phi1(m_selectingFace)]);
m_drawer->end(); m_selectingCellDrawer->vertex(p.positionAttribute[m->phi_1(m_selectingFace)]);
m_drawer->endList(); m_selectingCellDrawer->end();
m_selectingCellDrawer->endList();
break; break;
} }
case WithinSphere : { case WithinSphere : {
...@@ -278,6 +267,7 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) ...@@ -278,6 +267,7 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
break; break;
} }
} }
updateSelectedCellsRendering();
} }
break; break;
} }
...@@ -297,6 +287,7 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) ...@@ -297,6 +287,7 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
break; break;
} }
} }
updateSelectedCellsRendering();
} }
break; break;
} }
...@@ -390,24 +381,23 @@ void Surface_Selection_Plugin::viewLinked(View *view) ...@@ -390,24 +381,23 @@ void Surface_Selection_Plugin::viewLinked(View *view)
void Surface_Selection_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur) void Surface_Selection_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur)
{ {
m_dockTab->updateMapParameters(); m_dockTab->updateMapParameters();
if(prev)
{
disconnect(prev, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&)));
disconnect(prev, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&)));
}
if(cur) if(cur)
{
connect(cur, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&)));
connect(cur, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&)));
m_selectionRadius = cur->getBBdiagSize() / 50.0f; m_selectionRadius = cur->getBBdiagSize() / 50.0f;
} }
void Surface_Selection_Plugin::mapAdded(MapHandlerGen* map)
{
connect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(attributeAdded(unsigned int, const QString&)));
}
void Surface_Selection_Plugin::mapRemoved(MapHandlerGen* map)
{
disconnect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(attributeAdded(unsigned int, const QString&)));
} }
void Surface_Selection_Plugin::updateSelectedCellsRendering() void Surface_Selection_Plugin::updateSelectedCellsRendering()
{ {
MapHandlerGen* mh = m_schnapps->getSelectedMap(); MapHandlerGen* map = m_schnapps->getSelectedMap();
const MapParameters& p = h_parameterSet[mh]; const MapParameters& p = h_parameterSet[map];
if(p.positionAttribute.isValid()) if(p.positionAttribute.isValid())
{ {
unsigned int orbit = m_schnapps->getCurrentOrbit(); unsigned int orbit = m_schnapps->getCurrentOrbit();
...@@ -423,9 +413,35 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering() ...@@ -423,9 +413,35 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering()
break; break;
} }
case EDGE : { case EDGE : {
PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();
m_selectedEdgesDrawer->newList(GL_COMPILE);
m_selectedEdgesDrawer->lineWidth(3.0f);
m_selectedEdgesDrawer->color3f(1.0f, 0.0f, 0.0f);
m_selectedEdgesDrawer->begin(GL_LINES);
for(std::vector<Dart>::const_iterator it = selectedCells.begin(); it != selectedCells.end(); ++it)
{
m_selectedEdgesDrawer->vertex(p.positionAttribute[*it]);
m_selectedEdgesDrawer->vertex(p.positionAttribute[m->phi1(*it)]);
}
m_selectedEdgesDrawer->end();
m_selectedEdgesDrawer->endList();
break; break;
} }
case FACE : { case FACE : {
PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();
m_selectedFacesDrawer->newList(GL_COMPILE);
m_selectedFacesDrawer->color3f(1.0f, 0.0f, 0.0f);
m_selectedFacesDrawer->begin(GL_TRIANGLES);
for(std::vector<Dart>::const_iterator it = selectedCells.begin(); it != selectedCells.end(); ++it)
{
m_selectedFacesDrawer->vertex(p.positionAttribute[*it]);
m_selectedFacesDrawer->vertex(p.positionAttribute[m->phi1(*it)]);
m_selectedFacesDrawer->vertex(p.positionAttribute[m->phi_1(*it)]);
}
m_selectedFacesDrawer->end();
m_selectedFacesDrawer->endList();
break; break;
} }
} }
...@@ -433,7 +449,7 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering() ...@@ -433,7 +449,7 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering()
foreach(View* view, l_views) foreach(View* view, l_views)
{ {
if(view->isLinkedToMap(mh)) if(view->isLinkedToMap(map))
view->updateGL(); view->updateGL();
} }
} }
...@@ -442,13 +458,23 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering() ...@@ -442,13 +458,23 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering()
void Surface_Selection_Plugin::attributeAdded(unsigned int orbit, const QString& name) void Surface_Selection_Plugin::selectedMapAttributeAdded(unsigned int orbit, const QString& name)
{ {
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender()); if(orbit == VERTEX)
if(orbit == VERTEX && map->isSelectedMap())
m_dockTab->addVertexAttribute(name); m_dockTab->addVertexAttribute(name);
} }
void Surface_Selection_Plugin::selectedMapAttributeModified(unsigned int orbit, const QString &name)
{
if(orbit == VERTEX)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
const MapParameters& p = h_parameterSet[map];
if(p.positionAttribute.isValid() && QString::fromStdString(p.positionAttribute.name()) == name)
updateSelectedCellsRendering();
}
}
......
...@@ -315,11 +315,11 @@ public: ...@@ -315,11 +315,11 @@ public:
// that means it just replaces VTBL of the object by VTBL of another class. // that means it just replaces VTBL of the object by VTBL of another class.
// NOTE: these two classes has to be ABI compatible! // NOTE: these two classes has to be ABI compatible!
template <typename TO_T, typename FROM_T> template <typename TO_T, typename FROM_T>
inline void turn_to(FROM_T* p) inline void turn_to(FROM_T* p)
{ {
assert( sizeof(FROM_T) == sizeof(TO_T)); assert(sizeof(FROM_T) == sizeof(TO_T));
::new(p) TO_T(); // use of placement new ::new(p) TO_T(); // use of placement new
} }
} // namespace CGoGN } // namespace CGoGN
......
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