1 | #include <vector> |
---|
2 | #include <algorithm> |
---|
3 | #include <Detection/detection.hh> |
---|
4 | |
---|
5 | using std::vector; |
---|
6 | |
---|
7 | class Pair |
---|
8 | { |
---|
9 | public: |
---|
10 | Pair(){}; |
---|
11 | virtual ~Pair(){}; |
---|
12 | friend bool operator< (const Pair& lhs, const Pair& rhs){ |
---|
13 | return (lhs.primary < rhs.primary); |
---|
14 | }; |
---|
15 | void define(float p, float m){primary=p; matching=m;}; |
---|
16 | float get1(){return primary;}; |
---|
17 | float get2(){return matching;}; |
---|
18 | private: |
---|
19 | float primary; |
---|
20 | float matching; |
---|
21 | }; |
---|
22 | |
---|
23 | void Detection::SortByZ() |
---|
24 | { |
---|
25 | /** |
---|
26 | * Detection::SortByZ(): |
---|
27 | * A Function that takes a Detection and |
---|
28 | * sorts the pixels by z-pixel |
---|
29 | * Upon return, the inputList is sorted. |
---|
30 | * We use stable_sort, so that the order of objects with the same |
---|
31 | * z-value is preserved. |
---|
32 | */ |
---|
33 | |
---|
34 | long size = this->pix.size(); |
---|
35 | Pair *info = new Pair[size]; |
---|
36 | |
---|
37 | for(int i=0;i<size;i++) info[i].define(this->pix[i].getZ(),float(i)); |
---|
38 | |
---|
39 | std::stable_sort(info,info+size); |
---|
40 | |
---|
41 | vector <Voxel> sorted(size); |
---|
42 | for(int i=0;i<size;i++) sorted[i] = this->pix[int(info[i].get2())] ; |
---|
43 | |
---|
44 | delete [] info; |
---|
45 | |
---|
46 | for(int i=0;i<size;i++){ |
---|
47 | this->pix.erase(this->pix.begin()+i); |
---|
48 | this->pix.insert(this->pix.begin()+i, sorted[i]); |
---|
49 | } |
---|
50 | |
---|
51 | sorted.clear(); |
---|
52 | |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | void SortByZ(vector <Detection> &inputList) |
---|
57 | { |
---|
58 | /** |
---|
59 | * SortByZ(vector <Detection> &): |
---|
60 | * A Function that takes a list of Detections and |
---|
61 | * sorts them in order of increasing z-pixel value. |
---|
62 | * Upon return, the inputList is sorted. |
---|
63 | */ |
---|
64 | |
---|
65 | long size = inputList.size(); |
---|
66 | Pair *info = new Pair[size]; |
---|
67 | |
---|
68 | for(int i=0;i<size;i++) info[i].define(inputList[i].getZcentre(), float(i)); |
---|
69 | |
---|
70 | std::stable_sort(info,info+size); |
---|
71 | |
---|
72 | vector <Detection> sorted; |
---|
73 | for(int i=0;i<size;i++) sorted.push_back( inputList[int(info[i].get2())] ); |
---|
74 | |
---|
75 | delete [] info; |
---|
76 | |
---|
77 | inputList.clear(); |
---|
78 | for(int i=0;i<size;i++) inputList.push_back( sorted[i] ); |
---|
79 | sorted.clear(); |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | void SortByVel(vector <Detection> &inputList) |
---|
84 | { |
---|
85 | /** |
---|
86 | * SortByVel(vector <Detection> &): |
---|
87 | * A Function that takes a list of Detections and |
---|
88 | * sorts them in order of increasing velocity. |
---|
89 | * Every member of the vector needs to have WCS defined, (and if so, |
---|
90 | * then vel is assumed to be defined for all), otherwise no sorting |
---|
91 | * is done. |
---|
92 | * Upon return (if all WCS are good), the inputList is sorted. |
---|
93 | */ |
---|
94 | |
---|
95 | bool isGood = true; |
---|
96 | for(int i=0;i<inputList.size();i++) isGood = isGood && inputList[i].isWCS(); |
---|
97 | |
---|
98 | if(isGood){ |
---|
99 | |
---|
100 | long size = inputList.size(); |
---|
101 | Pair *info = new Pair[size]; |
---|
102 | |
---|
103 | for(int i=0;i<size;i++) info[i].define(inputList[i].getVel(), float(i)); |
---|
104 | |
---|
105 | std::stable_sort(info, info+size); |
---|
106 | |
---|
107 | vector <Detection> sorted; |
---|
108 | for(int i=0;i<size;i++) sorted.push_back( inputList[int(info[i].get2())] ); |
---|
109 | |
---|
110 | delete [] info; |
---|
111 | |
---|
112 | inputList.clear(); |
---|
113 | for(int i=0;i<size;i++) inputList.push_back( sorted[i] ); |
---|
114 | sorted.clear(); |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | } |
---|