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