Marine systems simulation
DataStructures.h
1#pragma once
2
3#include "GeometryTools.h"
4#include "ObjectFactoryStack.h"
5
6namespace CoRiBoDynamics{
7
8namespace DataStructures{
9
10struct LINKEDLIST {LINKEDLIST* next; int value;};
11
12
28public:
29 static const unsigned int BUFFER_SIZE = 128;
30 static const unsigned int BRANCH_FACTOR = 4;
31 static const unsigned int TREE_DEPTH = 4;
32
33 static const unsigned int BLOCK_SIZE = 0x1<<BRANCH_FACTOR;
34 static const unsigned int BIT_MASK = BLOCK_SIZE-1;
35 static const unsigned int MAX_INDEX = 0x1<<(TREE_DEPTH*BRANCH_FACTOR);
36
38
39 void insert(int value); // adds value to set
40 bool insert_and_check(int value); // adds value to set. return true if it was already present
41 bool check(int value); // return true if value is present
42
43 LINKEDLIST* getValues(); // get linked list of all values in set
44
45 void reset(); // remove all values from set
46protected:
47 struct ARRAY {
48 void* POINTERS[BLOCK_SIZE];
49 void SetToNULL(){for(size_t i = 0; i < BLOCK_SIZE; ++i){POINTERS[i] = nullptr;}}
50 };
51 ARRAY m_rootArray;
52 ObjectFactoryStack<ARRAY> m_ARRAY_factory;
53 ObjectFactoryStack<LINKEDLIST> m_List_factory;
54};
55
66public:
67static const unsigned int BUFFER_SIZE = 512;
68static const unsigned int BRANCH_FACTOR = 5;
69static const unsigned int TREE_DEPTH = 3;
70
71static const unsigned int BLOCK_SIZE = 0x1<<BRANCH_FACTOR;
72static const unsigned int INDEX_SIZE = 3*TREE_DEPTH;
73static const unsigned int BIT_MASK = BLOCK_SIZE-1;
74static const unsigned int MAX_INDEX = 0x1<<(TREE_DEPTH*BRANCH_FACTOR);
75
77
79
80 void InsertToMap(int x, int y, int z, int ID, RadixSparseSet* set); // adds ID to map at coordinates x,y,z. previously present values are added to set
81 void CheckMap(int x, int y, int z, RadixSparseSet* set); // adds all values at coordinates x,y,z to set
82 void Reset(); // remove all values from map
83
84protected:
85 struct ARRAY {
86 void* POINTERS[BLOCK_SIZE];
87 void SetToNULL(){for(size_t i = 0; i < BLOCK_SIZE; ++i){POINTERS[i] = nullptr;}}
88 };
89
90 struct INDEX {int i[INDEX_SIZE];};
91
92 struct LINKEDLIST {int value; LINKEDLIST* next;};
93
94 INDEX convert(int x, int y, int z);
95
96 ARRAY m_rootArray;
97
98 ObjectFactoryStack<ARRAY> m_ARRAY_factory;
99 ObjectFactoryStack<LINKEDLIST> m_List_factory;
100};
101
108public:
110
111 // tuning parameter for grid cell side length. to large value gives more false collition positives, too small value gives high cell count allocation and a smaller total bounding volume
112 void SetLength(double length);
113
114 // insert ID into all grid cells that contains any part of boundingVolume. Returns all values already present.
115 LINKEDLIST* InsertToMap(const GeometryTools::AABB& boundingVolume, int ID);
116
117 // returns all values in grid cells that contains any part of boundingVolume
118 LINKEDLIST* CheckMap(const GeometryTools::AABB& boundingVolume);
119
120 // remove all values from map
121 void Reset();
122 void setOrigo(double x, double y, double z);
123
124protected:
125 Sparse3DArray m_Array;
126 struct SpatialIndex{unsigned int x; unsigned int y; unsigned int z; SpatialIndex(unsigned int X, unsigned int Y, unsigned int Z){x=X;y=Y;z=Z;}};
127 SpatialIndex CoordinateToIndex( double d_x, double d_y, double d_z );
128
129 DataStructures::RadixSparseSet m_CollisionTestSet;
130
131 double m_lengthInv;
132
133 double m_origoX;
134 double m_origoY;
135 double m_origoZ;
136};
137
138}
139
140}
Definition: DataStructures.h:27
Definition: DataStructures.h:107
Definition: DataStructures.h:65
Definition: ObjectFactoryStack.h:22
Definition: CollisionManager.h:6
Definition: DataStructures.h:10
Definition: GeometryTools.h:88