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