Tulip  6.0.0
Large graphs analysis and drawing
GlNode.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_GLNODE_H
22 #define Tulip_GLNODE_H
23 
24 #ifndef DOXYGEN_NOTFOR_DEVEL
25 
26 #include <climits>
27 #include <tulip/Color.h>
28 #include <tulip/Coord.h>
29 #include <tulip/Size.h>
30 #include <tulip/GlBox.h>
31 #include <tulip/GlEntity.h>
32 #include <tulip/GlLabel.h>
33 #include <tulip/GlSceneVisitor.h>
34 #include <tulip/GlGraphInputData.h>
35 
36 #include <vector>
37 
38 namespace tlp {
39 
40 struct OcclusionTest;
41 class TextRenderer;
42 class GlGraphInputData;
43 class Camera;
44 
45 /**
46  * Class to represent a node of a graph
47  */
48 class TLP_GL_SCOPE GlNode final : public GlEntity {
49 
50 public:
51  /**
52  * Default constructor with id
53  * id must be the id of the node in graph
54  */
55  GlNode(unsigned int _nid = UINT_MAX, unsigned int _npos = UINT_MAX)
56  : id(_nid), pos(_npos), oldId(UINT_MAX),
57  selectionBox(Coord(0, 0, 0), Size(1, 1, 1), Color(0, 0, 255, 255), Color(0, 255, 0, 255),
58  false, true, "", 3) {}
59 
60  /**
61  * Virtual function to accept GlSceneVisitor on this class
62  */
63  void acceptVisitor(GlSceneVisitor *visitor) override {
64  visitor->visit(this);
65  }
66 
67  /**
68  * Return the node bounding box
69  */
70  BoundingBox getBoundingBox(const GlGraphInputData *data);
71 
72  /**
73  * Draw the node with level of detail : lod and Camera : camera
74  */
75  void draw(float lod, const GlGraphInputData *data, Camera *camera);
76 
77  /**
78  * Draw the label of the node if drawEdgesLabel is true
79  */
80  void drawLabel(GlLabel &label, OcclusionTest *test, const GlGraphInputData *data, float lod,
81  Camera *camera = nullptr);
82 
83  // node id and node position in graph->nodes()
84  unsigned int id, pos;
85 
86  /**
87  * This function is used by the engine to get point coordinates of the node
88  */
89  Coord getPoint(GlGraphInputData *inputData) {
90  init(inputData);
91  return coord;
92  }
93 
94  /**
95  * This function is used by the engine to get color of the node
96  */
97  Color getColor(GlGraphInputData *inputData) {
98  node n(id);
99 
100  return (inputData->getElementBorderWidth()->getNodeValue(n) > 0)
101  ? inputData->getElementBorderColor()->getNodeValue(n)
102  : inputData->getElementColor()->getNodeValue(n);
103  }
104 
105 protected:
106  unsigned int oldId;
107  GlBox selectionBox;
108 
109  // initialize the data member below
110  void init(const GlGraphInputData *data);
111 
112  tlp::Coord coord;
113  int glyph;
114  tlp::Size size;
115  float rot;
116  bool selected;
117 };
118 } // namespace tlp
119 
120 #endif // DOXYGEN_NOTFOR_DEVEL
121 
122 #endif // Tulip_GLNODE_H
123 ///@endcond