Tulip  5.1.0
Large graphs analysis and drawing
OcclusionTest.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_OCCLUSIONTEST_H
22 #define Tulip_OCCLUSIONTEST_H
23 #ifndef DOXYGEN_NOTFOR_DEVEL
24 
25 #include <vector>
26 
27 #include <tulip/Rectangle.h>
28 
29 namespace tlp {
30 
31 typedef Rectangle<int> RectangleInt2D;
32 
33 /**
34 * @brief Manage a set of non overlapping 2D Axis Aligned Bounding Box
35 *
36 * That class enables to store a set of non overlapping 2D AABB.
37 *
38 * @todo Use the Tulip quadtree to store AABB and thus speedup testRectangle function
39 */
40 struct TLP_GL_SCOPE OcclusionTest {
41  std::vector<RectangleInt2D> data;
42  /**
43  * Remove all 2D AABB previously added.
44  */
45  void clear() {
46  data.clear();
47  }
48  /**
49  * Add a new 2D AABB to the set of non overlapping AABB
50  * if that AABB intersect with AABB already inserted,
51  * the AABB is not inserted.
52  *
53  * @return true if the AABB is inserted else false.
54  *
55  */
56  bool addRectangle(const RectangleInt2D &rec) {
57  if (!testRectangle(rec)) {
58  data.push_back(rec);
59  return true;
60  }
61 
62  return false;
63  }
64  /**
65  * @brief test wehter or nort the AABB intersect with a AABB already inserted.
66  *
67  * @return true if the AABB intersect else false.
68  */
69  bool testRectangle(const RectangleInt2D &rec) {
70  for (std::vector<RectangleInt2D>::const_iterator it=data.begin(); it!=data.end(); ++it) {
71  if (rec.intersect(*it))
72  return true;
73  }
74 
75  return false;
76  }
77 };
78 
79 }
80 
81 #endif //DOXYGEN_NOTFOR_DEVEL
82 #endif
83 ///@endcond