資源簡介
一個外國人寫的,用C++語言實現了R樹,代碼質量很高,注釋也很到位,很值得參考學習!!
代碼片段和文件信息
#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?&&?//?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?
??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]?????{
??????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;??????????????????????????///??Vec3?m_min?m_max;??????????????????????????????///
??static?int?s_outstandingAllocs;?????????????????///jects?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
- 上一篇:CDib類MFC圖像編程必備
- 下一篇:簡易學生管理系統(C++)
評論
共有 條評論