00001 /**************************************************************************** 00002 00003 This file is part of the GLC-lib library. 00004 Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net) 00005 http://glc-lib.sourceforge.net 00006 00007 GLC-lib is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 GLC-lib is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with GLC-lib; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 *****************************************************************************/ 00023 00024 00025 #ifndef GLC_OCTREENODE_H_ 00026 #define GLC_OCTREENODE_H_ 00027 00028 #include "glc_3dviewinstance.h" 00029 #include "../glc_boundingbox.h" 00030 #include "../glc_config.h" 00031 #include "../viewport/glc_frustum.h" 00032 #include <QList> 00033 #include <QSet> 00034 00035 class GLC_LIB_EXPORT GLC_OctreeNode; 00036 00039 00040 00041 class GLC_OctreeNode 00042 { 00043 typedef QList<GLC_OctreeNode*> NodeList; 00045 00047 00048 public: 00050 GLC_OctreeNode(const GLC_BoundingBox&, GLC_OctreeNode* pParent= NULL); 00051 00053 GLC_OctreeNode(const GLC_OctreeNode&, GLC_OctreeNode* pParent= NULL); 00054 00056 virtual ~GLC_OctreeNode(); 00058 00059 00061 00062 public: 00063 00064 // Return this octree node bounding box 00065 inline GLC_BoundingBox& boundingBox() 00066 {return m_BoundingBox;} 00067 00069 inline bool intersect(const GLC_BoundingBox& boundingBox); 00070 00072 inline bool hasChild() const 00073 {return !m_Children.isEmpty();} 00074 00076 00077 inline GLC_OctreeNode* childAt(int i) const 00078 { 00079 Q_ASSERT(i < m_Children.size()); 00080 return m_Children.at(i); 00081 } 00082 00084 inline int childCount() const 00085 {return m_Children.size();} 00086 00088 inline bool hasGeometry() const 00089 {return !m_3DViewInstanceSet.isEmpty();} 00090 00092 00093 inline bool isEmpty() const 00094 {return m_Empty;} 00095 00097 static bool intersectionWithBoundingSphereUsed(); 00098 00100 QSet<GLC_3DViewInstance*> setOfIntersectedInstances(const GLC_BoundingBox& bBox); 00101 00102 00104 00106 00108 00109 public: 00110 00112 void addChildren(); 00113 00115 void addInstance(GLC_3DViewInstance*, int); 00116 00118 00119 void updateViewableInstances(const GLC_Frustum&, QSet<GLC_3DViewInstance*>* pInstanceSet= NULL); 00120 00122 void removeEmptyChildren(); 00123 00125 static void useBoundingSphereIntersection(bool); 00127 00129 // Private services function 00131 private: 00133 void unableViewFlag(QSet<GLC_3DViewInstance*>*); 00134 00136 void disableViewFlag(QSet<GLC_3DViewInstance*>*); 00137 00139 // Private members 00141 private: 00143 GLC_BoundingBox m_BoundingBox; 00144 00146 GLC_OctreeNode* m_pParent; 00147 00149 NodeList m_Children; 00150 00152 QSet<GLC_3DViewInstance*> m_3DViewInstanceSet; 00153 00155 bool m_Empty; 00156 00158 static bool m_useBoundingSphere; 00159 00160 }; 00161 00162 bool GLC_OctreeNode::intersect(const GLC_BoundingBox& boundingBox) 00163 { 00164 if (m_useBoundingSphere) 00165 return m_BoundingBox.intersectBoundingSphere(boundingBox); 00166 else 00167 return m_BoundingBox.intersect(boundingBox); 00168 } 00169 00170 #endif /* GLC_OCTREENODE_H_ */