Commit 04f62a6c authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

add normal angle selector to surface selection plugin

parent a517c887
...@@ -14,15 +14,8 @@ ...@@ -14,15 +14,8 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="3" column="1">
<widget class="QLabel" name="label_2"> <widget class="QComboBox" name="combo_selectionMethod">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -31,27 +24,50 @@ ...@@ -31,27 +24,50 @@
</property> </property>
<item> <item>
<property name="text"> <property name="text">
<string>- select attribute -</string> <string>SingleCell</string>
</property>
</item>
<item>
<property name="text">
<string>WithinSphere</string>
</property>
</item>
<item>
<property name="text">
<string>NormalAngle</string>
</property> </property>
</item> </item>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="4" column="1">
<widget class="Line" name="line"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
<item row="2" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Method :</string> <string>Method :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="0" colspan="2">
<widget class="QComboBox" name="combo_selectionMethod"> <widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -60,29 +76,34 @@ ...@@ -60,29 +76,34 @@
</property> </property>
<item> <item>
<property name="text"> <property name="text">
<string>SingleCell</string> <string>- select attribute -</string>
</property> </property>
</item> </item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Normal :</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combo_normalAttribute">
<item> <item>
<property name="text"> <property name="text">
<string>WithinSphere</string> <string>- select attribute -</string>
</property> </property>
</item> </item>
</widget> </widget>
</item> </item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
......
...@@ -16,7 +16,8 @@ namespace SCHNApps ...@@ -16,7 +16,8 @@ namespace SCHNApps
enum SelectionMethod enum SelectionMethod
{ {
SingleCell = 0, SingleCell = 0,
WithinSphere = 1 WithinSphere = 1,
NormalAngle = 2
}; };
struct MapParameters struct MapParameters
...@@ -26,6 +27,7 @@ struct MapParameters ...@@ -26,6 +27,7 @@ struct MapParameters
{} {}
VertexAttribute<PFP2::VEC3> positionAttribute; VertexAttribute<PFP2::VEC3> positionAttribute;
VertexAttribute<PFP2::VEC3> normalAttribute;
SelectionMethod selectionMethod; SelectionMethod selectionMethod;
}; };
...@@ -70,8 +72,9 @@ private slots: ...@@ -70,8 +72,9 @@ private slots:
public slots: public slots:
// slots for Python calls // slots for Python calls
void changePositionAttribute(const QString& view, const QString& map, const QString& name); void changePositionAttribute(const QString& map, const QString& name);
void changeSelectionMethod(const QString& view, const QString& map, unsigned int method); void changeNormalAttribute(const QString& map, const QString& name);
void changeSelectionMethod(const QString& map, unsigned int method);
protected: protected:
Surface_Selection_DockTab* m_dockTab; Surface_Selection_DockTab* m_dockTab;
...@@ -96,6 +99,9 @@ protected: ...@@ -96,6 +99,9 @@ protected:
// WithinSphere parameters // WithinSphere parameters
Utils::VBO* m_selectionSphereVBO; Utils::VBO* m_selectionSphereVBO;
PFP2::REAL m_selectionRadius; PFP2::REAL m_selectionRadius;
// NormalAngle parameters
PFP2::REAL m_normalAngleThreshold;
}; };
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -29,6 +29,7 @@ private: ...@@ -29,6 +29,7 @@ private:
private slots: private slots:
void positionAttributeChanged(int index); void positionAttributeChanged(int index);
void normalAttributeChanged(int index);
void selectionMethodChanged(int index); void selectionMethodChanged(int index);
private: private:
......
...@@ -17,7 +17,8 @@ namespace SCHNApps ...@@ -17,7 +17,8 @@ namespace SCHNApps
{ {
Surface_Selection_Plugin::Surface_Selection_Plugin() : Surface_Selection_Plugin::Surface_Selection_Plugin() :
m_selecting(false) m_selecting(false),
m_normalAngleThreshold(10)
{} {}
bool Surface_Selection_Plugin::enable() bool Surface_Selection_Plugin::enable()
...@@ -113,6 +114,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -113,6 +114,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
switch(p.selectionMethod) switch(p.selectionMethod)
{ {
case NormalAngle :
case SingleCell : { case SingleCell : {
m_pointSprite->setSize(30 * map->getBBdiagSize() / nbCells); m_pointSprite->setSize(30 * map->getBBdiagSize() / nbCells);
break; break;
...@@ -139,6 +141,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -139,6 +141,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
{ {
switch(p.selectionMethod) switch(p.selectionMethod)
{ {
case NormalAngle :
case SingleCell : { case SingleCell : {
PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap(); PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();
m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE); m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE);
...@@ -180,6 +183,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -180,6 +183,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
{ {
switch(p.selectionMethod) switch(p.selectionMethod)
{ {
case NormalAngle :
case SingleCell : { case SingleCell : {
PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap(); PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();
m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE); m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE);
...@@ -277,6 +281,18 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) ...@@ -277,6 +281,18 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
selector->unselect(neigh.getInsideVertices()); selector->unselect(neigh.getInsideVertices());
break; break;
} }
case NormalAngle : {
if(p.normalAttribute.isValid())
{
Algo::Surface::Selection::Collector_NormalAngle<PFP2> neigh(*map, p.normalAttribute, m_selectionRadius);
neigh.collectAll(m_selectingVertex);
if(event->button() == Qt::LeftButton)
selector->select(neigh.getInsideVertices());
else if(event->button() == Qt::RightButton)
selector->unselect(neigh.getInsideVertices());
}
break;
}
} }
updateSelectedCellsRendering(); updateSelectedCellsRendering();
} }
...@@ -303,6 +319,18 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) ...@@ -303,6 +319,18 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
selector->unselect(neigh.getInsideEdges()); selector->unselect(neigh.getInsideEdges());
break; break;
} }
case NormalAngle : {
if(p.normalAttribute.isValid())
{
Algo::Surface::Selection::Collector_NormalAngle<PFP2> neigh(*map, p.normalAttribute, m_selectionRadius);
neigh.collectAll(m_selectingEdge);
if(event->button() == Qt::LeftButton)
selector->select(neigh.getInsideEdges());
else if(event->button() == Qt::RightButton)
selector->unselect(neigh.getInsideEdges());
}
break;
}
} }
updateSelectedCellsRendering(); updateSelectedCellsRendering();
} }
...@@ -329,6 +357,18 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) ...@@ -329,6 +357,18 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
selector->unselect(neigh.getInsideFaces()); selector->unselect(neigh.getInsideFaces());
break; break;
} }
case NormalAngle : {
if(p.normalAttribute.isValid())
{
Algo::Surface::Selection::Collector_NormalAngle<PFP2> neigh(*map, p.normalAttribute, m_selectionRadius);
neigh.collectAll(m_selectingFace);
if(event->button() == Qt::LeftButton)
selector->select(neigh.getInsideFaces());
else if(event->button() == Qt::RightButton)
selector->unselect(neigh.getInsideFaces());
}
break;
}
} }
updateSelectedCellsRendering(); updateSelectedCellsRendering();
} }
...@@ -394,13 +434,26 @@ void Surface_Selection_Plugin::wheelEvent(View* view, QWheelEvent* event) ...@@ -394,13 +434,26 @@ void Surface_Selection_Plugin::wheelEvent(View* view, QWheelEvent* event)
MapHandlerGen* mh = m_schnapps->getSelectedMap(); MapHandlerGen* mh = m_schnapps->getSelectedMap();
const MapParameters& p = h_parameterSet[mh]; const MapParameters& p = h_parameterSet[mh];
if(p.selectionMethod == WithinSphere) switch(p.selectionMethod)
{ {
if(event->delta() > 0) case SingleCell : {
m_selectionRadius *= 0.9f; break;
else }
m_selectionRadius *= 1.1f; case WithinSphere : {
view->updateGL(); if(event->delta() > 0)
m_selectionRadius *= 0.9f;
else
m_selectionRadius *= 1.1f;
view->updateGL();
break;
}
case NormalAngle : {
if(event->delta() > 0)
m_normalAngleThreshold *= 0.9f;
else
m_normalAngleThreshold *= 1.1f;
break;
}
} }
} }
} }
...@@ -527,11 +580,10 @@ void Surface_Selection_Plugin::selectedMapConnectivityModified() ...@@ -527,11 +580,10 @@ void Surface_Selection_Plugin::selectedMapConnectivityModified()
void Surface_Selection_Plugin::changePositionAttribute(const QString& view, const QString& map, const QString& name) void Surface_Selection_Plugin::changePositionAttribute(const QString& map, const QString& name)
{ {
View* v = m_schnapps->getView(view);
MapHandlerGen* m = m_schnapps->getMap(map); MapHandlerGen* m = m_schnapps->getMap(map);
if(v && m) if(m)
{ {
h_parameterSet[m].positionAttribute = m->getAttribute<PFP2::VEC3, VERTEX>(name); h_parameterSet[m].positionAttribute = m->getAttribute<PFP2::VEC3, VERTEX>(name);
if(m->isSelectedMap()) if(m->isSelectedMap())
...@@ -539,11 +591,21 @@ void Surface_Selection_Plugin::changePositionAttribute(const QString& view, cons ...@@ -539,11 +591,21 @@ void Surface_Selection_Plugin::changePositionAttribute(const QString& view, cons
} }
} }
void Surface_Selection_Plugin::changeSelectionMethod(const QString& view, const QString& map, unsigned int method) void Surface_Selection_Plugin::changeNormalAttribute(const QString& map, const QString& name)
{
MapHandlerGen* m = m_schnapps->getMap(map);
if(m)
{
h_parameterSet[m].normalAttribute = m->getAttribute<PFP2::VEC3, VERTEX>(name);
if(m->isSelectedMap())
m_dockTab->updateMapParameters();
}
}
void Surface_Selection_Plugin::changeSelectionMethod(const QString& map, unsigned int method)
{ {
View* v = m_schnapps->getView(view);
MapHandlerGen* m = m_schnapps->getMap(map); MapHandlerGen* m = m_schnapps->getMap(map);
if(v && m) if(m)
{ {
h_parameterSet[m].selectionMethod = SelectionMethod(method); h_parameterSet[m].selectionMethod = SelectionMethod(method);
if(m->isSelectedMap()) if(m->isSelectedMap())
......
...@@ -17,6 +17,7 @@ Surface_Selection_DockTab::Surface_Selection_DockTab(SCHNApps* s, Surface_Select ...@@ -17,6 +17,7 @@ Surface_Selection_DockTab::Surface_Selection_DockTab(SCHNApps* s, Surface_Select
setupUi(this); setupUi(this);
connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int))); connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
connect(combo_normalAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(normalAttributeChanged(int)));
connect(combo_selectionMethod, SIGNAL(currentIndexChanged(int)), this, SLOT(selectionMethodChanged(int))); connect(combo_selectionMethod, SIGNAL(currentIndexChanged(int)), this, SLOT(selectionMethodChanged(int)));
} }
...@@ -34,6 +35,16 @@ void Surface_Selection_DockTab::positionAttributeChanged(int index) ...@@ -34,6 +35,16 @@ void Surface_Selection_DockTab::positionAttributeChanged(int index)
} }
} }
void Surface_Selection_DockTab::normalAttributeChanged(int index)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->h_parameterSet[map].normalAttribute = map->getAttribute<PFP2::VEC3, VERTEX>(combo_normalAttribute->currentText());
}
}
void Surface_Selection_DockTab::selectionMethodChanged(int index) void Surface_Selection_DockTab::selectionMethodChanged(int index)
{ {
if(!b_updatingUI) if(!b_updatingUI)
...@@ -54,7 +65,10 @@ void Surface_Selection_DockTab::addVertexAttribute(const QString& nameAttr) ...@@ -54,7 +65,10 @@ void Surface_Selection_DockTab::addVertexAttribute(const QString& nameAttr)
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3())); QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(VERTEX, nameAttr); const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(VERTEX, nameAttr);
if(typeAttr == vec3TypeName) if(typeAttr == vec3TypeName)
{
combo_positionAttribute->addItem(nameAttr); combo_positionAttribute->addItem(nameAttr);
combo_normalAttribute->addItem(nameAttr);
}
b_updatingUI = false; b_updatingUI = false;
} }
...@@ -64,6 +78,8 @@ void Surface_Selection_DockTab::updateMapParameters() ...@@ -64,6 +78,8 @@ void Surface_Selection_DockTab::updateMapParameters()
combo_positionAttribute->clear(); combo_positionAttribute->clear();
combo_positionAttribute->addItem("- select attribute -"); combo_positionAttribute->addItem("- select attribute -");
combo_normalAttribute->clear();
combo_normalAttribute->addItem("- select attribute -");
MapHandlerGen* map = m_schnapps->getSelectedMap(); MapHandlerGen* map = m_schnapps->getSelectedMap();
...@@ -83,6 +99,10 @@ void Surface_Selection_DockTab::updateMapParameters() ...@@ -83,6 +99,10 @@ void Surface_Selection_DockTab::updateMapParameters()
if(p.positionAttribute.isValid() && it.key() == QString::fromStdString(p.positionAttribute.name())) if(p.positionAttribute.isValid() && it.key() == QString::fromStdString(p.positionAttribute.name()))
combo_positionAttribute->setCurrentIndex(i); combo_positionAttribute->setCurrentIndex(i);
combo_normalAttribute->addItem(it.key());
if(p.normalAttribute.isValid() && it.key() == QString::fromStdString(p.normalAttribute.name()))
combo_normalAttribute->setCurrentIndex(i);
++i; ++i;
} }
} }
......
...@@ -46,4 +46,3 @@ ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/Plugins Plugins) ...@@ -46,4 +46,3 @@ ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/Plugins Plugins)
IF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins) IF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/../../Plugins ExtPlugins) ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/../../Plugins ExtPlugins)
ENDIF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins) ENDIF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
...@@ -257,17 +257,52 @@ public: ...@@ -257,17 +257,52 @@ public:
void collectBorder(Dart d) ; void collectBorder(Dart d) ;
}; };
/*********************************************************
* Collector Normal Angle (Triangles)
*********************************************************/
/*
* collect all primitives of the connected component containing "centerDart"
* the angle between the included triangles normal vectors and the central normal vector
* stays under a given threshold
* NB : is equivalent to Collector_Triangles with CollectorCriterion_TriangleNormalAngle
*/
template <typename PFP>
class Collector_NormalAngle_Triangles : public Collector<PFP>
{
protected:
const FaceAttribute<typename PFP::VEC3>& normal ;
typename PFP::REAL angleThreshold ;
public:
Collector_NormalAngle_Triangles(
typename PFP::MAP& m,
const FaceAttribute<typename PFP::VEC3>& n,
typename PFP::REAL a,
unsigned int thread=0
) : Collector<PFP>(m,thread), normal(n), angleThreshold(a)
{}
inline void setAngleThreshold(typename PFP::REAL a) { angleThreshold = a; }
inline typename PFP::REAL getAngleThreshold() const { return angleThreshold; }
inline const VertexAttribute<typename PFP::VEC3>& getNormal() const { return normal ; }
void collectAll(Dart d) ;
void collectBorder(Dart d) ;
};
/********************************************************* /*********************************************************
* Collector Criterions * Collector Criterions
*********************************************************/ *********************************************************/
class CollectorCriterion class CollectorCriterion
{ {
public : public :
CollectorCriterion() {}; CollectorCriterion() {}
virtual ~CollectorCriterion() {} ; virtual ~CollectorCriterion() {}
virtual void init(Dart center) = 0; virtual void init(Dart center) = 0;
virtual bool isInside(Dart d) = 0; virtual bool isInside(Dart d) = 0;
}; };
template <typename PFP> template <typename PFP>
...@@ -277,15 +312,16 @@ private : ...@@ -277,15 +312,16 @@ private :
typedef typename PFP::VEC3 VEC3;