29 #ifndef __VECTORSET_H__
30 #define __VECTORSET_H__
42 template<
class type,
int dimension >
53 void Init(
const type &mins,
const type &maxs,
const int boxHashSize,
const int initialSize );
68 template<
class type,
int dimension >
70 hash.Clear(
idMath::IPow( boxHashSize, dimension ), 128 );
72 memset( boxInvSize, 0, dimension *
sizeof( boxInvSize[0] ) );
73 memset( boxHalfSize, 0, dimension *
sizeof( boxHalfSize[0] ) );
76 template<
class type,
int dimension >
78 Init( mins, maxs, boxHashSize, initialSize );
81 template<
class type,
int dimension >
89 hash.Clear(
idMath::IPow( boxHashSize, dimension ), initialSize );
93 this->boxHashSize = boxHashSize;
95 for ( i = 0; i < dimension; i++ ) {
96 boxSize = ( maxs[
i] - mins[
i] ) / (
float) boxHashSize;
97 boxInvSize[
i] = 1.0f / boxSize;
98 boxHalfSize[
i] = boxSize * 0.5f;
102 template<
class type,
int dimension >
105 hash.ResizeIndex( newSize );
108 template<
class type,
int dimension >
114 template<
class type,
int dimension >
116 int i,
j, k, hashKey, partialHashKey[dimension];
118 for ( i = 0; i < dimension; i++ ) {
119 assert( epsilon <= boxHalfSize[i] );
120 partialHashKey[
i] = (
int) ( ( v[i] - mins[i] - boxHalfSize[i] ) * boxInvSize[
i] );
123 for ( i = 0; i < ( 1 << dimension ); i++ ) {
126 for ( j = 0; j < dimension; j++ ) {
127 hashKey *= boxHashSize;
128 hashKey += partialHashKey[
j] + ( ( i >>
j ) & 1 );
131 for ( j = hash.First( hashKey ); j >= 0; j = hash.Next( j ) ) {
132 const type &lv = (*this)[
j];
133 for ( k = 0; k < dimension; k++ ) {
138 if ( k >= dimension ) {
145 for ( i = 0; i < dimension; i++ ) {
146 hashKey *= boxHashSize;
147 hashKey += (
int) ( ( v[i] - mins[i] ) * boxInvSize[
i] );
166 template<
class type,
int dimension >
177 void Init(
const type &mins,
const type &maxs,
const int boxHashSize,
const int initialSize );
181 int FindVector(
const type *vectorList,
const int vectorNum,
const float epsilon );
192 template<
class type,
int dimension >
194 hash.Clear(
idMath::IPow( boxHashSize, dimension ), 128 );
196 memset( boxInvSize, 0, dimension *
sizeof( boxInvSize[0] ) );
197 memset( boxHalfSize, 0, dimension *
sizeof( boxHalfSize[0] ) );
200 template<
class type,
int dimension >
202 Init( mins, maxs, boxHashSize, initialSize );
205 template<
class type,
int dimension >
210 hash.Clear(
idMath::IPow( boxHashSize, dimension ), initialSize );
214 this->boxHashSize = boxHashSize;
216 for ( i = 0; i < dimension; i++ ) {
217 boxSize = ( maxs[
i] - mins[
i] ) / (
float) boxHashSize;
218 boxInvSize[
i] = 1.0f / boxSize;
219 boxHalfSize[
i] = boxSize * 0.5f;
223 template<
class type,
int dimension >
229 template<
class type,
int dimension >
231 int i,
j, k, hashKey, partialHashKey[dimension];
232 const type &
v = vectorList[vectorNum];
234 for ( i = 0; i < dimension; i++ ) {
235 assert( epsilon <= boxHalfSize[i] );
236 partialHashKey[
i] = (
int) ( ( v[i] - mins[i] - boxHalfSize[i] ) * boxInvSize[
i] );
239 for ( i = 0; i < ( 1 << dimension ); i++ ) {
242 for ( j = 0; j < dimension; j++ ) {
243 hashKey *= boxHashSize;
244 hashKey += partialHashKey[
j] + ( ( i >>
j ) & 1 );
247 for ( j = hash.First( hashKey ); j >= 0; j = hash.Next( j ) ) {
248 const type &lv = vectorList[
j];
249 for ( k = 0; k < dimension; k++ ) {
254 if ( k >= dimension ) {
261 for ( i = 0; i < dimension; i++ ) {
262 hashKey *= boxHashSize;
263 hashKey += (
int) ( ( v[i] - mins[i] ) * boxInvSize[
i] );
266 hash.Add( hashKey, vectorNum );
void Init(const type &mins, const type &maxs, const int boxHashSize, const int initialSize)
assert(prefInfo.fullscreenBtn)
float boxInvSize[dimension]
float boxHalfSize[dimension]
void SetNum(int newnum, bool resize=true)
void AssureSize(int newSize)
GLuint GLuint GLsizei GLenum type
static float Fabs(float f)
int FindVector(const type &v, const float epsilon)
float boxInvSize[dimension]
size_t Allocated(void) const
size_t Allocated(void) const
size_t Allocated(void) const
float boxHalfSize[dimension]
size_t Allocated(void) const
int FindVector(const type *vectorList, const int vectorNum, const float epsilon)
static int IPow(int x, int y)
void ResizeIndex(const int newSize)
void Init(const type &mins, const type &maxs, const int boxHashSize, const int initialSize)