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