-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTree2D.h
54 lines (49 loc) · 1.61 KB
/
RTree2D.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef RTREE2D_H_INCLUDED
#define RTREE2D_H_INCLUDED
#include <LexRisLogic/DataStructures/RTree.h>
#include "Object.h"
LL_MathStructure::MBB object_to_mbb(Object object)
{
LL_MathStructure::MBB mbb;
mbb.set_dimension(2);
mbb.first_point=object.get_point(MinMaxType::T_MIN).point;
mbb.second_point=object.get_point(MinMaxType::T_MAX).point;
return mbb;
}
void RTree2D(std::vector<Object>& objects,
std::vector<int>& total_collision,
std::list<std::pair<int,int>>& collision,
float* time_construction,float* time_collision)
{
LL::Chronometer chronometer;
chronometer.play();
LL_DataStructure::RTree<Object,2,5> S(object_to_mbb);
for(unsigned int i=0;i<objects.size();++i)
S.insert(objects[i]);
chronometer.stop();
if(time_construction)
*time_construction=chronometer.get_time();
chronometer.play();
for(unsigned int i=0;i<objects.size();++i)
{
S.remove(objects[i]);
std::list<Object> result=S.range_query(object_to_mbb(objects[i]));
for(auto d=result.begin();d!=result.end();++d)
{
int index_i=d->get_id();
int index_j=objects[i].get_id();
if(index_i>index_j)
std::swap(index_i,index_j);
if(index_i!=index_j)
{
++total_collision[index_i];
++total_collision[index_j];
collision.push_back(std::pair<int,int>(index_i,index_j));
}
}
}
chronometer.stop();
if(time_collision)
*time_collision=chronometer.get_time();
}
#endif // RTREE2D_H_INCLUDED