Commit e13ec600 authored by CGoGN GIT Supervisor's avatar CGoGN GIT Supervisor

Merge branch 'master' of /home/maire/CGoGN

* 'master' of /home/maire/CGoGN:
  Fin de staaaaaaaaage !!!
  Rajout de 2 presets animés. Quelques améliorations dans l'appli clipping
  Rajout d'un preset animé.
  Rajout d'une option zigzag dans un des presets animés.
  Rajout d'un module de presets de clipping animés. Intégration (plus ou moins finie) dans l'interface Qt de clipping.
parents 52e633f8 6c799243
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,15 @@ 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_setAnimationState(bool state);
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>-100.000000000000000</double>
</property>
<property name="maximum">
<double>100.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"
#include <cmath>
#include <vector>
#include <cstdlib>
#include <time.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
* @param zigzag true to enable zigzag mode
*/
ClippingPresetAnimatedDualPlanes(
Geom::Vec3f centerStart, Geom::Vec3f centerEnd, float size, int axis, bool facing, bool zigzag);
/**
* 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;
/// zigzag mode ?
bool m_zigzag;
};
class ClippingPresetAnimatedRotatingPlane : public ClippingPresetAnimated
{
public :
/**
* constructor
* @param center center of plane
* @param axis axis on which plane is aligned (0 for x, 1 for y, 2 for z)
*/
ClippingPresetAnimatedRotatingPlane(Geom::Vec3f center, int axis);
/**
* runs the animation some steps further
* @param amount amount of steps the animation should do
*/
void step(unsigned int amount);
private :
/// axis of plane
int m_axis;
};
class ClippingPresetAnimatedScaledSphere : public ClippingPresetAnimated
{
public :
/**
* constructor
* @param center center of sphere
* @param radiusStart radius of the sphere at the beginning of the animation
* @param radiusEnd radius of the sphere at the end of the animation
* @param zigzag true to enable zigzag mode
*/
ClippingPresetAnimatedScaledSphere(Geom::Vec3f center, float radiusStart, float radiusEnd, bool zigzag);
/**
* runs the animation some steps further
* @param amount amount of steps the animation should do
*/
void step(unsigned int amount);
private :
/// start radius of the animation
float m_startRadius;
/// end radius of the animation
float m_endRadius;
/// zigzag mode ?
bool m_zigzag;
};
class ClippingPresetAnimatedSpheresCubeCollision : public ClippingPresetAnimated
{
public :
/**
* constructor
* @param center center of cube
* @param size size of cube
* @param spheresCount spheres count
* @param radius radius of spheres
*/
ClippingPresetAnimatedSpheresCubeCollision(Geom::Vec3f center, float size, int spheresCount, float radius);
/**
* runs the animation some steps further
* @param amount amount of steps the animation should do
*/
void step(unsigned int amount);
private :
/// center of cube
Geom::Vec3f m_cubeCenter;
/// size of cube
float m_cubeSize;
/// direction vector of spheres
std::vector<Geom::Vec3f> m_spheresDirections;
};
} // 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);
......
......@@ -50,14 +50,15 @@ ClippingPreset* ClippingPreset::CreateDualPlanesPreset(Geom::Vec3f center, float
ClippingPreset *preset = new ClippingPreset;
// Correct axis if necessary
if ((axis < 0) || (axis > 2))
axis = 0;
int usedAxis = axis;
if ((usedAxis < 0) || (usedAxis > 2))
usedAxis = 0;
// Axis on which planes will be aligned
Geom::Vec3f positDir (0.0f, 0.0f, 0.0f);
positDir[axis] = 1.0f;
positDir[usedAxis] = 1.0f;
Geom::Vec3f negDir (0.0f, 0.0f, 0.0f);
negDir[axis] = -1.0f;
negDir[usedAxis] = -1.0f;
// Facing of planes
float side = 1.0f;
......@@ -116,8 +117,9 @@ ClippingPreset* ClippingPreset::CreateTubePreset(Geom::Vec3f center, float size,
ClippingPreset *preset = new ClippingPreset;
// Correct axis if necessary
if ((axis < 0) || (axis > 2))
axis = 0;
int usedAxis = axis;
if ((usedAxis < 0) || (usedAxis > 2))
usedAxis = 0;
// Correct precision if necessary
if (precision < 1)
......@@ -129,12 +131,12 @@ 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++)
{
direction[(axis + 1) % 3] = cos(i*dAngle);
direction[(axis + 2) % 3] = sin(i*dAngle);
direction[(usedAxis + 1) % 3] = cos(i*dAngle);
direction[(usedAxis + 2) % 3] = sin(i*dAngle);
preset->addClipPlane(direction, center + direction*(size / 2.0f)*(side));
}
......
This diff is collapsed.
......@@ -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;
}
void ClippingShader::setClipSphereParamsAll(unsigned int id, Geom::Vec3f center, float radius)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::setClipSphereParamsAll"))
return;
if (errorRaiseWrongId(!m_clipSpheresIds[id].used, "ClippingShader::setClipSphereParamsAll"))
if (errorRaiseWrongId(!isClipSphereIdValid(id), "ClippingShader::setClipSphereParamsAll"))
return;
// Get the corresponding sphere index
......@@ -520,9 +532,7 @@ void ClippingShader::setClipSphereParamsAll(unsigned int id, Geom::Vec3f center,
void ClippingShader::setClipSphereParamsCenter(unsigned int id, Geom::Vec3f center)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::setClipSphereParamsCenter"))
return;
if (errorRaiseWrongId(!m_clipSpheresIds[id].used, "ClippingShader::setClipSphereParamsCenter"))
if (errorRaiseWrongId(!isClipSphereIdValid(id), "ClippingShader::setClipSphereParamsCenter"))
return;
// Get the corresponding sphere index
......@@ -545,9 +555,7 @@ void ClippingShader::setClipSphereParamsCenter(unsigned int id, Geom::Vec3f cent
void ClippingShader::setClipSphereParamsRadius(unsigned int id, float radius)
{
// Check if the given id is valid
if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::setClipSphereParamsRadius"))
return;
if (errorRaiseWrongId(!m_clipSpheresIds[id].used, "ClippingShader::setClipSphereParamsRadius"))
if (errorRaiseWrongId(!isClipSphereIdValid(id), "ClippingShader::setClipSphereParamsRadius"))
return;
// Get the corresponding sphere index
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment