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,314 +32,388 @@
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkBox_vertices">
<property name="text">
<string>Vertices</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_lines">
<property name="text">
<string>Lines</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_faces">
<property name="text">
<string>Faces</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_topo">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Topo</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="explod_phi2">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>0.900000000000000</double>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="explod_phi3">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>0.900000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_faces">
<property name="text">
<string>Faces</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_volumes">
<property name="text">
<string>Volumes</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="explod_phi1">
<property name="prefix">
<string/>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>0.900000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_edges">
<property name="text">
<string>Edges</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="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>
<widget class="QGroupBox" name="groupBox_clipPlanes">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Clipping Planes</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_addPlane">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_12">
<item row="0" column="0">
<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_GridResolution">
<property name="maximum">
<number>200</number>
</property>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkBox_vertices">
<property name="text">
<string>Vertices</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_lines">
<property name="text">
<string>Lines</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_faces">
<property name="text">
<string>Faces</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_topo">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Topo</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<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_changePlanesColor">
<property name="text">
<string>Change Color</string>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="explod_phi2">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>0.900000000000000</double>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="explod_phi3">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>0.900000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_faces">
<property name="text">
<string>Faces</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_volumes">
<property name="text">
<string>Volumes</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="explod_phi1">
<property name="prefix">
<string/>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>0.900000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_edges">
<property name="text">
<string>Edges</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</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>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="title">
<string>Clipping Spheres</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pushButton_addSphere">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_13">
<item row="0" column="0">
<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_SphereResolution">
<property name="maximum">
<number>200</number>
</property>
</widget>
</item>
<item row="1" column="0">
<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_changeSpheresColor">
<property name="text">
<string>Change Color</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_8">
</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_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>
<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>