Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlLODCalculator.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_GLLODCALCULATOR_H
22 #define Tulip_GLLODCALCULATOR_H
23 #ifndef DOXYGEN_NOTFOR_DEVEL
24 
25 #include <tulip/BoundingBox.h>
26 
27 #include <vector>
28 
29 namespace tlp {
30 
31 class Camera;
32 class GlEntity;
33 class GlSimpleEntity;
34 class GlScene;
35 class GlGraphInputData;
36 
37 enum RenderingEntitiesFlag {
38  RenderingSimpleEntities =1,
39  RenderingNodes = 2,
40  RenderingEdges = 4,
41  RenderingAll = 7,
42  RenderingWithoutRemove = 8
43 };
44 
45 struct EntityLODUnit {
46  EntityLODUnit(const BoundingBox &boundingBox):boundingBox(boundingBox),lod(-1) {}
47  BoundingBox boundingBox;
48  float lod;
49 };
50 
51 // struct to store simple entity lod
52 struct SimpleEntityLODUnit : public EntityLODUnit {
53  SimpleEntityLODUnit(GlSimpleEntity *entity, const BoundingBox &boundingBox):
54  EntityLODUnit(boundingBox),
55  entity(entity) {
56  }
57  GlSimpleEntity *entity;
58 };
59 
60 // struct to store complex entity (nodes/edges) lod
61 struct ComplexEntityLODUnit : public EntityLODUnit {
62  ComplexEntityLODUnit(unsigned int id,const BoundingBox &boundingBox):EntityLODUnit(boundingBox),id(id) {}
63  unsigned int id;
64 };
65 
66 struct LayerLODUnit {
67  std::vector<SimpleEntityLODUnit> simpleEntitiesLODVector;
68  std::vector<ComplexEntityLODUnit> nodesLODVector;
69  std::vector<ComplexEntityLODUnit> edgesLODVector;
70  Camera * camera;
71 };
72 
73 typedef std::vector<LayerLODUnit> LayersLODVector;
74 
75 /**
76  * Class use to calculate lod of scene entities
77  */
78 class TLP_GL_SCOPE GlLODCalculator {
79 
80 public:
81 
82  GlLODCalculator():glScene(NULL),inputData(NULL),attachedLODCalculator(NULL) {}
83  virtual ~GlLODCalculator() {}
84  virtual GlLODCalculator *clone()=0;
85 
86  /**
87  * Set scene use by this LOD calculator
88  */
89  virtual void setScene(GlScene &scene) {
90  glScene=&scene;
91  }
92 
93  /**
94  * Set input data use to render
95  */
96  virtual void setInputData(const GlGraphInputData *inputData) {
97  this->inputData=inputData;
98  }
99 
100  /**
101  * Set RenderingEntitiesFlag to : RenderingSimpleEntities,RenderingNodes,RenderingEdges,RenderingAll,RenderingWithoutRemove
102  */
103  virtual void setRenderingEntitiesFlag(RenderingEntitiesFlag flag) {
104  renderingEntitiesFlag=flag;
105  }
106 
107  /**
108  * Return if the LODCalculator need to have entities to compute
109  */
110  virtual bool needEntities() {
111  return true;
112  }
113  /**
114  * Set if the LODCalculator need to have entities to compute
115  */
116  virtual void setNeedEntities(bool) {}
117  /**
118  * Begin a new camera
119  */
120  virtual void beginNewCamera(Camera* camera)=0;
121  /**
122  * Record a new simple entity in current camera context
123  */
124  virtual void addSimpleEntityBoundingBox(GlSimpleEntity *entity,const BoundingBox& bb)=0;
125  /**
126  * Record a new node in current camera context
127  */
128  virtual void addNodeBoundingBox(unsigned int id,const BoundingBox& bb)=0;
129  /**
130  * Record a new edge in current camera context
131  */
132  virtual void addEdgeBoundingBox(unsigned int id,const BoundingBox& bb)=0;
133 
134  /**
135  * Reserve memory to store nodes LOD
136  */
137  virtual void reserveMemoryForNodes(unsigned int) {}
138 
139  /**
140  * Reserve memory to store edges LOD
141  */
142  virtual void reserveMemoryForEdges(unsigned int) {}
143 
144  /**
145  * Compute all lod
146  */
147  virtual void compute(const Vector<int,4>& globalViewport, const Vector<int,4>& currentViewport)=0;
148 
149  /**
150  * Return a pointer on LOD result
151  */
152  LayersLODVector &getResult() {
153  return layersLODVector;
154  }
155 
156  /**
157  * Clear class data
158  */
159  virtual void clear() {
160  layersLODVector.clear();
161  }
162 
163  virtual BoundingBox getSceneBoundingBox()=0;
164 
165  void setAttachedLODCalculator(GlLODCalculator *calculator) {
166  attachedLODCalculator=calculator;
167  }
168 
169 protected :
170 
171  GlScene *glScene;
172  const GlGraphInputData *inputData;
173 
174  RenderingEntitiesFlag renderingEntitiesFlag;
175 
176  LayersLODVector layersLODVector;
177 
178  GlLODCalculator *attachedLODCalculator;
179 };
180 
181 }
182 
183 #endif // DOXYGEN_NOTFOR_DEVEL
184 
185 #endif // Tulip_GLLODCALCULATOR_H
186 ///@endcond