2017-08-01 14:30:58 +02:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
///b3DynamicBvh implementation by Nathanael Presson
|
|
|
|
|
|
|
|
#include "b3DynamicBvh.h"
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
typedef b3AlignedObjectArray<b3DbvtNode*> b3NodeArray;
|
|
|
|
typedef b3AlignedObjectArray<const b3DbvtNode*> b3ConstNodeArray;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
struct b3DbvtNodeEnumerator : b3DynamicBvh::ICollide
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3ConstNodeArray nodes;
|
2017-08-01 14:30:58 +02:00
|
|
|
void Process(const b3DbvtNode* n) { nodes.push_back(n); }
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static B3_DBVT_INLINE int b3IndexOf(const b3DbvtNode* node)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return (node->parent->childs[1] == node);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static B3_DBVT_INLINE b3DbvtVolume b3Merge(const b3DbvtVolume& a,
|
|
|
|
const b3DbvtVolume& b)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
#if (B3_DBVT_MERGE_IMPL == B3_DBVT_IMPL_SSE)
|
2017-08-01 14:30:58 +02:00
|
|
|
B3_ATTRIBUTE_ALIGNED16(char locals[sizeof(b3DbvtAabbMm)]);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtVolume& res = *(b3DbvtVolume*)locals;
|
2017-08-01 14:30:58 +02:00
|
|
|
#else
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtVolume res;
|
2017-08-01 14:30:58 +02:00
|
|
|
#endif
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Merge(a, b, res);
|
|
|
|
return (res);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// volume+edge lengths
|
2019-01-03 14:26:51 +01:00
|
|
|
static B3_DBVT_INLINE b3Scalar b3Size(const b3DbvtVolume& a)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const b3Vector3 edges = a.Lengths();
|
|
|
|
return (edges.x * edges.y * edges.z +
|
|
|
|
edges.x + edges.y + edges.z);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static void b3GetMaxDepth(const b3DbvtNode* node, int depth, int& maxdepth)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (node->isinternal())
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3GetMaxDepth(node->childs[0], depth + 1, maxdepth);
|
|
|
|
b3GetMaxDepth(node->childs[1], depth + 1, maxdepth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
maxdepth = b3Max(maxdepth, depth);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static B3_DBVT_INLINE void b3DeleteNode(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode* node)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
b3AlignedFree(pdbvt->m_free);
|
2019-01-03 14:26:51 +01:00
|
|
|
pdbvt->m_free = node;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static void b3RecurseDeleteNode(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode* node)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (!node->isleaf())
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3RecurseDeleteNode(pdbvt, node->childs[0]);
|
|
|
|
b3RecurseDeleteNode(pdbvt, node->childs[1]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (node == pdbvt->m_root) pdbvt->m_root = 0;
|
|
|
|
b3DeleteNode(pdbvt, node);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static B3_DBVT_INLINE b3DbvtNode* b3CreateNode(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode* parent,
|
|
|
|
void* data)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* node;
|
|
|
|
if (pdbvt->m_free)
|
|
|
|
{
|
|
|
|
node = pdbvt->m_free;
|
|
|
|
pdbvt->m_free = 0;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
else
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
node = new (b3AlignedAlloc(sizeof(b3DbvtNode), 16)) b3DbvtNode();
|
|
|
|
}
|
|
|
|
node->parent = parent;
|
|
|
|
node->data = data;
|
|
|
|
node->childs[1] = 0;
|
|
|
|
return (node);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static B3_DBVT_INLINE b3DbvtNode* b3CreateNode(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode* parent,
|
|
|
|
const b3DbvtVolume& volume,
|
|
|
|
void* data)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* node = b3CreateNode(pdbvt, parent, data);
|
|
|
|
node->volume = volume;
|
|
|
|
return (node);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static B3_DBVT_INLINE b3DbvtNode* b3CreateNode(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode* parent,
|
|
|
|
const b3DbvtVolume& volume0,
|
|
|
|
const b3DbvtVolume& volume1,
|
|
|
|
void* data)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* node = b3CreateNode(pdbvt, parent, data);
|
|
|
|
b3Merge(volume0, volume1, node->volume);
|
|
|
|
return (node);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static void b3InsertLeaf(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode* root,
|
|
|
|
b3DbvtNode* leaf)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (!pdbvt->m_root)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
pdbvt->m_root = leaf;
|
|
|
|
leaf->parent = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (!root->isleaf())
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
root = root->childs[b3Select(leaf->volume,
|
|
|
|
root->childs[0]->volume,
|
|
|
|
root->childs[1]->volume)];
|
|
|
|
} while (!root->isleaf());
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* prev = root->parent;
|
|
|
|
b3DbvtNode* node = b3CreateNode(pdbvt, prev, leaf->volume, root->volume, 0);
|
|
|
|
if (prev)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
prev->childs[b3IndexOf(root)] = node;
|
|
|
|
node->childs[0] = root;
|
|
|
|
root->parent = node;
|
|
|
|
node->childs[1] = leaf;
|
|
|
|
leaf->parent = node;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!prev->volume.Contain(node->volume))
|
|
|
|
b3Merge(prev->childs[0]->volume, prev->childs[1]->volume, prev->volume);
|
2017-08-01 14:30:58 +02:00
|
|
|
else
|
|
|
|
break;
|
2019-01-03 14:26:51 +01:00
|
|
|
node = prev;
|
|
|
|
} while (0 != (prev = node->parent));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
node->childs[0] = root;
|
|
|
|
root->parent = node;
|
|
|
|
node->childs[1] = leaf;
|
|
|
|
leaf->parent = node;
|
|
|
|
pdbvt->m_root = node;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static b3DbvtNode* b3RemoveLeaf(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode* leaf)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (leaf == pdbvt->m_root)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
pdbvt->m_root = 0;
|
|
|
|
return (0);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* parent = leaf->parent;
|
|
|
|
b3DbvtNode* prev = parent->parent;
|
|
|
|
b3DbvtNode* sibling = parent->childs[1 - b3IndexOf(leaf)];
|
|
|
|
if (prev)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
prev->childs[b3IndexOf(parent)] = sibling;
|
|
|
|
sibling->parent = prev;
|
|
|
|
b3DeleteNode(pdbvt, parent);
|
|
|
|
while (prev)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const b3DbvtVolume pb = prev->volume;
|
|
|
|
b3Merge(prev->childs[0]->volume, prev->childs[1]->volume, prev->volume);
|
|
|
|
if (b3NotEqual(pb, prev->volume))
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
prev = prev->parent;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
return (prev ? prev : pdbvt->m_root);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
pdbvt->m_root = sibling;
|
|
|
|
sibling->parent = 0;
|
|
|
|
b3DeleteNode(pdbvt, parent);
|
|
|
|
return (pdbvt->m_root);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static void b3FetchLeaves(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode* root,
|
|
|
|
b3NodeArray& leaves,
|
|
|
|
int depth = -1)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (root->isinternal() && depth)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3FetchLeaves(pdbvt, root->childs[0], leaves, depth - 1);
|
|
|
|
b3FetchLeaves(pdbvt, root->childs[1], leaves, depth - 1);
|
|
|
|
b3DeleteNode(pdbvt, root);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
leaves.push_back(root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
static bool b3LeftOfAxis(const b3DbvtNode* node,
|
|
|
|
const b3Vector3& org,
|
|
|
|
const b3Vector3& axis)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return b3Dot(axis, node->volume.Center() - org) <= 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Partitions leaves such that leaves[0, n) are on the
|
|
|
|
// left of axis, and leaves[n, count) are on the right
|
|
|
|
// of axis. returns N.
|
2019-01-03 14:26:51 +01:00
|
|
|
static int b3Split(b3DbvtNode** leaves,
|
|
|
|
int count,
|
|
|
|
const b3Vector3& org,
|
|
|
|
const b3Vector3& axis)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
int begin = 0;
|
|
|
|
int end = count;
|
|
|
|
for (;;)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
while (begin != end && b3LeftOfAxis(leaves[begin], org, axis))
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (begin == end)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
while (begin != end && !b3LeftOfAxis(leaves[end - 1], org, axis))
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (begin == end)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// swap out of place nodes
|
|
|
|
--end;
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* temp = leaves[begin];
|
|
|
|
leaves[begin] = leaves[end];
|
|
|
|
leaves[end] = temp;
|
2017-08-01 14:30:58 +02:00
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static b3DbvtVolume b3Bounds(b3DbvtNode** leaves,
|
|
|
|
int count)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
#if B3_DBVT_MERGE_IMPL == B3_DBVT_IMPL_SSE
|
|
|
|
B3_ATTRIBUTE_ALIGNED16(char locals[sizeof(b3DbvtVolume)]);
|
|
|
|
b3DbvtVolume& volume = *(b3DbvtVolume*)locals;
|
|
|
|
volume = leaves[0]->volume;
|
2017-08-01 14:30:58 +02:00
|
|
|
#else
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtVolume volume = leaves[0]->volume;
|
2017-08-01 14:30:58 +02:00
|
|
|
#endif
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 1, ni = count; i < ni; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Merge(volume, leaves[i]->volume, volume);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
return (volume);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static void b3BottomUp(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode** leaves,
|
|
|
|
int count)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
while (count > 1)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Scalar minsize = B3_INFINITY;
|
|
|
|
int minidx[2] = {-1, -1};
|
|
|
|
for (int i = 0; i < count; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = i + 1; j < count; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const b3Scalar sz = b3Size(b3Merge(leaves[i]->volume, leaves[j]->volume));
|
|
|
|
if (sz < minsize)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
minsize = sz;
|
|
|
|
minidx[0] = i;
|
|
|
|
minidx[1] = j;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* n[] = {leaves[minidx[0]], leaves[minidx[1]]};
|
|
|
|
b3DbvtNode* p = b3CreateNode(pdbvt, 0, n[0]->volume, n[1]->volume, 0);
|
|
|
|
p->childs[0] = n[0];
|
|
|
|
p->childs[1] = n[1];
|
|
|
|
n[0]->parent = p;
|
|
|
|
n[1]->parent = p;
|
|
|
|
leaves[minidx[0]] = p;
|
|
|
|
leaves[minidx[1]] = leaves[count - 1];
|
2017-08-01 14:30:58 +02:00
|
|
|
--count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static b3DbvtNode* b3TopDown(b3DynamicBvh* pdbvt,
|
|
|
|
b3DbvtNode** leaves,
|
|
|
|
int count,
|
|
|
|
int bu_treshold)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
static const b3Vector3 axis[] = {b3MakeVector3(1, 0, 0),
|
|
|
|
b3MakeVector3(0, 1, 0),
|
|
|
|
b3MakeVector3(0, 0, 1)};
|
|
|
|
b3Assert(bu_treshold > 1);
|
|
|
|
if (count > 1)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (count > bu_treshold)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const b3DbvtVolume vol = b3Bounds(leaves, count);
|
|
|
|
const b3Vector3 org = vol.Center();
|
|
|
|
int partition;
|
|
|
|
int bestaxis = -1;
|
|
|
|
int bestmidp = count;
|
|
|
|
int splitcount[3][2] = {{0, 0}, {0, 0}, {0, 0}};
|
2017-08-01 14:30:58 +02:00
|
|
|
int i;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (i = 0; i < count; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const b3Vector3 x = leaves[i]->volume.Center() - org;
|
|
|
|
for (int j = 0; j < 3; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
++splitcount[j][b3Dot(x, axis[j]) > 0 ? 1 : 0];
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
for (i = 0; i < 3; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if ((splitcount[i][0] > 0) && (splitcount[i][1] > 0))
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const int midp = (int)b3Fabs(b3Scalar(splitcount[i][0] - splitcount[i][1]));
|
|
|
|
if (midp < bestmidp)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
bestaxis = i;
|
|
|
|
bestmidp = midp;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (bestaxis >= 0)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
partition = b3Split(leaves, count, org, axis[bestaxis]);
|
|
|
|
b3Assert(partition != 0 && partition != count);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
partition = count / 2 + 1;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* node = b3CreateNode(pdbvt, 0, vol, 0);
|
|
|
|
node->childs[0] = b3TopDown(pdbvt, &leaves[0], partition, bu_treshold);
|
|
|
|
node->childs[1] = b3TopDown(pdbvt, &leaves[partition], count - partition, bu_treshold);
|
|
|
|
node->childs[0]->parent = node;
|
|
|
|
node->childs[1]->parent = node;
|
|
|
|
return (node);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3BottomUp(pdbvt, leaves, count);
|
|
|
|
return (leaves[0]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
return (leaves[0]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
static B3_DBVT_INLINE b3DbvtNode* b3Sort(b3DbvtNode* n, b3DbvtNode*& r)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* p = n->parent;
|
2017-08-01 14:30:58 +02:00
|
|
|
b3Assert(n->isinternal());
|
2019-01-03 14:26:51 +01:00
|
|
|
if (p > n)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const int i = b3IndexOf(n);
|
|
|
|
const int j = 1 - i;
|
|
|
|
b3DbvtNode* s = p->childs[j];
|
|
|
|
b3DbvtNode* q = p->parent;
|
|
|
|
b3Assert(n == p->childs[i]);
|
|
|
|
if (q)
|
|
|
|
q->childs[b3IndexOf(p)] = n;
|
|
|
|
else
|
|
|
|
r = n;
|
|
|
|
s->parent = n;
|
|
|
|
p->parent = n;
|
|
|
|
n->parent = q;
|
|
|
|
p->childs[0] = n->childs[0];
|
|
|
|
p->childs[1] = n->childs[1];
|
|
|
|
n->childs[0]->parent = p;
|
|
|
|
n->childs[1]->parent = p;
|
|
|
|
n->childs[i] = p;
|
|
|
|
n->childs[j] = s;
|
|
|
|
b3Swap(p->volume, n->volume);
|
|
|
|
return (p);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
return (n);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static B3_DBVT_INLINE b3DbvtNode* walkup(b3DbvtNode* n,int count)
|
|
|
|
{
|
|
|
|
while(n&&(count--)) n=n->parent;
|
|
|
|
return(n);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// Api
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
b3DynamicBvh::b3DynamicBvh()
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
m_root = 0;
|
|
|
|
m_free = 0;
|
|
|
|
m_lkhd = -1;
|
|
|
|
m_leaves = 0;
|
|
|
|
m_opath = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
b3DynamicBvh::~b3DynamicBvh()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::clear()
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_root)
|
|
|
|
b3RecurseDeleteNode(this, m_root);
|
2017-08-01 14:30:58 +02:00
|
|
|
b3AlignedFree(m_free);
|
2019-01-03 14:26:51 +01:00
|
|
|
m_free = 0;
|
|
|
|
m_lkhd = -1;
|
2017-08-01 14:30:58 +02:00
|
|
|
m_stkStack.clear();
|
2019-01-03 14:26:51 +01:00
|
|
|
m_opath = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::optimizeBottomUp()
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_root)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
b3NodeArray leaves;
|
|
|
|
leaves.reserve(m_leaves);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3FetchLeaves(this, m_root, leaves);
|
|
|
|
b3BottomUp(this, &leaves[0], leaves.size());
|
|
|
|
m_root = leaves[0];
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::optimizeTopDown(int bu_treshold)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_root)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3NodeArray leaves;
|
2017-08-01 14:30:58 +02:00
|
|
|
leaves.reserve(m_leaves);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3FetchLeaves(this, m_root, leaves);
|
|
|
|
m_root = b3TopDown(this, &leaves[0], leaves.size(), bu_treshold);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::optimizeIncremental(int passes)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (passes < 0) passes = m_leaves;
|
|
|
|
if (m_root && (passes > 0))
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
b3DbvtNode* node = m_root;
|
|
|
|
unsigned bit = 0;
|
|
|
|
while (node->isinternal())
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
node = b3Sort(node, m_root)->childs[(m_opath >> bit) & 1];
|
|
|
|
bit = (bit + 1) & (sizeof(unsigned) * 8 - 1);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
update(node);
|
|
|
|
++m_opath;
|
2019-01-03 14:26:51 +01:00
|
|
|
} while (--passes);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* b3DynamicBvh::insert(const b3DbvtVolume& volume, void* data)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* leaf = b3CreateNode(this, 0, volume, data);
|
|
|
|
b3InsertLeaf(this, m_root, leaf);
|
2017-08-01 14:30:58 +02:00
|
|
|
++m_leaves;
|
2019-01-03 14:26:51 +01:00
|
|
|
return (leaf);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::update(b3DbvtNode* leaf, int lookahead)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* root = b3RemoveLeaf(this, leaf);
|
|
|
|
if (root)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (lookahead >= 0)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; (i < lookahead) && root->parent; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
root = root->parent;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
root = m_root;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3InsertLeaf(this, root, leaf);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::update(b3DbvtNode* leaf, b3DbvtVolume& volume)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNode* root = b3RemoveLeaf(this, leaf);
|
|
|
|
if (root)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_lkhd >= 0)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; (i < m_lkhd) && root->parent; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
root = root->parent;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
root = m_root;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
leaf->volume = volume;
|
|
|
|
b3InsertLeaf(this, root, leaf);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
bool b3DynamicBvh::update(b3DbvtNode* leaf, b3DbvtVolume& volume, const b3Vector3& velocity, b3Scalar margin)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (leaf->volume.Contain(volume)) return (false);
|
|
|
|
volume.Expand(b3MakeVector3(margin, margin, margin));
|
2017-08-01 14:30:58 +02:00
|
|
|
volume.SignedExpand(velocity);
|
2019-01-03 14:26:51 +01:00
|
|
|
update(leaf, volume);
|
|
|
|
return (true);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
bool b3DynamicBvh::update(b3DbvtNode* leaf, b3DbvtVolume& volume, const b3Vector3& velocity)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (leaf->volume.Contain(volume)) return (false);
|
2017-08-01 14:30:58 +02:00
|
|
|
volume.SignedExpand(velocity);
|
2019-01-03 14:26:51 +01:00
|
|
|
update(leaf, volume);
|
|
|
|
return (true);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
bool b3DynamicBvh::update(b3DbvtNode* leaf, b3DbvtVolume& volume, b3Scalar margin)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (leaf->volume.Contain(volume)) return (false);
|
|
|
|
volume.Expand(b3MakeVector3(margin, margin, margin));
|
|
|
|
update(leaf, volume);
|
|
|
|
return (true);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::remove(b3DbvtNode* leaf)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3RemoveLeaf(this, leaf);
|
|
|
|
b3DeleteNode(this, leaf);
|
2017-08-01 14:30:58 +02:00
|
|
|
--m_leaves;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::write(IWriter* iwriter) const
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtNodeEnumerator nodes;
|
|
|
|
nodes.nodes.reserve(m_leaves * 2);
|
|
|
|
enumNodes(m_root, nodes);
|
|
|
|
iwriter->Prepare(m_root, nodes.nodes.size());
|
|
|
|
for (int i = 0; i < nodes.nodes.size(); ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const b3DbvtNode* n = nodes.nodes[i];
|
|
|
|
int p = -1;
|
|
|
|
if (n->parent) p = nodes.nodes.findLinearSearch(n->parent);
|
|
|
|
if (n->isinternal())
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const int c0 = nodes.nodes.findLinearSearch(n->childs[0]);
|
|
|
|
const int c1 = nodes.nodes.findLinearSearch(n->childs[1]);
|
|
|
|
iwriter->WriteNode(n, i, p, c0, c1);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
iwriter->WriteLeaf(n, i, p);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::clone(b3DynamicBvh& dest, IClone* iclone) const
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
dest.clear();
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_root != 0)
|
|
|
|
{
|
|
|
|
b3AlignedObjectArray<sStkCLN> stack;
|
2017-08-01 14:30:58 +02:00
|
|
|
stack.reserve(m_leaves);
|
2019-01-03 14:26:51 +01:00
|
|
|
stack.push_back(sStkCLN(m_root, 0));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
const int i = stack.size() - 1;
|
|
|
|
const sStkCLN e = stack[i];
|
|
|
|
b3DbvtNode* n = b3CreateNode(&dest, e.parent, e.node->volume, e.node->data);
|
2017-08-01 14:30:58 +02:00
|
|
|
stack.pop_back();
|
2019-01-03 14:26:51 +01:00
|
|
|
if (e.parent != 0)
|
|
|
|
e.parent->childs[i & 1] = n;
|
2017-08-01 14:30:58 +02:00
|
|
|
else
|
2019-01-03 14:26:51 +01:00
|
|
|
dest.m_root = n;
|
|
|
|
if (e.node->isinternal())
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
stack.push_back(sStkCLN(e.node->childs[0], n));
|
|
|
|
stack.push_back(sStkCLN(e.node->childs[1], n));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iclone->CloneLeaf(n);
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
} while (stack.size() > 0);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
int b3DynamicBvh::maxdepth(const b3DbvtNode* node)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
int depth = 0;
|
|
|
|
if (node) b3GetMaxDepth(node, 1, depth);
|
|
|
|
return (depth);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
int b3DynamicBvh::countLeaves(const b3DbvtNode* node)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (node->isinternal())
|
|
|
|
return (countLeaves(node->childs[0]) + countLeaves(node->childs[1]));
|
2017-08-01 14:30:58 +02:00
|
|
|
else
|
2019-01-03 14:26:51 +01:00
|
|
|
return (1);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::extractLeaves(const b3DbvtNode* node, b3AlignedObjectArray<const b3DbvtNode*>& leaves)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (node->isinternal())
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
extractLeaves(node->childs[0], leaves);
|
|
|
|
extractLeaves(node->childs[1], leaves);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
leaves.push_back(node);
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
#if B3_DBVT_ENABLE_BENCHMARK
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
q6600,2.4ghz
|
|
|
|
|
|
|
|
/Ox /Ob2 /Oi /Ot /I "." /I "..\.." /I "..\..\src" /D "NDEBUG" /D "_LIB" /D "_WINDOWS" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32"
|
|
|
|
/GF /FD /MT /GS- /Gy /arch:SSE2 /Zc:wchar_t- /Fp"..\..\out\release8\build\libbulletcollision\libbulletcollision.pch"
|
|
|
|
/Fo"..\..\out\release8\build\libbulletcollision\\"
|
|
|
|
/Fd"..\..\out\release8\build\libbulletcollision\bulletcollision.pdb"
|
|
|
|
/W3 /nologo /c /Wp64 /Zi /errorReport:prompt
|
|
|
|
|
|
|
|
Benchmarking dbvt...
|
|
|
|
World scale: 100.000000
|
|
|
|
Extents base: 1.000000
|
|
|
|
Extents range: 4.000000
|
|
|
|
Leaves: 8192
|
|
|
|
sizeof(b3DbvtVolume): 32 bytes
|
|
|
|
sizeof(b3DbvtNode): 44 bytes
|
|
|
|
[1] b3DbvtVolume intersections: 3499 ms (-1%)
|
|
|
|
[2] b3DbvtVolume merges: 1934 ms (0%)
|
|
|
|
[3] b3DynamicBvh::collideTT: 5485 ms (-21%)
|
|
|
|
[4] b3DynamicBvh::collideTT self: 2814 ms (-20%)
|
|
|
|
[5] b3DynamicBvh::collideTT xform: 7379 ms (-1%)
|
|
|
|
[6] b3DynamicBvh::collideTT xform,self: 7270 ms (-2%)
|
|
|
|
[7] b3DynamicBvh::rayTest: 6314 ms (0%),(332143 r/s)
|
|
|
|
[8] insert/remove: 2093 ms (0%),(1001983 ir/s)
|
|
|
|
[9] updates (teleport): 1879 ms (-3%),(1116100 u/s)
|
|
|
|
[10] updates (jitter): 1244 ms (-4%),(1685813 u/s)
|
|
|
|
[11] optimize (incremental): 2514 ms (0%),(1668000 o/s)
|
|
|
|
[12] b3DbvtVolume notequal: 3659 ms (0%)
|
|
|
|
[13] culling(OCL+fullsort): 2218 ms (0%),(461 t/s)
|
|
|
|
[14] culling(OCL+qsort): 3688 ms (5%),(2221 t/s)
|
|
|
|
[15] culling(KDOP+qsort): 1139 ms (-1%),(7192 t/s)
|
|
|
|
[16] insert/remove batch(256): 5092 ms (0%),(823704 bir/s)
|
|
|
|
[17] b3DbvtVolume select: 3419 ms (0%)
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct b3DbvtBenchmark
|
|
|
|
{
|
|
|
|
struct NilPolicy : b3DynamicBvh::ICollide
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
NilPolicy() : m_pcount(0), m_depth(-B3_INFINITY), m_checksort(true) {}
|
|
|
|
void Process(const b3DbvtNode*, const b3DbvtNode*) { ++m_pcount; }
|
|
|
|
void Process(const b3DbvtNode*) { ++m_pcount; }
|
|
|
|
void Process(const b3DbvtNode*, b3Scalar depth)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
++m_pcount;
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_checksort)
|
|
|
|
{
|
|
|
|
if (depth >= m_depth)
|
|
|
|
m_depth = depth;
|
|
|
|
else
|
|
|
|
printf("wrong depth: %f (should be >= %f)\r\n", depth, m_depth);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
int m_pcount;
|
|
|
|
b3Scalar m_depth;
|
|
|
|
bool m_checksort;
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
struct P14 : b3DynamicBvh::ICollide
|
|
|
|
{
|
|
|
|
struct Node
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const b3DbvtNode* leaf;
|
|
|
|
b3Scalar depth;
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
2019-01-03 14:26:51 +01:00
|
|
|
void Process(const b3DbvtNode* leaf, b3Scalar depth)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
Node n;
|
|
|
|
n.leaf = leaf;
|
|
|
|
n.depth = depth;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
static int sortfnc(const Node& a, const Node& b)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (a.depth < b.depth) return (+1);
|
|
|
|
if (a.depth > b.depth) return (-1);
|
|
|
|
return (0);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3AlignedObjectArray<Node> m_nodes;
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
struct P15 : b3DynamicBvh::ICollide
|
|
|
|
{
|
|
|
|
struct Node
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const b3DbvtNode* leaf;
|
|
|
|
b3Scalar depth;
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
void Process(const b3DbvtNode* leaf)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
Node n;
|
|
|
|
n.leaf = leaf;
|
|
|
|
n.depth = dot(leaf->volume.Center(), m_axis);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
static int sortfnc(const Node& a, const Node& b)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (a.depth < b.depth) return (+1);
|
|
|
|
if (a.depth > b.depth) return (-1);
|
|
|
|
return (0);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3AlignedObjectArray<Node> m_nodes;
|
|
|
|
b3Vector3 m_axis;
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
2019-01-03 14:26:51 +01:00
|
|
|
static b3Scalar RandUnit()
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return (rand() / (b3Scalar)RAND_MAX);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
static b3Vector3 RandVector3()
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return (b3Vector3(RandUnit(), RandUnit(), RandUnit()));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
static b3Vector3 RandVector3(b3Scalar cs)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return (RandVector3() * cs - b3Vector3(cs, cs, cs) / 2);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
static b3DbvtVolume RandVolume(b3Scalar cs, b3Scalar eb, b3Scalar es)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return (b3DbvtVolume::FromCE(RandVector3(cs), b3Vector3(eb, eb, eb) + RandVector3() * es));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
static b3Transform RandTransform(b3Scalar cs)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Transform t;
|
2017-08-01 14:30:58 +02:00
|
|
|
t.setOrigin(RandVector3(cs));
|
2019-01-03 14:26:51 +01:00
|
|
|
t.setRotation(b3Quaternion(RandUnit() * B3_PI * 2, RandUnit() * B3_PI * 2, RandUnit() * B3_PI * 2).normalized());
|
|
|
|
return (t);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
static void RandTree(b3Scalar cs, b3Scalar eb, b3Scalar es, int leaves, b3DynamicBvh& dbvt)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
dbvt.clear();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < leaves; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
dbvt.insert(RandVolume(cs, eb, es), 0);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3DynamicBvh::benchmark()
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
static const b3Scalar cfgVolumeCenterScale = 100;
|
|
|
|
static const b3Scalar cfgVolumeExentsBase = 1;
|
|
|
|
static const b3Scalar cfgVolumeExentsScale = 4;
|
|
|
|
static const int cfgLeaves = 8192;
|
|
|
|
static const bool cfgEnable = true;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
//[1] b3DbvtVolume intersections
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark1_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark1_Iterations = 8;
|
|
|
|
static const int cfgBenchmark1_Reference = 3499;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[2] b3DbvtVolume merges
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark2_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark2_Iterations = 4;
|
|
|
|
static const int cfgBenchmark2_Reference = 1945;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[3] b3DynamicBvh::collideTT
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark3_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark3_Iterations = 512;
|
|
|
|
static const int cfgBenchmark3_Reference = 5485;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[4] b3DynamicBvh::collideTT self
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark4_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark4_Iterations = 512;
|
|
|
|
static const int cfgBenchmark4_Reference = 2814;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[5] b3DynamicBvh::collideTT xform
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark5_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark5_Iterations = 512;
|
|
|
|
static const b3Scalar cfgBenchmark5_OffsetScale = 2;
|
|
|
|
static const int cfgBenchmark5_Reference = 7379;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[6] b3DynamicBvh::collideTT xform,self
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark6_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark6_Iterations = 512;
|
|
|
|
static const b3Scalar cfgBenchmark6_OffsetScale = 2;
|
|
|
|
static const int cfgBenchmark6_Reference = 7270;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[7] b3DynamicBvh::rayTest
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark7_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark7_Passes = 32;
|
|
|
|
static const int cfgBenchmark7_Iterations = 65536;
|
|
|
|
static const int cfgBenchmark7_Reference = 6307;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[8] insert/remove
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark8_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark8_Passes = 32;
|
|
|
|
static const int cfgBenchmark8_Iterations = 65536;
|
|
|
|
static const int cfgBenchmark8_Reference = 2105;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[9] updates (teleport)
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark9_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark9_Passes = 32;
|
|
|
|
static const int cfgBenchmark9_Iterations = 65536;
|
|
|
|
static const int cfgBenchmark9_Reference = 1879;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[10] updates (jitter)
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark10_Enable = cfgEnable;
|
|
|
|
static const b3Scalar cfgBenchmark10_Scale = cfgVolumeCenterScale / 10000;
|
|
|
|
static const int cfgBenchmark10_Passes = 32;
|
|
|
|
static const int cfgBenchmark10_Iterations = 65536;
|
|
|
|
static const int cfgBenchmark10_Reference = 1244;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[11] optimize (incremental)
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark11_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark11_Passes = 64;
|
|
|
|
static const int cfgBenchmark11_Iterations = 65536;
|
|
|
|
static const int cfgBenchmark11_Reference = 2510;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[12] b3DbvtVolume notequal
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark12_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark12_Iterations = 32;
|
|
|
|
static const int cfgBenchmark12_Reference = 3677;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[13] culling(OCL+fullsort)
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark13_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark13_Iterations = 1024;
|
|
|
|
static const int cfgBenchmark13_Reference = 2231;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[14] culling(OCL+qsort)
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark14_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark14_Iterations = 8192;
|
|
|
|
static const int cfgBenchmark14_Reference = 3500;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[15] culling(KDOP+qsort)
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark15_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark15_Iterations = 8192;
|
|
|
|
static const int cfgBenchmark15_Reference = 1151;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[16] insert/remove batch
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark16_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark16_BatchCount = 256;
|
|
|
|
static const int cfgBenchmark16_Passes = 16384;
|
|
|
|
static const int cfgBenchmark16_Reference = 5138;
|
2017-08-01 14:30:58 +02:00
|
|
|
//[17] select
|
2019-01-03 14:26:51 +01:00
|
|
|
bool cfgBenchmark17_Enable = cfgEnable;
|
|
|
|
static const int cfgBenchmark17_Iterations = 4;
|
|
|
|
static const int cfgBenchmark17_Reference = 3390;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Clock wallclock;
|
2017-08-01 14:30:58 +02:00
|
|
|
printf("Benchmarking dbvt...\r\n");
|
2019-01-03 14:26:51 +01:00
|
|
|
printf("\tWorld scale: %f\r\n", cfgVolumeCenterScale);
|
|
|
|
printf("\tExtents base: %f\r\n", cfgVolumeExentsBase);
|
|
|
|
printf("\tExtents range: %f\r\n", cfgVolumeExentsScale);
|
|
|
|
printf("\tLeaves: %u\r\n", cfgLeaves);
|
|
|
|
printf("\tsizeof(b3DbvtVolume): %u bytes\r\n", sizeof(b3DbvtVolume));
|
|
|
|
printf("\tsizeof(b3DbvtNode): %u bytes\r\n", sizeof(b3DbvtNode));
|
|
|
|
if (cfgBenchmark1_Enable)
|
|
|
|
{ // Benchmark 1
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3AlignedObjectArray<b3DbvtVolume> volumes;
|
|
|
|
b3AlignedObjectArray<bool> results;
|
2017-08-01 14:30:58 +02:00
|
|
|
volumes.resize(cfgLeaves);
|
|
|
|
results.resize(cfgLeaves);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgLeaves; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
volumes[i] = b3DbvtBenchmark::RandVolume(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
printf("[1] b3DbvtVolume intersections: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark1_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgLeaves; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int k = 0; k < cfgLeaves; ++k)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
results[k] = Intersect(volumes[j], volumes[k]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
printf("%u ms (%i%%)\r\n", time, (time - cfgBenchmark1_Reference) * 100 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark2_Enable)
|
|
|
|
{ // Benchmark 2
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3AlignedObjectArray<b3DbvtVolume> volumes;
|
|
|
|
b3AlignedObjectArray<b3DbvtVolume> results;
|
2017-08-01 14:30:58 +02:00
|
|
|
volumes.resize(cfgLeaves);
|
|
|
|
results.resize(cfgLeaves);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgLeaves; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
volumes[i] = b3DbvtBenchmark::RandVolume(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
printf("[2] b3DbvtVolume merges: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark2_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgLeaves; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int k = 0; k < cfgLeaves; ++k)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
Merge(volumes[j], volumes[k], results[k]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
printf("%u ms (%i%%)\r\n", time, (time - cfgBenchmark2_Reference) * 100 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark3_Enable)
|
|
|
|
{ // Benchmark 3
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt[2];
|
|
|
|
b3DbvtBenchmark::NilPolicy policy;
|
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt[0]);
|
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt[1]);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt[0].optimizeTopDown();
|
|
|
|
dbvt[1].optimizeTopDown();
|
|
|
|
printf("[3] b3DynamicBvh::collideTT: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark3_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh::collideTT(dbvt[0].m_root, dbvt[1].m_root, policy);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
printf("%u ms (%i%%)\r\n", time, (time - cfgBenchmark3_Reference) * 100 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark4_Enable)
|
|
|
|
{ // Benchmark 4
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3DbvtBenchmark::NilPolicy policy;
|
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
printf("[4] b3DynamicBvh::collideTT self: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark4_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh::collideTT(dbvt.m_root, dbvt.m_root, policy);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
printf("%u ms (%i%%)\r\n", time, (time - cfgBenchmark4_Reference) * 100 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark5_Enable)
|
|
|
|
{ // Benchmark 5
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt[2];
|
|
|
|
b3AlignedObjectArray<b3Transform> transforms;
|
|
|
|
b3DbvtBenchmark::NilPolicy policy;
|
2017-08-01 14:30:58 +02:00
|
|
|
transforms.resize(cfgBenchmark5_Iterations);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < transforms.size(); ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
transforms[i] = b3DbvtBenchmark::RandTransform(cfgVolumeCenterScale * cfgBenchmark5_OffsetScale);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt[0]);
|
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt[1]);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt[0].optimizeTopDown();
|
|
|
|
dbvt[1].optimizeTopDown();
|
|
|
|
printf("[5] b3DynamicBvh::collideTT xform: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark5_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh::collideTT(dbvt[0].m_root, dbvt[1].m_root, transforms[i], policy);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
printf("%u ms (%i%%)\r\n", time, (time - cfgBenchmark5_Reference) * 100 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark6_Enable)
|
|
|
|
{ // Benchmark 6
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3AlignedObjectArray<b3Transform> transforms;
|
|
|
|
b3DbvtBenchmark::NilPolicy policy;
|
2017-08-01 14:30:58 +02:00
|
|
|
transforms.resize(cfgBenchmark6_Iterations);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < transforms.size(); ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
transforms[i] = b3DbvtBenchmark::RandTransform(cfgVolumeCenterScale * cfgBenchmark6_OffsetScale);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
printf("[6] b3DynamicBvh::collideTT xform,self: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark6_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh::collideTT(dbvt.m_root, dbvt.m_root, transforms[i], policy);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
printf("%u ms (%i%%)\r\n", time, (time - cfgBenchmark6_Reference) * 100 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark7_Enable)
|
|
|
|
{ // Benchmark 7
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3AlignedObjectArray<b3Vector3> rayorg;
|
|
|
|
b3AlignedObjectArray<b3Vector3> raydir;
|
|
|
|
b3DbvtBenchmark::NilPolicy policy;
|
2017-08-01 14:30:58 +02:00
|
|
|
rayorg.resize(cfgBenchmark7_Iterations);
|
|
|
|
raydir.resize(cfgBenchmark7_Iterations);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < rayorg.size(); ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
rayorg[i] = b3DbvtBenchmark::RandVector3(cfgVolumeCenterScale * 2);
|
|
|
|
raydir[i] = b3DbvtBenchmark::RandVector3(cfgVolumeCenterScale * 2);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
printf("[7] b3DynamicBvh::rayTest: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark7_Passes; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgBenchmark7_Iterations; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh::rayTest(dbvt.m_root, rayorg[j], rayorg[j] + raydir[j], policy);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
unsigned rays = cfgBenchmark7_Passes * cfgBenchmark7_Iterations;
|
|
|
|
printf("%u ms (%i%%),(%u r/s)\r\n", time, (time - cfgBenchmark7_Reference) * 100 / time, (rays * 1000) / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark8_Enable)
|
|
|
|
{ // Benchmark 8
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
printf("[8] insert/remove: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark8_Passes; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgBenchmark8_Iterations; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
dbvt.remove(dbvt.insert(b3DbvtBenchmark::RandVolume(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale), 0));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
const int ir = cfgBenchmark8_Passes * cfgBenchmark8_Iterations;
|
|
|
|
printf("%u ms (%i%%),(%u ir/s)\r\n", time, (time - cfgBenchmark8_Reference) * 100 / time, ir * 1000 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark9_Enable)
|
|
|
|
{ // Benchmark 9
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3AlignedObjectArray<const b3DbvtNode*> leaves;
|
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
2019-01-03 14:26:51 +01:00
|
|
|
dbvt.extractLeaves(dbvt.m_root, leaves);
|
2017-08-01 14:30:58 +02:00
|
|
|
printf("[9] updates (teleport): ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark9_Passes; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgBenchmark9_Iterations; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
dbvt.update(const_cast<b3DbvtNode*>(leaves[rand() % cfgLeaves]),
|
|
|
|
b3DbvtBenchmark::RandVolume(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
const int up = cfgBenchmark9_Passes * cfgBenchmark9_Iterations;
|
|
|
|
printf("%u ms (%i%%),(%u u/s)\r\n", time, (time - cfgBenchmark9_Reference) * 100 / time, up * 1000 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark10_Enable)
|
|
|
|
{ // Benchmark 10
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3AlignedObjectArray<const b3DbvtNode*> leaves;
|
|
|
|
b3AlignedObjectArray<b3Vector3> vectors;
|
2017-08-01 14:30:58 +02:00
|
|
|
vectors.resize(cfgBenchmark10_Iterations);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < vectors.size(); ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
vectors[i] = (b3DbvtBenchmark::RandVector3() * 2 - b3Vector3(1, 1, 1)) * cfgBenchmark10_Scale;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
2019-01-03 14:26:51 +01:00
|
|
|
dbvt.extractLeaves(dbvt.m_root, leaves);
|
2017-08-01 14:30:58 +02:00
|
|
|
printf("[10] updates (jitter): ");
|
|
|
|
wallclock.reset();
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark10_Passes; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgBenchmark10_Iterations; ++j)
|
|
|
|
{
|
|
|
|
const b3Vector3& d = vectors[j];
|
|
|
|
b3DbvtNode* l = const_cast<b3DbvtNode*>(leaves[rand() % cfgLeaves]);
|
|
|
|
b3DbvtVolume v = b3DbvtVolume::FromMM(l->volume.Mins() + d, l->volume.Maxs() + d);
|
|
|
|
dbvt.update(l, v);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
const int up = cfgBenchmark10_Passes * cfgBenchmark10_Iterations;
|
|
|
|
printf("%u ms (%i%%),(%u u/s)\r\n", time, (time - cfgBenchmark10_Reference) * 100 / time, up * 1000 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark11_Enable)
|
|
|
|
{ // Benchmark 11
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
printf("[11] optimize (incremental): ");
|
2019-01-03 14:26:51 +01:00
|
|
|
wallclock.reset();
|
|
|
|
for (int i = 0; i < cfgBenchmark11_Passes; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
dbvt.optimizeIncremental(cfgBenchmark11_Iterations);
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
const int op = cfgBenchmark11_Passes * cfgBenchmark11_Iterations;
|
|
|
|
printf("%u ms (%i%%),(%u o/s)\r\n", time, (time - cfgBenchmark11_Reference) * 100 / time, op / time * 1000);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark12_Enable)
|
|
|
|
{ // Benchmark 12
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3AlignedObjectArray<b3DbvtVolume> volumes;
|
|
|
|
b3AlignedObjectArray<bool> results;
|
2017-08-01 14:30:58 +02:00
|
|
|
volumes.resize(cfgLeaves);
|
|
|
|
results.resize(cfgLeaves);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgLeaves; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
volumes[i] = b3DbvtBenchmark::RandVolume(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
printf("[12] b3DbvtVolume notequal: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark12_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgLeaves; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int k = 0; k < cfgLeaves; ++k)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
results[k] = NotEqual(volumes[j], volumes[k]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
printf("%u ms (%i%%)\r\n", time, (time - cfgBenchmark12_Reference) * 100 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark13_Enable)
|
|
|
|
{ // Benchmark 13
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3AlignedObjectArray<b3Vector3> vectors;
|
|
|
|
b3DbvtBenchmark::NilPolicy policy;
|
2017-08-01 14:30:58 +02:00
|
|
|
vectors.resize(cfgBenchmark13_Iterations);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < vectors.size(); ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
vectors[i] = (b3DbvtBenchmark::RandVector3() * 2 - b3Vector3(1, 1, 1)).normalized();
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
printf("[13] culling(OCL+fullsort): ");
|
2019-01-03 14:26:51 +01:00
|
|
|
wallclock.reset();
|
|
|
|
for (int i = 0; i < cfgBenchmark13_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
static const b3Scalar offset = 0;
|
|
|
|
policy.m_depth = -B3_INFINITY;
|
|
|
|
dbvt.collideOCL(dbvt.m_root, &vectors[i], &offset, vectors[i], 1, policy);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
const int t = cfgBenchmark13_Iterations;
|
|
|
|
printf("%u ms (%i%%),(%u t/s)\r\n", time, (time - cfgBenchmark13_Reference) * 100 / time, (t * 1000) / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark14_Enable)
|
|
|
|
{ // Benchmark 14
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3AlignedObjectArray<b3Vector3> vectors;
|
|
|
|
b3DbvtBenchmark::P14 policy;
|
2017-08-01 14:30:58 +02:00
|
|
|
vectors.resize(cfgBenchmark14_Iterations);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < vectors.size(); ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
vectors[i] = (b3DbvtBenchmark::RandVector3() * 2 - b3Vector3(1, 1, 1)).normalized();
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
policy.m_nodes.reserve(cfgLeaves);
|
|
|
|
printf("[14] culling(OCL+qsort): ");
|
2019-01-03 14:26:51 +01:00
|
|
|
wallclock.reset();
|
|
|
|
for (int i = 0; i < cfgBenchmark14_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
static const b3Scalar offset = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
policy.m_nodes.resize(0);
|
2019-01-03 14:26:51 +01:00
|
|
|
dbvt.collideOCL(dbvt.m_root, &vectors[i], &offset, vectors[i], 1, policy, false);
|
2017-08-01 14:30:58 +02:00
|
|
|
policy.m_nodes.quickSort(b3DbvtBenchmark::P14::sortfnc);
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
const int t = cfgBenchmark14_Iterations;
|
|
|
|
printf("%u ms (%i%%),(%u t/s)\r\n", time, (time - cfgBenchmark14_Reference) * 100 / time, (t * 1000) / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark15_Enable)
|
|
|
|
{ // Benchmark 15
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3AlignedObjectArray<b3Vector3> vectors;
|
|
|
|
b3DbvtBenchmark::P15 policy;
|
2017-08-01 14:30:58 +02:00
|
|
|
vectors.resize(cfgBenchmark15_Iterations);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < vectors.size(); ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
vectors[i] = (b3DbvtBenchmark::RandVector3() * 2 - b3Vector3(1, 1, 1)).normalized();
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
policy.m_nodes.reserve(cfgLeaves);
|
|
|
|
printf("[15] culling(KDOP+qsort): ");
|
2019-01-03 14:26:51 +01:00
|
|
|
wallclock.reset();
|
|
|
|
for (int i = 0; i < cfgBenchmark15_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
static const b3Scalar offset = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
policy.m_nodes.resize(0);
|
2019-01-03 14:26:51 +01:00
|
|
|
policy.m_axis = vectors[i];
|
|
|
|
dbvt.collideKDOP(dbvt.m_root, &vectors[i], &offset, 1, policy);
|
2017-08-01 14:30:58 +02:00
|
|
|
policy.m_nodes.quickSort(b3DbvtBenchmark::P15::sortfnc);
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
const int t = cfgBenchmark15_Iterations;
|
|
|
|
printf("%u ms (%i%%),(%u t/s)\r\n", time, (time - cfgBenchmark15_Reference) * 100 / time, (t * 1000) / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark16_Enable)
|
|
|
|
{ // Benchmark 16
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3DynamicBvh dbvt;
|
|
|
|
b3AlignedObjectArray<b3DbvtNode*> batch;
|
|
|
|
b3DbvtBenchmark::RandTree(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale, cfgLeaves, dbvt);
|
2017-08-01 14:30:58 +02:00
|
|
|
dbvt.optimizeTopDown();
|
|
|
|
batch.reserve(cfgBenchmark16_BatchCount);
|
2019-01-03 14:26:51 +01:00
|
|
|
printf("[16] insert/remove batch(%u): ", cfgBenchmark16_BatchCount);
|
2017-08-01 14:30:58 +02:00
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark16_Passes; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgBenchmark16_BatchCount; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
batch.push_back(dbvt.insert(b3DbvtBenchmark::RandVolume(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale), 0));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgBenchmark16_BatchCount; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
dbvt.remove(batch[j]);
|
|
|
|
}
|
|
|
|
batch.resize(0);
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
const int ir = cfgBenchmark16_Passes * cfgBenchmark16_BatchCount;
|
|
|
|
printf("%u ms (%i%%),(%u bir/s)\r\n", time, (time - cfgBenchmark16_Reference) * 100 / time, int(ir * 1000.0 / time));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (cfgBenchmark17_Enable)
|
|
|
|
{ // Benchmark 17
|
2017-08-01 14:30:58 +02:00
|
|
|
srand(380843);
|
2019-01-03 14:26:51 +01:00
|
|
|
b3AlignedObjectArray<b3DbvtVolume> volumes;
|
|
|
|
b3AlignedObjectArray<int> results;
|
|
|
|
b3AlignedObjectArray<int> indices;
|
2017-08-01 14:30:58 +02:00
|
|
|
volumes.resize(cfgLeaves);
|
|
|
|
results.resize(cfgLeaves);
|
|
|
|
indices.resize(cfgLeaves);
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgLeaves; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
indices[i] = i;
|
|
|
|
volumes[i] = b3DbvtBenchmark::RandVolume(cfgVolumeCenterScale, cfgVolumeExentsBase, cfgVolumeExentsScale);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgLeaves; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Swap(indices[i], indices[rand() % cfgLeaves]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
printf("[17] b3DbvtVolume select: ");
|
|
|
|
wallclock.reset();
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < cfgBenchmark17_Iterations; ++i)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int j = 0; j < cfgLeaves; ++j)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int k = 0; k < cfgLeaves; ++k)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const int idx = indices[k];
|
|
|
|
results[idx] = Select(volumes[idx], volumes[j], volumes[k]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
const int time = (int)wallclock.getTimeMilliseconds();
|
|
|
|
printf("%u ms (%i%%)\r\n", time, (time - cfgBenchmark17_Reference) * 100 / time);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
printf("\r\n\r\n");
|
|
|
|
}
|
|
|
|
#endif
|