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