Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
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 1 and Inria Bordeaux - Sud Ouest
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 ///@cond DOXYGEN_HIDDEN
20 
21 
22 #ifndef GLSCENEZOOMANDPAN_H_
23 #define GLSCENEZOOMANDPAN_H_
24 
25 #include <tulip/GlScene.h>
26 
27 namespace tlp {
28 
29 /**
30  * \brief A class which encapsulate a Tulip OpenGL scene animation
31  * This class aims to encapsulate a Tulip OpenGL scene animation.
32  * Derive it if you want to add extra animations to the Tulip OpenGL scene while a Zoom and Pan is performed
33  */
34 class TLP_GL_SCOPE AdditionalGlSceneAnimation {
35 
36 public :
37 
38  /**
39  * Method to set the total number of animation steps. No need to call it because the GlSceneZoomAndPan class do that task.
40  *
41  */
42  void setNbAnimationSteps(int nbAnimationSteps) {
43  this->nbAnimationSteps = nbAnimationSteps;
44  }
45 
46  /**
47  * Pure virtual method called at each step of the Zoom and Pan animation.
48  *
49  * Implement it in your derived class to perform any extra animation you want on the Tulip OpenGL scene.
50  */
51  virtual void animationStep(int animationStep) = 0;
52 
53 protected :
54 
55  int nbAnimationSteps;
56 };
57 
58 /** \brief A convenient class to perform Zoom and Pan animation on Tulip OpenGL scene
59  *
60  * This class allow to perform a smooth and efficient zooming and panning on Tulip OpenGL scene.
61  * 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"
62  * For more details, the paper can be downloaded at the following url : www.win.tue.nl/~vanwijk/zoompan.pdf
63  * 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.
64  * Use the derived class QtGlSceneZoomAndPanAnimator in the tulip-qt library instead to perform the animation.
65  */
66 class TLP_GL_SCOPE GlSceneZoomAndPan {
67 
68 public :
69 
70  /**
71  * GlSceneZoomAndPan constructor
72  *
73  * \param glScene the Tulip OpenGL scene on which to perform zooming and panning
74  * \param boundingBox the bounding box in scene coordinates on which the Tulip OpenGL scene has to be zoomed and panned.
75  * At the end of the animation, the viewport will be zoomed and centered on the content of that bounding box.
76  * \param layerName The name of the layer animation should be done on
77  * \param nbAnimationSteps the number of steps to perform during the animation
78  * \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
79  * \param p zoom/pan trade-off parameter, adjust it according to your needs
80  */
81  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));
82 
83  /**
84  * Method to add an additional scene animation while zooming and panning
85  *
86  * \param additionalAnimation The animation to add
87  */
88  void setAdditionalGlSceneAnimation(AdditionalGlSceneAnimation *additionalAnimation);
89 
90  /**
91  * Method which return the number of animation steps
92  */
93  int getNbAnimationsStep() const {
94  return nbAnimationSteps;
95  }
96 
97  /**
98  * Method to set the number of animation steps
99  */
100  void setNbAnimationSteps(const int nbAnimationSteps) {
101  this->nbAnimationSteps = nbAnimationSteps;
102  }
103 
104  /**
105  * Method which performs the zoom and pan animation. Its role is to compute new camera parameters at step animationStep.
106  * The scene is not redrawn with this method, you have to call the draw method on the associated GlScene object
107  */
108  void zoomAndPanAnimationStep(int animationStep);
109 
110 protected :
111 
112  Camera &camera;
113  Vector<int, 4> viewport;
114  int nbAnimationSteps;
115  bool optimalPath;
116  double p;
117  Coord camCenterStart, camCenterEnd;
118  double w0, w1, u0, u1, b0, b1, r0, r1, S, sA, sB, wm;
119  AdditionalGlSceneAnimation *additionalAnimation;
120  float zoomAreaWidth, zoomAreaHeight;
121  bool doZoomAndPan;
122 
123 };
124 
125 }
126 
127 #endif /* GLSCENEZOOMANDPAN_H_ */
128 ///@endcond