[3] | 1 | #include <iostream> |
---|
| 2 | #include <Cubes/cubes.hh> |
---|
| 3 | |
---|
| 4 | void Cube::trimCube() |
---|
| 5 | { |
---|
| 6 | if(this->par.getFlagBlankPix()) { |
---|
| 7 | |
---|
| 8 | long xdim = this->axisDim[0]; |
---|
| 9 | long ydim = this->axisDim[1]; |
---|
| 10 | long zdim = this->axisDim[2]; |
---|
| 11 | // const long ZCHAN = zdim/2; |
---|
| 12 | const long ZCHAN = 0; |
---|
| 13 | |
---|
| 14 | for(int z = 0; z < zdim; z++){ |
---|
| 15 | |
---|
| 16 | for(int row=0;row<ydim;row++){ |
---|
| 17 | int borderLeft=0; |
---|
| 18 | int borderRight=0; |
---|
| 19 | while((borderLeft<xdim)&& |
---|
| 20 | (this->par.isBlank(this->array[row*xdim+borderLeft+ZCHAN*xdim*ydim])) ) { |
---|
| 21 | borderLeft++; |
---|
| 22 | } |
---|
| 23 | while((borderRight<xdim)&& |
---|
| 24 | (this->par.isBlank(this->array[row*xdim+(xdim-1-borderRight)+ZCHAN*xdim*ydim]))){ |
---|
| 25 | borderRight++; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | if( ((z==0)&&(row==0)) || (borderLeft < this->par.getBorderLeft()) ) |
---|
| 29 | this->par.setBorderLeft(borderLeft); |
---|
| 30 | if( ((z==0)&&(row==0)) || (borderRight < this->par.getBorderRight()) ) |
---|
| 31 | this->par.setBorderRight(borderRight); |
---|
| 32 | |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | for(int col=0;col<xdim;col++){ |
---|
| 36 | int borderBottom=0; |
---|
| 37 | int borderTop=0; |
---|
| 38 | while((borderBottom<ydim)&& |
---|
| 39 | (this->par.isBlank(this->array[col+borderBottom*xdim+ZCHAN*xdim*ydim])) ) borderBottom++; |
---|
| 40 | |
---|
| 41 | while((borderTop<ydim)&& |
---|
| 42 | (this->par.isBlank(this->array[col+(ydim-1-borderTop)*xdim+ZCHAN*xdim*ydim])) ) borderTop++; |
---|
| 43 | |
---|
| 44 | if( ((z==0)&&(col==0)) || (borderBottom < this->par.getBorderBottom()) ) |
---|
| 45 | this->par.setBorderBottom(borderBottom); |
---|
| 46 | if( ((z==0)&&(col==0)) || (borderTop < this->par.getBorderTop()) ) |
---|
| 47 | this->par.setBorderTop(borderTop); |
---|
| 48 | |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | this->axisDim[0] = xdim - this->par.getBorderLeft() - this->par.getBorderRight(); |
---|
| 54 | this->axisDim[1] = ydim - this->par.getBorderBottom() - this->par.getBorderTop(); |
---|
| 55 | this->axisDim[2] = zdim; |
---|
| 56 | this->numPixels = this->axisDim[0]*this->axisDim[1]*this->axisDim[2]; |
---|
| 57 | |
---|
| 58 | long oldpos,newpos; |
---|
| 59 | |
---|
| 60 | // Do the trimming, but only if we need to -- is there a border of Blanks? |
---|
| 61 | if((this->par.getBorderLeft()>0)||(this->par.getBorderRight()>0)|| |
---|
| 62 | (this->par.getBorderBottom()>0)||(this->par.getBorderTop()>0)) { |
---|
| 63 | |
---|
| 64 | // Trim the array of pixel values |
---|
| 65 | float *newarray = new float[this->numPixels]; |
---|
| 66 | for(int x = 0; x < axisDim[0]; x++){ |
---|
| 67 | for(int y = 0; y < axisDim[1]; y++){ |
---|
| 68 | for(int z = 0; z < axisDim[2]; z++){ |
---|
| 69 | oldpos = (x+this->par.getBorderLeft()) + (y+this->par.getBorderBottom())*xdim + z*xdim*ydim; |
---|
| 70 | newpos = x + y*axisDim[0] + z*axisDim[0]*axisDim[1]; |
---|
| 71 | newarray[newpos] = this->array[oldpos]; |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | delete [] this->array; |
---|
| 76 | this->array = newarray; |
---|
| 77 | |
---|
| 78 | // Trim the 2-D detection map |
---|
| 79 | short *newdetect = new short[this->axisDim[0]*this->axisDim[1]]; |
---|
| 80 | for(int x = 0; x < axisDim[0]; x++){ |
---|
| 81 | for(int y = 0; y < axisDim[1]; y++){ |
---|
| 82 | oldpos = (x+this->par.getBorderLeft()) + (y+this->par.getBorderBottom())*xdim; |
---|
| 83 | newpos = x + y*axisDim[0]; |
---|
| 84 | newdetect[newpos] = this->detectMap[oldpos]; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | delete [] this->detectMap; |
---|
| 88 | this->detectMap = newdetect; |
---|
| 89 | |
---|
| 90 | if(this->par.getFlagATrous()){ |
---|
| 91 | // Trim the reconstructed array if we are going to do the reconstruction |
---|
| 92 | float *newrecon = new float[this->numPixels]; |
---|
| 93 | for(int x = 0; x < axisDim[0]; x++){ |
---|
| 94 | for(int y = 0; y < axisDim[1]; y++){ |
---|
| 95 | for(int z = 0; z < axisDim[2]; z++){ |
---|
| 96 | oldpos = (x+this->par.getBorderLeft()) + (y+this->par.getBorderBottom())*xdim + z*xdim*ydim; |
---|
| 97 | newpos = x + y*axisDim[0] + z*axisDim[0]*axisDim[1]; |
---|
| 98 | newrecon[newpos] = this->recon[oldpos]; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | delete [] this->recon; |
---|
| 103 | this->recon = newrecon; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | // Set the flag indicating trimming has taken place only if it has. |
---|
| 107 | this->par.setFlagCubeTrimmed(true); |
---|
| 108 | |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | void Cube::unTrimCube() |
---|
| 118 | { |
---|
| 119 | |
---|
| 120 | if(this->par.getFlagCubeTrimmed()){ |
---|
| 121 | |
---|
| 122 | long smallXDim = this->axisDim[0]; |
---|
| 123 | long smallYDim = this->axisDim[1]; |
---|
| 124 | long smallZDim = this->axisDim[2]; |
---|
| 125 | |
---|
| 126 | // first correct the dimension sizes |
---|
| 127 | this->axisDim[0] = smallXDim + this->par.getBorderLeft() + this->par.getBorderRight(); |
---|
| 128 | this->axisDim[1] = smallYDim + this->par.getBorderBottom() + this->par.getBorderTop(); |
---|
| 129 | this->axisDim[2] = smallZDim; |
---|
| 130 | this->numPixels = this->axisDim[0]*this->axisDim[1]*this->axisDim[2]; |
---|
| 131 | |
---|
| 132 | long pos,smlpos; |
---|
| 133 | bool isDud; |
---|
| 134 | |
---|
| 135 | // Correct the array of pixel values |
---|
| 136 | float *newarray = new float[this->numPixels]; |
---|
| 137 | for(int x = 0; x < this->axisDim[0]; x++){ |
---|
| 138 | for(int y = 0; y < this->axisDim[1]; y++){ |
---|
| 139 | isDud = (x<this->par.getBorderLeft()) || (x>=smallXDim+this->par.getBorderLeft()) || |
---|
| 140 | (y<this->par.getBorderBottom()) || (y>=smallYDim+this->par.getBorderBottom()); |
---|
| 141 | |
---|
| 142 | for(int z = 0; z < this->axisDim[2]; z++){ |
---|
| 143 | pos = x + y*this->axisDim[0] + z*this->axisDim[0]*this->axisDim[1]; |
---|
| 144 | smlpos = (x-this->par.getBorderLeft()) + (y-this->par.getBorderBottom())*smallXDim |
---|
| 145 | + z * smallXDim * smallYDim; |
---|
| 146 | if(isDud) newarray[pos] = this->par.getBlankPixVal(); |
---|
| 147 | else newarray[pos] = this->array[smlpos]; |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | delete [] this->array; |
---|
| 152 | this->array = newarray; |
---|
| 153 | |
---|
| 154 | if(this->reconExists){ |
---|
| 155 | // Correct the reconstructed array |
---|
| 156 | float *newrecon = new float[this->numPixels]; |
---|
| 157 | for(int x = 0; x < this->axisDim[0]; x++){ |
---|
| 158 | for(int y = 0; y < this->axisDim[1]; y++){ |
---|
| 159 | isDud = (x<this->par.getBorderLeft()) || (x>=smallXDim+this->par.getBorderLeft()) || |
---|
| 160 | (y<this->par.getBorderBottom()) || (y>=smallYDim+this->par.getBorderBottom()); |
---|
| 161 | |
---|
| 162 | for(int z = 0; z < this->axisDim[2]; z++){ |
---|
| 163 | pos = x + y*this->axisDim[0] + z*this->axisDim[0]*this->axisDim[1]; |
---|
| 164 | smlpos = (x-this->par.getBorderLeft()) + (y-this->par.getBorderBottom())*smallXDim |
---|
| 165 | + z * smallXDim * smallYDim; |
---|
| 166 | if(isDud) newrecon[pos] = this->par.getBlankPixVal(); |
---|
| 167 | else newrecon[pos] = this->recon[smlpos]; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | delete [] this->recon; |
---|
| 172 | this->recon = newrecon; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | // Correct the 2-D detection map |
---|
| 176 | short *newdetect = new short[this->axisDim[0]*this->axisDim[1]]; |
---|
| 177 | for(int x = 0; x < this->axisDim[0]; x++){ |
---|
| 178 | for(int y = 0; y < this->axisDim[1]; y++){ |
---|
| 179 | pos = x + y*this->axisDim[0]; |
---|
| 180 | smlpos = (x-this->par.getBorderLeft()) + (y-this->par.getBorderBottom())*smallXDim; |
---|
| 181 | isDud = (x<this->par.getBorderLeft()) || (x>=smallXDim+this->par.getBorderLeft()) || |
---|
| 182 | (y<this->par.getBorderBottom()) || (y>=smallYDim+this->par.getBorderBottom()); |
---|
| 183 | if(isDud) newdetect[pos]=0; |
---|
| 184 | else newdetect[pos] = this->detectMap[smlpos]; |
---|
| 185 | } |
---|
| 186 | } |
---|
| 187 | delete [] this->detectMap; |
---|
| 188 | this->detectMap = newdetect; |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | // Now update the positions for all the detections |
---|
| 192 | |
---|
| 193 | for(int i=0;i<this->objectList.size();i++){ |
---|
| 194 | for(int pix=0;pix<objectList[i].getSize();pix++){ |
---|
| 195 | long x = objectList[i].getX(pix); |
---|
| 196 | long y = objectList[i].getY(pix); |
---|
| 197 | objectList[i].setX(pix,x+this->par.getBorderLeft()); |
---|
| 198 | objectList[i].setY(pix,y+this->par.getBorderBottom()); |
---|
| 199 | } |
---|
| 200 | objectList[i].calcParams(); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | } |
---|