Commit c60e9ea1 authored by Sylvain Thery's avatar Sylvain Thery Committed by Pierre Kraemer
Browse files

color/scale for each vector (RenderVector plugin)

parent 3ea99389
...@@ -50,12 +50,18 @@ ...@@ -50,12 +50,18 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<widget class="QLabel" name="label"> <spacer name="verticalSpacer">
<property name="text"> <property name="orientation">
<string>Vectors Size :</string> <enum>Qt::Vertical</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>161</height>
</size>
</property>
</spacer>
</item> </item>
<item row="4" column="0" colspan="2"> <item row="4" column="0" colspan="2">
<widget class="QSlider" name="slider_vectorsScaleFactor"> <widget class="QSlider" name="slider_vectorsScaleFactor">
...@@ -67,21 +73,25 @@ ...@@ -67,21 +73,25 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<spacer name="verticalSpacer"> <widget class="QLabel" name="label">
<property name="orientation"> <property name="text">
<enum>Qt::Vertical</enum> <string>Vectors Size :</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>161</height>
</size>
</property> </property>
</spacer> </widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="ColorComboBox" name="combo_color"/>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>ColorComboBox</class>
<extends>QComboBox</extends>
<header>colorComboBox.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>
...@@ -12,16 +12,34 @@ namespace CGoGN ...@@ -12,16 +12,34 @@ namespace CGoGN
namespace SCHNApps namespace SCHNApps
{ {
//struct SVectorInfo
//{
// Utils::VBO* vbo;
// QColor color;
// float scaleFactor;
// SVectorInfo() :
// vbo(NULL), color(QColor("red")), scaleFactor(1.0f)
// {}
// SVectorInfo(Utils::VBO* ptr) :
// vbo(ptr), color(QColor("red")), scaleFactor(1.0f)
// {}
//};
struct MapParameters struct MapParameters
{ {
MapParameters() : MapParameters() :
positionVBO(NULL), positionVBO(NULL)
vectorsScaleFactor(1.0f)
{} {}
Utils::VBO* positionVBO; Utils::VBO* positionVBO;
QList<Utils::VBO*> vectorVBOs; QList<Utils::VBO*> vectorVBOs;
float vectorsScaleFactor; QList<QColor> colors;
QList<float> scaleFactors;
//float vectorsScaleFactor;
}; };
class Surface_RenderVector_Plugin : public PluginInteraction class Surface_RenderVector_Plugin : public PluginInteraction
...@@ -72,7 +90,8 @@ public slots: ...@@ -72,7 +90,8 @@ public slots:
void changePositionVBO(const QString& view, const QString& map, const QString& vbo); void changePositionVBO(const QString& view, const QString& map, const QString& vbo);
void addVectorVBO(const QString& view, const QString& map, const QString& vbo); void addVectorVBO(const QString& view, const QString& map, const QString& vbo);
void removeVectorVBO(const QString& view, const QString& map, const QString& vbo); void removeVectorVBO(const QString& view, const QString& map, const QString& vbo);
void changeVectorsScaleFactor(const QString& view, const QString& map, float f); void changeVectorScaleFactor(const QString& view, const QString& map, const QString& vbo, float f);
void changeVectorColor(const QString& view, const QString& map, const QString& vbo, float r, float g, float b);
protected: protected:
Surface_RenderVector_DockTab* m_dockTab; Surface_RenderVector_DockTab* m_dockTab;
......
...@@ -26,11 +26,14 @@ private: ...@@ -26,11 +26,14 @@ private:
SCHNApps* m_schnapps; SCHNApps* m_schnapps;
Surface_RenderVector_Plugin* m_plugin; Surface_RenderVector_Plugin* m_plugin;
bool b_updatingUI; bool b_updatingUI;
int m_current_vbo;
private slots: private slots:
void positionVBOChanged(int index); void positionVBOChanged(int index);
void selectedVectorsVBOChanged(); void selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old);
void vectorsVBOChecked(QListWidgetItem* item);
void vectorsScaleFactorChanged(int i); void vectorsScaleFactorChanged(int i);
void colorChanged(int i);
private: private:
void addPositionVBO(QString name); void addPositionVBO(QString name);
......
...@@ -51,13 +51,29 @@ void Surface_RenderVector_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -51,13 +51,29 @@ void Surface_RenderVector_Plugin::drawMap(View* view, MapHandlerGen* map)
{ {
const MapParameters& p = h_viewParameterSet[view][map]; const MapParameters& p = h_viewParameterSet[view][map];
m_vectorShader->setScale(map->getBBdiagSize() / 100.0f * p.vectorsScaleFactor) ; //m_vectorShader->setScale(map->getBBdiagSize() / 100.0f * p.vectorsScaleFactor) ;
if(p.positionVBO) //if(p.positionVBO)
//{
// m_vectorShader->setAttributePosition(p.positionVBO);
// for(QList<Utils::VBO*>::const_iterator it = p.vectorVBOs.begin(); it != p.vectorVBOs.end(); ++it)
// {
// m_vectorShader->setAttributeVector(*it);
// glLineWidth(1.0f);
// map->draw(m_vectorShader, Algo::Render::GL2::POINTS);
// }
//}
if (p.positionVBO)
{ {
m_vectorShader->setAttributePosition(p.positionVBO); m_vectorShader->setAttributePosition(p.positionVBO);
for(QList<Utils::VBO*>::const_iterator it = p.vectorVBOs.begin(); it != p.vectorVBOs.end(); ++it) int nb = p.vectorVBOs.size();
for (int i = 0; i < nb; ++i)
{ {
m_vectorShader->setAttributeVector(*it); m_vectorShader->setAttributeVector(p.vectorVBOs[i]);
m_vectorShader->setScale(map->getBBdiagSize() / 100.0f * p.scaleFactors[i]);
const QColor& col = p.colors[i];
m_vectorShader->setColor(Geom::Vec4f(col.redF(), col.greenF(), col.blueF(), 0.0f));
glLineWidth(1.0f); glLineWidth(1.0f);
map->draw(m_vectorShader, Algo::Render::GL2::POINTS); map->draw(m_vectorShader, Algo::Render::GL2::POINTS);
} }
...@@ -177,6 +193,8 @@ void Surface_RenderVector_Plugin::addVectorVBO(const QString& view, const QStrin ...@@ -177,6 +193,8 @@ void Surface_RenderVector_Plugin::addVectorVBO(const QString& view, const QStrin
{ {
Utils::VBO* vbuf = m->getVBO(vbo); Utils::VBO* vbuf = m->getVBO(vbo);
h_viewParameterSet[v][m].vectorVBOs.append(vbuf); h_viewParameterSet[v][m].vectorVBOs.append(vbuf);
h_viewParameterSet[v][m].colors.append(QColor("red"));
h_viewParameterSet[v][m].scaleFactors.append(1.0f);
if(v->isSelectedView()) if(v->isSelectedView())
{ {
if(v->isLinkedToMap(m)) v->updateGL(); if(v->isLinkedToMap(m)) v->updateGL();
...@@ -192,7 +210,10 @@ void Surface_RenderVector_Plugin::removeVectorVBO(const QString& view, const QSt ...@@ -192,7 +210,10 @@ void Surface_RenderVector_Plugin::removeVectorVBO(const QString& view, const QSt
if(v && m) if(v && m)
{ {
Utils::VBO* vbuf = m->getVBO(vbo); Utils::VBO* vbuf = m->getVBO(vbo);
h_viewParameterSet[v][m].vectorVBOs.removeOne(vbuf); int idx = h_viewParameterSet[v][m].vectorVBOs.indexOf(vbuf);
h_viewParameterSet[v][m].vectorVBOs.removeAt(idx);
h_viewParameterSet[v][m].colors.removeAt(idx);
h_viewParameterSet[v][m].scaleFactors.removeAt(idx);
if(v->isSelectedView()) if(v->isSelectedView())
{ {
if(v->isLinkedToMap(m)) v->updateGL(); if(v->isLinkedToMap(m)) v->updateGL();
...@@ -201,13 +222,16 @@ void Surface_RenderVector_Plugin::removeVectorVBO(const QString& view, const QSt ...@@ -201,13 +222,16 @@ void Surface_RenderVector_Plugin::removeVectorVBO(const QString& view, const QSt
} }
} }
void Surface_RenderVector_Plugin::changeVectorsScaleFactor(const QString& view, const QString& map, float f) void Surface_RenderVector_Plugin::changeVectorScaleFactor(const QString& view, const QString& map, const QString& vbo, float f)
{ {
View* v = m_schnapps->getView(view); View* v = m_schnapps->getView(view);
MapHandlerGen* m = m_schnapps->getMap(map); MapHandlerGen* m = m_schnapps->getMap(map);
if(v && m) if(v && m)
{ {
h_viewParameterSet[v][m].vectorsScaleFactor = f; Utils::VBO* vboPtr = m->getVBO(vbo);
int idx = h_viewParameterSet[v][m].vectorVBOs.indexOf(vboPtr);
h_viewParameterSet[v][m].scaleFactors[idx] = f;
if(v->isSelectedView()) if(v->isSelectedView())
{ {
if(v->isLinkedToMap(m)) v->updateGL(); if(v->isLinkedToMap(m)) v->updateGL();
...@@ -216,6 +240,24 @@ void Surface_RenderVector_Plugin::changeVectorsScaleFactor(const QString& view, ...@@ -216,6 +240,24 @@ void Surface_RenderVector_Plugin::changeVectorsScaleFactor(const QString& view,
} }
} }
void Surface_RenderVector_Plugin::changeVectorColor(const QString& view, const QString& map, const QString& vbo, float r, float g, float b)
{
View* v = m_schnapps->getView(view);
MapHandlerGen* m = m_schnapps->getMap(map);
if (v && m)
{
Utils::VBO* vboPtr = m->getVBO(vbo);
int idx = h_viewParameterSet[v][m].vectorVBOs.indexOf(vboPtr);
h_viewParameterSet[v][m].colors[idx] = QColor(r,g,b);
if (v->isSelectedView())
{
if (v->isLinkedToMap(m)) v->updateGL();
if (m->isSelectedMap()) m_dockTab->updateMapParameters();
}
}
}
#if CGOGN_QT_DESIRED_VERSION == 5 #if CGOGN_QT_DESIRED_VERSION == 5
Q_PLUGIN_METADATA(IID "CGoGN.SCHNapps.Plugin") Q_PLUGIN_METADATA(IID "CGoGN.SCHNapps.Plugin")
#else #else
......
...@@ -15,17 +15,37 @@ namespace SCHNApps ...@@ -15,17 +15,37 @@ namespace SCHNApps
Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_RenderVector_Plugin* p) : Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_RenderVector_Plugin* p) :
m_schnapps(s), m_schnapps(s),
m_plugin(p), m_plugin(p),
b_updatingUI(false) b_updatingUI(false),
m_current_vbo(-1)
{ {
setupUi(this); setupUi(this);
list_vectorVBO->setSelectionMode(QAbstractItemView::SingleSelection);
slider_vectorsScaleFactor->hide();
combo_color->hide();
connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int))); connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
connect(list_vectorVBO, SIGNAL(itemSelectionChanged()), this, SLOT(selectedVectorsVBOChanged()));
connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int))); connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int)));
} connect(list_vectorVBO, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(vectorsVBOChecked(QListWidgetItem*)));
connect(list_vectorVBO, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(selectedVectorVBOChanged(QListWidgetItem*, QListWidgetItem*)));
connect(combo_color, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
}
void Surface_RenderVector_DockTab::colorChanged(int i)
{
if (!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if (view && map && (m_current_vbo >= 0))
{
m_plugin->h_viewParameterSet[view][map].colors[m_current_vbo] = combo_color->color();;
view->updateGL();
}
}
}
void Surface_RenderVector_DockTab::positionVBOChanged(int index) void Surface_RenderVector_DockTab::positionVBOChanged(int index)
...@@ -43,55 +63,93 @@ void Surface_RenderVector_DockTab::positionVBOChanged(int index) ...@@ -43,55 +63,93 @@ void Surface_RenderVector_DockTab::positionVBOChanged(int index)
} }
} }
void Surface_RenderVector_DockTab::selectedVectorsVBOChanged() void Surface_RenderVector_DockTab::selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old)
{ {
if(!b_updatingUI) if(!b_updatingUI)
{
if ((item->checkState() == Qt::Checked))
{
slider_vectorsScaleFactor->show();
combo_color->show();
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if (view && map)
{
const MapParameters& p = m_plugin->h_viewParameterSet[view][map];
Utils::VBO* v = map->getVBO(item->text());
m_current_vbo = p.vectorVBOs.indexOf(v);
if (m_current_vbo >= 0)
{
slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0);
combo_color->setColor(p.colors[m_current_vbo]);
}
}
}
else
{
slider_vectorsScaleFactor->hide();
combo_color->hide();
}
}
}
void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
{
if (!b_updatingUI)
{ {
View* view = m_schnapps->getSelectedView(); View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap(); MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map) if (view && map)
{ {
QList<QListWidgetItem*> currentItems = list_vectorVBO->selectedItems(); MapParameters& p = m_plugin->h_viewParameterSet[view][map];
QList<Utils::VBO*> vbos; Utils::VBO* vbo = map->getVBO(item->text());
const QList<Utils::VBO*>& vboList = m_plugin->h_viewParameterSet[view][map].vectorVBOs; if (item->checkState() == Qt::Checked)
foreach(QListWidgetItem* item, currentItems)
{ {
Utils::VBO* vbo = map->getVBO(item->text()); p.vectorVBOs.append(vbo);
vbos.append(vbo); p.scaleFactors.append(1.0f);
if (!vboList.contains(vbo)) p.colors.append(QColor("red"));
m_plugin->pythonRecording("addVectorVBO", "", view->getName(), map->getName(), item->text()); if (list_vectorVBO->currentItem() == item)
selectedVectorVBOChanged(item, NULL);
else
list_vectorVBO->setCurrentItem(item);
m_plugin->pythonRecording("addVectorVBO", "", view->getName(), map->getName(), item->text());
} }
else
foreach(Utils::VBO* vbo, vboList)
{ {
if (!vbos.contains(vbo)) int idx = p.vectorVBOs.indexOf(vbo);
m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(vbo->name().c_str())); p.vectorVBOs.removeAt(idx);
p.scaleFactors.removeAt(idx);
p.colors.removeAt(idx);
list_vectorVBO->setCurrentItem(item);
list_vectorVBO->clearSelection();
slider_vectorsScaleFactor->hide();
combo_color->hide();
m_current_vbo = -1;
m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(item->text()));
} }
m_plugin->h_viewParameterSet[view][map].vectorVBOs = vbos;
view->updateGL(); view->updateGL();
} }
} }
} }
void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i) void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i)
{ {
if(!b_updatingUI) if(!b_updatingUI)
{ {
View* view = m_schnapps->getSelectedView(); View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap(); MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map) if (view && map && (m_current_vbo>=0))
{ {
m_plugin->h_viewParameterSet[view][map].vectorsScaleFactor = i / 50.0; m_plugin->h_viewParameterSet[view][map].scaleFactors[m_current_vbo] = i / 50.0;
view->updateGL(); view->updateGL();
} }
} }
} }
void Surface_RenderVector_DockTab::addPositionVBO(QString name) void Surface_RenderVector_DockTab::addPositionVBO(QString name)
{ {
b_updatingUI = true; b_updatingUI = true;
...@@ -114,6 +172,9 @@ void Surface_RenderVector_DockTab::addVectorVBO(QString name) ...@@ -114,6 +172,9 @@ void Surface_RenderVector_DockTab::addVectorVBO(QString name)
{ {
b_updatingUI = true; b_updatingUI = true;
list_vectorVBO->addItem(name); list_vectorVBO->addItem(name);
QListWidgetItem* item = list_vectorVBO->item(list_vectorVBO->count() - 1);
item->setFlags(item->flags() | Qt::ItemIsEditable);
item->setCheckState(Qt::Unchecked);
b_updatingUI = false; b_updatingUI = false;
} }
...@@ -151,14 +212,17 @@ void Surface_RenderVector_DockTab::updateMapParameters() ...@@ -151,14 +212,17 @@ void Surface_RenderVector_DockTab::updateMapParameters()
combo_positionVBO->setCurrentIndex(i); combo_positionVBO->setCurrentIndex(i);
list_vectorVBO->addItem(QString::fromStdString(vbo->name())); list_vectorVBO->addItem(QString::fromStdString(vbo->name()));
QListWidgetItem* item = list_vectorVBO->item(list_vectorVBO->count() - 1);
item->setFlags(item->flags() | Qt::ItemIsEditable);
item->setCheckState(Qt::Unchecked);
if(p.vectorVBOs.contains(vbo)) if(p.vectorVBOs.contains(vbo))
list_vectorVBO->item(i)->setSelected(true); list_vectorVBO->item(i)->setCheckState(Qt::Checked);
++i; ++i;
} }
} }
if (m_current_vbo>=0)
slider_vectorsScaleFactor->setSliderPosition(p.vectorsScaleFactor * 50.0); slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0);
// set color
} }
b_updatingUI = false; b_updatingUI = false;
......
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