Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
OcclusionTest.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 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 nor the AABB intersect with a AABB already inserted.
66  *
67  * @return true is the ABBB intersect else false.
68  */
69  bool testRectangle(const RectangleInt2D &rec) {
70  bool intersect=false;
71 
72  for (std::vector<RectangleInt2D>::const_iterator it=data.begin(); it!=data.end(); ++it) {
73  if (rec.intersect(*it)) {
74  intersect=true;
75  break;
76  }
77  }
78 
79  return intersect;
80  }
81 
82 };
83 
84 }
85 
86 #endif //DOXYGEN_NOTFOR_DEVEL
87 #endif
88 ///@endcond