Tulip  5.1.0
Large graphs analysis and drawing
GlCPULODCalculator.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_GLCPULODCALCULATOR_H
22 #define Tulip_GLCPULODCALCULATOR_H
23 
24 #include <tulip/Coord.h>
25 #include <tulip/GlLODCalculator.h>
26 #include <tulip/Matrix.h>
27 
28 namespace tlp {
29 class GlSimpleEntity;
30 class Camera;
31 
32 /**
33  * \brief Class used to compute LOD of GlEntities with OpenMP parallelization
34  *
35  * This class perform LOD computation of GlEntities based on screen projection of entities bounding boxes
36  * \warning By default this class don't compute LOD for edges (for optimisation) and return a lod of 10. to these edges, if you want to compute edges' LOD call setComputeEdgesLOD(true)
37  */
38 class TLP_GL_SCOPE GlCPULODCalculator : public GlLODCalculator {
39 
40 public:
41 
42  GlCPULODCalculator();
43  virtual ~GlCPULODCalculator();
44  virtual GlLODCalculator *clone() {
45  GlCPULODCalculator *calculator=new GlCPULODCalculator();
46  calculator->setComputeOutScreenLOD(computeOutScreenLOD);
47  return calculator;
48  }
49 
50  /**
51  * Begin a new camera (use to render next entities)
52  */
53  virtual void beginNewCamera(Camera* camera);
54  /**
55  * This function is called by GlLODSceneVisitor when a simple entity is found
56  */
57  virtual void addSimpleEntityBoundingBox(GlSimpleEntity * entity, const BoundingBox& bb);
58  /**
59  * This function is called by GlLODSceneVisitor when a node is found
60  */
61  virtual void addNodeBoundingBox(unsigned int id,const BoundingBox& bb);
62  /**
63  * This function is called by GlLODSceneVisitor when an edge is found
64  */
65  virtual void addEdgeBoundingBox(unsigned int id,const BoundingBox& bb);
66 
67  /**
68  * Reserve memory to store nodes LOD, this function is an optimisation function
69  */
70  virtual void reserveMemoryForNodes(unsigned int numberOfNodes);
71 
72  /**
73  * Reserve memory to store edges LOD, this function is an optimisation function
74  */
75  virtual void reserveMemoryForEdges(unsigned int numberOfEdges);
76 
77  /**
78  * Compute all bounding boxes
79  * If you want to compute LOD for a simple scene, you just have to call this function with the same value for globalViewport and currentViewport
80  * But if you want to perform a sub screen part selection you have to call this function with: globalViewport the viewport of the visualisation and currentViewport the viewport of the selection
81  * \param globalViewport is used to compute LOD
82  * \param currentViewport return -1 for all entities outside this viewport
83  */
84  virtual void compute(const Vector<int,4>& globalViewport,const Vector<int,4>& currentViewport);
85 
86  /**
87  * This function return the scene bounding box
88  */
89  virtual BoundingBox getSceneBoundingBox() {
90  return sceneBoundingBox;
91  }
92 
93  /**
94  * Set if the edge LOD must be calculated
95  * \Warning If not calcultated, the default edge LOD is 10.
96  */
97  inline void setComputeEdgesLOD(bool state) {
98  computeEdgesLOD=state;
99  }
100 
101  /**
102  * Set if the LOD is computed for out screen entities
103  */
104  inline void setComputeOutScreenLOD(bool state) {
105  computeOutScreenLOD=state;
106  }
107 
108 
109 protected:
110 
111  virtual void computeFor3DCamera(LayerLODUnit *layerLODUnit, const Coord &eye, const Matrix<float, 4>& transformMatrix, const Vector<int,4>& globalViewport,const Vector<int,4>& currentViewport);
112 
113  virtual void computeFor2DCamera(LayerLODUnit *layerLODUnit,const Vector<int,4>& globalViewport,const Vector<int,4>& currentViewport);
114 
115  bool computeEdgesLOD;
116  bool computeOutScreenLOD;
117 
118  BoundingBox sceneBoundingBox;
119 
120  LayerLODUnit *currentLayerLODUnit;
121 
122 };
123 
124 }
125 
126 #endif // Tulip_GLCPULODCALCULATOR_H
127 ///@endcond