Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
HoughMap.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2005 Badri Krishnan, Alicia Sintes, Bernd Machenschalk
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20#include <lal/HoughMap.h>
21
22/*
23 * The functions that make up the guts of this module
24 */
25
26/**
27 * This function initializes the Hough map derivative
28 * space HOUGHMapDeriv *hd to zero. Note that the length of the map
29 * hd->map should be hd->ySide * (hd->xSide + 1).
30 */
32 HOUGHMapDeriv *hd) /* the Hough map derivative */
33{
34
35 INT4 k, maxk;
36 HoughDT *pointer;
37
38 /* --------------------------------------------- */
41
42 /* Make sure the arguments are not NULL: */
44 /* Make sure the map contains some pixels */
47
48 /* ------------------------------------------- */
49
50 /* initializing the Hough map derivative space */
51 pointer = &( hd->map[0]);
52 maxk = hd->ySide*(hd->xSide+1);
53
54 for ( k=0; k< maxk; ++k ){
55 *pointer = 0;
56 ++pointer;
57 }
58
59 /* ------------------------------------------- */
60
62
63 /* normal exit */
64 RETURN (status);
65}
66
67/**
68 * This function initializes the total Hough map
69 * HOUGHMapTotal *ht to zero and checks consistency between
70 * the number of physical pixels in the
71 * map and those given by the grid information structure
72 * HOUGHPatchGrid *patch.
73 */
75 HOUGHMapTotal *ht, /* the total Hough map */
76 HOUGHPatchGrid *patch) /* patch information */
77{
78
79 INT4 k,maxk;
80 HoughTT *pointer;
81
82 /* --------------------------------------------- */
84
85 /* Make sure the arguments are not NULL: */
88 /* Make sure the map contains some pixels */
93 /* Check consistency between patch and ht size (size mismatch) */
96
97 /* ------------------------------------------- */
98
99 /* number of physical pixels */
100 maxk = ht->ySide * ht->xSide;
101
102 /* initializing the Hough map space */
103 pointer = &(ht->map[0]);
104 for ( k=0; k< maxk; ++k ){
105 *pointer = 0;
106 ++pointer;
107 }
108
109 (void)patch;
110
111 /* normal exit */
112 RETURN (status);
113}
114
115
116/**
117 * Given an initial Hough map derivative HOUGHMapDeriv *hd and a representation
118 * of a phmd HOUGHphmd *phmd, the function LALHOUGHAddPHMD2HD() accumulates
119 * the partial Hough map derivative *phmd to *hd by adding +1 or
120 * -1 to the pixels corresponding to the left or right borders respectively.
121 * It takes into account corrections due to border effects as well.
122 */
123void LALHOUGHAddPHMD2HD (LALStatus *status, /**< the status pointer */
124 HOUGHMapDeriv *hd, /**< the Hough map derivative */
125 HOUGHphmd *phmd) /**< info from a partial map */
126{
127
128 INT2 k,j;
129 INT2 yLower, yUpper;
130 UINT2 lengthLeft,lengthRight, xSide,ySide;
131 COORType *xPixel;
132 HOUGHBorder *borderP;
133
134 /* --------------------------------------------- */
137
138 /* Make sure the arguments are not NULL: */
141 /* ------------------------------------------- */
142 /* Make sure the map contains some pixels */
145
146 xSide = hd->xSide;
147 ySide = hd->ySide;
148
149 /* first column correction */
150 for ( k=0; k< ySide; ++k ){
151 hd->map[k*(xSide+1) + 0] += phmd->firstColumn[k];
152 }
153
154 lengthLeft = phmd->lengthLeft;
155 lengthRight= phmd->lengthRight;
156
157 /* left borders => +1 increase */
158 for (k=0; k< lengthLeft; ++k){
159
160 /* Make sure the arguments are not NULL: (Commented for performance) */
161 /* ASSERT (phmd->leftBorderP[k], status, HOUGHMAPH_ENULL,
162 HOUGHMAPH_MSGENULL); */
163
164 borderP = phmd->leftBorderP[k];
165
166 yLower = (*borderP).yLower;
167 yUpper = (*borderP).yUpper;
168 xPixel = &( (*borderP).xPixel[0] );
169
170
171 if (yLower < 0) {
172 fprintf(stderr,"WARNING: Fixing yLower (%d -> 0) [HoughMap.c %d]\n",
173 yLower, __LINE__);
174 yLower = 0;
175 }
176 if (yUpper >= ySide) {
177 fprintf(stderr,"WARNING: Fixing yUpper (%d -> %d) [HoughMap.c %d]\n",
178 yUpper, ySide-1, __LINE__);
179 yUpper = ySide - 1;
180 }
181
182 for(j=yLower; j<=yUpper;++j){
183 hd->map[j *(xSide+1) + xPixel[j] ] += 1;
184 }
185 }
186
187 /* right borders => -1 decrease */
188 for (k=0; k< lengthRight; ++k){
189
190 /* Make sure the arguments are not NULL: (Commented for performance) */
191 /* ASSERT (phmd->rightBorderP[k], status, HOUGHMAPH_ENULL,
192 HOUGHMAPH_MSGENULL); */
193
194 borderP = phmd->rightBorderP[k];
195
196 yLower = (*borderP).yLower;
197 yUpper = (*borderP).yUpper;
198 xPixel = &( (*borderP).xPixel[0] );
199
200
201 if (yLower < 0) {
202 fprintf(stderr,"WARNING: Fixing yLower (%d -> 0) [HoughMap.c %d]\n",
203 yLower, __LINE__);
204 yLower = 0;
205 }
206 if (yUpper >= ySide) {
207 fprintf(stderr,"WARNING: Fixing yUpper (%d -> %d) [HoughMap.c %d]\n",
208 yUpper, ySide-1, __LINE__);
209 yUpper = ySide - 1;
210 }
211
212 for(j=yLower; j<=yUpper;++j){
213 hd->map[j*(xSide+1) + xPixel[j] ] -= 1;
214 }
215 }
216
217
218 /* ------------------------------------------- */
219
221
222 /* normal exit */
223 RETURN (status);
224}
225
226
227/**
228 * Adds a hough map derivative into a total hough map derivative taking into
229 * account the weight of the partial hough map
230 */
231void LALHOUGHAddPHMD2HD_W (LALStatus *status, /**< the status pointer */
232 HOUGHMapDeriv *hd, /**< the Hough map derivative */
233 HOUGHphmd *phmd) /**< info from a partial map */
234{
235
236 INT2 k,j;
237 INT2 yLower, yUpper;
238 UINT2 lengthLeft,lengthRight, xSide,ySide;
239 COORType *xPixel;
240 HOUGHBorder *borderP;
241 HoughDT weight;
242 INT4 sidx; /* pre-calcuted array index for sanity check */
243
244 /* --------------------------------------------- */
247
248 /* Make sure the arguments are not NULL: */
251 /* ------------------------------------------- */
252 /* Make sure the map contains some pixels */
255
256 weight = phmd->weight;
257
258 xSide = hd->xSide;
259 ySide = hd->ySide;
260
261 /* first column correction */
262 for ( k=0; k< ySide; ++k ){
263 hd->map[k*(xSide+1) + 0] += phmd->firstColumn[k] * weight;
264 }
265
266 lengthLeft = phmd->lengthLeft;
267 lengthRight= phmd->lengthRight;
268
269 /* left borders => increase according to weight*/
270 for (k=0; k< lengthLeft; ++k){
271
272 /* Make sure the arguments are not NULL: (Commented for performance) */
273 /* ASSERT (phmd->leftBorderP[k], status, HOUGHMAPH_ENULL,
274 HOUGHMAPH_MSGENULL); */
275
276 borderP = phmd->leftBorderP[k];
277
278 yLower = (*borderP).yLower;
279 yUpper = (*borderP).yUpper;
280 xPixel = &( (*borderP).xPixel[0] );
281
282 if (yLower < 0) {
283 fprintf(stderr,"WARNING: Fixing yLower (%d -> 0) [HoughMap.c %d]\n",
284 yLower, __LINE__);
285 yLower = 0;
286 }
287 if (yUpper >= ySide) {
288 fprintf(stderr,"WARNING: Fixing yUpper (%d -> %d) [HoughMap.c %d]\n",
289 yUpper, ySide-1, __LINE__);
290 yUpper = ySide - 1;
291 }
292
293 for(j=yLower; j<=yUpper;++j){
294 sidx = j *(xSide+1) + xPixel[j];
295 if ((sidx < 0) || (sidx >= ySide*(xSide+1))) {
296 fprintf(stderr,"\nERROR: %s %d: map index out of bounds: %d [0..%d] j:%d xp[j]:%d\n",
297 __FILE__,__LINE__,sidx,ySide*(xSide+1),j,xPixel[j] );
299 }
300 hd->map[sidx] += weight;
301 }
302 }
303
304 /* right borders => decrease according to weight*/
305 for (k=0; k< lengthRight; ++k){
306
307 /* Make sure the arguments are not NULL: (Commented for performance) */
308 /* ASSERT (phmd->rightBorderP[k], status, HOUGHMAPH_ENULL,
309 HOUGHMAPH_MSGENULL); */
310
311 borderP = phmd->rightBorderP[k];
312
313 yLower = (*borderP).yLower;
314 yUpper = (*borderP).yUpper;
315 xPixel = &( (*borderP).xPixel[0] );
316
317 if (yLower < 0) {
318 fprintf(stderr,"WARNING: Fixing yLower (%d -> 0) [HoughMap.c %d]\n",
319 yLower, __LINE__);
320 yLower = 0;
321 }
322 if (yUpper >= ySide) {
323 fprintf(stderr,"WARNING: Fixing yUpper (%d -> %d) [HoughMap.c %d]\n",
324 yUpper, ySide-1, __LINE__);
325 yUpper = ySide - 1;
326 }
327
328 for(j=yLower; j<=yUpper;++j){
329 sidx = j*(xSide+1) + xPixel[j];
330 if ((sidx < 0) || (sidx >= ySide*(xSide+1))) {
331 fprintf(stderr,"\nERROR: %s %d: map index out of bounds: %d [0..%d] j:%d xp[j]:%d\n",
332 __FILE__,__LINE__,sidx,ySide*(xSide+1),j,xPixel[j] );
334 }
335 hd->map[sidx] -= weight;
336 }
337 }
338
339
340 /* ------------------------------------------- */
341
343
344 /* normal exit */
345 RETURN (status);
346}
347
348/**
349 * This function constructs a total Hough map
350 * HOUGHMapTotal *ht from its derivative HOUGHMapDeriv *hd by
351 * integrating each row (x-direction).
352 */
354 HOUGHMapTotal *ht, /* the total Hough map */
355 HOUGHMapDeriv *hd) /* the Hough map derivative */
356{
357
358 INT2 i,j;
359 UINT2 xSide,ySide;
360 HoughTT accumulator;
361
362 /* --------------------------------------------- */
365
366 /* Make sure the arguments are not NULL: */
369 /* Make sure the map contains some pixels */
374 /* Check consistency between hd and ht size (size mismatch) */
377 /* ------------------------------------------- */
378
379 /* number of physical pixels */
380 xSide = ht->xSide;
381 ySide = ht->ySide;
382
383 /* To construct the Hough map from the derivative,
384 the latter must be integrated row-wise (x direction) */
385
386 /* Loop on the rows */
387 for (j=0; j< ySide; ++j){
388 accumulator = 0;
389 for ( i=0; i<xSide; ++i){
390 ht->map[j*xSide +i] = ( accumulator += hd->map[j*(xSide+1) +i]);
391 }
392 }
393
394
395
396 /* ------------------------------------------- */
397
399
400 /* normal exit */
401 RETURN (status);
402}
403
404/** Find source sky location given stereographic coordinates indexes */
406 REAL8UnitPolarCoor *sourceLocation, /* output*/
407 UINT2 xPos,
408 UINT2 yPos,
409 HOUGHPatchGrid *patch,
410 HOUGHDemodPar *parDem)
411{
412
413 REAL8Cart2Coor sourceProjected;
414 REAL8UnitPolarCoor sourceRotated;
415 REAL8UnitPolarCoor skyPatchCenter;
416 /* --------------------------------------------- */
419
423
424 sourceProjected.x = patch->xCoor[xPos];
425 sourceProjected.y = patch->yCoor[yPos];
426
427 skyPatchCenter.alpha = parDem->skyPatch.alpha;
428 skyPatchCenter.delta = parDem->skyPatch.delta;
429
430 /* invert the stereographic projection for a point on the projected plane */
432 &sourceRotated, &sourceProjected ), status );
433
434 /* undo roation in case the patch is not centered at the south pole */
435 TRY( LALInvRotatePolarU( status->statusPtr,
436 sourceLocation, &sourceRotated, &skyPatchCenter ), status );
437
439 /* normal exit */
440 RETURN (status);
441}
int j
int k
#define ABORT(statusptr, code, mesg)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define fprintf
#define HOUGHMAPH_ENULL
Definition: HoughMap.h:75
#define HOUGHMAPH_ESZMM
Definition: HoughMap.h:77
void LALHOUGHAddPHMD2HD_W(LALStatus *status, HOUGHMapDeriv *hd, HOUGHphmd *phmd)
Adds a hough map derivative into a total hough map derivative taking into account the weight of the p...
Definition: HoughMap.c:231
void LALStereo2SkyLocation(LALStatus *status, REAL8UnitPolarCoor *sourceLocation, UINT2 xPos, UINT2 yPos, HOUGHPatchGrid *patch, HOUGHDemodPar *parDem)
Find source sky location given stereographic coordinates indexes.
Definition: HoughMap.c:405
#define HOUGHMAPH_ESIZE
Definition: HoughMap.h:76
void LALHOUGHInitializeHD(LALStatus *status, HOUGHMapDeriv *hd)
This function initializes the Hough map derivative space HOUGHMapDeriv *hd to zero.
Definition: HoughMap.c:31
#define HOUGHMAPH_MSGESIZE
Definition: HoughMap.h:84
#define HOUGHMAPH_MSGESZMM
Definition: HoughMap.h:85
REAL8 HoughTT
Total Hough Map pixel type.
Definition: HoughMap.h:113
void LALHOUGHAddPHMD2HD(LALStatus *status, HOUGHMapDeriv *hd, HOUGHphmd *phmd)
Given an initial Hough map derivative HOUGHMapDeriv *hd and a representation of a phmd HOUGHphmd *phm...
Definition: HoughMap.c:123
#define HOUGHMAPH_MSGENULL
Definition: HoughMap.h:83
void LALHOUGHIntegrHD2HT(LALStatus *status, HOUGHMapTotal *ht, HOUGHMapDeriv *hd)
This function constructs a total Hough map HOUGHMapTotal *ht from its derivative HOUGHMapDeriv *hd by...
Definition: HoughMap.c:353
void LALHOUGHInitializeHT(LALStatus *status, HOUGHMapTotal *ht, HOUGHPatchGrid *patch)
This function initializes the total Hough map HOUGHMapTotal *ht to zero and checks consistency betwee...
Definition: HoughMap.c:74
int16_t INT2
uint16_t UINT2
int32_t INT4
void LALInvRotatePolarU(LALStatus *status, REAL8UnitPolarCoor *out, REAL8UnitPolarCoor *in, REAL8UnitPolarCoor *par)
void LALStereoInvProjectCart(LALStatus *status, REAL8UnitPolarCoor *out, REAL8Cart2Coor *in)
INT2 COORType
To be changed to {INT2 COORType} if the number of pixels in the x-direction exceeds 255.
Definition: LUT.h:218
REAL8 HoughDT
Hough Map derivative pixel type.
Definition: PHMD.h:121
This structure stores the border of a circle clipped on the projected plane.
Definition: LUT.h:221
INT4 yLower
lower y pixel affected by this border and yUpper<yLower or yUpper<0 are possible
Definition: LUT.h:223
Demodulation parameters needed for the Hough transform; all coordinates are assumed to be with respec...
Definition: LUT.h:353
REAL8UnitPolarCoor skyPatch
(alpha, delta): position of the center of the patch
Definition: LUT.h:355
This structure stores the Hough map derivative.
Definition: HoughMap.h:121
UINT2 ySide
number of physical pixels in the y direction
Definition: HoughMap.h:123
UINT2 xSide
number of physical pixels in the x direction
Definition: HoughMap.h:122
HoughDT * map
the pixel count derivatives; the number of elements to allocate is ySide*(xSide+1)*
Definition: HoughMap.h:124
This structure stores the Hough map.
Definition: HoughMap.h:130
UINT2 ySide
number of physical pixels in the y direction
Definition: HoughMap.h:142
UINT2 xSide
number of physical pixels in the x direction
Definition: HoughMap.h:141
HoughTT * map
the pixel counts; the number of elements to allocate is ySide*xSide
Definition: HoughMap.h:143
This structure stores patch-frequency grid information.
Definition: LUT.h:264
UINT2 ySide
Real number of pixels in the y-direction (in the projected plane).
Definition: LUT.h:275
REAL8 * xCoor
Coordinates of the pixel centers.
Definition: LUT.h:271
UINT2 xSide
Real number of pixels in the x direction (in the projected plane); it should be less than or equal to...
Definition: LUT.h:270
REAL8 * yCoor
Coordinates of the pixel centers.
Definition: LUT.h:278
This structure stores a partial Hough map derivative.
Definition: PHMD.h:141
UINT2 lengthRight
Exact number of Right borders.
Definition: PHMD.h:144
UINT2 lengthLeft
Exact number of Left borders.
Definition: PHMD.h:143
HoughDT weight
First column border, containing the edge effects when clipping on a finite patch.
Definition: PHMD.h:152
UCHAR * firstColumn
Number of elements of firstColumn.
Definition: PHMD.h:151
HOUGHBorder ** rightBorderP
Pointers to borders.
Definition: PHMD.h:149
HOUGHBorder ** leftBorderP
Pointers to borders.
Definition: PHMD.h:148
Two dimensional Cartessian coordinates.
Definition: LUT.h:315
REAL8 y
Definition: LUT.h:317
REAL8 x
Definition: LUT.h:316
Polar coordinates of a unitary vector on the sphere.
Definition: LUT.h:327
REAL8 alpha
any value
Definition: LUT.h:328
REAL8 delta
In the interval [ ].
Definition: LUT.h:329