Commit 17bd0a69 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

scalar attribute rendering plugin update

parent f84dbc6f
...@@ -226,7 +226,7 @@ void DifferentialPropertiesPlugin::computeCurvature( ...@@ -226,7 +226,7 @@ void DifferentialPropertiesPlugin::computeCurvature(
PFP2::MAP* map = mh->getMap(); PFP2::MAP* map = mh->getMap();
Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP2>(*map, position, edgeAngle); Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP2>(*map, position, edgeAngle);
Algo::Surface::Geometry::computeCurvatureVertices_NormalCycles_Projected<PFP2>(*map, 0.02f * mh->getBBdiagSize(), position, normal, edgeAngle, kmax, kmin, Kmax, Kmin, Knormal); Algo::Surface::Geometry::computeCurvatureVertices_NormalCycles_Projected<PFP2>(*map, 0.01f * mh->getBBdiagSize(), position, normal, edgeAngle, kmax, kmin, Kmax, Kmin, Knormal);
computeCurvatureLastParameters[mapName] = computeCurvatureLastParameters[mapName] =
ComputeCurvatureParameters( ComputeCurvatureParameters(
......
...@@ -111,7 +111,7 @@ public slots: ...@@ -111,7 +111,7 @@ public slots:
void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false); void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false);
void changeNormalVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false); void changeNormalVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false);
void changeRenderVertices(View* view, MapHandlerGen* map, bool b, bool fromUI = false); void changeRenderVertices(View* view, MapHandlerGen* map, bool b, bool fromUI = false);
void changeVerticesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI = false); void changeVerticesScaleFactor(View* view, MapHandlerGen* map, float f, bool fromUI = false);
void changeRenderEdges(View* view, MapHandlerGen* map, bool b, bool fromUI = false); void changeRenderEdges(View* view, MapHandlerGen* map, bool b, bool fromUI = false);
void changeRenderFaces(View* view, MapHandlerGen* map, bool b, bool fromUI = false); void changeRenderFaces(View* view, MapHandlerGen* map, bool b, bool fromUI = false);
void changeFacesStyle(View* view, MapHandlerGen* map, FaceShadingStyle style, bool fromUI = false); void changeFacesStyle(View* view, MapHandlerGen* map, FaceShadingStyle style, bool fromUI = false);
......
...@@ -287,10 +287,10 @@ void RenderPlugin::changeRenderVertices(View* view, MapHandlerGen* map, bool b, ...@@ -287,10 +287,10 @@ void RenderPlugin::changeRenderVertices(View* view, MapHandlerGen* map, bool b,
} }
} }
void RenderPlugin::changeVerticesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI) void RenderPlugin::changeVerticesScaleFactor(View* view, MapHandlerGen* map, float f, bool fromUI)
{ {
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()]->verticesScaleFactor = i / 50.0; params->perMap[map->getName()]->verticesScaleFactor = f;
if(view->isCurrentView()) if(view->isCurrentView())
{ {
......
...@@ -127,7 +127,7 @@ void RenderDockTab::verticesScaleFactorChanged(int i) ...@@ -127,7 +127,7 @@ void RenderDockTab::verticesScaleFactorChanged(int i)
{ {
View* view = m_window->getCurrentView(); View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap; MapHandlerGen* map = m_currentParams->selectedMap;
m_plugin->changeVerticesScaleFactor(view, map, i, true); m_plugin->changeVerticesScaleFactor(view, map, i / 50.0, true);
} }
} }
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QGridLayout" name="gridLayout">
<item> <item row="0" column="0" colspan="2">
<widget class="QListWidget" name="mapList"/> <widget class="QListWidget" name="mapList"/>
</item> </item>
<item> <item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
...@@ -38,21 +38,41 @@ ...@@ -38,21 +38,41 @@
</item> </item>
</layout> </layout>
</item> </item>
<item> <item row="2" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Scalars :</string> <string>Scalar :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="3" column="0" colspan="2">
<widget class="QListWidget" name="list_scalarVBO"> <widget class="QListWidget" name="list_scalarVBO">
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum> <enum>QAbstractItemView::MultiSelection</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Expansion :</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSlider" name="slider_expansion">
<property name="maximum">
<number>10</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
......
...@@ -21,7 +21,9 @@ struct PerMapParameterSet ...@@ -21,7 +21,9 @@ struct PerMapParameterSet
PerMapParameterSet(MapHandlerGen* map); PerMapParameterSet(MapHandlerGen* map);
Utils::VBO* positionVBO; Utils::VBO* positionVBO;
std::vector<Utils::VBO*> scalarVBO; Utils::VBO* scalarVBO;
float scalarMin, scalarMax;
int expansion;
}; };
struct ParameterSet struct ParameterSet
...@@ -82,7 +84,8 @@ public slots: ...@@ -82,7 +84,8 @@ public slots:
void changeSelectedMap(View* view, MapHandlerGen* map); void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false); void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false);
void changeSelectedScalarsVBO(View* view, MapHandlerGen* map, const std::vector<Utils::VBO*>& vbos, bool fromUI = false); void changeScalarVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false);
void changeExpansion(View* view, MapHandlerGen* map, int i, bool fromUI = false);
}; };
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -33,7 +33,8 @@ public slots: ...@@ -33,7 +33,8 @@ public slots:
void selectedMapChanged(); void selectedMapChanged();
void positionVBOChanged(int index); void positionVBOChanged(int index);
void selectedScalarsVBOChanged(); void selectedScalarVBOChanged();
void expansionChanged(int i);
void addVBOToList(Utils::VBO* vbo); void addVBOToList(Utils::VBO* vbo);
}; };
......
...@@ -9,7 +9,9 @@ namespace SCHNApps ...@@ -9,7 +9,9 @@ namespace SCHNApps
{ {
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* map) : PerMapParameterSet::PerMapParameterSet(MapHandlerGen* map) :
positionVBO(NULL) positionVBO(NULL),
scalarVBO(NULL),
expansion(0)
{ {
bool positionFound = false; bool positionFound = false;
...@@ -58,14 +60,14 @@ void RenderScalarPlugin::redraw(View* view) ...@@ -58,14 +60,14 @@ void RenderScalarPlugin::redraw(View* view)
foreach(MapHandlerGen* m, maps) foreach(MapHandlerGen* m, maps)
{ {
PerMapParameterSet* p = params->perMap[m->getName()]; PerMapParameterSet* p = params->perMap[m->getName()];
if(p->positionVBO != NULL) if(p->positionVBO != NULL && p->scalarVBO != NULL)
{ {
m_scalarShader->setAttributePosition(p->positionVBO) ; m_scalarShader->setAttributePosition(p->positionVBO);
for(std::vector<Utils::VBO*>::const_iterator it = p->scalarVBO.begin(); it != p->scalarVBO.end(); ++it) m_scalarShader->setAttributeScalar(p->scalarVBO);
{ m_scalarShader->setMinValue(p->scalarMin);
m_scalarShader->setAttributeScalar(*it) ; m_scalarShader->setMaxValue(p->scalarMax);
m->draw(m_scalarShader, Algo::Render::GL2::TRIANGLES) ; m_scalarShader->setExpansion(p->expansion);
} m->draw(m_scalarShader, Algo::Render::GL2::TRIANGLES);
} }
} }
} }
...@@ -195,10 +197,37 @@ void RenderScalarPlugin::changePositionVBO(View* view, MapHandlerGen* map, Utils ...@@ -195,10 +197,37 @@ void RenderScalarPlugin::changePositionVBO(View* view, MapHandlerGen* map, Utils
} }
} }
void RenderScalarPlugin::changeSelectedScalarsVBO(View* view, MapHandlerGen* map, const std::vector<Utils::VBO*>& vbos, bool fromUI) void RenderScalarPlugin::changeScalarVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI)
{
ParameterSet* params = h_viewParams[view];
PerMapParameterSet* perMap = params->perMap[map->getName()];
perMap->scalarVBO = vbo;
if(vbo != NULL)
{
const VertexAttribute<PFP2::REAL>& attr = map->getAttribute<PFP2::REAL, VERTEX>(QString::fromStdString(vbo->name()));
perMap->scalarMin = 1e20;
perMap->scalarMax= -1e20;
for(unsigned int i = attr.begin(); i != attr.end(); attr.next(i))
{
perMap->scalarMin = attr[i] < perMap->scalarMin ? attr[i] : perMap->scalarMin;
perMap->scalarMax = attr[i] > perMap->scalarMax ? attr[i] : perMap->scalarMax;
}
}
if(view->isCurrentView())
{
if(!fromUI)
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderScalarPlugin::changeExpansion(View* view, MapHandlerGen* map, int i, bool fromUI)
{ {
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()]->scalarVBO = vbos; params->perMap[map->getName()]->expansion = i;
if(view->isCurrentView()) if(view->isCurrentView())
{ {
......
...@@ -19,7 +19,8 @@ RenderScalarDockTab::RenderScalarDockTab(Window* w, RenderScalarPlugin* p) : ...@@ -19,7 +19,8 @@ RenderScalarDockTab::RenderScalarDockTab(Window* w, RenderScalarPlugin* p) :
connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged())); connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int))); connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
connect(list_scalarVBO, SIGNAL(itemSelectionChanged()), this, SLOT(selectedScalarsVBOChanged())); connect(list_scalarVBO, SIGNAL(itemSelectionChanged()), this, SLOT(selectedScalarVBOChanged()));
connect(slider_expansion, SIGNAL(valueChanged(int)), this, SLOT(expansionChanged(int)));
} }
void RenderScalarDockTab::refreshUI(ParameterSet* params) void RenderScalarDockTab::refreshUI(ParameterSet* params)
...@@ -47,6 +48,7 @@ void RenderScalarDockTab::refreshUI(ParameterSet* params) ...@@ -47,6 +48,7 @@ void RenderScalarDockTab::refreshUI(ParameterSet* params)
QList<Utils::VBO*> vbos = map->getVBOList(); QList<Utils::VBO*> vbos = map->getVBOList();
unsigned int j = 0; unsigned int j = 0;
unsigned int k = 0;
for(int i = 0; i < vbos.count(); ++i) for(int i = 0; i < vbos.count(); ++i)
{ {
unsigned int dataSize = vbos[i]->dataSize(); unsigned int dataSize = vbos[i]->dataSize();
...@@ -60,10 +62,13 @@ void RenderScalarDockTab::refreshUI(ParameterSet* params) ...@@ -60,10 +62,13 @@ void RenderScalarDockTab::refreshUI(ParameterSet* params)
else if(dataSize == 1) else if(dataSize == 1)
{ {
list_scalarVBO->addItem(QString::fromStdString(vbos[i]->name())); list_scalarVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(std::find(p->scalarVBO.begin(), p->scalarVBO.end(), vbos[i]) != p->scalarVBO.end()) if(vbos[i] == p->scalarVBO)
list_scalarVBO->item(j)->setSelected(true); list_scalarVBO->item(k)->setSelected(true);
++k;
} }
} }
slider_expansion->setSliderPosition(p->expansion);
} }
++i; ++i;
} }
...@@ -91,17 +96,34 @@ void RenderScalarDockTab::positionVBOChanged(int index) ...@@ -91,17 +96,34 @@ void RenderScalarDockTab::positionVBOChanged(int index)
} }
} }
void RenderScalarDockTab::selectedScalarsVBOChanged() void RenderScalarDockTab::selectedScalarVBOChanged()
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
QList<QListWidgetItem*> selectedItems = list_scalarVBO->selectedItems();
if(!selectedItems.empty())
{
foreach(QListWidgetItem* item, selectedItems)
{
if(item != list_scalarVBO->currentItem())
item->setSelected(false);
}
m_plugin->changeScalarVBO(view, map, map->getVBO(list_scalarVBO->currentItem()->text()), true);
}
else
m_plugin->changeScalarVBO(view, map, NULL, true);
}
}
void RenderScalarDockTab::expansionChanged(int i)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* view = m_window->getCurrentView(); View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap; MapHandlerGen* map = m_currentParams->selectedMap;
QList<QListWidgetItem*> currentItems = list_scalarVBO->selectedItems(); m_plugin->changeExpansion(view, map, i, true);
std::vector<Utils::VBO*> vbos;
foreach(QListWidgetItem* item, currentItems)
vbos.push_back(map->getVBO(item->text()));
m_plugin->changeSelectedScalarsVBO(view, map, vbos, true);
} }
} }
......
importPlugin = schnapps.loadPlugin("ImportSurface"); importPlugin = schnapps.loadPlugin("ImportSurface");
renderPlugin = schnapps.loadPlugin("Render"); renderPlugin = schnapps.loadPlugin("Render");
renderVectorPlugin = schnapps.loadPlugin("RenderVector"); renderVectorPlugin = schnapps.loadPlugin("RenderVector");
renderScalarPlugin = schnapps.loadPlugin("RenderScalar");
renderTopoSurfacePlugin = schnapps.loadPlugin("RenderTopoSurface"); renderTopoSurfacePlugin = schnapps.loadPlugin("RenderTopoSurface");
differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties"); differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties");
subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface"); subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface");
surfaceDeformationPlugin = schnapps.loadPlugin("SurfaceDeformation"); surfaceDeformationPlugin = schnapps.loadPlugin("SurfaceDeformation");
obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/midRes/cow_3k.off"); obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/midRes/cow_11k.off");
v = schnapps.getView("view_0"); v = schnapps.getView("view_0");
schnapps.linkViewAndPlugin(v.getName(), renderPlugin.getName()); schnapps.linkViewAndPlugin(v.getName(), renderPlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), renderVectorPlugin.getName()); schnapps.linkViewAndPlugin(v.getName(), renderVectorPlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), renderTopoSurfacePlugin.getName()); schnapps.linkViewAndPlugin(v.getName(), renderScalarPlugin.getName());
#schnapps.linkViewAndPlugin(v.getName(), renderTopoSurfacePlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), surfaceDeformationPlugin.getName()); schnapps.linkViewAndPlugin(v.getName(), surfaceDeformationPlugin.getName());
schnapps.linkViewAndMap(v.getName(), obj.getName()); schnapps.linkViewAndMap(v.getName(), obj.getName());
#differentialPropertiesPlugin.computeNormal(obj.getName()); differentialPropertiesPlugin.computeNormal(obj.getName());
#differentialPropertiesPlugin.computeCurvature(obj.getName()); differentialPropertiesPlugin.computeCurvature(obj.getName());
...@@ -6,9 +6,9 @@ VARYING_FRAG float scalar; ...@@ -6,9 +6,9 @@ VARYING_FRAG float scalar;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
float s = scalar * 30.0; // float s = scalar * 20.0;
if( s - floor(s) <= 0.01 ) // if( s - floor(s) <= 0.01 )
gl_FragColor = vec4(0.0); // gl_FragColor = vec4(0.0);
else // else
gl_FragColor = vec4(color, 0.0); gl_FragColor = vec4(color, 0.0);
} }
...@@ -42,9 +42,21 @@ protected: ...@@ -42,9 +42,21 @@ protected:
static std::string vertexShaderText; static std::string vertexShaderText;
static std::string fragmentShaderText; static std::string fragmentShaderText;
CGoGNGLuint m_uniform_minValue;
CGoGNGLuint m_uniform_maxValue;
CGoGNGLuint m_uniform_expansion;
float m_minValue;
float m_maxValue;
int m_expansion;
VBO* m_vboPos; VBO* m_vboPos;
VBO* m_vboScal; VBO* m_vboScal;
void getLocations();
void sendParams();
void restoreUniformsAttribs(); void restoreUniformsAttribs();
public: public:
...@@ -53,6 +65,12 @@ public: ...@@ -53,6 +65,12 @@ public:
unsigned int setAttributePosition(VBO* vbo); unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeScalar(VBO* vbo); unsigned int setAttributeScalar(VBO* vbo);
void setMinValue(float f);
void setMaxValue(float f);
void setExpansion(int i);
}; };
} // namespace Utils } // namespace Utils
......
...@@ -3,10 +3,39 @@ ...@@ -3,10 +3,39 @@
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE float VertexScalar; ATTRIBUTE float VertexScalar;
uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewProjectionMatrix;
uniform float minValue;
uniform float maxValue;
uniform int expansion;
VARYING_VERT vec3 color; VARYING_VERT vec3 color;
VARYING_VERT float scalar; VARYING_VERT float scalar;
INVARIANT_POS; INVARIANT_POS;
#define M_PI 3.1415926535897932384626433832795
float scale_and_clamp_to_0_1(float x, float min, float max)
{
float v = (x - min) / (max - min);
return v < 0.0 ? 0.0 : (v > 1.0 ? 1.0 : v);
}
float scale_expand_within_0_1(float x, int n)
{
for (int i = 1; i <= n; i++)
x = (1.0 - cos(M_PI * x)) / 2.0;
for (int i = -1; i >= n; i--)
x = acos(1.0 - 2.0 * x) / M_PI;
return x;
}
float scale_expand_towards_1(float x, int n)
{
for (int i = 1; i <= n; i++)
x = sin(x * M_PI / 2.0);
for (int i = -1; i >= n; i--)
x = asin(x) * 2.0 / M_PI;
return x;
}
vec3 color_map_blue_white_red(float x) vec3 color_map_blue_white_red(float x)
{ {
vec3 c = vec3(0); vec3 c = vec3(0);
...@@ -32,6 +61,15 @@ vec3 color_map_blue_white_red(float x) ...@@ -32,6 +61,15 @@ vec3 color_map_blue_white_red(float x)
void main () void main ()
{ {
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0); gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
color = color_map_blue_white_red(VertexScalar); float value =
scalar = VertexScalar; scale_expand_within_0_1(
scale_and_clamp_to_0_1(
VertexScalar,
minValue,
maxValue
),
expansion
);
color = color_map_blue_white_red(value);
scalar = value;
} }
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define __CGOGN_SHADER_VPV__ #define __CGOGN_SHADER_VPV__
#include "Utils/GLSLShader.h" #include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
namespace CGoGN namespace CGoGN
...@@ -34,7 +35,7 @@ namespace CGoGN ...@@ -34,7 +35,7 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
class ShaderVectorPerVertex : public GLSLShader class ShaderVectorPerVertex : public ClippingShader
{ {
protected: protected:
// shader sources // shader sources
......
...@@ -98,7 +98,7 @@ public: ...@@ -98,7 +98,7 @@ public:
const std::string& name() const { return m_name; } const std::string& name() const { return m_name; }