Tulip  5.2.1
Large graphs analysis and drawing
GlSceneZoomAndPan.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
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
36  * performed
37  */
38 class TLP_GL_SCOPE AdditionalGlSceneAnimation {
39 
40 public:
41  virtual ~AdditionalGlSceneAnimation() {}
42 
43  /**
44  * Method to set the total number of animation steps. No need to call it because the
45  * GlSceneZoomAndPan class do that task.
46  *
47  */
48  inline void setNbAnimationSteps(int nbAnimationSteps) {
49  this->nbAnimationSteps = nbAnimationSteps;
50  }
51 
52  /**
53  * Pure virtual method called at each step of the Zoom and Pan animation.
54  *
55  * Implement it in your derived class to perform any extra animation you want on the Tulip OpenGL
56  * scene.
57  */
58  virtual void animationStep(int animationStep) = 0;
59 
60 protected:
61  int nbAnimationSteps;
62 };
63 
64 /** \brief A convenient class to perform Zoom and Pan animation on Tulip OpenGL scene
65  *
66  * This class allow to perform a smooth and efficient zooming and panning on Tulip OpenGL scene.
67  * The algorithm used to perform this task is the one published in: Jarke J. van Wijk and Wim A.A.
68  * Nuij, "Smooth and efficient zooming and panning"
69  * For more details, the paper can be downloaded at the following url:
70  * http://www.win.tue.nl/~vanwijk/zoompan.pdf
71  * Even if this class contains the whole Zoom and Pan implementation, it is not aimed to be used
72  * directly because its role is only to compute new camera parameters.
73  * Use the derived class QtGlSceneZoomAndPanAnimator in the tulip-gui library instead to perform
74  * the animation.
75  */
76 class TLP_GL_SCOPE GlSceneZoomAndPan {
77 
78 public:
79  virtual ~GlSceneZoomAndPan() {}
80 
81  /**
82  * GlSceneZoomAndPan constructor
83  *
84  * \param glScene the Tulip OpenGL scene on which to perform zooming and panning
85  * \param boundingBox the bounding box in scene coordinates on which the Tulip OpenGL scene has to
86  * be zoomed and panned.
87  * At the end of the animation, the viewport will be zoomed and centered on the content
88  * of that bounding box.
89  * \param layerName The name of the layer animation should be done on
90  * \param nbAnimationSteps the number of steps to perform during the animation
91  * \param optimalPath if true zooming and panning will be combined at each step of the animation,
92  * if false the scene will be zoomed out/in, panned then zoomed in/out
93  * \param p zoom/pan trade-off parameter, adjust it according to your needs
94  */
95  GlSceneZoomAndPan(GlScene *glScene, const BoundingBox &boundingBox,
96  const std::string &layerName = "Main", const int nbAnimationSteps = 50,
97  const bool optimalPath = true, const double p = sqrt(1.6));
98 
99  /**
100  * Method to add an additional scene animation while zooming and panning
101  *
102  * \param additionalAnimation The animation to add
103  */
104  void setAdditionalGlSceneAnimation(AdditionalGlSceneAnimation *additionalAnimation);
105 
106  /**
107  * Method which return the number of animation steps
108  */
109  inline int getNbAnimationsStep() const {
110  return nbAnimationSteps;
111  }
112 
113  /**
114  * Method to set the number of animation steps
115  */
116  inline void setNbAnimationSteps(const int nbAnimationSteps) {
117  this->nbAnimationSteps = nbAnimationSteps;
118  }
119 
120  /**
121  * Method which performs the zoom and pan animation. Its role is to compute new camera parameters
122  * at step animationStep.
123  * The scene is not redrawn with this method, you have to call the draw method on the associated
124  * GlScene object
125  */
126  void zoomAndPanAnimationStep(int animationStep);
127 
128 protected:
129  Camera &camera;
130  Vector<int, 4> viewport;
131  int nbAnimationSteps;
132  bool optimalPath;
133  double p;
134  Coord camCenterStart, camCenterEnd;
135  double w0, w1, u0, u1, b0, b1, r0, r1, S, sA, sB, wm;
136  AdditionalGlSceneAnimation *additionalAnimation;
137  float zoomAreaWidth, zoomAreaHeight;
138  bool doZoomAndPan;
139 };
140 } // namespace tlp
141 
142 #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:160
This class represents the 3D bounding box of an object. It is mostly used to determine whether or not...
Definition: BoundingBox.h:66
Tulip OpenGL camera object.
Definition: Camera.h:47