[3] | 1 | #include <iostream> |
---|
[189] | 2 | #include <param.hh> |
---|
[3] | 3 | #include <Cubes/cubes.hh> |
---|
[243] | 4 | #include <PixelMap/Object3D.hh> |
---|
[3] | 5 | |
---|
[252] | 6 | using namespace PixelInfo; |
---|
| 7 | |
---|
[3] | 8 | void Cube::trimCube() |
---|
| 9 | { |
---|
[86] | 10 | /** |
---|
[220] | 11 | * If the blankPix flag has been set, this routine trims excess blank |
---|
[189] | 12 | * pixels from the edges of the spatial image. |
---|
| 13 | * It uses as its template the first channel, assuming that its non-BLANK |
---|
| 14 | * size is representative of the rest of the channels. |
---|
[86] | 15 | * The edges are moved in until the first non-BLANK pixel is encountered. |
---|
[189] | 16 | * All other arrays are similarly edited, and the amount of trimming is |
---|
| 17 | * recorded. |
---|
[86] | 18 | */ |
---|
| 19 | |
---|
[3] | 20 | if(this->par.getFlagBlankPix()) { |
---|
| 21 | |
---|
| 22 | long xdim = this->axisDim[0]; |
---|
| 23 | long ydim = this->axisDim[1]; |
---|
| 24 | long zdim = this->axisDim[2]; |
---|
| 25 | const long ZCHAN = 0; |
---|
| 26 | |
---|
[246] | 27 | int left,right,top,bottom; |
---|
| 28 | |
---|
[3] | 29 | for(int z = 0; z < zdim; z++){ |
---|
| 30 | |
---|
| 31 | for(int row=0;row<ydim;row++){ |
---|
[246] | 32 | left=0; |
---|
| 33 | right=0; |
---|
| 34 | while((left<xdim)&& |
---|
| 35 | (this->par.isBlank(this->array[row*xdim+left+ZCHAN*xdim*ydim])) ) { |
---|
| 36 | left++; |
---|
[3] | 37 | } |
---|
[246] | 38 | while((right<xdim)&& |
---|
| 39 | (this->par.isBlank(this->array[row*xdim+(xdim-1-right)+ZCHAN*xdim*ydim]))){ |
---|
| 40 | right++; |
---|
[3] | 41 | } |
---|
| 42 | |
---|
[246] | 43 | if( ((z==0)&&(row==0)) || (left < this->par.getBorderLeft()) ) |
---|
| 44 | this->par.setBorderLeft(left); |
---|
| 45 | if( ((z==0)&&(row==0)) || (right < this->par.getBorderRight()) ) |
---|
| 46 | this->par.setBorderRight(right); |
---|
[3] | 47 | |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | for(int col=0;col<xdim;col++){ |
---|
[246] | 51 | bottom=0; |
---|
| 52 | top=0; |
---|
| 53 | while((bottom<ydim)&& |
---|
| 54 | (this->par.isBlank(this->array[col+bottom*xdim+ZCHAN*xdim*ydim])) ) bottom++; |
---|
[3] | 55 | |
---|
[246] | 56 | while((top<ydim)&& |
---|
| 57 | (this->par.isBlank(this->array[col+(ydim-1-top)*xdim+ZCHAN*xdim*ydim])) ) top++; |
---|
[3] | 58 | |
---|
[246] | 59 | if( ((z==0)&&(col==0)) || (bottom < this->par.getBorderBottom()) ) |
---|
| 60 | this->par.setBorderBottom(bottom); |
---|
| 61 | if( ((z==0)&&(col==0)) || (top < this->par.getBorderTop()) ) |
---|
| 62 | this->par.setBorderTop(top); |
---|
[3] | 63 | |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | } |
---|
| 67 | |
---|
[246] | 68 | left = this->par.getBorderLeft(); |
---|
| 69 | right = this->par.getBorderRight(); |
---|
| 70 | top = this->par.getBorderTop(); |
---|
| 71 | bottom = this->par.getBorderBottom(); |
---|
| 72 | |
---|
| 73 | this->axisDim[0] = xdim - left - right; |
---|
| 74 | this->axisDim[1] = ydim - bottom - top; |
---|
[3] | 75 | this->axisDim[2] = zdim; |
---|
| 76 | this->numPixels = this->axisDim[0]*this->axisDim[1]*this->axisDim[2]; |
---|
| 77 | |
---|
| 78 | long oldpos,newpos; |
---|
| 79 | |
---|
| 80 | // Do the trimming, but only if we need to -- is there a border of Blanks? |
---|
[246] | 81 | if((left>0)||(right>0)||(bottom>0)||(top>0)) { |
---|
[3] | 82 | |
---|
| 83 | // Trim the array of pixel values |
---|
| 84 | float *newarray = new float[this->numPixels]; |
---|
| 85 | for(int x = 0; x < axisDim[0]; x++){ |
---|
| 86 | for(int y = 0; y < axisDim[1]; y++){ |
---|
| 87 | for(int z = 0; z < axisDim[2]; z++){ |
---|
[246] | 88 | oldpos = (x+left) + (y+bottom)*xdim + z*xdim*ydim; |
---|
[3] | 89 | newpos = x + y*axisDim[0] + z*axisDim[0]*axisDim[1]; |
---|
| 90 | newarray[newpos] = this->array[oldpos]; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | delete [] this->array; |
---|
| 95 | this->array = newarray; |
---|
| 96 | |
---|
| 97 | // Trim the 2-D detection map |
---|
| 98 | short *newdetect = new short[this->axisDim[0]*this->axisDim[1]]; |
---|
| 99 | for(int x = 0; x < axisDim[0]; x++){ |
---|
| 100 | for(int y = 0; y < axisDim[1]; y++){ |
---|
[246] | 101 | oldpos = (x+left) + (y+bottom)*xdim; |
---|
[3] | 102 | newpos = x + y*axisDim[0]; |
---|
| 103 | newdetect[newpos] = this->detectMap[oldpos]; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | delete [] this->detectMap; |
---|
| 107 | this->detectMap = newdetect; |
---|
| 108 | |
---|
[76] | 109 | if(this->par.getFlagATrous()){ |
---|
[246] | 110 | // Trim the reconstructed array if we are going to do the |
---|
| 111 | // reconstruction |
---|
[3] | 112 | float *newrecon = new float[this->numPixels]; |
---|
| 113 | for(int x = 0; x < axisDim[0]; x++){ |
---|
| 114 | for(int y = 0; y < axisDim[1]; y++){ |
---|
| 115 | for(int z = 0; z < axisDim[2]; z++){ |
---|
[246] | 116 | oldpos = (x+left) + (y+bottom)*xdim + z*xdim*ydim; |
---|
[3] | 117 | newpos = x + y*axisDim[0] + z*axisDim[0]*axisDim[1]; |
---|
| 118 | newrecon[newpos] = this->recon[oldpos]; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | delete [] this->recon; |
---|
| 123 | this->recon = newrecon; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // Set the flag indicating trimming has taken place only if it has. |
---|
| 127 | this->par.setFlagCubeTrimmed(true); |
---|
| 128 | |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | void Cube::unTrimCube() |
---|
| 137 | { |
---|
[86] | 138 | /** |
---|
[220] | 139 | * If the cube has been trimmed by trimCube(), this task adds back the |
---|
| 140 | * BLANK pixels on the edges, so that it returns to its original size. |
---|
[86] | 141 | * All arrays are similarly edited. |
---|
| 142 | */ |
---|
[3] | 143 | |
---|
| 144 | if(this->par.getFlagCubeTrimmed()){ |
---|
| 145 | |
---|
[246] | 146 | long left = this->par.getBorderLeft(); |
---|
| 147 | long right = this->par.getBorderRight(); |
---|
| 148 | long top = this->par.getBorderTop(); |
---|
| 149 | long bottom = this->par.getBorderBottom(); |
---|
| 150 | |
---|
[3] | 151 | long smallXDim = this->axisDim[0]; |
---|
| 152 | long smallYDim = this->axisDim[1]; |
---|
| 153 | long smallZDim = this->axisDim[2]; |
---|
| 154 | |
---|
| 155 | // first correct the dimension sizes |
---|
[246] | 156 | this->axisDim[0] = smallXDim + left + right; |
---|
| 157 | this->axisDim[1] = smallYDim + bottom + top; |
---|
[3] | 158 | this->axisDim[2] = smallZDim; |
---|
| 159 | this->numPixels = this->axisDim[0]*this->axisDim[1]*this->axisDim[2]; |
---|
| 160 | |
---|
| 161 | long pos,smlpos; |
---|
| 162 | bool isDud; |
---|
| 163 | |
---|
| 164 | // Correct the array of pixel values |
---|
| 165 | float *newarray = new float[this->numPixels]; |
---|
| 166 | for(int x = 0; x < this->axisDim[0]; x++){ |
---|
| 167 | for(int y = 0; y < this->axisDim[1]; y++){ |
---|
[246] | 168 | isDud = (x<left) || (x>=smallXDim+left) || |
---|
| 169 | (y<bottom) || (y>=smallYDim+bottom); |
---|
[3] | 170 | |
---|
| 171 | for(int z = 0; z < this->axisDim[2]; z++){ |
---|
| 172 | pos = x + y*this->axisDim[0] + z*this->axisDim[0]*this->axisDim[1]; |
---|
[246] | 173 | smlpos = (x-left) + (y-bottom)*smallXDim + z * smallXDim * smallYDim; |
---|
[3] | 174 | if(isDud) newarray[pos] = this->par.getBlankPixVal(); |
---|
| 175 | else newarray[pos] = this->array[smlpos]; |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | delete [] this->array; |
---|
| 180 | this->array = newarray; |
---|
| 181 | |
---|
| 182 | if(this->reconExists){ |
---|
| 183 | // Correct the reconstructed array |
---|
| 184 | float *newrecon = new float[this->numPixels]; |
---|
| 185 | for(int x = 0; x < this->axisDim[0]; x++){ |
---|
| 186 | for(int y = 0; y < this->axisDim[1]; y++){ |
---|
[246] | 187 | isDud = (x<left) || (x>=smallXDim+left) || |
---|
| 188 | (y<bottom) || (y>=smallYDim+bottom); |
---|
[3] | 189 | |
---|
| 190 | for(int z = 0; z < this->axisDim[2]; z++){ |
---|
| 191 | pos = x + y*this->axisDim[0] + z*this->axisDim[0]*this->axisDim[1]; |
---|
[246] | 192 | smlpos = (x-left) + (y-bottom)*smallXDim |
---|
[3] | 193 | + z * smallXDim * smallYDim; |
---|
| 194 | if(isDud) newrecon[pos] = this->par.getBlankPixVal(); |
---|
| 195 | else newrecon[pos] = this->recon[smlpos]; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | delete [] this->recon; |
---|
| 200 | this->recon = newrecon; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | // Correct the 2-D detection map |
---|
| 204 | short *newdetect = new short[this->axisDim[0]*this->axisDim[1]]; |
---|
| 205 | for(int x = 0; x < this->axisDim[0]; x++){ |
---|
| 206 | for(int y = 0; y < this->axisDim[1]; y++){ |
---|
| 207 | pos = x + y*this->axisDim[0]; |
---|
[246] | 208 | smlpos = (x-left) + (y-bottom)*smallXDim; |
---|
| 209 | isDud = (x<left) || (x>=smallXDim+left) || |
---|
| 210 | (y<bottom) || (y>=smallYDim+bottom); |
---|
[3] | 211 | if(isDud) newdetect[pos]=0; |
---|
| 212 | else newdetect[pos] = this->detectMap[smlpos]; |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | delete [] this->detectMap; |
---|
| 216 | this->detectMap = newdetect; |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | // Now update the positions for all the detections |
---|
| 220 | |
---|
| 221 | for(int i=0;i<this->objectList.size();i++){ |
---|
[246] | 222 | this->objectList[i].pixels().addOffsets(left,bottom,0); |
---|
| 223 | // objectList[i].calcParams(this->array,this->axisDim); |
---|
[3] | 224 | } |
---|
| 225 | |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | } |
---|