2
* Adapted from code copyright 2009-2010 NVIDIA Corporation
3
* Modifications Copyright 2011, Blender Foundation.
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
#ifndef __BVH_NODE_H__
19
#define __BVH_NODE_H__
21
#include "util_boundbox.h"
22
#include "util_debug.h"
23
#include "util_types.h"
32
BVH_STAT_TRIANGLE_COUNT,
33
BVH_STAT_CHILDNODE_COUNT
46
virtual bool is_leaf() const = 0;
47
virtual int num_children() const = 0;
48
virtual BVHNode *get_child(int i) const = 0;
49
virtual int num_triangles() const { return 0; }
50
virtual void print(int depth = 0) const = 0;
52
float getArea() const { return m_bounds.area(); }
58
int getSubtreeSize(BVH_STAT stat=BVH_STAT_NODE_COUNT) const;
59
float computeSubtreeSAHCost(const BVHParams& p, float probability = 1.0f) const;
63
class InnerNode : public BVHNode
66
InnerNode(const BoundBox& bounds, BVHNode* child0, BVHNode* child1)
69
m_visibility = child0->m_visibility|child1->m_visibility;
74
bool is_leaf() const { return false; }
75
int num_children() const { return 2; }
76
BVHNode *get_child(int i) const{ assert(i>=0 && i<2); return children[i]; }
77
void print(int depth) const;
82
class LeafNode : public BVHNode
85
LeafNode(const BoundBox& bounds, uint visibility, int lo, int hi)
88
m_visibility = visibility;
93
LeafNode(const LeafNode& s)
99
bool is_leaf() const { return true; }
100
int num_children() const { return 0; }
101
BVHNode *get_child(int) const { return NULL; }
102
int num_triangles() const { return m_hi - m_lo; }
103
void print(int depth) const;
111
#endif /* __BVH_NODE_H__ */