glc_octreenode.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  Version 2.0.0 Beta 1, packaged on April 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023  *****************************************************************************/
00025 
00026 
00027 #ifndef GLC_OCTREENODE_H_
00028 #define GLC_OCTREENODE_H_
00029 
00030 #include "glc_3dviewinstance.h"
00031 #include "../glc_boundingbox.h"
00032 #include "../glc_config.h"
00033 #include "../viewport/glc_frustum.h"
00034 #include <QList>
00035 #include <QSet>
00036 
00037 class GLC_LIB_EXPORT GLC_OctreeNode;
00038 
00041 
00042 
00043 class GLC_OctreeNode
00044 {
00045         typedef QList<GLC_OctreeNode*> NodeList;
00047 
00049 
00050 public:
00052         GLC_OctreeNode(const GLC_BoundingBox&, GLC_OctreeNode* pParent= NULL);
00053 
00055         GLC_OctreeNode(const GLC_OctreeNode&, GLC_OctreeNode* pParent= NULL);
00056 
00058         virtual ~GLC_OctreeNode();
00060 
00061 
00063 
00064 public:
00065 
00066         // Return this octree node bounding box
00067         inline GLC_BoundingBox& boundingBox()
00068         {return m_BoundingBox;}
00069 
00071         inline bool intersect(const GLC_BoundingBox& boundingBox);
00072 
00074         inline bool hasChild() const
00075         {return !m_Children.isEmpty();}
00076 
00078 
00079         inline GLC_OctreeNode* childAt(int i) const
00080         {
00081                 Q_ASSERT(i < m_Children.size());
00082                 return m_Children.at(i);
00083         }
00084 
00086         inline int childCount() const
00087         {return m_Children.size();}
00088 
00090         inline bool hasGeometry() const
00091         {return !m_3DViewInstanceSet.isEmpty();}
00092 
00094 
00095         inline bool isEmpty() const
00096         {return m_Empty;}
00097 
00099         static bool intersectionWithBoundingSphereUsed();
00100 
00102         QSet<GLC_3DViewInstance*> setOfIntersectedInstances(const GLC_BoundingBox& bBox);
00103 
00104 
00106 
00108 
00110 
00111 public:
00112 
00114         void addChildren();
00115 
00117         void addInstance(GLC_3DViewInstance*, int);
00118 
00120 
00121         void updateViewableInstances(const GLC_Frustum&, QSet<GLC_3DViewInstance*>* pInstanceSet= NULL);
00122 
00124         void removeEmptyChildren();
00125 
00127         static void useBoundingSphereIntersection(bool);
00129 
00131 // Private services function
00133 private:
00135         void unableViewFlag(QSet<GLC_3DViewInstance*>*);
00136 
00138         void disableViewFlag(QSet<GLC_3DViewInstance*>*);
00139 
00141 // Private members
00143 private:
00145         GLC_BoundingBox m_BoundingBox;
00146 
00148         GLC_OctreeNode* m_pParent;
00149 
00151         NodeList m_Children;
00152 
00154         QSet<GLC_3DViewInstance*> m_3DViewInstanceSet;
00155 
00157         bool m_Empty;
00158 
00160         static bool m_useBoundingSphere;
00161 
00162 };
00163 
00164 bool GLC_OctreeNode::intersect(const GLC_BoundingBox& boundingBox)
00165 {
00166         if (m_useBoundingSphere)
00167                 return m_BoundingBox.intersectBoundingSphere(boundingBox);
00168         else
00169                 return m_BoundingBox.intersect(boundingBox);
00170 }
00171 
00172 #endif /* GLC_OCTREENODE_H_ */

SourceForge.net Logo

©2005 Laurent Ribon