资源简介
R树的C++实现,初学者可以看看,挺不错的
代码片段和文件信息
#include
#include
#include
#include “RTree.h“
//
// MemoryTest.cpp
//
// This demonstrates a use of RTree
//
// Use CRT Debug facility to dump memory leaks on app exit
#ifdef WIN32
// These two are for MSVS 2005 security consciousness until safe std lib funcs are available
#pragma warning(disable : 4996) // Deprecated functions
#define _CRT_SECURE_NO_DEPRECATE // Allow old unsecure standard library functions Disable some ‘warning C4996 - function was deprecated‘
// The following macros set and clear respectively given bits
// of the C runtime library debug flag as specified by a bitmask.
#ifdef _DEBUG
#define SET_CRT_DEBUG_FIELD(a) \
_CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
#define CLEAR_CRT_DEBUG_FIELD(a) \
_CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
#else
#define SET_CRT_DEBUG_FIELD(a) ((void) 0)
#define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
#endif
#endif //WIN32
//
// Get a random float b/n two values
// The returned value is >= min && < max (exclusive of max)
// Note this is a low precision random value since it is generated from an int.
//
static float RandFloat(float a_min float a_max)
{
const float ooMax = 1.0f / (float)(RAND_MAX+1);
float retValue = ( (float)rand() * ooMax * (a_max - a_min) + a_min);
ASSERT(retValue >= a_min && retValue < a_max); // Paranoid check
return retValue;
}
/// Simplify handling of 3 dimensional coordinate
struct Vec3
{
/// Default constructor
Vec3() {}
/// Construct from three elements
Vec3(float a_x float a_y float a_z)
{
v[0] = a_x;
v[1] = a_y;
v[2] = a_z;
}
/// Add two vectors and return result
Vec3 operator+ (const Vec3& a_other) const
{
return Vec3(v[0] + a_other.v[0]
v[1] + a_other.v[1]
v[2] + a_other.v[2]);
}
float v[3]; ///< 3 float components for axes or dimensions
};
static bool BoxesIntersect(const Vec3& a_boxMinA const Vec3& a_boxMaxA
const Vec3& a_boxMinB const Vec3& a_boxMaxB)
{
for(int axis=0; axis<3; ++axis)
{
if(a_boxMinA.v[axis] > a_boxMaxB.v[axis] ||
a_boxMaxA.v[axis] < a_boxMinB.v[axis])
{
return false;
}
}
return true;
}
/// A user type to test with instead of a simple type such as an ‘int‘
struct SomeThing
{
SomeThing()
{
++s_outstandingAllocs;
}
~SomeThing()
{
--s_outstandingAllocs;
}
int m_creationCounter; ///< Just a number for identifying within test program
Vec3 m_min m_max; ///< Minimal bounding rect values must be known and constant in order to remove from RTree
static int s_outstandingAllocs; ///< Count how many outstanding objects remain
};
/
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7699 2009-12-03 16:41 RTreeTemplate\MemoryTest.cpp
文件 1247 2010-01-05 16:04 RTreeTemplate\README.TXT
文件 45267 2010-01-05 15:55 RTreeTemplate\RTree.h
文件 2171 2009-12-03 16:41 RTreeTemplate\Test.cpp
- 上一篇:MFC程序开发之聊天室客户端+服务器源码
- 下一篇:C语言实现计算乘法逆元
评论
共有 条评论