1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Ogre_Volume_OctreeNodeSplitPolicy_H__
29 #define __Ogre_Volume_OctreeNodeSplitPolicy_H__
30 
31 #include "OgreVector3.h"
32 
33 #include "OgreVolumePrerequisites.h"
34 
35 namespace Ogre {
36 namespace Volume {
37     /** \addtogroup Optional
38     *  @{
39     */
40     /** \addtogroup Volume
41     *  @{
42     */
43     class OctreeNode;
44     class Source;
45 
46     /** The class deciding on whether to split an octree node or not
47         when building the octree.
48         Splitting like Zhang in http://www.andrew.cmu.edu/user/jessicaz/publication/meshing/.
49     */
50     class _OgreVolumeExport OctreeNodeSplitPolicy
51     {
52     protected:
53 
54         /// Holds the volume source to decide something.
55         const Source *mSrc;
56 
57         /// The maximum cell size where the policy stops the splitting.
58         Real mMaxCellSize;
59 
60         /** Trilinear interpolation of a relative point.
61         @param f000
62             Value of the lower back left corner.
63         @param f001
64             Value of the lower front right corner.
65         @param f010
66             Value of the upper back left corner.
67         @param f011
68             Value of the upper front left corner.
69         @param f100
70             Value of the lower back right corner.
71         @param f101
72             Value of the lower back right corner.
73         @param f110
74             Value of the upper front right corner.
75         @param f111
76             Value of the upper front right corner.
77         @param position
78             The relative (0-1) position to interpolate.
79         @return
80             The interpolated value.
81         */
interpolate(const Real f000,const Real f001,const Real f010,const Real f011,const Real f100,const Real f101,const Real f110,const Real f111,const Vector3 & position)82         inline Real interpolate(const Real f000, const Real f001, const Real f010, const Real f011,
83             const Real f100, const Real f101, const Real f110, const Real f111, const Vector3 &position) const
84         {
85             Real oneMinX = (Real)1.0 - position.x;
86             Real oneMinY = (Real)1.0 - position.y;
87             Real oneMinZ = (Real)1.0 - position.z;
88             Real oneMinXoneMinY = oneMinX * oneMinY;
89             Real xOneMinY = position.x * oneMinY;
90             return oneMinZ * (f000 * oneMinXoneMinY
91                 + f100 * xOneMinY
92                 + f010 * oneMinX * position.y)
93                 + position.z * (f001 * oneMinXoneMinY
94                 + f101 * xOneMinY
95                 + f011 * oneMinX * position.y)
96                 + position.x * position.y * (f110 * oneMinZ
97                 + f111 * position.z);
98         }
99 
100     public:
101 
102         /** Constructur. Protected to have the initialization.
103         @param src
104             The volume source to decide something.
105         @param maxCellSize
106             The maximum size when the splitting will stop anyway.
107         */
108         OctreeNodeSplitPolicy(const Source *src, const Real maxCellSize);
109 
110         /** Decider for the splitting.
111         @param node
112             The split candidate.
113         @param geometricError
114             The accepted geometric error.
115         @return
116             true if the node should be split.
117         */
118         virtual bool doSplit(OctreeNode *node, const Real geometricError) const;
119     };
120     /** @} */
121     /** @} */
122 }
123 }
124 
125 #endif
126