Commit 44fd6316 authored by Maire Nicolas's avatar Maire Nicolas
Browse files

Rajout d'un module de presets de clipping animés. Intégration (plus ou moins...

Rajout d'un module de presets de clipping animés. Intégration (plus ou moins finie) dans l'interface Qt de clipping.
parent 13e149b1
...@@ -29,12 +29,12 @@ ...@@ -29,12 +29,12 @@
* MISCELLANOUS * MISCELLANOUS
*******************************************************************************/ *******************************************************************************/
void computeBasisFromVector(const Geom::Vec3f& vec1, Geom::Vec3f& vec2, Geom::Vec3f& vec3) void computeBasisFromVector(const Geom::Vec3f& inVec1, Geom::Vec3f& vec2, Geom::Vec3f& vec3)
{ {
const float epsilon = 0.0001f; const float epsilon = 0.000001f;
// Check if the given vector length is acceptable // Check if the given vector length is acceptable
if (vec1.norm() < epsilon) if (inVec1.norm() < epsilon)
return; return;
// First take a non colinear second vector to cross product with vec1 // First take a non colinear second vector to cross product with vec1
...@@ -42,17 +42,49 @@ void computeBasisFromVector(const Geom::Vec3f& vec1, Geom::Vec3f& vec2, Geom::Ve ...@@ -42,17 +42,49 @@ void computeBasisFromVector(const Geom::Vec3f& vec1, Geom::Vec3f& vec2, Geom::Ve
Geom::Vec3f tempVec (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 // Construct second vector, check other vectors non colinearity at the same time
vec2 = vec1 ^ tempVec; vec2 = inVec1 ^ tempVec;
float sinAngle = vec2.norm() / (vec1.norm() + tempVec.norm()); float sinAngle = vec2.norm() / (inVec1.norm()*tempVec.norm());
if (sinAngle < epsilon) // f:x->sin(x) ~ f:x->x when x ~ 0 if (sinAngle < epsilon) // f:x->sin(x) ~ f:x->x when x ~ 0
{ {
tempVec = Geom::Vec3f (1.0, 0.0, 0.0); tempVec = Geom::Vec3f (1.0, 0.0, 0.0);
vec2 = vec1 ^ tempVec; vec2 = inVec1 ^ tempVec;
} }
// Normalize second vector
vec2.normalize();
// Get third vector // Get third vector
vec3 = vec1 ^ vec2; vec3 = inVec1 ^ vec2;
// Normalize third vector
vec3.normalize();
}
void Clipping::updatePickables()
{
for (size_t i = 0; i < m_pickablePlanes.size(); i++)
{
unsigned int id = m_pickablePlanes[i]->id();
Geom::Vec3f pos = m_shader->getClipPlaneParamsOrigin(id);
Geom::Vec3f vec1, vec2, vec3;
vec1 = m_shader->getClipPlaneParamsNormal(id);
computeBasisFromVector(vec1, vec2, vec3);
glm::mat4& transfoMat = m_pickablePlanes[i]->transfo();
for (int j = 0; j < 3; j++)
{
transfoMat[0][j] = vec2[j];
transfoMat[1][j] = vec3[j];
transfoMat[2][j] = vec1[j];
transfoMat[3][j] = pos[j];
}
}
for (size_t i = 0; i < m_pickableSpheres.size(); i++)
{
unsigned int id = m_pickableSpheres[i]->id();
m_pickableSpheres[i]->translate(m_shader->getClipSphereParamsCenter(id));
m_pickableSpheres[i]->scale(m_shader->getClipSphereParamsRadius(id));
}
} }
/******************************************************************************* /*******************************************************************************
...@@ -247,6 +279,8 @@ void Clipping::slot_pushButton_deleteSelectedObject() ...@@ -247,6 +279,8 @@ void Clipping::slot_pushButton_deleteSelectedObject()
} }
} }
m_lastPickedObject = NULL; m_lastPickedObject = NULL;
m_frameManipulator->highlight(m_frameManipulatorPickedAxis);
m_frameManipulatorPickedAxis = 0;
// Update shader sources edits // Update shader sources edits
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc())); dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
...@@ -257,11 +291,11 @@ void Clipping::slot_pushButton_deleteSelectedObject() ...@@ -257,11 +291,11 @@ void Clipping::slot_pushButton_deleteSelectedObject()
} }
} }
void Clipping::slot_pushButton_applyClippingPreset() void Clipping::slot_pushButton_applyStaticClippingPreset()
{ {
// Create and apply preset // Create and apply preset
Utils::ClippingPreset *preset = NULL; Utils::ClippingPreset *preset = NULL;
switch (dock.comboBox_ClippingPresets->currentIndex()) switch (dock.comboBox_StaticClippingPresets->currentIndex())
{ {
case 0 : // Dual planes case 0 : // Dual planes
{ {
...@@ -347,6 +381,10 @@ void Clipping::slot_pushButton_applyClippingPreset() ...@@ -347,6 +381,10 @@ void Clipping::slot_pushButton_applyClippingPreset()
} }
break; break;
} }
if (preset == NULL)
return;
std::vector<unsigned int> planesIds; std::vector<unsigned int> planesIds;
std::vector<unsigned int> spheresIds; std::vector<unsigned int> spheresIds;
preset->apply(m_shader, &planesIds, &spheresIds); preset->apply(m_shader, &planesIds, &spheresIds);
...@@ -365,28 +403,99 @@ void Clipping::slot_pushButton_applyClippingPreset() ...@@ -365,28 +403,99 @@ void Clipping::slot_pushButton_applyClippingPreset()
for (size_t i = 0; i < planesIds.size(); i++) for (size_t i = 0; i < planesIds.size(); i++)
{ {
Utils::Pickable* pickable = new Utils::Pickable(m_planeDrawable, planesIds[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); m_pickablePlanes.push_back(pickable);
} }
for (size_t i = 0; i < spheresIds.size(); i++) for (size_t i = 0; i < spheresIds.size(); i++)
{ {
Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, spheresIds[i]); Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, spheresIds[i]);
pickable->translate(m_shader->getClipSphereParamsCenter(spheresIds[i])); m_pickableSpheres.push_back(pickable);
pickable->scale(m_shader->getClipSphereParamsRadius(spheresIds[i])); }
updatePickables();
// 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::slot_pushButton_applyAnimatedClippingPreset()
{
// Create and apply preset
Utils::ClippingPresetAnimated *animatedPreset = NULL;
switch (dock.comboBox_AnimatedClippingPresets->currentIndex())
{
case 0 : // Moving Dual planes
{
Utils::ClippingPresetAnimatedDualPlanes *preset = NULL;
using namespace CGoGN::Utils::QT;
double centerStartX = (double)m_bb.center()[0] - (double)m_bb.size(0)*0.25;
double centerStartY = (double)m_bb.center()[1];
double centerStartZ = (double)m_bb.center()[2];
double centerEndX = (double)m_bb.center()[0] + (double)m_bb.size(0)*0.25;
double centerEndY = (double)m_bb.center()[1];
double centerEndZ = (double)m_bb.center()[2];
double size = (double)m_bb.maxSize()*0.1;
int axis = 0;
bool facing = false;
if (inputValues(VarDbl(centerStartX - 100.0, centerStartX + 100.0, centerStartX, "Center Start X",
VarDbl(centerStartY - 100.0, centerStartY + 100.0, centerStartY, "Center Start Y",
VarDbl(centerStartZ - 100.0, centerStartZ + 100.0, centerStartZ, "Center Start Z",
VarDbl(centerEndX - 100.0, centerEndX + 100.0, centerEndX, "Center End X",
VarDbl(centerEndY - 100.0, centerEndY + 100.0, centerEndY, "Center End Y",
VarDbl(centerEndZ - 100.0, centerEndZ + 100.0, centerEndZ, "Center End Z",
VarDbl(size - 100.0, size + 100.0, size, "Size",
VarSlider(0, 2, axis, "Axis",
VarBool(facing, "Facing"
))))))))), "Preset Setup"))
preset = new Utils::ClippingPresetAnimatedDualPlanes(
Geom::Vec3f((float)centerStartX, (float)centerStartY, (float)centerStartZ), Geom::Vec3f((float)centerEndX, (float)centerEndY, (float)centerEndZ),
(float)size, axis, facing);
animatedPreset = preset;
}
break;
}
if (animatedPreset == NULL)
return;
std::vector<unsigned int> planesIds;
std::vector<unsigned int> spheresIds;
animatedPreset->apply(m_shader, &planesIds, &spheresIds);
// 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]);
m_pickablePlanes.push_back(pickable);
}
for (size_t i = 0; i < spheresIds.size(); i++)
{
Utils::Pickable* pickable = new Utils::Pickable(m_sphereDrawable, spheresIds[i]);
m_pickableSpheres.push_back(pickable); m_pickableSpheres.push_back(pickable);
} }
updatePickables();
// Update shader sources edits // Update shader sources edits
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc())); dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
...@@ -399,10 +508,43 @@ void Clipping::slot_pushButton_applyClippingPreset() ...@@ -399,10 +508,43 @@ void Clipping::slot_pushButton_applyClippingPreset()
else if (clipMode == Utils::ClippingShader::CLIPPING_MODE_OR) else if (clipMode == Utils::ClippingShader::CLIPPING_MODE_OR)
dock.radioButton_ClippingModeOr->setChecked(true); dock.radioButton_ClippingModeOr->setChecked(true);
// Set on animated mode
m_lastAnimatedClippingPreset = animatedPreset;
m_timer->start(1000.0f/60.0f);
updateGLMatrices(); updateGLMatrices();
} }
void Clipping::slot_pushButton_StopAnimation()
{
if (m_lastAnimatedClippingPreset != NULL)
{
delete m_lastAnimatedClippingPreset;
m_lastAnimatedClippingPreset = NULL;
}
}
void Clipping::slot_doubleSpinBox_AnimatedClippingPresetSpeed(double c)
{
if (m_lastAnimatedClippingPreset != NULL)
m_lastAnimatedClippingPreset->setAnimationSpeedFactor((float)c);
}
void Clipping::slot_animationTimer()
{
if (m_lastAnimatedClippingPreset == NULL)
{
m_timer->stop();
return;
}
m_lastAnimatedClippingPreset->step(1);
updatePickables();
updateGL();
}
void Clipping::button_compile() void Clipping::button_compile()
{ {
QString st1 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->vertexEdit->toPlainText(); QString st1 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->vertexEdit->toPlainText();
...@@ -427,7 +569,9 @@ Clipping::Clipping(): ...@@ -427,7 +569,9 @@ Clipping::Clipping():
m_render(NULL), m_render(NULL),
m_render_topo(NULL), m_render_topo(NULL),
m_positionVBO(NULL), m_positionVBO(NULL),
m_shader(NULL) m_shader(NULL),
m_timer(NULL),
m_lastAnimatedClippingPreset(NULL)
{ {
m_coeffTopoExplod = Geom::Vec3f(0.9,0.9,0.9); m_coeffTopoExplod = Geom::Vec3f(0.9,0.9,0.9);
} }
...@@ -494,12 +638,24 @@ void Clipping::initGUI() ...@@ -494,12 +638,24 @@ void Clipping::initGUI()
dock.radioButton_ColorAttenuationModeQuadratic->setChecked(true); dock.radioButton_ColorAttenuationModeQuadratic->setChecked(true);
setCallBack(dock.PushButton_ApplyClippingPreset, SIGNAL(clicked()), SLOT(slot_pushButton_applyClippingPreset())); setCallBack(dock.PushButton_ApplyStaticClippingPreset, SIGNAL(clicked()), SLOT(slot_pushButton_applyStaticClippingPreset()));
dock.comboBox_StaticClippingPresets->addItem("Dual Planes");
dock.comboBox_StaticClippingPresets->addItem("Cube");
dock.comboBox_StaticClippingPresets->addItem("Tube");
dock.comboBox_StaticClippingPresets->addItem("Molecule");
setCallBack(dock.PushButton_ApplyAnimatedClippingPreset, SIGNAL(clicked()), SLOT(slot_pushButton_applyAnimatedClippingPreset()));
dock.comboBox_AnimatedClippingPresets->addItem("Moving Dual Planes");
setCallBack(dock.pushButton_StopAnimation, SIGNAL(clicked()), SLOT(slot_pushButton_StopAnimation()));
setCallBack(dock.doubleSpinBox_AnimatedClippingPresetSpeed, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_AnimatedClippingPresetSpeed(double)));
dock.comboBox_ClippingPresets->addItem("Dual Planes"); // timer used for animation
dock.comboBox_ClippingPresets->addItem("Cube"); m_timer = new QTimer( this );
dock.comboBox_ClippingPresets->addItem("Tube"); setCallBack( m_timer, SIGNAL(timeout()), SLOT(slot_animationTimer()) );
dock.comboBox_ClippingPresets->addItem("Molecule");
} }
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include "Utils/frameManipulator.h" #include "Utils/frameManipulator.h"
#include "Utils/clippingPresets.h" #include "Utils/clippingPresets.h"
#include "Utils/clippingPresetsAnimated.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
#include "Utils/drawer.h" #include "Utils/drawer.h"
...@@ -107,6 +108,7 @@ public: ...@@ -107,6 +108,7 @@ public:
//QT //QT
Utils::QT::uiDockInterface dock; Utils::QT::uiDockInterface dock;
QTimer *m_timer;
// Picking // Picking
Utils::LineDrawable* m_planeDrawable; Utils::LineDrawable* m_planeDrawable;
...@@ -118,6 +120,9 @@ public: ...@@ -118,6 +120,9 @@ public:
Utils::Pickable* m_lastPickedObject; Utils::Pickable* m_lastPickedObject;
int m_lastClickedX, m_lastClickedY; int m_lastClickedX, m_lastClickedY;
// Clipping
Utils::ClippingPresetAnimated *m_lastAnimatedClippingPreset;
Clipping(); Clipping();
void initGUI(); void initGUI();
...@@ -129,6 +134,7 @@ public: ...@@ -129,6 +134,7 @@ public:
void cb_mouseMove(int buttons, int x, int y); void cb_mouseMove(int buttons, int x, int y);
void cb_keyPress(int code); void cb_keyPress(int code);
void importMesh(std::string& filename); void importMesh(std::string& filename);
void updatePickables();
public slots: public slots:
void slot_drawVertices(bool b); void slot_drawVertices(bool b);
...@@ -156,7 +162,13 @@ public slots: ...@@ -156,7 +162,13 @@ public slots:
void slot_pushButton_deleteSelectedObject(); void slot_pushButton_deleteSelectedObject();
void slot_pushButton_applyClippingPreset(); void slot_pushButton_applyStaticClippingPreset();
void slot_pushButton_applyAnimatedClippingPreset();
void slot_pushButton_StopAnimation();
void slot_doubleSpinBox_AnimatedClippingPresetSpeed(double c);
void slot_animationTimer();
void button_compile(); void button_compile();
}; };
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>374</width> <width>374</width>
<height>783</height> <height>780</height>
</rect> </rect>
</property> </property>
<property name="allowedAreas"> <property name="allowedAreas">
...@@ -316,29 +316,6 @@ ...@@ -316,29 +316,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QGroupBox" name="groupBox_ClippingPresets">
<property name="title">
<string>Clipping Presets</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QComboBox" name="comboBox_ClippingPresets"/>
</item>
<item>
<widget class="QPushButton" name="PushButton_ApplyClippingPreset">
<property name="text">
<string>Apply Preset</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_10"> <layout class="QVBoxLayout" name="verticalLayout_10">
<item> <item>
...@@ -413,6 +390,108 @@ ...@@ -413,6 +390,108 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_ClippingPresets">
<attribute name="title">
<string>Clipping Presets</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QGroupBox" name="groupBox_StaticClippingPresets">
<property name="title">
<string>Static Clipping Presets</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QComboBox" name="comboBox_StaticClippingPresets"/>
</item>
<item>
<widget class="QPushButton" name="PushButton_ApplyStaticClippingPreset">
<property name="text">
<string>Apply Static Preset</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<widget class="QGroupBox" name="groupBox_AnimatedClippingPresets">
<property name="title">
<string>Animated Clipping Presets</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QComboBox" name="comboBox_AnimatedClippingPresets"/>
</item>
<item>
<widget class="QPushButton" name="PushButton_ApplyAnimatedClippingPreset">
<property name="text">
<string>Apply Animated Preset</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_StopAnimation">
<property name="text">
<string>Stop Animation</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_AnimatedClippingPresetSpeed">
<property name="title">
<string>Speed Factor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox_AnimatedClippingPresetSpeed">
<property name="minimum">
<double>-10.000000000000000</double>
</property>
<property name="maximum">
<double>10.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<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> </widget>
</item> </item>
</layout> </layout>
......
...@@ -87,9 +87,9 @@ public : ...@@ -87,9 +87,9 @@ public :
*/ */
static ClippingPreset* CreateMoleculePreset(Geom::Vec3f center, float size, float atomsRadiuses, bool orClipping); static ClippingPreset* CreateMoleculePreset(Geom::Vec3f center, float size, float atomsRadiuses, bool orClipping);
private : protected :
/// private constructor (used by public static constructors) /// protected constructor (used by public static constructors or child class)
ClippingPreset(); ClippingPreset();
...@@ -159,9 +159,9 @@ public : ...@@ -159,9 +159,9 @@ public :
* @param clipShader pointer to the clipping shader object * @param clipShader pointer to the clipping shader object
* @param planesIds returns the new added planes ids * @param planesIds returns the new added planes ids
* @param spheresIds returns the new added spheres ids * @param spheresIds returns the new added spheres ids
* @warning planesIds and spheresIds must not be NULL, otherwise the function does nothing * @warning clipShader, planesIds and spheresIds must not be NULL, otherwise the function does nothing
*/