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

scalar attribute rendering plugin update

parent f84dbc6f
......@@ -226,7 +226,7 @@ void DifferentialPropertiesPlugin::computeCurvature(
PFP2::MAP* map = mh->getMap();
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] =
ComputeCurvatureParameters(
......
......@@ -111,7 +111,7 @@ public slots:
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 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 changeRenderFaces(View* view, MapHandlerGen* map, bool b, 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,
}
}
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];
params->perMap[map->getName()]->verticesScaleFactor = i / 50.0;
params->perMap[map->getName()]->verticesScaleFactor = f;
if(view->isCurrentView())
{
......
......@@ -127,7 +127,7 @@ void RenderDockTab::verticesScaleFactorChanged(int i)
{
View* view = m_window->getCurrentView();
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 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QListWidget" name="mapList"/>
</item>
<item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
......@@ -38,21 +38,41 @@
</item>
</layout>
</item>
<item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Scalars :</string>
<string>Scalar :</string>
</property>
</widget>
</item>
<item>
<item row="3" column="0" colspan="2">
<widget class="QListWidget" name="list_scalarVBO">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</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">
<property name="orientation">
<enum>Qt::Vertical</enum>
......
......@@ -21,7 +21,9 @@ struct PerMapParameterSet
PerMapParameterSet(MapHandlerGen* map);
Utils::VBO* positionVBO;
std::vector<Utils::VBO*> scalarVBO;
Utils::VBO* scalarVBO;
float scalarMin, scalarMax;
int expansion;
};
struct ParameterSet
......@@ -82,7 +84,8 @@ public slots:
void changeSelectedMap(View* view, MapHandlerGen* map);
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
......
......@@ -33,7 +33,8 @@ public slots:
void selectedMapChanged();
void positionVBOChanged(int index);
void selectedScalarsVBOChanged();
void selectedScalarVBOChanged();
void expansionChanged(int i);
void addVBOToList(Utils::VBO* vbo);
};
......
......@@ -9,7 +9,9 @@ namespace SCHNApps
{
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* map) :
positionVBO(NULL)
positionVBO(NULL),
scalarVBO(NULL),
expansion(0)
{
bool positionFound = false;
......@@ -58,14 +60,14 @@ void RenderScalarPlugin::redraw(View* view)
foreach(MapHandlerGen* m, maps)
{
PerMapParameterSet* p = params->perMap[m->getName()];
if(p->positionVBO != NULL)
if(p->positionVBO != NULL && p->scalarVBO != NULL)
{
m_scalarShader->setAttributePosition(p->positionVBO) ;
for(std::vector<Utils::VBO*>::const_iterator it = p->scalarVBO.begin(); it != p->scalarVBO.end(); ++it)
{
m_scalarShader->setAttributeScalar(*it) ;
m->draw(m_scalarShader, Algo::Render::GL2::TRIANGLES) ;
}
m_scalarShader->setAttributePosition(p->positionVBO);
m_scalarShader->setAttributeScalar(p->scalarVBO);
m_scalarShader->setMinValue(p->scalarMin);
m_scalarShader->setMaxValue(p->scalarMax);
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
}
}
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];
params->perMap[map->getName()]->scalarVBO = vbos;
params->perMap[map->getName()]->expansion = i;
if(view->isCurrentView())
{
......
......@@ -19,7 +19,8 @@ RenderScalarDockTab::RenderScalarDockTab(Window* w, RenderScalarPlugin* p) :
connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
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)
......@@ -47,6 +48,7 @@ void RenderScalarDockTab::refreshUI(ParameterSet* params)
QList<Utils::VBO*> vbos = map->getVBOList();
unsigned int j = 0;
unsigned int k = 0;
for(int i = 0; i < vbos.count(); ++i)
{
unsigned int dataSize = vbos[i]->dataSize();
......@@ -60,10 +62,13 @@ void RenderScalarDockTab::refreshUI(ParameterSet* params)
else if(dataSize == 1)
{
list_scalarVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(std::find(p->scalarVBO.begin(), p->scalarVBO.end(), vbos[i]) != p->scalarVBO.end())
list_scalarVBO->item(j)->setSelected(true);
if(vbos[i] == p->scalarVBO)
list_scalarVBO->item(k)->setSelected(true);
++k;
}
}
slider_expansion->setSliderPosition(p->expansion);
}
++i;
}
......@@ -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)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
QList<QListWidgetItem*> currentItems = list_scalarVBO->selectedItems();
std::vector<Utils::VBO*> vbos;
foreach(QListWidgetItem* item, currentItems)
vbos.push_back(map->getVBO(item->text()));
m_plugin->changeSelectedScalarsVBO(view, map, vbos, true);
m_plugin->changeExpansion(view, map, i, true);
}
}
......
importPlugin = schnapps.loadPlugin("ImportSurface");
renderPlugin = schnapps.loadPlugin("Render");
renderVectorPlugin = schnapps.loadPlugin("RenderVector");
renderScalarPlugin = schnapps.loadPlugin("RenderScalar");
renderTopoSurfacePlugin = schnapps.loadPlugin("RenderTopoSurface");
differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties");
subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface");
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");
schnapps.linkViewAndPlugin(v.getName(), renderPlugin.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.linkViewAndMap(v.getName(), obj.getName());
#differentialPropertiesPlugin.computeNormal(obj.getName());
#differentialPropertiesPlugin.computeCurvature(obj.getName());
differentialPropertiesPlugin.computeNormal(obj.getName());
differentialPropertiesPlugin.computeCurvature(obj.getName());
......@@ -6,9 +6,9 @@ VARYING_FRAG float scalar;
FRAG_OUT_DEF;
void main()
{
float s = scalar * 30.0;
if( s - floor(s) <= 0.01 )
gl_FragColor = vec4(0.0);
else
// float s = scalar * 20.0;
// if( s - floor(s) <= 0.01 )
// gl_FragColor = vec4(0.0);
// else
gl_FragColor = vec4(color, 0.0);
}
......@@ -42,9 +42,21 @@ protected:
static std::string vertexShaderText;
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_vboScal;
void getLocations();
void sendParams();
void restoreUniformsAttribs();
public:
......@@ -53,6 +65,12 @@ public:
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeScalar(VBO* vbo);
void setMinValue(float f);
void setMaxValue(float f);
void setExpansion(int i);
};
} // namespace Utils
......
......@@ -3,10 +3,39 @@
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE float VertexScalar;
uniform mat4 ModelViewProjectionMatrix;
uniform float minValue;
uniform float maxValue;
uniform int expansion;
VARYING_VERT vec3 color;
VARYING_VERT float scalar;
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 c = vec3(0);
......@@ -32,6 +61,15 @@ vec3 color_map_blue_white_red(float x)
void main ()
{
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
color = color_map_blue_white_red(VertexScalar);
scalar = VertexScalar;
float value =
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 @@
#define __CGOGN_SHADER_VPV__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
namespace CGoGN
......@@ -34,7 +35,7 @@ namespace CGoGN
namespace Utils
{
class ShaderVectorPerVertex : public GLSLShader
class ShaderVectorPerVertex : public ClippingShader
{
protected:
// shader sources
......
......@@ -98,7 +98,7 @@ public:
const std::string& name() const { return m_name; }
/**
* get name
* get type name
*/
const std::string& typeName() const { return m_typeName; }
......
......@@ -46,6 +46,28 @@ ShaderScalarField::ShaderScalarField()
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
// get and fill uniforms
getLocations();
sendParams();
}
void ShaderScalarField::getLocations()
{
bind();
*m_uniform_minValue = glGetUniformLocation(this->program_handler(), "minValue");
*m_uniform_maxValue = glGetUniformLocation(this->program_handler(), "maxValue");
*m_uniform_expansion = glGetUniformLocation(this->program_handler(), "expansion");
unbind();
}
void ShaderScalarField::sendParams()
{
bind();
glUniform1f(*m_uniform_minValue, m_minValue);
glUniform1f(*m_uniform_maxValue, m_maxValue);
glUniform1i(*m_uniform_expansion, m_expansion);
unbind();
}
unsigned int ShaderScalarField::setAttributePosition(VBO* vbo)
......@@ -66,6 +88,30 @@ unsigned int ShaderScalarField::setAttributeScalar(VBO* vbo)
return id;
}
void ShaderScalarField::setMinValue(float f)
{
bind();
glUniform1f(*m_uniform_minValue, f);
m_minValue = f;
unbind();
}
void ShaderScalarField::setMaxValue(float f)
{
bind();
glUniform1f(*m_uniform_maxValue, f);
m_maxValue = f;
unbind();
}
void ShaderScalarField::setExpansion(int f)
{
bind();
glUniform1i(*m_uniform_expansion, f);
m_expansion = f;
unbind();
}
void ShaderScalarField::restoreUniformsAttribs()
{
bind();
......
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