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