Tulip  5.0.0
Large graphs analysis and drawing
GlSceneZoomAndPan.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 #ifndef GLSCENEZOOMANDPAN_H_
20 #define GLSCENEZOOMANDPAN_H_
21 
22 #include <tulip/tulipconf.h>
23 #include <tulip/Vector.h>
24 #include <tulip/Coord.h>
25 
26 namespace tlp {
27 
28 class GlScene;
29 struct BoundingBox;
30 class Camera;
31 
32 /**
33  * \brief A class which encapsulate a Tulip OpenGL scene animation
34  * This class aims to encapsulate a Tulip OpenGL scene animation.
35  * Derive it if you want to add extra animations to the Tulip OpenGL scene while a Zoom and Pan is performed
36  */
37 class TLP_GL_SCOPE AdditionalGlSceneAnimation {
38 
39 public :
40 
41  virtual ~AdditionalGlSceneAnimation() {}
42 
43  /**
44  * Method to set the total number of animation steps. No need to call it because the GlSceneZoomAndPan class do that task.
45  *
46  */
47  inline void setNbAnimationSteps(int nbAnimationSteps) {
48  this->nbAnimationSteps = nbAnimationSteps;
49  }
50 
51  /**
52  * Pure virtual method called at each step of the Zoom and Pan animation.
53  *
54  * Implement it in your derived class to perform any extra animation you want on the Tulip OpenGL scene.
55  */
56  virtual void animationStep(int animationStep) = 0;
57 
58 protected :
59 
60  int nbAnimationSteps;
61 };
62 
63 /** \brief A convenient class to perform Zoom and Pan animation on Tulip OpenGL scene
64  *
65  * This class allow to perform a smooth and efficient zooming and panning on Tulip OpenGL scene.
66  * The algorithm used to perform this task is the one published in: Jarke J. van Wijk and Wim A.A. Nuij, "Smooth and efficient zooming and panning"
67  * For more details, the paper can be downloaded at the following url: http://www.win.tue.nl/~vanwijk/zoompan.pdf
68  * Even if this class contains the whole Zoom and Pan implementation, it is not aimed to be used directly because its role is only to compute new camera parameters.
69  * Use the derived class QtGlSceneZoomAndPanAnimator in the tulip-gui library instead to perform the animation.
70  */
71 class TLP_GL_SCOPE GlSceneZoomAndPan {
72 
73 public :
74 
75  virtual ~GlSceneZoomAndPan() {}
76 
77  /**
78  * GlSceneZoomAndPan constructor
79  *
80  * \param glScene the Tulip OpenGL scene on which to perform zooming and panning
81  * \param boundingBox the bounding box in scene coordinates on which the Tulip OpenGL scene has to be zoomed and panned.
82  * At the end of the animation, the viewport will be zoomed and centered on the content of that bounding box.
83  * \param layerName The name of the layer animation should be done on
84  * \param nbAnimationSteps the number of steps to perform during the animation
85  * \param optimalPath if true zooming and panning will be combined at each step of the animation, if false the scene will be zoomed out/in, panned then zoomed in/out
86  * \param p zoom/pan trade-off parameter, adjust it according to your needs
87  */
88  GlSceneZoomAndPan(GlScene *glScene, const BoundingBox &boundingBox, const std::string &layerName="Main", const int nbAnimationSteps = 50, const bool optimalPath = true, const double p = sqrt(1.6));
89 
90  /**
91  * Method to add an additional scene animation while zooming and panning
92  *
93  * \param additionalAnimation The animation to add
94  */
95  void setAdditionalGlSceneAnimation(AdditionalGlSceneAnimation *additionalAnimation);
96 
97  /**
98  * Method which return the number of animation steps
99  */
100  inline int getNbAnimationsStep() const {
101  return nbAnimationSteps;
102  }
103 
104  /**
105  * Method to set the number of animation steps
106  */
107  inline void setNbAnimationSteps(const int nbAnimationSteps) {
108  this->nbAnimationSteps = nbAnimationSteps;
109  }
110 
111  /**
112  * Method which performs the zoom and pan animation. Its role is to compute new camera parameters at step animationStep.
113  * The scene is not redrawn with this method, you have to call the draw method on the associated GlScene object
114  */
115  void zoomAndPanAnimationStep(int animationStep);
116 
117 protected :
118 
119  Camera &camera;
120  Vector<int, 4> viewport;
121  int nbAnimationSteps;
122  bool optimalPath;
123  double p;
124  Coord camCenterStart, camCenterEnd;
125  double w0, w1, u0, u1, b0, b1, r0, r1, S, sA, sB, wm;
126  AdditionalGlSceneAnimation *additionalAnimation;
127  float zoomAreaWidth, zoomAreaHeight;
128  bool doZoomAndPan;
129 
130 };
131 
132 }
133 
134 #endif /* GLSCENEZOOMANDPAN_H_ */
void setNbAnimationSteps(const int nbAnimationSteps)
void setNbAnimationSteps(int nbAnimationSteps)
A class which encapsulate a Tulip OpenGL scene animation This class aims to encapsulate a Tulip OpenG...
A convenient class to perform Zoom and Pan animation on Tulip OpenGL scene.
Tulip scene class.
Definition: GlScene.h:153
This class represents the 3D bounding box of an object. It is mostly used to determine whether or not...
Definition: BoundingBox.h:63
Tulip OpenGL camera object.
Definition: Camera.h:45
int getNbAnimationsStep() const