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
This diff is collapsed.
......@@ -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);
/**
* sets all parameters for one clip plane
* @param id clip plane id
* @param normal normal
* @param origin origin
* @return true on success
*/
void setClipPlaneParamsAll(unsigned int id, Geom::Vec3f normal, Geom::Vec3f origin);
......@@ -94,6 +98,7 @@ public:
* sets first vector for one clip plane
* @param id clip plane id
* @param normal normal
* @return true on success
*/
void setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f normal);
......@@ -101,6 +106,7 @@ public:
* sets origin for one clip plane
* @param id clip plane id
* @param origin origin
* @return true on success
*/
void setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origin);
......@@ -180,11 +186,15 @@ public:
/// gets the clip spheres count
int getClipSpheresCount();
/// checks if clip sphere id is valid
bool isClipSphereIdValid(unsigned int id);
/**
* sets all parameters for one clip sphere
* @param id clip sphere id
* @param center center
* @param radius radius
* @return true on success
*/
void setClipSphereParamsAll(unsigned int id, Geom::Vec3f center, float radius);
......@@ -192,6 +202,7 @@ public:
* sets center for one clip sphere
* @param id clip sphere id
* @param center center
* @return true on success
*/
void setClipSphereParamsCenter(unsigned int id, Geom::Vec3f center);
......@@ -199,6 +210,7 @@ public:
* sets radius for one clip sphere
* @param id clip sphere id
* @param radius radius
* @return true on success
*/
void setClipSphereParamsRadius(unsigned int id, float radius);
......
......@@ -129,7 +129,7 @@ ClippingPreset* ClippingPreset::CreateTubePreset(Geom::Vec3f center, float size,
side = -1.0f;
// Add planes to preset
Geom::Vec3f direction (0.0, 0.0, 0.0);
Geom::Vec3f direction (0.0f, 0.0f, 0.0f);
float dAngle = 2.0f * M_PI / precision;
for (int i = 0; i < precision; i++)
{
......
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
#include "Utils/clippingPresetsAnimated.h"
namespace CGoGN
{
namespace Utils
{
/***********************************************
*
* Base Class
*
***********************************************/
void ClippingPresetAnimated::apply(ClippingShader* clipShader, std::vector<unsigned int> *planesIds, std::vector<unsigned int> *spheresIds)
{
if ( (clipShader == NULL) || (planesIds == NULL) || (spheresIds == NULL) )
return;
// Apply preset
ClippingPreset::apply(clipShader, planesIds, spheresIds);
// Store the clipping shader pointer
m_attachedClippingShader = clipShader;
// Store ids
m_planesIds.resize(0);
m_planesIds.insert(m_planesIds.begin(), planesIds->begin(), planesIds->end());
m_spheresIds.resize(0);
m_spheresIds.insert(m_spheresIds.begin(), spheresIds->begin(), spheresIds->end());
}
/***********************************************
*
* Derived Classes
*
***********************************************/
ClippingPresetAnimatedDualPlanes::ClippingPresetAnimatedDualPlanes(
Geom::Vec3f centerStart, Geom::Vec3f centerEnd, float size, int axis, bool facing)
{
// Store the animation settings
m_dirVec = centerEnd - centerStart;
m_dirVec.normalize();
m_startPoint = centerStart;
m_endPoint = centerEnd;
// Correct axis if necessary
if ((axis < 0) || (axis > 2))
axis = 0;
// Axis on which planes will be aligned
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.0f;
if (facing)
side = -1.0f;
// Add planes to preset
addClipPlane(positDir, centerStart + positDir*(size / 2.0f)*(side));
addClipPlane(negDir, centerStart + negDir*(size / 2.0f)*(side));
// Set clipping mode
ClippingShader::clippingMode clipMode = ClippingShader::CLIPPING_MODE_AND;
if (facing)
clipMode = ClippingShader::CLIPPING_MODE_OR;
setClippingMode(clipMode);
}
void ClippingPresetAnimatedDualPlanes::step(unsigned int amount)
{
// Check if the animation has been stopped
if (m_animationSpeedFactor == 0.0f)
return;
// Check the validity of planes or spheres ids
if ( !m_attachedClippingShader->isClipPlaneIdValid(m_planesIds[0])
|| !m_attachedClippingShader->isClipPlaneIdValid(m_planesIds[1]) )
{
CGoGNerr
<< "ERROR -"
<< "ClippingPresetAnimatedDualPlanes::step"
<< " - Some planes or spheres ids are not valid anymore - Animation stopped"
<< CGoGNendl;
m_animationSpeedFactor = 0.0f;
return;
}
// Store the old center
Geom::Vec3f oldCenter = (1.0f - m_animParam)*m_startPoint + m_animParam*m_endPoint;
// Update animation parameter value
m_animParam += (float)amount * m_animationOneStepIncrement * m_animationSpeedFactor;
while (m_animParam < 0.0f)
m_animParam += 1.0f;
while (m_animParam > 1.0f)
m_animParam -= 1.0f;
// Calculate new center
Geom::Vec3f newCenter = (1.0f - m_animParam)*m_startPoint + m_animParam*m_endPoint;
// Update clipping planes
Geom::Vec3f plane1CurrPos = m_attachedClippingShader->getClipPlaneParamsOrigin(m_planesIds[0]);
Geom::Vec3f plane2CurrPos = m_attachedClippingShader->getClipPlaneParamsOrigin(m_planesIds[1]);
m_attachedClippingShader->setClipPlaneParamsOrigin(m_planesIds[0], plane1CurrPos + newCenter - oldCenter);
m_attachedClippingShader->setClipPlaneParamsOrigin(m_planesIds[1], plane2CurrPos + newCenter - oldCenter);
}
} // namespace Utils
} // namespace CGoGN
......@@ -196,12 +196,20 @@ int ClippingShader::getClipPlanesCount()
return (int)m_clipPlanes.size();
}
bool ClippingShader::isClipPlaneIdValid(unsigned int id)
{
if (id > m_clipPlanesIds.size())
return false;
if (!m_clipPlanesIds[id].used)
return false;
return true;
}
void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f normal, Geom::Vec3f origin)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsAll"))
return;
if (errorRaiseWrongId(!m_clipPlanesIds[id].used, "ClippingShader::setClipPlaneParamsAll"))
if (errorRaiseWrongId(!isClipPlaneIdValid(id), "ClippingShader::setClipPlaneParamsAll"))
return;
// Get the corresponding plane index
......@@ -230,9 +238,7 @@ void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f normal,
void ClippingShader::setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f normal)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsFirstVec"))
return;
if (errorRaiseWrongId(!m_clipPlanesIds[id].used, "ClippingShader::setClipPlaneParamsFirstVec"))
if (errorRaiseWrongId(!isClipPlaneIdValid(id), "ClippingShader::setClipPlaneParamsFirstVec"))
return;
// Get the corresponding plane index
......@@ -259,9 +265,7 @@ void ClippingShader::setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f norma
void ClippingShader::setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origin)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsOrigin"))
return;
if (errorRaiseWrongId(!m_clipPlanesIds[id].used, "ClippingShader::setClipPlaneParamsOrigin"))
if (errorRaiseWrongId(!isClipPlaneIdValid(id), "ClippingShader::setClipPlaneParamsOrigin"))
return;
// Get the corresponding plane index
......@@ -490,12 +494,20 @@ int ClippingShader::getClipSpheresCount()
return (int)m_clipSpheres.size();
}
bool ClippingShader::isClipSphereIdValid(unsigned int id)
{
if (id > m_clipSpheresIds.size())
return false;
if (!m_clipSpheresIds[id].used)
return false;
return true;
}