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