OgreVolumeOctreeNode.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2013 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __Ogre_Volume_OctreeNode_H__
00029 #define __Ogre_Volume_OctreeNode_H__
00030 
00031 #include "OgreMatrix3.h"
00032 #include "OgreEntity.h"
00033 #include "OgreSceneManager.h"
00034 #include "OgreManualObject.h"
00035 #include "OgreVolumeOctreeNodeSplitPolicy.h"
00036 #include "OgreVolumePrerequisites.h"
00037 
00038 namespace Ogre {
00039 namespace Volume {
00040 
00041     class OctreeNodeSplitPolicy;
00042 
00045     class _OgreVolumeExport OctreeNode : public UtilityAlloc
00046     {
00047     protected:
00048         
00050         static const Real NEAR_FACTOR;
00051 
00053         static uint32 mGridPositionCount;
00054 
00056         static size_t mNodeI;
00057 
00059         Vector3 mFrom;
00060         
00062         Vector3 mTo;
00063 
00065         OctreeNode **mChildren;
00066 
00068         Entity* mOctreeGrid;
00069 
00071         Vector4 mCenterValue;
00072 
00078         void buildOctreeGridLines(ManualObject *manual) const;
00079     public:
00080 
00082         static const size_t OCTREE_CHILDREN_COUNT;
00083         
00098         static inline void getChildrenDimensions(const Vector3 &from, const Vector3 &to, Vector3 &center, Vector3 &width, Vector3 &height, Vector3 &depth)
00099         {
00100             center = (to - from) / (Real)2.0;
00101             width.x = center.x;
00102             width.y = (Real)0.0;
00103             width.z = (Real)0.0;
00104             height.x = (Real)0.0;
00105             height.y = center.y;
00106             height.z = (Real)0.0;
00107             depth.x = (Real)0.0;
00108             depth.y = (Real)0.0;
00109             depth.z = center.z;
00110             center += from;
00111         }
00112 
00119         OctreeNode(const Vector3 &from = Vector3::ZERO, const Vector3 &to = Vector3::ZERO);
00120 
00123         virtual ~OctreeNode(void);
00124 
00133         virtual OctreeNode* createInstance(const Vector3& from, const Vector3& to);
00134 
00143         void split(const OctreeNodeSplitPolicy *splitPolicy, const Source *src, const Real geometricError);
00144 
00152         Entity* getOctreeGrid(SceneManager *sceneManager);
00153 
00158         inline void setFrom(Vector3 from)
00159         {
00160             mFrom = from;
00161         }
00162         
00167         inline void setTo(Vector3 to)
00168         {
00169             mTo = to;
00170         }
00171 
00176         inline bool isSubdivided(void) const 
00177         {
00178             return mChildren != 0;
00179         }
00180 
00191         inline const OctreeNode* getChild(const size_t i) const
00192         {
00193             return mChildren[i];
00194         }
00195         
00200         inline const Vector3 getCenter(void) const
00201         {
00202             return (mFrom + mTo) / (Real)2.0;
00203         }
00204         
00209         inline const Vector3& getFrom(void) const
00210         {
00211             return mFrom;
00212         }
00213         
00218         inline const Vector3& getTo(void) const
00219         {
00220             return mTo;
00221         }
00222 
00229         inline bool isBorderLeft(const OctreeNode &root) const
00230         {
00231             return mFrom.x == root.mFrom.x;
00232         }
00233         
00240         inline bool isBorderRight(const OctreeNode &root) const
00241         {
00242             return mTo.x == root.mTo.x;
00243         }
00244         
00251         inline bool isBorderBottom(const OctreeNode &root) const
00252         {
00253             return mFrom.y == root.mFrom.y;
00254         }
00255         
00262         inline bool isBorderTop(const OctreeNode &root) const
00263         {
00264             return mTo.y == root.mTo.y;
00265         }
00266         
00273         inline bool isBorderBack(const OctreeNode &root) const
00274         {
00275             return mFrom.z == root.mFrom.z;
00276         }
00277         
00284         inline bool isBorderFront(const OctreeNode &root) const
00285         {
00286             return mTo.z == root.mTo.z;
00287         }
00288 
00293         inline const Vector3 getCenterBack(void) const
00294         {
00295             return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
00296         }
00297         
00302         inline const Vector3 getCenterFront(void) const
00303         {
00304             return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
00305         }
00306         
00311         inline const Vector3 getCenterLeft(void) const
00312         {
00313             return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
00314         }
00315         
00320         inline const Vector3 getCenterRight(void) const
00321         {
00322             return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
00323         }
00324         
00329         inline const Vector3 getCenterTop(void) const
00330         {
00331             return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
00332         }
00333         
00338         inline const Vector3 getCenterBottom(void) const
00339         {
00340             return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
00341         }
00342         
00347         inline const Vector3 getCenterBackTop(void) const
00348         {
00349             return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mFrom.z);
00350         }
00351         
00356         inline const Vector3 getCenterBackBottom(void) const
00357         {
00358             return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mFrom.z);
00359         }
00360         
00365         inline const Vector3 getCenterFrontTop(void) const
00366         {
00367             return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mTo.z);
00368         }
00369         
00374         inline const Vector3 getCenterFrontBottom(void) const
00375         {
00376             return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mTo.z);
00377         }
00378         
00383         inline const Vector3 getCenterLeftTop(void) const
00384         {
00385             return Vector3(mFrom.x, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
00386         }
00387         
00392         inline const Vector3 getCenterLeftBottom(void) const
00393         {
00394             return Vector3(mFrom.x, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
00395         }
00396         
00401         inline const Vector3 getCenterRightTop(void) const
00402         {
00403             return Vector3(mTo.x, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
00404         }
00405         
00410         inline const Vector3 getCenterRightBottom(void) const
00411         {
00412             return Vector3(mTo.x, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
00413         }
00414         
00419         inline const Vector3 getCenterBackLeft(void) const
00420         {
00421             return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
00422         }
00423 
00428         inline const Vector3 getCenterFrontLeft(void) const
00429         {
00430             return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
00431         }
00432         
00437         inline const Vector3 getCenterBackRight(void) const
00438         {
00439             return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
00440         }
00441 
00446         inline const Vector3 getCenterFrontRight(void) const
00447         {
00448             return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
00449         }
00450 
00455         inline const Vector3 getCorner1(void) const
00456         {
00457             return Vector3(mTo.x, mFrom.y, mFrom.z);
00458         }
00459         
00464         inline const Vector3 getCorner2(void) const
00465         {
00466             return Vector3(mTo.x, mFrom.y, mTo.z);
00467         }
00468         
00473         inline const Vector3 getCorner3(void) const
00474         {
00475             return Vector3(mFrom.x, mFrom.y, mTo.z);
00476         }
00477         
00482         inline const Vector3 getCorner4(void) const
00483         {
00484             return Vector3(mFrom.x, mTo.y, mFrom.z);
00485         }
00486         
00491         inline const Vector3 getCorner5(void) const
00492         {
00493             return Vector3(mTo.x, mTo.y, mFrom.z);
00494         }
00495         
00500         inline const Vector3 getCorner7(void) const
00501         {
00502             return Vector3(mFrom.x, mTo.y, mTo.z);
00503         }
00504 
00509         inline void setCenterValue(Vector4 value)
00510         {
00511             mCenterValue = value;
00512         }
00513 
00518         inline const Vector4 getCenterValue(void) const
00519         {
00520             return mCenterValue;
00521         }
00522 
00527         inline bool isIsoSurfaceNear(void) const
00528         {
00529             if (mCenterValue.w == (Real)0.0)
00530             {
00531                 return true;
00532             }
00533             return Math::Abs(mCenterValue.w) < (mFrom - mTo).length() * NEAR_FACTOR;
00534         }
00535     };
00536 }
00537 }
00538 
00539 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48