![]() |
Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 ///@cond DOXYGEN_HIDDEN 00020 00021 #ifndef Tulip_OCCLUSIONTEST_H 00022 #define Tulip_OCCLUSIONTEST_H 00023 #ifndef DOXYGEN_NOTFOR_DEVEL 00024 00025 #include <vector> 00026 00027 #include <tulip/Rectangle.h> 00028 00029 namespace tlp { 00030 00031 typedef Rectangle<int> RectangleInt2D; 00032 00033 /** 00034 * @brief Manage a set of non overlapping 2D Axis Aligned Bounding Box 00035 * 00036 * That class enables to store a set of non overlapping 2D AABB. 00037 * 00038 * @todo Use the Tulip quadtree to store AABB and thus speedup testRectangle function 00039 */ 00040 struct TLP_GL_SCOPE OcclusionTest { 00041 std::vector<RectangleInt2D> data; 00042 /** 00043 * Remove all 2D AABB previously added. 00044 */ 00045 void clear() { 00046 data.clear(); 00047 } 00048 /** 00049 * Add a new 2D AABB to the set of non overlapping AABB 00050 * if that AABB intersect with AABB already inserted, 00051 * the AABB is not inserted. 00052 * 00053 * @return true if the AABB is inserted else false. 00054 * 00055 */ 00056 bool addRectangle(const RectangleInt2D &rec) { 00057 if (!testRectangle(rec)) { 00058 data.push_back(rec); 00059 return true; 00060 } 00061 00062 return false; 00063 } 00064 /** 00065 * @brief test wehter or nor the AABB intersect with a AABB already inserted. 00066 * 00067 * @return true is the ABBB intersect else false. 00068 */ 00069 bool testRectangle(const RectangleInt2D &rec) { 00070 bool intersect=false; 00071 00072 for (std::vector<RectangleInt2D>::const_iterator it=data.begin(); it!=data.end(); ++it) { 00073 if (rec.intersect(*it)) { 00074 intersect=true; 00075 break; 00076 } 00077 } 00078 00079 return intersect; 00080 } 00081 00082 }; 00083 00084 } 00085 00086 #endif //DOXYGEN_NOTFOR_DEVEL 00087 #endif 00088 ///@endcond