PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: GraphNode.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 __PLMATH_GRAPH_NODE_H__ 00024 #define __PLMATH_GRAPH_NODE_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Container/Element.h> 00032 #include "PLMath/Vector3.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLMath { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Classes ] 00043 //[-------------------------------------------------------] 00044 /** 00045 * @brief 00046 * Graph node class 00047 */ 00048 class GraphNode : public PLCore::Element<GraphNode> { 00049 00050 00051 //[-------------------------------------------------------] 00052 //[ Public functions ] 00053 //[-------------------------------------------------------] 00054 public: 00055 //[-------------------------------------------------------] 00056 //[ Main ] 00057 //[-------------------------------------------------------] 00058 /** 00059 * @brief 00060 * Constructor 00061 * 00062 * @param[in] sName 00063 * Element name to set 00064 * @param[in] pManager 00065 * Element manager using this element, can be a null pointer 00066 */ 00067 PLMATH_API GraphNode(const PLCore::String &sName = "", PLCore::ElementManager<GraphNode> *pManager = nullptr); 00068 00069 /** 00070 * @brief 00071 * Constructor 00072 * 00073 * @param[in] cSource 00074 * Node to copy from 00075 */ 00076 PLMATH_API GraphNode(GraphNode &cSource); 00077 00078 /** 00079 * @brief 00080 * Destructor 00081 */ 00082 PLMATH_API virtual ~GraphNode(); 00083 00084 //[-------------------------------------------------------] 00085 //[ Neighbours ] 00086 //[-------------------------------------------------------] 00087 /** 00088 * @brief 00089 * Returns the number of neighbours 00090 * 00091 * @return 00092 * Number of neighbours 00093 */ 00094 PLMATH_API PLCore::uint32 GetNumOfNeighbours() const; 00095 00096 /** 00097 * @brief 00098 * Clears all neighbour connectivity 00099 */ 00100 PLMATH_API void ClearNeighbours(); 00101 00102 /** 00103 * @brief 00104 * Returns whether a node is a neighbour of this node or not 00105 * 00106 * @param[in] cNode 00107 * Node to check 00108 * 00109 * @return 00110 * 'true' if the given node is a neighbour of this node, else 'false' 00111 */ 00112 PLMATH_API bool IsNeighbour(const GraphNode &cNode) const; 00113 00114 /** 00115 * @brief 00116 * Returns a neighbour 00117 * 00118 * @param[in] nNeighbour 00119 * Neighbour index 00120 * 00121 * @return 00122 * Requested neighbour node, a null pointer on error 00123 */ 00124 PLMATH_API const GraphNode *GetNeighbour(PLCore::uint32 nNeighbour) const; 00125 00126 /** 00127 * @brief 00128 * Returns a neighbour 00129 * 00130 * @param[in] nNeighbour 00131 * Neighbour index 00132 * 00133 * @return 00134 * Requested neighbour node, a null pointer on error 00135 */ 00136 PLMATH_API GraphNode *GetNeighbour(PLCore::uint32 nNeighbour); 00137 00138 /** 00139 * @brief 00140 * Returns the distance to a neighbour 00141 * 00142 * @param[in] nNeighbour 00143 * Neighbour index 00144 * 00145 * @return 00146 * Requested distance to a neighbour node, -1 on error 00147 * 00148 * @note 00149 * - By default the neighbour distance from AddNeighbour() is set, if 00150 * SetPos() is called the neighbour distances are updated automatically. 00151 */ 00152 PLMATH_API float GetNeighbourDistance(PLCore::uint32 nNeighbour) const; 00153 00154 /** 00155 * @brief 00156 * Adds a neighbour connection 00157 * 00158 * @param[in] cNode 00159 * Neighbour node to add 00160 * @param[in] fDistance 00161 * Distance to the neighbour node, if negative the distance is calculated automatically 00162 * using the current node positions. (see GetPos()) 00163 * 00164 * @return 00165 * 'true' if all went fine, else 'false' (maybe this node is already a neighbour) 00166 */ 00167 PLMATH_API bool AddNeighbour(GraphNode &cNode, float fDistance = -1.0f); 00168 00169 /** 00170 * @brief 00171 * Removes a neighbour connection 00172 * 00173 * @param[in] cNode 00174 * Neighbour node to remove 00175 * 00176 * @return 00177 * 'true' if all went fine, else 'false' 00178 */ 00179 PLMATH_API bool RemoveNeighbour(GraphNode &cNode); 00180 00181 /** 00182 * @brief 00183 * Removes a neighbour connection at the given index 00184 * 00185 * @param[in] nNeighbour 00186 * Neighbour index 00187 * 00188 * @return 00189 * 'true' if all went fine, else 'false' 00190 */ 00191 PLMATH_API bool RemoveNeighbourAtIndex(PLCore::uint32 nNeighbour); 00192 00193 //[-------------------------------------------------------] 00194 //[ Position ] 00195 //[-------------------------------------------------------] 00196 /** 00197 * @brief 00198 * Returns the node position 00199 * 00200 * @return 00201 * Node position 00202 */ 00203 PLMATH_API const Vector3 &GetPos() const; 00204 00205 /** 00206 * @brief 00207 * Sets the node position 00208 * 00209 * @param[in] vPos 00210 * Node position 00211 */ 00212 PLMATH_API void SetPos(const Vector3 &vPos); 00213 00214 /** 00215 * @brief 00216 * Sets the node position 00217 * 00218 * @param[in] fX 00219 * X component of the node position 00220 * @param[in] fY 00221 * Y component of the node position 00222 * @param[in] fZ 00223 * Z component of the node position 00224 */ 00225 PLMATH_API void SetPos(float fX = 0.0f, float fY = 0.0f, float fZ = 0.0f); 00226 00227 /** 00228 * @brief 00229 * Returns the distance between two graph nodes 00230 * 00231 * @param[in] cNode 00232 * Other node 00233 * 00234 * @return 00235 * The positions (see GetPos()) are used to calculate the distance 00236 */ 00237 PLMATH_API float GetDistance(const GraphNode &cNode) const; 00238 00239 00240 //[-------------------------------------------------------] 00241 //[ Private structures ] 00242 //[-------------------------------------------------------] 00243 private: 00244 /** 00245 * @brief 00246 * Internal graph node neighbour structure 00247 */ 00248 struct Neighbour { 00249 GraphNode *pNode; /**< Neighbour node (always valid!) */ 00250 float fDistance; /**< Distance to neighbour node */ 00251 }; 00252 00253 00254 //[-------------------------------------------------------] 00255 //[ Private data ] 00256 //[-------------------------------------------------------] 00257 private: 00258 Vector3 m_vPos; /**< Node position */ 00259 PLCore::List<Neighbour*> m_lstNeighbours; /**< Neighbour nodes */ 00260 PLCore::List<GraphNode*> m_lstIsNeighbourFrom; /**< This node is a neighbour from... */ 00261 00262 00263 //[-------------------------------------------------------] 00264 //[ Public virtual PLCore::Element functions ] 00265 //[-------------------------------------------------------] 00266 public: 00267 PLMATH_API virtual GraphNode &operator =(const GraphNode &cSource); 00268 00269 00270 }; 00271 00272 00273 //[-------------------------------------------------------] 00274 //[ Namespace ] 00275 //[-------------------------------------------------------] 00276 } // PLMath 00277 00278 00279 #endif // __PLMATH_GRAPH_NODE_H__
|