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