Commit 2a38ff36 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps: bug fix in render vector plugin

parent 8167cd1c
......@@ -54,17 +54,30 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi
std::string glxvert(GLSLShader::defines_gl());
std::string glxfrag(GLSLShader::defines_gl());
// get choose GL defines (2 or 3)
// ans compile shaders
std::string glxvert(GLSLShader::defines_gl());
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
std::string glxfrag(GLSLShader::defines_gl());
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
if (withClipping)
{
m_nameVS = "ShaderPhongClip_vs";
m_nameFS = "ShaderPhongClip_fs";
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderClipText);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderClipText);
}
else
{
m_nameVS = "ShaderPhong_vs";
m_nameFS = "ShaderPhong_fs";
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
}
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
......
......@@ -335,50 +335,43 @@ void Surface_Radiance_Plugin::decimate(const QString& mapName, const QString& po
mapParams.positionApproximator = new Algo::Surface::Decimation::Approximator_QEM<PFP2>(*map, position);
}
// if (mapParams.normalApproximator == NULL)
// {
// mapParams.normalApproximator =
// new Algo::Surface::Decimation::Approximator_InterpolateAlongEdge<PFP2, PFP2::VEC3>(
// *map,
// normal,
// position,
// ((Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator))->getApproximationResultAttribute()
// );
// }
// if (mapParams.radianceApproximator == NULL)
// {
// mapParams.radianceApproximator =
// new Algo::Surface::Decimation::Approximator_InterpolateAlongEdge<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >(
// *map,
// mapParams.radiance,
// position,
// ((Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator))->getApproximationResultAttribute()
// );
// }
if (mapParams.normalApproximator == NULL)
{
mapParams.normalApproximator =
new Algo::Surface::Decimation::Approximator_InterpolateAlongEdge<PFP2, PFP2::VEC3>(
*map,
normal,
position,
((Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator))->getApproximationResultAttribute()
);
}
if (mapParams.radianceApproximator == NULL)
{
mapParams.radianceApproximator =
new Algo::Surface::Decimation::Approximator_InterpolateAlongEdge<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >(
*map,
mapParams.radiance,
position,
((Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator))->getApproximationResultAttribute()
);
}
if (mapParams.selector == NULL)
{
// mapParams.selector =
// new EdgeSelector_Radiance<PFP2>(
// *map,
// position,
// normal,
// mapParams.radiance,
// *(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator),
// *(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.normalApproximator),
// *(Algo::Surface::Decimation::Approximator<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, EDGE>*)(mapParams.radianceApproximator)
// );
// mapParams.selector =
// new Algo::Surface::Decimation::EdgeSelector_QEM<PFP2>(
// *map,
// position,
// *(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator)
// );
mapParams.selector =
new EdgeSelector_Radiance<PFP2>(
*map,
position,
normal,
mapParams.radiance,
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.normalApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, EDGE>*)(mapParams.radianceApproximator)
);
mapParams.selector =
new Algo::Surface::Decimation::EdgeSelector_ColorNaive<PFP2>(
new Algo::Surface::Decimation::EdgeSelector_QEM<PFP2>(
*map,
position,
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator)
......
......@@ -50,7 +50,7 @@ void Surface_Render_DockTab::positionVBOChanged(int index)
{
m_plugin->h_viewParameterSet[view][map].positionVBO = map->getVBO(combo_positionVBO->currentText());
view->updateGL();
m_plugin->pythonRecording("changeVertexColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText());
}
}
}
......@@ -65,7 +65,7 @@ void Surface_Render_DockTab::normalVBOChanged(int index)
{
m_plugin->h_viewParameterSet[view][map].normalVBO = map->getVBO(combo_normalVBO->currentText());
view->updateGL();
m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText());
m_plugin->pythonRecording("changeNormalVBO", "", view->getName(), map->getName(), combo_normalVBO->currentText());
}
}
}
......@@ -80,7 +80,7 @@ void Surface_Render_DockTab::colorVBOChanged(int index)
{
m_plugin->h_viewParameterSet[view][map].colorVBO = map->getVBO(combo_colorVBO->currentText());
view->updateGL();
m_plugin->pythonRecording("changeNormalVBO", "", view->getName(), map->getName(), combo_normalVBO->currentText());
m_plugin->pythonRecording("changeColorVBO", "", view->getName(), map->getName(), combo_colorVBO->currentText());
}
}
}
......@@ -208,7 +208,6 @@ void Surface_Render_DockTab::colorSelected(const QColor& col)
{
if (m_currentColorDial == 1)
{
m_diffuseColor = col;
dcolorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}");
......@@ -220,12 +219,12 @@ void Surface_Render_DockTab::colorSelected(const QColor& col)
{
m_plugin->h_viewParameterSet[view][map].diffuseColor = rgbCol;
view->updateGL();
m_plugin->pythonRecording("changeFaceColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
}
}
if (m_currentColorDial == 2)
{
m_simpleColor = col;
scolorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}");
......@@ -237,12 +236,12 @@ void Surface_Render_DockTab::colorSelected(const QColor& col)
{
m_plugin->h_viewParameterSet[view][map].simpleColor = rgbCol;
view->updateGL();
m_plugin->pythonRecording("changeEdgeColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
}
}
if (m_currentColorDial == 3)
{
m_vertexColor = col;
vcolorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}");
......@@ -254,6 +253,7 @@ void Surface_Render_DockTab::colorSelected(const QColor& col)
{
m_plugin->h_viewParameterSet[view][map].vertexColor = rgbCol;
view->updateGL();
m_plugin->pythonRecording("changeVertexColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
}
}
}
......
......@@ -14,23 +14,6 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="0" colspan="2">
<widget class="QLineEdit" name="selectedName">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="ColorComboBox" name="combo_color"/>
</item>
<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_positionVBO">
<property name="sizePolicy">
......@@ -46,13 +29,23 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Vectors :</string>
<string>Selected vector size :</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="ColorComboBox" name="combo_color"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QListWidget" name="list_vectorVBO">
<property name="selectionMode">
......@@ -60,7 +53,14 @@
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Vectors :</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -73,7 +73,7 @@
</property>
</spacer>
</item>
<item row="8" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QSlider" name="slider_vectorsScaleFactor">
<property name="value">
<number>50</number>
......@@ -83,30 +83,10 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Vectors Size :</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="0">
<item row="7" column="0" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Color:</string>
<string>Selected vector color :</string>
</property>
</widget>
</item>
......
......@@ -12,22 +12,8 @@ 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)
{}
......@@ -36,10 +22,6 @@ struct MapParameters
QList<Utils::VBO*> vectorVBOs;
QList<QColor> colors;
QList<float> scaleFactors;
//float vectorsScaleFactor;
};
class Surface_RenderVector_Plugin : public PluginInteraction
......
......@@ -26,8 +26,6 @@ private:
SCHNApps* m_schnapps;
Surface_RenderVector_Plugin* m_plugin;
bool b_updatingUI;
int m_current_vbo;
QString m_currentVBOName;
private slots:
void positionVBOChanged(int index);
......
......@@ -51,19 +51,6 @@ 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->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);
......
......@@ -15,8 +15,7 @@ namespace SCHNApps
Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_RenderVector_Plugin* p) :
m_schnapps(s),
m_plugin(p),
b_updatingUI(false),
m_current_vbo(-1)
b_updatingUI(false)
{
setupUi(this);
......@@ -24,11 +23,6 @@ Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_
slider_vectorsScaleFactor->setDisabled(true);
combo_color->setDisabled(true);
QFont font = selectedName->font();
font.setBold(true);
selectedName->setFont(font);
selectedName->setText("not selected");
connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int)));
connect(list_vectorVBO, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(vectorsVBOChecked(QListWidgetItem*)));
......@@ -37,10 +31,9 @@ Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_
connect(combo_color, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
}
void Surface_RenderVector_DockTab::positionVBOChanged(int index)
{
if(!b_updatingUI)
if (!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
......@@ -55,38 +48,31 @@ void Surface_RenderVector_DockTab::positionVBOChanged(int index)
void Surface_RenderVector_DockTab::selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old)
{
if(!b_updatingUI)
if (!b_updatingUI)
{
if ((item->checkState() == Qt::Checked))
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if (view && map)
{
selectedName->setText(item->text());
slider_vectorsScaleFactor->setEnabled(true);
combo_color->setEnabled(true);
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if (view && map)
if ((item->checkState() == Qt::Checked))
{
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.0f);
std::cout << item->text().toStdString() << " : " << p.scaleFactors[m_current_vbo] << " / " << slider_vectorsScaleFactor->value() << std::endl;
combo_color->setColor(p.colors[m_current_vbo]);
}
int idx = p.vectorVBOs.indexOf(v);
slider_vectorsScaleFactor->setEnabled(true);
slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[idx] * 50.0f);
combo_color->setEnabled(true);
combo_color->setColor(p.colors[idx]);
}
else
{
slider_vectorsScaleFactor->setDisabled(true);
combo_color->setDisabled(true);
}
}
else
{
selectedName->setText("not selected");
slider_vectorsScaleFactor->setDisabled(true);
combo_color->setDisabled(true);
}
}
}
void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
{
if (!b_updatingUI)
......@@ -97,6 +83,7 @@ void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
{
MapParameters& p = m_plugin->h_viewParameterSet[view][map];
Utils::VBO* vbo = map->getVBO(item->text());
if (item->checkState() == Qt::Checked)
{
p.vectorVBOs.append(vbo);
......@@ -114,11 +101,10 @@ void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
p.vectorVBOs.removeAt(idx);
p.scaleFactors.removeAt(idx);
p.colors.removeAt(idx);
list_vectorVBO->setCurrentItem(item);
list_vectorVBO->clearSelection();
// list_vectorVBO->setCurrentItem(item);
// list_vectorVBO->clearSelection();
slider_vectorsScaleFactor->setDisabled(true);
combo_color->setDisabled(true);
m_current_vbo = -1;
m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(item->text()));
}
view->updateGL();
......@@ -126,45 +112,49 @@ void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
}
}
void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i)
{
if(!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if (view && map && (m_current_vbo>=0))
QListWidgetItem* item = list_vectorVBO->currentItem();
if (view && map && item)
{
float& scale = m_plugin->h_viewParameterSet[view][map].scaleFactors[m_current_vbo];
MapParameters& p = m_plugin->h_viewParameterSet[view][map];
Utils::VBO* vbo = map->getVBO(item->text());
int idx = p.vectorVBOs.indexOf(vbo);
float& scale = p.scaleFactors[idx];
float newScale = float(i) / 50.0f;
std::cout << "vectorsScaleFactorChanged " << i << " -> " << newScale << " / old:" << scale << std::endl;
if (fabs(scale - newScale) > 0.01f)
{
scale = newScale;
m_plugin->pythonRecording("changeVectorScaleFactor", "", view->getName(), map->getName(),
selectedName->text(), newScale);
item->text(), newScale);
view->updateGL();
}
}
}
}
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))
QListWidgetItem* item = list_vectorVBO->currentItem();
if (view && map && item)
{
QColor& col = m_plugin->h_viewParameterSet[view][map].colors[m_current_vbo];
MapParameters& p = m_plugin->h_viewParameterSet[view][map];
Utils::VBO* vbo = map->getVBO(item->text());
int idx = p.vectorVBOs.indexOf(vbo);
QColor& col = p.colors[idx];
if (col != combo_color->color())
{
col = combo_color->color();
m_plugin->pythonRecording("changeVectorColor", "", view->getName(), map->getName(),
selectedName->text(), combo_color->color().name());
item->text(), combo_color->color().name());
view->updateGL();
}
}
......@@ -172,6 +162,9 @@ void Surface_RenderVector_DockTab::colorChanged(int i)
}
void Surface_RenderVector_DockTab::addPositionVBO(QString name)
{
b_updatingUI = true;
......@@ -211,14 +204,13 @@ void Surface_RenderVector_DockTab::removeVectorVBO(QString name)
void Surface_RenderVector_DockTab::updateMapParameters()
{
std::cout << "Surface_RenderVector_DockTab::updateMapParameters" << std::endl;
b_updatingUI = true;
combo_positionVBO->clear();
combo_positionVBO->addItem("- select VBO -");
list_vectorVBO->clear();
list_vectorVBO->clearSelection();
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
......@@ -226,32 +218,30 @@ void Surface_RenderVector_DockTab::updateMapParameters()
{
const MapParameters& p = m_plugin->h_viewParameterSet[view][map];
unsigned int i = 0;
unsigned int i = 1;
foreach(Utils::VBO* vbo, map->getVBOSet().values())
{
if(vbo->dataSize() == 3)
{
combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
if(vbo == p.positionVBO)
combo_positionVBO->setCurrentIndex(i+1); // +1 for "- select VBO -"
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)->setCheckState(Qt::Checked);
list_vectorVBO->item(i-1)->setCheckState(Qt::Checked);
++i;
}
}
if (m_current_vbo >= 0)
{
slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0f);
combo_color->setColor(p.colors[m_current_vbo]);
}
// set color
}
slider_vectorsScaleFactor->setDisabled(true);
combo_color->setDisabled(true);
b_updatingUI = false;
}
......
......@@ -13,6 +13,7 @@
#include <QKeyEvent>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QMessageBox>
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