211 #include <lal/LALStdlib.h>
212 #include <lal/LALConstants.h>
213 #include <lal/TwoDMesh.h>
218 static UINT4 columnNo;
221 #define TWODMESHINTERNALC_WMAXFAC (1.189207115)
222 #define TWODMESHINTERNALC_WRETRYFAC LAL_SQRT2
247 #define TOOWIDERETURN \
250 if ( lalDebugLevel&LALINFO ) { \
251 LALInfo( stat, "Column too wide" ); \
252 XLALPrintError( "\tnode count %u\n", params->nOut ); \
254 TRY( LALDestroyTwoDMesh( stat->statusPtr, &((*tail)->next), \
256 params->nOut -= nFree; \
257 column->tooWide = 1; \
258 DETATCHSTATUSPTR( stat ); \
273 #define GETWIDTH( dx, metric, mismatch ) \
275 REAL4 det = (metric)[0]*(metric)[1] - (metric)[2]*(metric)[2]; \
276 if ( ( (metric)[0] <= 0.0 ) || ( (metric)[1] <= 0.0 ) || \
278 TRY( LALDestroyTwoDMesh( stat->statusPtr, &((*(tail))->next), \
280 ABORT( stat, TWODMESHH_EMETRIC, TWODMESHH_MSGEMETRIC ); \
282 (dx) = sqrt( (metric)[1]*(mismatch)/det ); \
301 #define GETSIZE( dy, dx, metric, mismatch ) \
303 REAL4 det = (metric)[0]*(metric)[1] - (metric)[2]*(metric)[2]; \
305 if ( ( metric[0] <= 0.0 ) || ( metric[1] <= 0.0 ) || \
307 TRY( LALDestroyTwoDMesh( stat->statusPtr, &((*(tail))->next), \
309 ABORT( stat, TWODMESHH_EMETRIC, TWODMESHH_MSGEMETRIC ); \
311 if ( widthMaxFac*(dx) > sqrt( (metric)[1]*(mismatch)/det ) ) \
313 disc = sqrt( (metric)[1]*(mismatch) - det*(dx)*(dx) ); \
314 (dy)[0] = ( -metric[2]*dx - disc ) / metric[1]; \
315 (dy)[1] = ( -metric[2]*dx + disc ) / metric[1]; \
329 REAL4 widthRetryFac = TWODMESHINTERNALC_WRETRYFAC;
330 REAL4 maxColumnFac = 0.0;
347 if (
params->widthRetryFac > 1.0 ) {
348 widthRetryFac =
params->widthRetryFac;
350 if (
params->maxColumns > 0 ) {
351 maxColumnFac = 1.0 /
params->maxColumns;
380 position[0] = column.
domain[0];
382 (
params->getMetric )(
stat->statusPtr, metric, position,
388 GETWIDTH( w1, metric,
params->mThresh );
390 (
params->getMetric )(
stat->statusPtr, metric, position,
396 GETWIDTH(
w2, metric,
params->mThresh );
434 if (
params->nOut >= nIn ) {
475 REAL4 centreRange[2];
483 REAL4 widthMaxFac = TWODMESHINTERNALC_WMAXFAC;
502 if (
params->widthMaxFac > 1.0 ) {
503 widthMaxFac =
params->widthMaxFac;
518 position[0] = 0.5 * ( column->
domain[1] + column->
domain[0] );
520 TRY( (
params->getRange )(
stat->statusPtr, centreRange, position[0],
525 position[1] = centreClip[0];
526 if ( position[1] < centreRange[0] ) {
527 position[1] = centreRange[0];
529 if ( position[1] <= centreRange[1] ) {
533 TRY( (
params->getMetric )(
stat->statusPtr, metric, position,
536 if ( here == NULL ) {
544 GETSIZE( here->
next->dy, dx, metric,
params->mThresh );
545 here->
next->y = position[1];
547 here->
x = position[0];
550 if (
params->nOut >= nIn ) {
557 myy0 = here->
y + here->
dy[0];
558 myy1 = here->
y - here->
dy[1];
559 if ( leftTiled[0] > myy1 ) {
562 if ( rightTiled[0] > myy0 ) {
563 rightTiled[0] = myy0;
565 leftTiled[1] = here->
y - here->
dy[0];
566 rightTiled[1] = here->
y + here->
dy[1];
567 position[1] = 0.5 * leftTiled[1] + 0.5 * rightTiled[1];
570 while ( ( position[1] < centreRange[1] ) &&
571 ( position[1] < centreClip[1] ) ) {
572 (
params->getMetric )(
stat->statusPtr, metric, position,
579 if ( here == NULL ) {
589 GETSIZE( here->
next->dy, dx, metric,
params->mThresh );
590 myy0 = here->
dy[1] - here->
next->dy[0];
591 myy1 = here->
next->dy[1] - here->
dy[0];
598 here->
next->y = here->
y + myy0;
600 if ( here->
y > centreRange[1] ) {
601 here->
y = centreRange[1];
603 here->
x = position[0];
606 if (
params->nOut >= nIn ) {
613 leftTiled[1] = here->
y - here->
dy[0];
614 rightTiled[1] = here->
y + here->
dy[1];
615 position[1] = 0.5 * leftTiled[1] + 0.5 * rightTiled[1];
623 myy0 = 0.5 * leftTiled[0] + 0.5 * rightTiled[0];
626 if ( ( ( column->
leftClip[0] < leftTiled[0] ) ||
627 ( centreClip[0] < myy0 ) ) &&
628 ( column->
leftRange[0] < leftTiled[0] ) &&
630 ( centreRange[1] > centreClip[0] ) ) ) {
633 column2.
domain[1] = position[0];
638 if ( ( leftTiled[0] < column2.
leftClip[1] ) &&
648 if (
params->nOut >= nIn ) {
659 if ( ( ( column->
rightClip[0] < rightTiled[0] ) ||
660 ( centreClip[0] < myy0 ) ) &&
663 ( centreRange[1] > centreClip[0] ) ) ) {
666 column2.
domain[0] = position[0];
671 if ( ( rightTiled[0] < column2.
rightClip[1] ) &&
681 if (
params->nOut >= nIn ) {
693 myy0 = 0.5 * leftTiled[1] + 0.5 * rightTiled[1];
696 if ( ( ( column->
leftClip[1] > leftTiled[1] ) ||
697 ( centreClip[1] > myy0 ) ) &&
698 ( column->
leftRange[1] > leftTiled[1] ) &&
700 ( centreRange[0] < centreClip[1] ) ) ) {
703 column2.
domain[1] = position[0];
708 if ( ( leftTiled[1] > column2.
leftClip[0] ) &&
718 if (
params->nOut >= nIn ) {
729 if ( ( ( column->
rightClip[1] > rightTiled[1] ) ||
730 ( centreClip[1] > myy0 ) ) &&
733 ( centreRange[0] < centreClip[1] ) ) ) {
736 column2.
domain[0] = position[0];
741 if ( ( rightTiled[1] > column2.
rightClip[0] ) &&
751 if (
params->nOut >= nIn ) {
789 if ( *
new == NULL ) {
793 ( *new )->
next = ( *new )->subMesh = NULL;
797 tailCopy = &( ( *new )->next );
798 while ( tail != NULL ) {
804 tailCopy = &( ( *tailCopy )->next );
#define ABORT(statusptr, code, mesg)
#define ENDFAIL(statusptr)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define BEGINFAIL(statusptr)
void LALTwoDMesh(LALStatus *stat, TwoDMeshNode **tail, TwoDMeshParamStruc *params)
#define TWODMESHH_MSGENUL
#define TWODMESHH_MSGEMEM
void LALTwoDColumn(LALStatus *stat, TwoDMeshNode **tail, TwoDColumnParamStruc *column, TwoDMeshParamStruc *params)
#define TWODMESHH_MSGEWIDTH
void LALTwoDNodeCopy(LALStatus *stat, TwoDMeshNode **new, TwoDMeshNode *old)
#define TWODMESHH_MSGEOUT
void LALDestroyTwoDMesh(LALStatus *stat, TwoDMeshNode **mesh, UINT4 *nFree)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
This structure stores additional parameters required when laying down a single column of a two-dimens...
BOOLEAN tooWide
This is set to 1 if the column-placement routine determines that the region is too wide to be covered...
REAL4 leftClip[2]
The values of the bottom and top corners (in that order) of the clipping boundary at domain[0].
REAL4 domain[2]
The region in spanned by the column; We require that domain[1] domain[0]
REAL4 rightClip[2]
The values of the bottom and top corners (in that order) of the clipping boundary at domain[1]
REAL4 rightRange[2]
The values of , (in that order) of the boundary functions at domain[1]
REAL4 leftRange[2]
The values , (in that order) of the boundary functions at domain[0]
This structure represents a single node in a linked list of mesh points, specified in the coordinate ...
struct tagTwoDMeshNode * next
The next mesh point in the linked list; NULL if this is the tail.
REAL4 dx
The half-width of the tile centred on the mesh point.
struct tagTwoDMeshNode * subMesh
The head of a linked list of fine mesh points within the rectangular area spanned by this mesh point ...
REAL4 dy[2]
The heights of the two right-hand corners of the tile, relative to the mesh point.
REAL4 y
The coordinates of the mesh point.
This structure stores the parameters required by the two-dimensional mesh placement functions.