PixelLightAPI  .
SHKdTree.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SHKdTree.h                                     *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight 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. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLSCENE_SCENEHIERARCHY_KDTREE_H__
00024 #define __PLSCENE_SCENEHIERARCHY_KDTREE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLScene/Scene/SceneHierarchy.h"
00032 #include "PLScene/Scene/SceneHierarchyNode.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLScene {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    Kd tree scene hierarchy (axis aligned binary tree)
00047 *
00048 *  @remarks
00049 *    A node has two children. The node can be either an interior node (i.e., left and
00050 *    right child) or a leaf node, which holds the actual scene nodes.
00051 */
00052 class SHKdTree : public SceneHierarchy {
00053 
00054 
00055     //[-------------------------------------------------------]
00056     //[ RTTI interface                                        ]
00057     //[-------------------------------------------------------]
00058     pl_class(PLS_RTTI_EXPORT, SHKdTree, "PLScene", PLScene::SceneHierarchy, "Kd tree scene hierarchy (axis aligned binary tree)")
00059         // Constructors
00060         pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00061     pl_class_end
00062 
00063 
00064     //[-------------------------------------------------------]
00065     //[ Public functions                                      ]
00066     //[-------------------------------------------------------]
00067     public:
00068         /**
00069         *  @brief
00070         *    Default constructor
00071         */
00072         PLS_API SHKdTree();
00073 
00074 
00075     //[-------------------------------------------------------]
00076     //[ Private virtual SceneHierarchy functions              ]
00077     //[-------------------------------------------------------]
00078     private:
00079         virtual SceneHierarchyNode &CreateNode() override;
00080 
00081 
00082 };
00083 
00084 /**
00085 *  @brief
00086 *    Kd tree scene hierarchy node class
00087 */
00088 class SHKdTreeNode : public SceneHierarchyNode {
00089 
00090 
00091     //[-------------------------------------------------------]
00092     //[ Friends                                               ]
00093     //[-------------------------------------------------------]
00094     friend class SHKdTree;
00095 
00096 
00097     //[-------------------------------------------------------]
00098     //[ Private functions                                     ]
00099     //[-------------------------------------------------------]
00100     private:
00101         /**
00102         *  @brief
00103         *    Constructor
00104         *
00105         *  @param[in] cHierarchy
00106         *    The owner hierarchy
00107         */
00108         SHKdTreeNode(SceneHierarchy &cHierarchy);
00109 
00110         /**
00111         *  @brief
00112         *    Destructor
00113         */
00114         virtual ~SHKdTreeNode();
00115 
00116         /**
00117         *  @brief
00118         *    Merges the items of the scene hierarchy child nodes to this nodes if required
00119         */
00120         void Merge();
00121 
00122         /**
00123         *  @brief
00124         *    Splits this scene hierarchy node
00125         */
00126         void Split();
00127 
00128 
00129     //[-------------------------------------------------------]
00130     //[ Private definitions                                   ]
00131     //[-------------------------------------------------------]
00132     private:
00133         /**
00134         *  @brief
00135         *    Split axis
00136         */
00137         enum EAxis {
00138             AxisX = 0,
00139             AxisY = 1,
00140             AxisZ = 2,
00141             Leaf  = 3
00142         };
00143 
00144 
00145     //[-------------------------------------------------------]
00146     //[ Private data                                          ]
00147     //[-------------------------------------------------------]
00148     private:
00149         SHKdTreeNode *m_pLeftNode;      /**< Left scene hierarchy node, can be a null pointer */
00150         SHKdTreeNode *m_pRightNode;     /**< Right scene hierarchy node, can be a null pointer */
00151         EAxis         m_nSplitAxis;     /**< Split axis */
00152         float         m_fSplitValue;    /**< Split value */
00153 
00154 
00155     //[-------------------------------------------------------]
00156     //[ Public virtual SceneHierarchyNode functions           ]
00157     //[-------------------------------------------------------]
00158     public:
00159         PLS_API virtual void Touch(bool bRecursive = false) override;
00160         PLS_API virtual PLCore::uint32 GetNumOfNodes() const override;
00161         PLS_API virtual SceneHierarchyNode *GetNode(PLCore::uint32 nIndex) const override;
00162 
00163 
00164     //[-------------------------------------------------------]
00165     //[ Private virtual SceneHierarchyNode functions          ]
00166     //[-------------------------------------------------------]
00167     private:
00168         virtual void Init() override;
00169 
00170 
00171 };
00172 
00173 
00174 //[-------------------------------------------------------]
00175 //[ Namespace                                             ]
00176 //[-------------------------------------------------------]
00177 } // PLScene
00178 
00179 
00180 #endif // __PLSCENE_SCENEHIERARCHY_KDTREE_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:59
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported