Commit 15613817 authored by Sylvain Thery's avatar Sylvain Thery

color/scale for each vector (RenderVector plugin)

parent ce636fee
......@@ -50,12 +50,18 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Vectors Size :</string>
<item row="6" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>161</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QSlider" name="slider_vectorsScaleFactor">
......@@ -67,21 +73,25 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>161</height>
</size>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Vectors Size :</string>
</property>
</spacer>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="ColorComboBox" name="combo_color"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ColorComboBox</class>
<extends>QComboBox</extends>
<header>colorComboBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -12,16 +12,34 @@ namespace CGoGN
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
{
MapParameters() :
positionVBO(NULL),
vectorsScaleFactor(1.0f)
positionVBO(NULL)
{}
Utils::VBO* positionVBO;
QList<Utils::VBO*> vectorVBOs;
float vectorsScaleFactor;
QList<QColor> colors;
QList<float> scaleFactors;
//float vectorsScaleFactor;
};
class Surface_RenderVector_Plugin : public PluginInteraction
......@@ -72,7 +90,8 @@ public slots:
void changePositionVBO(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 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:
Surface_RenderVector_DockTab* m_dockTab;
......
......@@ -26,11 +26,14 @@ private:
SCHNApps* m_schnapps;
Surface_RenderVector_Plugin* m_plugin;
bool b_updatingUI;
int m_current_vbo;
private slots:
void positionVBOChanged(int index);
void selectedVectorsVBOChanged();
void selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old);
void vectorsVBOChecked(QListWidgetItem* item);
void vectorsScaleFactorChanged(int i);
void colorChanged(int i);
private:
void addPositionVBO(QString name);
......
......@@ -51,13 +51,29 @@ void Surface_RenderVector_Plugin::drawMap(View* view, MapHandlerGen* map)
{
const MapParameters& p = h_viewParameterSet[view][map];
m_vectorShader->setScale(map->getBBdiagSize() / 100.0f * p.vectorsScaleFactor) ;
if(p.positionVBO)
//m_vectorShader->setScale(map->getBBdiagSize() / 100.0f * p.vectorsScaleFactor) ;
//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);
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);
map->draw(m_vectorShader, Algo::Render::GL2::POINTS);
}
......@@ -177,6 +193,8 @@ void Surface_RenderVector_Plugin::addVectorVBO(const QString& view, const QStrin
{
Utils::VBO* vbuf = m->getVBO(vbo);
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->isLinkedToMap(m)) v->updateGL();
......@@ -192,7 +210,10 @@ void Surface_RenderVector_Plugin::removeVectorVBO(const QString& view, const QSt
if(v && m)
{
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->isLinkedToMap(m)) v->updateGL();
......@@ -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);
MapHandlerGen* m = m_schnapps->getMap(map);
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->isLinkedToMap(m)) v->updateGL();
......@@ -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
Q_PLUGIN_METADATA(IID "CGoGN.SCHNapps.Plugin")
#else
......
......@@ -15,17 +15,37 @@ namespace SCHNApps
Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_RenderVector_Plugin* p) :
m_schnapps(s),
m_plugin(p),
b_updatingUI(false)
b_updatingUI(false),
m_current_vbo(-1)
{
setupUi(this);
list_vectorVBO->setSelectionMode(QAbstractItemView::SingleSelection);
slider_vectorsScaleFactor->hide();
combo_color->hide();
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(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)
......@@ -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 ((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();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map)
if (view && map)
{
QList<QListWidgetItem*> currentItems = list_vectorVBO->selectedItems();
QList<Utils::VBO*> vbos;
const QList<Utils::VBO*>& vboList = m_plugin->h_viewParameterSet[view][map].vectorVBOs;
foreach(QListWidgetItem* item, currentItems)
MapParameters& p = m_plugin->h_viewParameterSet[view][map];
Utils::VBO* vbo = map->getVBO(item->text());
if (item->checkState() == Qt::Checked)
{
Utils::VBO* vbo = map->getVBO(item->text());
vbos.append(vbo);
if (!vboList.contains(vbo))
m_plugin->pythonRecording("addVectorVBO", "", view->getName(), map->getName(), item->text());
p.vectorVBOs.append(vbo);
p.scaleFactors.append(1.0f);
p.colors.append(QColor("red"));
if (list_vectorVBO->currentItem() == item)
selectedVectorVBOChanged(item, NULL);
else
list_vectorVBO->setCurrentItem(item);
m_plugin->pythonRecording("addVectorVBO", "", view->getName(), map->getName(), item->text());
}
foreach(Utils::VBO* vbo, vboList)
else
{
if (!vbos.contains(vbo))
m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(vbo->name().c_str()));
int idx = p.vectorVBOs.indexOf(vbo);
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();
}
}
}
void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i)
{
if(!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
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();
}
}
}
void Surface_RenderVector_DockTab::addPositionVBO(QString name)
{
b_updatingUI = true;
......@@ -114,6 +172,9 @@ void Surface_RenderVector_DockTab::addVectorVBO(QString name)
{
b_updatingUI = true;
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;
}
......@@ -151,14 +212,17 @@ void Surface_RenderVector_DockTab::updateMapParameters()
combo_positionVBO->setCurrentIndex(i);
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))
list_vectorVBO->item(i)->setSelected(true);
list_vectorVBO->item(i)->setCheckState(Qt::Checked);
++i;
}
}
slider_vectorsScaleFactor->setSliderPosition(p.vectorsScaleFactor * 50.0);
if (m_current_vbo>=0)
slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0);
// set color
}
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