Tulip  4.0.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlQuadTreeLODCalculator.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 #ifndef Tulip_QLQUADTREELODCALCULATOR_H
22 #define Tulip_QLQUADTREELODCALCULATOR_H
23 
24 #include <map>
25 #include <vector>
26 
27 #include <tulip/BoundingBox.h>
28 #include <tulip/GlGraphInputData.h>
29 #include <tulip/Matrix.h>
30 #include <tulip/Vector.h>
31 #include <tulip/GlSceneObserver.h>
32 #include <tulip/GlCPULODCalculator.h>
33 
34 namespace tlp {
35 
36 class Camera;
37 template <class TYPE> class QuadTreeNode;
38 class GlScene;
39 
40 /**
41  * Class use to compute bounding boxs of a vector of GlEntity
42  */
43 class TLP_GL_SCOPE GlQuadTreeLODCalculator : public GlCPULODCalculator, private Observable {
44 
45 public:
46 
47  GlQuadTreeLODCalculator();
48  ~GlQuadTreeLODCalculator();
49 
50  /**
51  * Set the SlScene used by this calculator
52  */
53  void setScene(GlScene &scene);
54 
55  /**
56  * To know if the calculator need to have entities returned by a visitor in GlScene
57  */
58  bool needEntities();
59  /**
60  * Set if the calculator need to have entities
61  */
62  void setNeedEntities(bool);
63 
64  /**
65  * This function is call by GlLODSceneVisitor when a simple entitie is found
66  */
67  void addSimpleEntityBoundingBox(GlSimpleEntity * entity,const BoundingBox& bb);
68  /**
69  * This function is call by GlLODSceneVisitor when a node is found
70  */
71  void addNodeBoundingBox(unsigned int id,const BoundingBox& bb);
72  /**
73  * This function is call by GlLODSceneVisitor when an edge is found
74  */
75  void addEdgeBoundingBox(unsigned int id,const BoundingBox& bb);
76 
77  /**
78  * This function compute LOD
79  * See compute function of GlCPULODCalculator for more details
80  * This function do some computation and after call computeFor2DCamera() or computeFor3DCamera()
81  */
82  void compute(const Vector<int,4>& globalViewport,const Vector<int,4>& currentViewport);
83 
84  /**
85  * Specific function to compute LOD for 3D cameras
86  */
87  void computeFor3DCamera(LayerLODUnit *layerLODUnit,const Coord &eye,
88  const Matrix<float, 4> transformMatrix,
89  const Vector<int,4>& globalViewport,
90  const Vector<int,4>& currentViewport);
91 
92  /**
93  * Change the input data used by this LOD calculator
94  */
95  void setInputData(const GlGraphInputData *newInputData);
96 
97  /**
98  * Clone the calculator
99  */
100  virtual GlLODCalculator *clone() {
101  GlQuadTreeLODCalculator *newCalculator=new GlQuadTreeLODCalculator();
102  newCalculator->setScene(*glScene);
103  newCalculator->setInputData(inputData);
104  return newCalculator;
105  }
106 
107 protected :
108 
109  void update(PropertyInterface *property);
110  void treatEvent(const Event &ev);
111 
112  void removeObservers();
113  void addObservers();
114 
115  void initCamerasObservers();
116  void clearCamerasObservers();
117 
118  void setHaveToCompute();
119 
120  std::vector<QuadTreeNode<unsigned int> *> nodesQuadTree;
121  std::vector<QuadTreeNode<unsigned int> *> edgesQuadTree;
122  std::vector<QuadTreeNode<GlSimpleEntity *> *> entitiesQuadTree;
123  std::vector<std::vector<SimpleEntityLODUnit> > simpleEntities;
124 
125  bool haveToCompute;
126  bool haveToInitObservers;
127 
128  BoundingBox nodesGlobalBoundingBox;
129  BoundingBox edgesGlobalBoundingBox;
130  BoundingBox entitiesGlobalBoundingBox;
131 
132  std::vector<Camera *> cameras;
133  std::map<GlLayer*, Camera> layerToCamera;
134  Camera *currentCamera;
135  Graph *currentGraph;
136  PropertyInterface *layoutProperty;
137  PropertyInterface *sizeProperty;
138  PropertyInterface *selectionProperty;
139  GlGraphRenderingParameters oldParameters;
140 
141  int quadTreesVectorPosition;
142  int simpleEntitiesVectorPosition;
143 };
144 
145 }
146 
147 #endif // Tulip_QTQUADTREELODCALCULATOR_H
148 ///@endcond