Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlConvexHull.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
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 of the graph
37  */
38 class TLP_GL_SCOPE GlConvexHull: public GlComposite {
39 public:
40 
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,
50  const std::vector<Color> &fillColors,
51  const std::vector<Color> &outlineColors,
52  const bool filled,
53  const bool outlined,
54  const std::string &name,
55  bool computeHull=true);
56 
57  virtual ~GlConvexHull() {}
58 
59  /**
60  * Function used to visit composite's children
61  */
62  virtual void acceptVisitor(GlSceneVisitor *visitor) {
63  if(boundingBox.isValid()) {
64  visitor->visit(this);
65  }
66 
67  for(std::list<GlSimpleEntity*>::iterator it=_sortedElements.begin(); it!=_sortedElements.end(); ++it) {
68  (*it)->acceptVisitor(visitor);
69  }
70  }
71 
72 
73  /**
74  * Retrun the name of this convex hull
75  */
76  std::string getName() {
77  return _name;
78  }
79 
80  /**
81  * Draw the convexHull
82  */
83  virtual void draw(float lod,Camera *camera);
84 
85  /**
86  * Static function who build a hierarchy of convexHull with the given graph
87  */
88  static ConvexHullItem *buildConvexHullsFromHierarchy(Graph *graph,
89  std::vector<Color> fColors,
90  std::vector<Color> oColors,
91  bool deduceFromChilds = true,
92  Graph *root = NULL,
93  unsigned int depth = 0);
94 
95  /**
96  * Translate entity
97  */
98  virtual void translate(const Coord& mouvement);
99 
100  /**
101  * Function to export data in outString (in XML format)
102  */
103  virtual void getXML(std::string &outString);
104 
105  /**
106  * Function to set data with inString (in XML format)
107  */
108  virtual void setWithXML(const std::string &inString, unsigned int &currentPosition);
109 
110  tlp::Graph *_graph;
111 
112 protected:
113  std::vector<Coord> _points;
114  std::vector<Color> _fillColors;
115  std::vector<Color> _outlineColors;
116  bool _filled;
117  bool _outlined;
118  std::string _name;
119 };
120 
121 struct ConvexHullItem {
122  GlConvexHull* hull;
123  Graph *_graph;
124  std::string name;
125  std::vector<ConvexHullItem *> children;
126 };
127 
128 }
129 #endif
130 ///@endcond