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