Commit fe9839c3 authored by Maire Nicolas's avatar Maire Nicolas

Implémentation des presets dans l'interface Qt.

parent 6d942ba2
......@@ -25,6 +25,36 @@
#include "clipping.h"
#include "Utils/static_assert.h"
/*******************************************************************************
* MISCELLANOUS
*******************************************************************************/
void computeBasisFromVector(const Geom::Vec3f& vec1, Geom::Vec3f& vec2, Geom::Vec3f& vec3)
{
const float epsilon = 0.0001f;
// Check if the given vector length is acceptable
if (vec1.norm() < epsilon)
return;
// First take a non colinear second vector to cross product with vec1
// (by default (0.0, 0.0, 1.0)
Geom::Vec3f tempVec (0.0, 0.0, 1.0);
// Construct second vector, check other vectors non colinearity at the same time
vec2 = vec1 ^ tempVec;
float sinAngle = vec2.norm() / (vec1.norm() + tempVec.norm());
if (sinAngle < epsilon) // f:x->sin(x) ~ f:x->x when x ~ 0
{
tempVec = Geom::Vec3f (1.0, 0.0, 0.0);
vec2 = vec1 ^ tempVec;
}
// Get third vector
vec3 = vec1 ^ vec2;
}
/*******************************************************************************
* SLOTS
*******************************************************************************/
......@@ -77,7 +107,7 @@ void Clipping::slot_explodTopoPhi3(double c)
void Clipping::slot_pushButton_addPlane()
{
// Create clipping and pickable objects
int newPlaneId = m_shader->addClipPlane();
unsigned int newPlaneId = m_shader->addClipPlane();
Utils::Pickable* pickable = new Utils::Pickable(m_planeDrawable, newPlaneId);
m_pickablePlanes.push_back(pickable);
......@@ -115,7 +145,7 @@ void Clipping::slot_pushButton_changePlanesColor()
void Clipping::slot_pushButton_addSphere()
{
// Create clipping and pickable objects
int newSphereId = m_shader->addClipSphere();
unsigned int newSphereId = m_shader->addClipSphere();
Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, newSphereId);
m_pickableSpheres.push_back(pickable);
......@@ -227,6 +257,106 @@ void Clipping::slot_pushButton_deleteSelectedObject()
}
}
void Clipping::slot_pushButton_applyClippingPreset()
{
// Create and apply preset
Utils::ClippingPreset *preset = NULL;
switch (dock.comboBox_ClippingPresets->currentIndex())
{
case 0 : // Dual planes
{
using namespace CGoGN::Utils::QT;
double centerX = (double)m_bb.center()[0];
double centerY = (double)m_bb.center()[1];
double centerZ = (double)m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.75;
int axis = 0;
bool facing = false;
if (inputValues(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
VarSlider(0, 2, axis, "Axis",
VarBool(facing, "Facing"
)))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f((float)centerX, (float)centerY, (float)centerZ), (float)size, axis, facing);
}
break;
case 1 : // Cube
{
using namespace CGoGN::Utils::QT;
double centerX = (double)m_bb.center()[0];
double centerY = (double)m_bb.center()[1];
double centerZ = (double)m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.75;
bool facing = false;
if (inputValues(VarDbl(centerX - 100.0, centerX + 100.0, centerX, "Center X",
VarDbl(centerY - 100.0, centerY + 100.0, centerY, "Center Y",
VarDbl(centerZ - 100.0, centerZ + 100.0, centerZ, "Center Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
VarBool(facing, "Facing"
))))), "Preset Setup"))
preset = Utils::ClippingPreset::CreateCubePreset(Geom::Vec3f((float)centerX, (float)centerY, (float)centerZ), (float)size, facing);
}
break;
}
std::vector<unsigned int> planesIds;
std::vector<unsigned int> spheresIds;
preset->apply(m_shader, &planesIds, &spheresIds);
delete preset;
// Cleanup of pickables before adding new ones
m_lastPickedObject = NULL;
for (size_t i = 0; i < m_pickablePlanes.size(); i++)
delete m_pickablePlanes[i];
m_pickablePlanes.resize(0);
for (size_t i = 0; i < m_pickableSpheres.size(); i++)
delete m_pickableSpheres[i];
m_pickableSpheres.resize(0);
// Add new pickable objects
for (size_t i = 0; i < planesIds.size(); i++)
{
Utils::Pickable* pickable = new Utils::Pickable(m_planeDrawable, planesIds[i]);
pickable->translate(m_shader->getClipPlaneParamsOrigin(planesIds[i]));
Geom::Vec3f vec1, vec2, vec3;
vec1 = m_shader->getClipPlaneParamsNormal(planesIds[i]);
computeBasisFromVector(vec1, vec2, vec3);
glm::mat4& transfoMat = pickable->transfo();
for (int i = 0; i < 3; i++)
{
transfoMat[0][i] = vec2[i];
transfoMat[1][i] = vec3[i];
transfoMat[2][i] = vec1[i];
}
m_pickablePlanes.push_back(pickable);
}
for (size_t i = 0; i < spheresIds.size(); i++)
{
Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, spheresIds[i]);
pickable->translate(m_shader->getClipSphereParamsCenter(spheresIds[i]));
pickable->scale(m_shader->getClipSphereParamsRadius(spheresIds[i]));
}
// Update shader sources edits
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
dock.fragmentEdit->setPlainText(QString(m_shader->getFragmentShaderSrc()));
// Update clipping parameters in interface
Utils::ClippingShader::clippingMode clipMode = m_shader->getClipMode();
if (clipMode == Utils::ClippingShader::CLIPPING_MODE_AND)
dock.radioButton_ClippingModeAnd->setChecked(true);
else if (clipMode == Utils::ClippingShader::CLIPPING_MODE_OR)
dock.radioButton_ClippingModeOr->setChecked(true);
updateGLMatrices();
}
void Clipping::button_compile()
{
QString st1 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->vertexEdit->toPlainText();
......@@ -317,6 +447,12 @@ void Clipping::initGUI()
else if (colorAttMode == Utils::ClippingShader::COLOR_ATTENUATION_MODE_QUADRATIC)
dock.radioButton_ColorAttenuationModeQuadratic->setChecked(true);
setCallBack(dock.PushButton_ApplyClippingPreset, SIGNAL(clicked()), SLOT(slot_pushButton_applyClippingPreset()));
dock.comboBox_ClippingPresets->addItem("Dual Planes");
dock.comboBox_ClippingPresets->addItem("Cube");
}
void Clipping::cb_Open()
......
......@@ -28,6 +28,7 @@
#include <iostream>
#include "Utils/qtSimple.h"
#include "Utils/qtInputs.h"
#include "ui_clipping.h"
// inclure qtui.h juste après le ui_xxx.h
......@@ -51,6 +52,8 @@
#include "Utils/frameManipulator.h"
#include "Utils/clippingPresets.h"
#include "Utils/cgognStream.h"
#include "Utils/drawer.h"
......@@ -153,6 +156,8 @@ public slots:
void slot_pushButton_deleteSelectedObject();
void slot_pushButton_applyClippingPreset();
void button_compile();
};
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>352</width>
<height>778</height>
<width>374</width>
<height>783</height>
</rect>
</property>
<property name="allowedAreas">
......@@ -32,6 +32,16 @@
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget_Options">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_Object">
<attribute name="title">
<string>Object</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkBox_vertices">
......@@ -145,49 +155,100 @@
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_Clipping">
<attribute name="title">
<string>Clipping</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QGroupBox" name="groupBox_clipPlanes">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QGroupBox" name="groupBox_ClippingMode">
<property name="title">
<string>Clipping Mode</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QRadioButton" name="radioButton_ClippingModeAnd">
<property name="text">
<string>AND</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_ClippingModeOr">
<property name="text">
<string>OR</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="0">
<item>
<widget class="QGroupBox" name="groupBox_clipSpheres">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Clipping Planes</string>
<string>Clipping Spheres</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pushButton_addPlane">
<widget class="QPushButton" name="pushButton_addSphere">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_12">
<layout class="QGridLayout" name="gridLayout_13">
<item row="0" column="0">
<widget class="QLabel" name="label_GridResolution">
<widget class="QLabel" name="label_SphereResolution">
<property name="text">
<string>Res.</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_GridResolution">
<widget class="QSpinBox" name="spinBox_SphereResolution">
<property name="maximum">
<number>200</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_GridColor">
<widget class="QLabel" name="label_GridColor_2">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pushButton_changePlanesColor">
<widget class="QPushButton" name="pushButton_changeSpheresColor">
<property name="text">
<string>Change Color</string>
</property>
......@@ -201,48 +262,48 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="0">
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0">
<item>
<widget class="QGroupBox" name="groupBox_clipSpheres">
<widget class="QGroupBox" name="groupBox_clipPlanes">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Clipping Spheres</string>
<string>Clipping Planes</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_addSphere">
<widget class="QPushButton" name="pushButton_addPlane">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_13">
<layout class="QGridLayout" name="gridLayout_12">
<item row="0" column="0">
<widget class="QLabel" name="label_SphereResolution">
<widget class="QLabel" name="label_GridResolution">
<property name="text">
<string>Res.</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_SphereResolution">
<widget class="QSpinBox" name="spinBox_GridResolution">
<property name="maximum">
<number>200</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_GridColor_2">
<widget class="QLabel" name="label_GridColor">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pushButton_changeSpheresColor">
<widget class="QPushButton" name="pushButton_changePlanesColor">
<property name="text">
<string>Change Color</string>
</property>
......@@ -256,24 +317,20 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_8">
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QGroupBox" name="groupBox_ClippingMode">
<widget class="QGroupBox" name="groupBox_ClippingPresets">
<property name="title">
<string>Clipping Mode</string>
<string>Clipping Presets</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QRadioButton" name="radioButton_ClippingModeAnd">
<property name="text">
<string>AND</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_ClippingPresets"/>
</item>
<item>
<widget class="QRadioButton" name="radioButton_ClippingModeOr">
<widget class="QPushButton" name="PushButton_ApplyClippingPreset">
<property name="text">
<string>OR</string>
<string>Apply Preset</string>
</property>
</widget>
</item>
......@@ -341,6 +398,23 @@
</item>
</layout>
</item>
<item>
<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>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
......
......@@ -57,7 +57,7 @@ public :
* @param axis axis on which planes are aligned (0 for x, 1 for y, 2 for z)
* @param facing true means having facing planes
*/
static ClippingPreset* CreateDualPlanesPreset(Geom::Vec3f center, float distance, int axis, bool facing);
static ClippingPreset* CreateDualPlanesPreset(Geom::Vec3f center, float size, int axis, bool facing);
/**
* public static constructor
......@@ -65,7 +65,7 @@ public :
* @param distance distance between planes
* @param facing true means having facing planes
*/
static ClippingPreset* CreateCubePreset(Geom::Vec3f center, float distance, bool facing);
static ClippingPreset* CreateCubePreset(Geom::Vec3f center, float size, bool facing);
private :
......
......@@ -45,50 +45,66 @@ ClippingPreset* ClippingPreset::CreateEmptyPreset()
return preset;
}
ClippingPreset* ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f center, float distance, int axis, bool facing)
ClippingPreset* ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f center, float size, int axis, bool facing)
{
ClippingPreset *preset = new ClippingPreset;
// Axis on which planes will be aligned
if ((axis < 0) || (axis > 2))
axis = 0;
Geom::Vec3f positDir (0.0, 0.0, 0.0);
positDir[axis] = 1.0;
Geom::Vec3f negDir (0.0, 0.0, 0.0);
negDir[axis] = -1.0;
Geom::Vec3f positDir (0.0f, 0.0f, 0.0f);
positDir[axis] = 1.0f;
Geom::Vec3f negDir (0.0f, 0.0f, 0.0f);
negDir[axis] = -1.0f;
// Facing of planes
float side = 1.0;
if (facing)
side = -1.0;
// Add planes to preset
preset->addClipPlane(positDir, center + positDir*(distance / 2.0));
preset->addClipPlane(negDir, center + negDir*(distance / 2.0));
preset->addClipPlane(positDir, center + positDir*(size / 2.0f)*(side));
preset->addClipPlane(negDir, center + negDir*(size / 2.0f)*(side));
// Set clipping mode
preset->setClippingMode(ClippingShader::CLIPPING_MODE_AND);
ClippingShader::clippingMode clipMode = ClippingShader::CLIPPING_MODE_AND;
if (facing)
clipMode = ClippingShader::CLIPPING_MODE_OR;
preset->setClippingMode(clipMode);
return preset;
}
ClippingPreset* ClippingPreset::CreateCubePreset(Geom::Vec3f center, float distance, bool facing)
ClippingPreset* ClippingPreset::CreateCubePreset(Geom::Vec3f center, float size, bool facing)
{
ClippingPreset *preset = new ClippingPreset;
// Directions
Geom::Vec3f xAxisPos = Geom::Vec3f (1.0, 0.0, 0.0);
Geom::Vec3f xAxisNeg = Geom::Vec3f (-1.0, 0.0, 0.0);
Geom::Vec3f yAxisPos = Geom::Vec3f (0.0, 1.0, 0.0);
Geom::Vec3f yAxisNeg = Geom::Vec3f (0.0, -1.0, 0.0);
Geom::Vec3f zAxisPos = Geom::Vec3f (0.0, 0.0, 1.0);
Geom::Vec3f zAxisNeg = Geom::Vec3f (0.0, 0.0, -1.0);
Geom::Vec3f xAxisPos = Geom::Vec3f (1.0f, 0.0f, 0.0f);
Geom::Vec3f xAxisNeg = Geom::Vec3f (-1.0f, 0.0f, 0.0f);
Geom::Vec3f yAxisPos = Geom::Vec3f (0.0f, 1.0f, 0.0f);
Geom::Vec3f yAxisNeg = Geom::Vec3f (0.0f, -1.0f, 0.0f);
Geom::Vec3f zAxisPos = Geom::Vec3f (0.0f, 0.0f, 1.0f);
Geom::Vec3f zAxisNeg = Geom::Vec3f (0.0f, 0.0f, -1.0f);
// Facing of planes
float side = 1.0;
if (facing)
side = -1.0;
// Add planes to preset
preset->addClipPlane(xAxisPos, center + xAxisPos*(distance / 2.0));
preset->addClipPlane(xAxisNeg, center + xAxisNeg*(distance / 2.0));
preset->addClipPlane(yAxisPos, center + yAxisPos*(distance / 2.0));
preset->addClipPlane(yAxisNeg, center + yAxisNeg*(distance / 2.0));
preset->addClipPlane(zAxisPos, center + zAxisPos*(distance / 2.0));
preset->addClipPlane(zAxisNeg, center + zAxisNeg*(distance / 2.0));
preset->addClipPlane(xAxisPos, center + xAxisPos*(size / 2.0f)*(side));
preset->addClipPlane(xAxisNeg, center + xAxisNeg*(size / 2.0f)*(side));
preset->addClipPlane(yAxisPos, center + yAxisPos*(size / 2.0f)*(side));
preset->addClipPlane(yAxisNeg, center + yAxisNeg*(size / 2.0f)*(side));
preset->addClipPlane(zAxisPos, center + zAxisPos*(size / 2.0f)*(side));
preset->addClipPlane(zAxisNeg, center + zAxisNeg*(size / 2.0f)*(side));
// Set clipping mode
preset->setClippingMode(ClippingShader::CLIPPING_MODE_AND);
ClippingShader::clippingMode clipMode = ClippingShader::CLIPPING_MODE_AND;
if (facing)
clipMode = ClippingShader::CLIPPING_MODE_OR;
preset->setClippingMode(clipMode);
return preset;
}
......
......@@ -45,7 +45,7 @@ ClippingShader::ClippingShader():
// Initialize default global clipping variables
m_hasClippingCodeBeenInserted (false),
m_clipColorAttenuationFactor (1.0),
m_clipColorAttenuationFactor (1.0f),
m_unif_clipColorAttenuationFactor (0),
m_colorAttenuationMode (COLOR_ATTENUATION_MODE_LINEAR),
m_clipMode (CLIPPING_MODE_AND)
......@@ -94,15 +94,15 @@ unsigned int ClippingShader::addClipPlane()
m_clipPlanes.resize((size_t)(previousPlanesCount + 1));
if (newPlaneId >= m_clipPlanesIds.size())
m_clipPlanesIds.resize((size_t)(newPlaneId + 1));
m_clipPlanesEquations.resize(4*(size_t)(previousPlanesCount + 1), 0.0);
m_clipPlanesEquations.resize(4*(size_t)(previousPlanesCount + 1), 0.0f);
// Set new plane id
m_clipPlanesIds[newPlaneId].used = true;
m_clipPlanesIds[newPlaneId].index = previousPlanesCount;
// Set default parameters values for the new plane
Geom::Vec3f defaultNormal (0.0, 0.0, 1.0);
Geom::Vec3f defaultOrigin (0.0, 0.0, 0.0);
Geom::Vec3f defaultNormal (0.0f, 0.0f, 1.0f);
Geom::Vec3f defaultOrigin (0.0f, 0.0f, 0.0f);
setClipPlaneParamsAll(newPlaneId, defaultNormal, defaultOrigin);
// Recompile shaders (automatically calls updateClippingUniforms)
......@@ -285,9 +285,9 @@ Geom::Vec3f ClippingShader::getClipPlaneParamsNormal(unsigned int id)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::getClipPlaneParamsFirstVec"))
return Geom::Vec3f(0.0, 0.0, 0.0);
return Geom::Vec3f(0.0f, 0.0f, 0.0f);
if (errorRaiseWrongId(!m_clipPlanesIds[id].used, "ClippingShader::getClipPlaneParamsFirstVec"))
return Geom::Vec3f(0.0, 0.0, 0.0);
return Geom::Vec3f(0.0f, 0.0f, 0.0f);
// Get the corresponding plane index
int planeIndex = m_clipPlanesIds[id].index;
......@@ -300,9 +300,9 @@ Geom::Vec3f ClippingShader::getClipPlaneParamsOrigin(unsigned int id)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::getClipPlaneParamsOrigin"))
return Geom::Vec3f(0.0, 0.0, 0.0);
return Geom::Vec3f(0.0f, 0.0f, 0.0f);
if (errorRaiseWrongId(!m_clipPlanesIds[id].used, "ClippingShader::getClipPlaneParamsOrigin"))
return Geom::Vec3f(0.0, 0.0, 0.0);
return Geom::Vec3f(0.0f, 0.0f, 0.0f);