Coverage Report

Created: 2025-12-14 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/PlugIns/OctreeSceneManager/src/OgreOctree.cpp
Line
Count
Source
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
/***************************************************************************
29
octree.cpp  -  description
30
-------------------
31
begin                : Mon Sep 30 2002
32
copyright            : (C) 2002 by Jon Anderson
33
email                : janders@users.sf.net
34
35
***************************************************************************/
36
37
#include "OgreOctree.h"
38
#include "OgreOctreeNode.h"
39
#include "OgreWireBoundingBox.h"
40
41
namespace Ogre
42
{
43
44
/** Returns true is the box will fit in a child.
45
*/
46
bool Octree::_isTwiceSize( const AxisAlignedBox &box ) const
47
0
{
48
    // infinite boxes never fit in a child - always root node
49
0
    if (box.isInfinite())
50
0
        return false;
51
52
0
    Vector3 halfMBoxSize = mBox.getHalfSize();
53
0
    Vector3 boxSize = box.getSize();
54
0
    return ((boxSize.x <= halfMBoxSize.x) && (boxSize.y <= halfMBoxSize.y) && (boxSize.z <= halfMBoxSize.z));
55
56
0
}
57
58
/** It's assumed the the given box has already been proven to fit into
59
* a child.  Since it's a loose octree, only the centers need to be
60
* compared to find the appropriate node.
61
*/
62
void Octree::_getChildIndexes( const AxisAlignedBox &box, int *x, int *y, int *z ) const
63
0
{
64
0
    Vector3 center = mBox.getMaximum().midPoint( mBox.getMinimum() );
65
66
0
    Vector3 ncenter = box.getMaximum().midPoint( box.getMinimum() );
67
68
0
    if ( ncenter.x > center.x )
69
0
        * x = 1;
70
0
    else
71
0
        *x = 0;
72
73
0
    if ( ncenter.y > center.y )
74
0
        * y = 1;
75
0
    else
76
0
        *y = 0;
77
78
0
    if ( ncenter.z > center.z )
79
0
        * z = 1;
80
0
    else
81
0
        *z = 0;
82
83
0
}
84
85
Octree::Octree( Octree * parent ) 
86
0
    : mWireBoundingBox(0),
87
0
      mHalfSize( 0, 0, 0 )
88
0
{
89
    //initialize all children to null.
90
0
    for ( int i = 0; i < 2; i++ )
91
0
    {
92
0
        for ( int j = 0; j < 2; j++ )
93
0
        {
94
0
            for ( int k = 0; k < 2; k++ )
95
0
            {
96
0
                mChildren[ i ][ j ][ k ] = 0;
97
0
            }
98
0
        }
99
0
    }
100
101
0
    mParent = parent;
102
0
    mNumNodes = 0;
103
0
}
104
105
Octree::~Octree()
106
0
{
107
    //initialize all children to null.
108
0
    for ( int i = 0; i < 2; i++ )
109
0
    {
110
0
        for ( int j = 0; j < 2; j++ )
111
0
        {
112
0
            for ( int k = 0; k < 2; k++ )
113
0
            {
114
0
                if ( mChildren[ i ][ j ][ k ] != 0 )
115
0
                    OGRE_DELETE mChildren[ i ][ j ][ k ];
116
0
            }
117
0
        }
118
0
    }
119
120
0
    if(mWireBoundingBox)
121
0
        OGRE_DELETE mWireBoundingBox;
122
123
0
    mParent = 0;
124
0
}
125
126
void Octree::_addNode( OctreeNode * n )
127
0
{
128
0
    mNodes.push_back( n );
129
0
    n -> setOctant( this );
130
131
    //update total counts.
132
0
    _ref();
133
134
0
}
135
136
void Octree::_removeNode( OctreeNode * n )
137
0
{
138
0
    mNodes.erase( std::find( mNodes.begin(), mNodes.end(), n ) );
139
0
    n -> setOctant( 0 );
140
141
    //update total counts.
142
0
    _unref();
143
0
}
144
145
void Octree::_getCullBounds( AxisAlignedBox *b ) const
146
0
{
147
0
    b -> setExtents( mBox.getMinimum() - mHalfSize, mBox.getMaximum() + mHalfSize );
148
0
}
149
150
WireBoundingBox* Octree::getWireBoundingBox()
151
0
{
152
    // Create a WireBoundingBox if needed
153
0
    if(mWireBoundingBox == 0)
154
0
        mWireBoundingBox = OGRE_NEW WireBoundingBox();
155
156
0
    mWireBoundingBox->setupBoundingBox(mBox);
157
0
    return mWireBoundingBox;
158
0
}
159
160
}