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

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 @@
* 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
if (vec1.norm() < epsilon)
if (inVec1.norm() < epsilon)
return;
// 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
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());
vec2 = inVec1 ^ tempVec;
float sinAngle = vec2.norm() / (inVec1.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;
vec2 = inVec1 ^ tempVec;
}
// Normalize second vector
vec2.normalize();
// 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()
}
}
m_lastPickedObject = NULL;
m_frameManipulator->highlight(m_frameManipulatorPickedAxis);
m_frameManipulatorPickedAxis = 0;
// Update shader sources edits
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
......@@ -257,11 +291,11 @@ void Clipping::slot_pushButton_deleteSelectedObject()
}
}
void Clipping::slot_pushButton_applyClippingPreset()
void Clipping::slot_pushButton_applyStaticClippingPreset()
{
// Create and apply preset
Utils::ClippingPreset *preset = NULL;
switch (dock.comboBox_ClippingPresets->currentIndex())
switch (dock.comboBox_StaticClippingPresets->currentIndex())
{
case 0 : // Dual planes
{
......@@ -347,6 +381,10 @@ void Clipping::slot_pushButton_applyClippingPreset()
}
break;
}
if (preset == NULL)
return;
std::vector<unsigned int> planesIds;
std::vector<unsigned int> spheresIds;
preset->apply(m_shader, &planesIds, &spheresIds);
......@@ -365,28 +403,99 @@ void Clipping::slot_pushButton_applyClippingPreset()
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]));
m_pickableSpheres.push_back(pickable);
}
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);
}
updatePickables();
// Update shader sources edits
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
......@@ -399,10 +508,43 @@ void Clipping::slot_pushButton_applyClippingPreset()
else if (clipMode == Utils::ClippingShader::CLIPPING_MODE_OR)
dock.radioButton_ClippingModeOr->setChecked(true);
// Set on animated mode
m_lastAnimatedClippingPreset = animatedPreset;
m_timer->start(1000.0f/60.0f);
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()
{
QString st1 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->vertexEdit->toPlainText();
......@@ -427,7 +569,9 @@ Clipping::Clipping():
m_render(NULL),
m_render_topo(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);
}
......@@ -494,12 +638,24 @@ void Clipping::initGUI()
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");
dock.comboBox_ClippingPresets->addItem("Cube");
dock.comboBox_ClippingPresets->addItem("Tube");
dock.comboBox_ClippingPresets->addItem("Molecule");
// timer used for animation
m_timer = new QTimer( this );
setCallBack( m_timer, SIGNAL(timeout()), SLOT(slot_animationTimer()) );
}
......
......@@ -53,6 +53,7 @@
#include "Utils/frameManipulator.h"
#include "Utils/clippingPresets.h"
#include "Utils/clippingPresetsAnimated.h"
#include "Utils/cgognStream.h"
#include "Utils/drawer.h"
......@@ -107,6 +108,7 @@ public:
//QT
Utils::QT::uiDockInterface dock;
QTimer *m_timer;
// Picking
Utils::LineDrawable* m_planeDrawable;
......@@ -118,6 +120,9 @@ public:
Utils::Pickable* m_lastPickedObject;
int m_lastClickedX, m_lastClickedY;
// Clipping
Utils::ClippingPresetAnimated *m_lastAnimatedClippingPreset;
Clipping();
void initGUI();
......@@ -129,6 +134,7 @@ public:
void cb_mouseMove(int buttons, int x, int y);
void cb_keyPress(int code);
void importMesh(std::string& filename);
void updatePickables();
public slots:
void slot_drawVertices(bool b);
......@@ -156,7 +162,13 @@ public slots:
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();
};
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>374</width>
<height>783</height>
<height>780</height>
</rect>
</property>
<property name="allowedAreas">
......@@ -316,29 +316,6 @@
</item>
</layout>
</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>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
......@@ -413,6 +390,108 @@
</item>
</layout>
</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>
</item>
</layout>
......
......@@ -87,9 +87,9 @@ public :
*/
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();
......@@ -159,9 +159,9 @@ public :
* @param clipShader pointer to the clipping shader object
* @param planesIds returns the new added planes 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
*/
void apply(ClippingShader* clipShader, std::vector<unsigned int> *planesIds, std::vector<unsigned int> *spheresIds);
virtual void apply(ClippingShader* clipShader, std::vector<unsigned int> *planesIds, std::vector<unsigned int> *spheresIds);
};
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _CGoGN_CLIPPINGPRESETSANIMATED_H_
#define _CGoGN_CLIPPINGPRESETSANIMATED_H_
#include "Utils/clippingPresets.h"
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
namespace CGoGN
{
namespace Utils
{
/***********************************************
*
* Base Class
*
***********************************************/
class ClippingPresetAnimated : public ClippingPreset
{
public :
/// constructor
ClippingPresetAnimated():
m_attachedClippingShader (NULL),
m_animationOneStepIncrement (0.01),
m_animationSpeedFactor (1.0),
m_animParam (0.0)
{}
public :
/*
* sets the animation speed factor (can be negative for reverse animation)
* @param speedFactor speed factor
*/
void setAnimationSpeedFactor(float speedFactor) { m_animationSpeedFactor = speedFactor; }
/// gets the animation speed factor
float getAnimationSpeedFactor() { return m_animationSpeedFactor; }
protected :
/// attached Clipping Shader, used for updating clipping shapes params
ClippingShader *m_attachedClippingShader;
/// stored ids used for updating clipping shapes params
std::vector<unsigned int> m_planesIds;
/// stored ids used for updating clipping shapes params
std::vector<unsigned int> m_spheresIds;
/// one step increment of animation parameter
float m_animationOneStepIncrement;
/// speed factor of the animation
float m_animationSpeedFactor;
/// animation parameter value (usually between 0.0 and 1.0)
float m_animParam;
public :
/**
* applies the preset on a clipping shader and store its pointer
* @param clipShader pointer to the clipping shader object
* @param planesIds returns the new added planes ids
* @param spheresIds returns the new added spheres ids
* @warning clipShader, planesIds and spheresIds must not be NULL, otherwise the function does nothing
* @warning clipShader must remain valid as long as step is being used and apply has not been called again
*/
void apply(ClippingShader* clipShader, std::vector<unsigned int> *planesIds, std::vector<unsigned int> *spheresIds);
/**
* runs the animation some steps further
* @param amount amount of steps the animation should do
*/
virtual void step(unsigned int amount) = 0;
};
/***********************************************
*
* Derived Classes
*
***********************************************/
class ClippingPresetAnimatedDualPlanes : public ClippingPresetAnimated
{
public :
/**
* constructor
* @param centerStart center between planes at the start of the animation
* @param centerEnd center between planes at the end of the animation
* @param size distance between planes
* @param axis axis on which planes are aligned (0 for x, 1 for y, 2 for z)
* @param facing true means having facing planes
*/
ClippingPresetAnimatedDualPlanes(
Geom::Vec3f centerStart, Geom::Vec3f centerEnd, float size, int axis, bool facing);
/**
* runs the animation some steps further
* @param amount amount of steps the animation should do
*/
void step(unsigned int amount);
private :
/// direction vector
Geom::Vec3f m_dirVec;
/// start point of the animation
Geom::Vec3f m_startPoint;
/// end point of the animation
Geom::Vec3f m_endPoint;
};
} // namespace Utils
} // namespace CGoGN
#endif
......@@ -82,11 +82,15 @@ public:
/// gets the clip planes count
int getClipPlanesCount();
/// checks if clip plane id is valid
bool isClipPlaneIdValid(unsigned int id);
/**