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