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