Tulip  5.3.0
Large graphs analysis and drawing
GlConvexHull.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 GL_CONVEX_HULL_H
22 #define GL_CONVEX_HULL_H
23 
24 #include <vector>
25 
26 #include <tulip/Color.h>
27 #include <tulip/GlComposite.h>
28 
29 namespace tlp {
30 
31 struct ConvexHullItem;
32 class Graph;
33 
34 /** \brief Class used to represent ConvexHull
35  *
36  * Class used to represent ConvexHull. GlHierarchyConvexHull class use this to create all convexHull
37  * of the graph
38  */
39 class TLP_GL_SCOPE GlConvexHull : public GlComposite {
40 public:
41  /**
42  * Default constructor
43  */
44  GlConvexHull() {}
45 
46  /**
47  * Build a Polygon with the convex hull of points
48  */
49  GlConvexHull(const std::vector<Coord> &points, const std::vector<Color> &fillColors,
50  const std::vector<Color> &outlineColors, const bool filled, const bool outlined,
51  const std::string &name, bool computeHull = true);
52 
53  ~GlConvexHull() override {}
54 
55  /**
56  * Function used to visit composite's children
57  */
58  void acceptVisitor(GlSceneVisitor *visitor) override {
59  if (boundingBox.isValid()) {
60  visitor->visit(this);
61  }
62 
63  for (std::list<GlSimpleEntity *>::iterator it = _sortedElements.begin();
64  it != _sortedElements.end(); ++it) {
65  (*it)->acceptVisitor(visitor);
66  }
67  }
68 
69  /**
70  * Retrun the name of this convex hull
71  */
72  std::string getName() {
73  return _name;
74  }
75 
76  /**
77  * Draw the convexHull
78  */
79  void draw(float lod, Camera *camera) override;
80 
81  /**
82  * Static function who build a hierarchy of convexHull with the given graph
83  */
84  static ConvexHullItem *buildConvexHullsFromHierarchy(Graph *graph, std::vector<Color> fColors,
85  std::vector<Color> oColors,
86  bool deduceFromChilds = true,
87  Graph *root = nullptr,
88  unsigned int depth = 0);
89 
90  /**
91  * Translate entity
92  */
93  void translate(const Coord &mouvement) override;
94 
95  /**
96  * Function to export data in outString (in XML format)
97  */
98  void getXML(std::string &outString) override;
99 
100  /**
101  * Function to set data with inString (in XML format)
102  */
103  void setWithXML(const std::string &inString, unsigned int &currentPosition) override;
104 
105  tlp::Graph *_graph;
106 
107 protected:
108  std::vector<Coord> _points;
109  std::vector<Color> _fillColors;
110  std::vector<Color> _outlineColors;
111  bool _filled;
112  bool _outlined;
113  std::string _name;
114 };
115 
116 struct ConvexHullItem {
117  GlConvexHull *hull;
118  Graph *_graph;
119  std::string name;
120  std::vector<ConvexHullItem *> children;
121 };
122 } // namespace tlp
123 #endif
124 ///@endcond