Commit 49e302e4 authored by Pierre Kraemer's avatar Pierre Kraemer

new plugin : surface selection (not functional yet..)

parent 12c601ff
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(surface_import) ADD_SUBDIRECTORY(surface_import)
ADD_SUBDIRECTORY(surface_differentialProperties)
ADD_SUBDIRECTORY(surface_subdivision)
ADD_SUBDIRECTORY(surface_selection)
ADD_SUBDIRECTORY(surface_render) ADD_SUBDIRECTORY(surface_render)
ADD_SUBDIRECTORY(surface_renderVector) ADD_SUBDIRECTORY(surface_renderVector)
ADD_SUBDIRECTORY(surface_renderScalar) ADD_SUBDIRECTORY(surface_renderScalar)
ADD_SUBDIRECTORY(surface_renderTopo) ADD_SUBDIRECTORY(surface_renderTopo)
ADD_SUBDIRECTORY(surface_differentialProperties)
ADD_SUBDIRECTORY(surface_subdivision)
...@@ -185,7 +185,7 @@ void Surface_RenderTopo_DockTab::updateMapParameters() ...@@ -185,7 +185,7 @@ void Surface_RenderTopo_DockTab::updateMapParameters()
if(it.value() == vec3TypeName) if(it.value() == vec3TypeName)
{ {
combo_positionAttribute->addItem(it.key()); combo_positionAttribute->addItem(it.key());
if(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);
++i; ++i;
...@@ -207,10 +207,12 @@ void Surface_RenderTopo_DockTab::updateMapParameters() ...@@ -207,10 +207,12 @@ void Surface_RenderTopo_DockTab::updateMapParameters()
void Surface_RenderTopo_DockTab::addAttributeToList(unsigned int orbit, const QString& nameAttr) void Surface_RenderTopo_DockTab::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{ {
b_updatingUI = true;
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3())); QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(orbit, nameAttr); const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(orbit, nameAttr);
if(typeAttr == vec3TypeName) if(typeAttr == vec3TypeName)
combo_positionAttribute->addItem(nameAttr); combo_positionAttribute->addItem(nameAttr);
b_updatingUI = false;
} }
} // namespace SCHNApps } // namespace SCHNApps
......
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME Surface_Selection )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/surface_selection )
INCLUDE_DIRECTORIES(
${PLUGIN_ROOT_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}
)
file(
GLOB_RECURSE
PLUGIN_FILES
${PLUGIN_ROOT_DIR}/src/*.cpp
${PLUGIN_ROOT_DIR}/include/*.h
${PLUGIN_ROOT_DIR}/include/*.hpp
)
file(
GLOB_RECURSE
PLUGIN_UI_FILES
${PLUGIN_ROOT_DIR}/forms/*.ui
)
SET(
PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/surface_selection.h
${PLUGIN_ROOT_DIR}/include/surface_selection_dockTab.h
)
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Surface_Selection_TabWidget</class>
<widget class="QWidget" name="Surface_Selection_TabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>200</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>- select attribute -</string>
</property>
</item>
</widget>
</item>
<item row="1" 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>
</widget>
<resources/>
<connections/>
</ui>
#ifndef _SURFACE_SELECTION_PLUGIN_H_
#define _SURFACE_SELECTION_PLUGIN_H_
#include "plugin_interaction.h"
#include "surface_selection_dockTab.h"
#include "Utils/pointSprite.h"
namespace CGoGN
{
namespace SCHNApps
{
struct MapParameters
{
MapParameters()
{}
VertexAttribute<PFP2::VEC3> positionAttribute;
};
class Surface_Selection_Plugin : public PluginInteraction
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
friend class Surface_Selection_DockTab;
public:
Surface_Selection_Plugin();
~Surface_Selection_Plugin()
{}
virtual bool enable();
virtual void disable();
virtual void draw(View *view) {}
virtual void drawMap(View* view, MapHandlerGen* map);
virtual void keyPress(View* view, QKeyEvent* event);
virtual void keyRelease(View* view, QKeyEvent* event);
virtual void mousePress(View* view, QMouseEvent* event);
virtual void mouseRelease(View* view, QMouseEvent* event);
virtual void mouseMove(View* view, QMouseEvent* event);
virtual void wheelEvent(View* view, QWheelEvent* event);
virtual void viewLinked(View *view) {}
virtual void viewUnlinked(View *view) {}
private slots:
// slots called from SCHNApps signals
void selectedViewChanged(View* prev, View* cur);
void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
void mapAdded(MapHandlerGen* map);
void mapRemoved(MapHandlerGen* map);
// slots called from MapHandler signals
void attributeAdded(unsigned int orbit, const QString& nameAttr);
public slots:
// slots for Python calls
protected:
Surface_Selection_DockTab* m_dockTab;
QHash<View*, QHash<MapHandlerGen*, MapParameters> > h_viewParameterSet;
Utils::PointSprite* m_pointSprite;
Utils::VBO* m_selectionSphereVBO;
bool m_selecting;
PFP2::VEC3 m_selectionCenter;
PFP2::REAL m_selectionRadius;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#ifndef _SURFACE_SELECTION_DOCK_TAB_H_
#define _SURFACE_SELECTION_DOCK_TAB_H_
#include "ui_surface_selection.h"
namespace CGoGN
{
namespace SCHNApps
{
class SCHNApps;
class Surface_Selection_Plugin;
struct MapParameters;
class Surface_Selection_DockTab : public QWidget, public Ui::Surface_Selection_TabWidget
{
Q_OBJECT
friend class Surface_Selection_Plugin;
public:
Surface_Selection_DockTab(SCHNApps* s, Surface_Selection_Plugin* p);
private:
SCHNApps* m_schnapps;
Surface_Selection_Plugin* m_plugin;
bool b_updatingUI;
private slots:
void positionAttributeChanged(int index);
private:
void addAttributeToList(unsigned int orbit, const QString& nameAttr);
void updateMapParameters();
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "surface_selection.h"
#include "schnapps.h"
#include "view.h"
#include "mapHandler.h"
#include "Algo/Selection/raySelector.h"
#include "Algo/Selection/collector.h"
#include <QKeyEvent>
#include <QMouseEvent>
namespace CGoGN
{
namespace SCHNApps
{
Surface_Selection_Plugin::Surface_Selection_Plugin() :
m_selecting(false)
{}
bool Surface_Selection_Plugin::enable()
{
m_dockTab = new Surface_Selection_DockTab(m_schnapps, this);
m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Selection");
m_selectionSphereVBO = new Utils::VBO();
m_pointSprite = new CGoGN::Utils::PointSprite();
registerShader(m_pointSprite);
connect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
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*)));
foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
mapAdded(map);
m_dockTab->updateMapParameters();
return true;
}
void Surface_Selection_Plugin::disable()
{
delete m_selectionSphereVBO;
delete m_pointSprite;
}
void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
{
if(m_selecting)
{
std::vector<PFP2::VEC3> selectionPoint;
selectionPoint.push_back(m_selectionCenter);
m_selectionSphereVBO->updateData(selectionPoint);
m_pointSprite->setAttributePosition(m_selectionSphereVBO);
m_pointSprite->setSize(m_selectionRadius);
m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f));
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, 1);
glDisable(GL_BLEND);
m_pointSprite->disableVertexAttribs();
}
}
void Surface_Selection_Plugin::keyPress(View* view, QKeyEvent* event)
{
if(event->key() == Qt::Key_Shift)
{
view->setMouseTracking(true);
m_selecting = true;
view->updateGL();
}
}
void Surface_Selection_Plugin::keyRelease(View* view, QKeyEvent* event)
{
if(event->key() == Qt::Key_Shift)
{
view->setMouseTracking(false);
m_selecting = false;
view->updateGL();
}
}
void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
{
if(event->button() == Qt::LeftButton && m_selecting)
{
MapHandlerGen* mh = m_schnapps->getSelectedMap();
const MapParameters& p = h_viewParameterSet[view][mh];
if(p.positionAttribute.isValid())
{
QPoint pixel(event->x(), event->y());
qglviewer::Vec orig;
qglviewer::Vec dir;
view->camera()->convertClickToLine(pixel, orig, dir);
PFP2::VEC3 rayA(orig.x, orig.y, orig.z);
PFP2::VEC3 AB(dir.x, dir.y, dir.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)
{
Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, p.positionAttribute, m_selectionRadius);
neigh.collectAll(d);
view->updateGL() ;
}
}
}
}
void Surface_Selection_Plugin::mouseRelease(View* view, QMouseEvent* event)
{
}
void Surface_Selection_Plugin::mouseMove(View* view, QMouseEvent* event)
{
if(m_selecting)
{
MapHandlerGen* mh = m_schnapps->getSelectedMap();
const MapParameters& p = h_viewParameterSet[view][mh];
if(p.positionAttribute.isValid())
{
QPoint pixel(event->x(), event->y());
qglviewer::Vec orig;
qglviewer::Vec dir;
view->camera()->convertClickToLine(pixel, orig, dir);
PFP2::VEC3 rayA(orig.x, orig.y, orig.z);
PFP2::VEC3 AB(dir.x, dir.y, dir.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)
{
m_selectionCenter = p.positionAttribute[d];
view->updateGL();
}
}
}
}
void Surface_Selection_Plugin::wheelEvent(View* view, QWheelEvent* event)
{
if(m_selecting)
{
if(event->delta() > 0)
m_selectionRadius *= 0.9f ;
else
m_selectionRadius *= 1.1f ;
view->updateGL() ;
}
}
void Surface_Selection_Plugin::selectedViewChanged(View *prev, View *cur)
{
m_dockTab->updateMapParameters();
}
void Surface_Selection_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur)
{
m_dockTab->updateMapParameters();
if(cur)
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::attributeAdded(unsigned int orbit, const QString& nameAttr)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
if(map == m_schnapps->getSelectedMap())
m_dockTab->addAttributeToList(orbit, nameAttr);
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(Surface_Selection_Plugin, Surface_Selection_Plugin)
#else
Q_EXPORT_PLUGIN2(Surface_Selection_PluginD, Surface_Selection_Plugin)
#endif
} // namespace SCHNApps
} // namespace CGoGN
#include "surface_selection_dockTab.h"
#include "surface_selection.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
Surface_Selection_DockTab::Surface_Selection_DockTab(SCHNApps* s, Surface_Selection_Plugin* p) :
m_schnapps(s),
m_plugin(p),
b_updatingUI(false)
{
setupUi(this);
connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
}
void Surface_Selection_DockTab::positionAttributeChanged(int index)
{
if(!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map)
{
m_plugin->h_viewParameterSet[view][map].positionAttribute = map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText());
view->updateGL();
}
}
}
void Surface_Selection_DockTab::updateMapParameters()
{
b_updatingUI = true;
combo_positionAttribute->clear();
combo_positionAttribute->addItem("- select attribute -");
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map)
{
const MapParameters& p = m_plugin->h_viewParameterSet[view][map];
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
unsigned int i = 1;
const AttributeSet& attribs = map->getAttributeSet(VERTEX);
for(AttributeSet::const_iterator it = attribs.constBegin(); it != attribs.constEnd(); ++it)
{
if(it.value() == vec3TypeName)
{
combo_positionAttribute->addItem(it.key());
if(p.positionAttribute.isValid() && it.key() == QString::fromStdString(p.positionAttribute.name()))
combo_positionAttribute->setCurrentIndex(i);
++i;
}
}
}
b_updatingUI = false;
}
void Surface_Selection_DockTab::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{
b_updatingUI = true;
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(orbit, nameAttr);
if(typeAttr == vec3TypeName)
combo_positionAttribute->addItem(nameAttr);
b_updatingUI = false;
}
} // namespace SCHNApps
} // namespace CGoGN
...@@ -353,6 +353,7 @@ Plugin* SCHNApps::enablePlugin(const QString& pluginName) ...@@ -353,6 +353,7 @@ Plugin* SCHNApps::enablePlugin(const QString& pluginName)
// if loading fails // if loading fails
else else
{ {
std::cout << "loader.instance() failed.." << std::endl;
return NULL; return NULL;
} }
} }
......
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