TwoDMesh.h

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Jolien Creighton, Reinhard Prix, Teviet Creighton
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /************************************* <lalVerbatim file="TwoDMeshHV">
00021 Author: Creighton, T. D.
00022 $Id: TwoDMesh.h,v 1.8 2007/06/08 14:41:50 bema Exp $
00023 **************************************************** </lalVerbatim> */
00024 
00025 /********************************************************** <lalLaTeX>
00026 
00027 \providecommand{\lessim}{\stackrel{<}{\scriptstyle\sim}}
00028 
00029 \section{Header \texttt{TwoDMesh.h}}
00030 \label{s:TwoDMesh.h}
00031 
00032 Provides routines to place search meshes for two-dimensional parameter
00033 spaces with varying metric.
00034 
00035 \subsection*{Synopsis}
00036 \begin{verbatim}
00037 #include <lal/TwoDMesh.h>
00038 \end{verbatim}
00039 
00040 \noindent This header covers routines that lay out a mesh of points on
00041 an 2-dimensional parameter space $\{(x,y)\}$, placed such that no
00042 point in the space lies further than some maximum proper distance
00043 $m_\mathrm{thresh}$ from a mesh point.
00044 
00045 The intended purpose of these routines is to place a set of ``target''
00046 search points over a parameter space, in order to detect signals with
00047 unknown parameters.  The formalism for defining a proper distance
00048 metric on the parameter space is defined in the header
00049 \verb@FlatMesh.h@.  However, whereas the routines under
00050 \verb@FlatMesh.h@ require the metric $\mathsf{g}_{ab}$ to be constant
00051 over the parameter space, the routines under this header only treat
00052 $\mathsf{g}_{ab}$ as constant over distances $\lessim
00053 m_\mathrm{thresh}$.
00054 
00055 \begin{figure}[h]
00056 \begin{center}
00057 \includegraphics{pulsar_tiling}
00058 \caption{\label{fig:tiling} Mesh placement using parallelogram tiling.
00059 (a)~The left and right sides of a tile are required to be vertical;
00060 the top and bottom sides can tilt to maximize the tile area.
00061 (b)~Tiles can be stacked in fixed-width columns, even as the
00062 elliptical contours change.  (c)~Extra overlapping tiles are sometimes
00063 required at the corners of columns.}
00064 \end{center}
00065 \end{figure}
00066 Since the metric is treated as constant over distances $\lessim
00067 m_\mathrm{thresh}$, this distance defines an elliptical contour around
00068 any mesh point.  We define a ``tile'' as a parallelogram inscribed
00069 within the ellipse, with its left and right sides aligned with the $y$
00070 axis.  This is shown in Fig.~\ref{fig:tiling}(a), above.  A ``column''
00071 is a set of tiles of constant horizontal width stacked one on top of
00072 the other, as shown in Fig.~\ref{fig:tiling}(b).  As the metric
00073 changes over space, the vertical height and tilt of the tiles in a
00074 column may change, so long as their width remains fixed; we note that
00075 if the tilt changes, the tiles will overlap slightly to ensure
00076 complete coverage.  Finally, the boundary of the parameter space may
00077 extend outside the ``corners'' of the column, crossing the end of a
00078 tile between its centre and its edge, as shown in
00079 Fig.~\ref{fig:tiling}(c).  These triangular corners can be covered
00080 with one or more extra overlapping tiles of reduced width.
00081 
00082 In a parameter space with constant metric, the tile area is maximized
00083 (and the number of covering tiles minimized) when the column width is
00084 $\sqrt{2}$ times smaller than the projected horizontal width of the
00085 ellipses.  When the ellipses vary, it is generally best to determine
00086 the column width from the \emph{narrowest} ellipse in a column, to
00087 avoid singular effects when tile widths approach the ellipse widths
00088 and become infinitesimally high.
00089 
00090 For the column-placement algorithm to work effectively, we require
00091 that the parameter space be representable as a range
00092 $y\in[y_1(x),y_2(x)]$ between two single-valued functions defined on a
00093 domain $x\in[x_\mathrm{min},x_\mathrm{max}]$.  If a desired search
00094 region is too complicated to express this way (e.g.\ it has
00095 disconnected regions, or ``branches'' where a vertical line intersects
00096 the boundary more than twice), then one should divide the region up
00097 into subregions with well-behaved boundary functions and tile these
00098 subregions separately.
00099 
00100 This header and its associated modules are placed in the \verb@pulsar@
00101 package because they were originally intended for use in searches over
00102 sky position, but they can be used generically for any two-dimensional
00103 parameter space search where the metric is not too poorly behaved.
00104 
00105 ******************************************************* </lalLaTeX> */
00106 
00107 #ifndef _TWODMESH_H
00108 #define _TWODMESH_H
00109 
00110 #include <lal/LALStdlib.h>
00111 
00112 #ifdef __cplusplus
00113 extern "C" {
00114 #pragma }
00115 #endif
00116 
00117 NRCSID(TWODMESHH,"$Id: TwoDMesh.h,v 1.8 2007/06/08 14:41:50 bema Exp $");
00118 
00119 /********************************************************** <lalLaTeX>
00120 \subsection*{Error conditions}
00121 ****************************************** </lalLaTeX><lalErrTable> */
00122 #define TWODMESHH_ENUL    1
00123 #define TWODMESHH_EOUT    2
00124 #define TWODMESHH_EMEM    3
00125 #define TWODMESHH_EMETRIC 4
00126 #define TWODMESHH_EWIDTH  5
00127 #define TWODMESHH_EDIM    6
00128 #define TWODMESHH_EINT    7
00129 
00130 #define TWODMESHH_MSGENUL    "Unexpected null pointer in arguments"
00131 #define TWODMESHH_MSGEOUT    "Output handle points to a non-null pointer"
00132 #define TWODMESHH_MSGEMEM    "Memory allocation error"
00133 #define TWODMESHH_MSGEMETRIC "Non-positive metric"
00134 #define TWODMESHH_MSGEWIDTH  "Column width too small"
00135 #define TWODMESHH_MSGEDIM    "Incorrect dimensions"
00136 #define TWODMESHH_MSGEINT    "Non-positive interval"
00137 /******************************************** </lalErrTable><lalLaTeX>
00138 
00139 \subsection*{Types}
00140 
00141 \subsubsection*{Structure \texttt{TwoDMeshNode}}
00142 \idx[Type]{TwoDMeshNode}
00143 
00144 \noindent This structure represents a single node in a linked list of
00145 mesh points, specified in the coordinate system used to place it.  The
00146 fields are:
00147 
00148 \begin{description}
00149 \item[\texttt{REAL4 x, y}] The coordinates of the mesh point.
00150 
00151 \item[\texttt{REAL4 dx}] The half-width of the tile centred on the
00152 mesh point.
00153 
00154 \item[\texttt{REAL4 dy[2]}] The heights of the two right-hand corners
00155 of the tile, relative to the mesh point.
00156 
00157 \item[\texttt{TwoDMeshNode *next}] The next mesh point in the linked
00158 list; \verb@NULL@ if this is the tail.
00159 
00160 \item[\texttt{TwoDMeshNode *subMesh}] The head of a linked list of
00161 fine mesh points within the rectangular area spanned by this mesh
00162 point list; \verb@NULL@ if there is no (further) refined mesh for this
00163 location.
00164 
00165 \item[\texttt{UINT4 nSub}] The number of fine mesh points in the
00166 above list.  It is an error for \verb@subNum@ to be nonzero and
00167 \verb@subMesh@ to be \verb@NULL@.
00168 \end{description}
00169 
00170 ******************************************************* </lalLaTeX> */
00171 
00172 typedef struct tagTwoDMeshNode {
00173   REAL4 x, y;
00174   REAL4 dx;
00175   REAL4 dy[2];
00176   struct tagTwoDMeshNode *next;
00177   struct tagTwoDMeshNode *subMesh;
00178   UINT4 nSub;
00179 } TwoDMeshNode;
00180 
00181 /******************************************************** <lalLaTeX>
00182 
00183 \subsubsection*{Structure \texttt{TwoDMeshParamStruc}}
00184 \idx[Type]{TwoDMeshParamStruc}
00185 
00186 \noindent This structure stores the parameters required by the
00187 two-dimensional mesh placement functions.  The fields are:
00188 
00189 \begin{description}
00190 \item[\texttt{REAL4 domain[2]}] The domain
00191 $[x_\mathrm{min},x_\mathrm{max}]$ spanned by the desired parameter
00192 region.
00193 
00194 \item[\texttt{void (*getRange)( LALStatus *, REAL4 [2], REAL4, void
00195 *)}] A function that returns in its second argument the range
00196 $[y_1(x),y_2(x)]$ spanned by the parameter region for a specified $x$,
00197 which is passed in as the third argument.  The fourth argument can be
00198 used to pass function-specific parameters.
00199 
00200 \item[\texttt{void *rangeParams}] The parameters to be passed as the
00201 fourth argument of \verb@*getRange()@, above.
00202 
00203 \item[\texttt{void (*getMetric)( LALStatus *, REAL4 [3], REAL4 [2],
00204 void *)}] A function that returns in its second argument the
00205 components $g_{xx}$, $g_{yy}$, and $g_{xy}$ (in that order) of the
00206 metric evaluated at a point $(x,y)$, which is passed in as the third
00207 argument.  The fourth argument can be used to pass function-specific
00208 parameters.
00209 
00210 \item[\texttt{void *metricParams}] The parameters to be passed as the
00211 fourth argument of \verb@*getMetric()@, above.
00212 
00213 \item[\texttt{REAL4 mThresh}] The maximum mismatch $m_\mathrm{thresh}$
00214 desired between any point in the region and the nearest mesh point;
00215 note that the maximum mismatch is equal to 1 minus the minimum match.
00216 
00217 \item[\texttt{REAL4 widthMaxFac}] The minimum ratio of mismatch
00218 ellipse width (projected onto the horizontal axis) to column width
00219 that must be maintained throughout the column: if an ellipse falls
00220 below this ratio due to shrinkage or rotation, as in Fig 29.1.b, the
00221 code will try a narrower column.  If set to $\leq1$, the default value
00222 \verb@TWODMESHINTERNALC_WMAXFAC@=$\sqrt[4]{2}$ will be used.
00223 
00224 \item[\texttt{REAL4 widthRetryFac}] If the column is determined to be
00225 too wide (e.g.\ due to the value of \verb@widthMaxFac@, above), the
00226 column width will be reduced by the factor \verb@widthRetryFac@.  If
00227 set to $\leq1$, the default value
00228 \verb@TWODMESHINTERNALC_WRETRYFAC@=$\sqrt{2}$ will be used.
00229 
00230 \item[\texttt{UINT4 maxColumns}] The maximum number of columns the
00231 mesh placement routine will try before giving up.  If zero, this
00232 number is ignored.
00233 
00234 \item[\texttt{UINT4 nIn}] The maximum number of mesh points allowed,
00235 after which the placement routine will quit.  If zero, this number is
00236 ignored.
00237 
00238 \item[\texttt{UINT4 nOut}] The number of mesh points added by the
00239 placement routine.  If an error occurs, this will store the number of
00240 mesh points completed before the error.
00241 \end{description}
00242 
00243 ******************************************************* </lalLaTeX> */
00244 
00245 typedef struct tagTwoDMeshParamStruc{
00246   REAL4 domain[2];
00247   void (*getRange)( LALStatus *, REAL4 [2], REAL4, void *);
00248   void *rangeParams;
00249   void (*getMetric)( LALStatus *, REAL4 [3], REAL4 [2], void *);
00250   void *metricParams;
00251   REAL4 mThresh;
00252   REAL4 widthMaxFac;
00253   REAL4 widthRetryFac;
00254   UINT4 maxColumns;
00255   UINT4 nIn;
00256   UINT4 nOut;
00257 } TwoDMeshParamStruc;
00258 
00259 
00260 /******************************************************** <lalLaTeX>
00261 
00262 \subsubsection*{Structure \texttt{TwoDColumnParamStruc}}
00263 \idx[Type]{TwoDColumnParamStruc}
00264 
00265 \noindent This structure stores additional parameters required when
00266 laying down a single column of a two-dimensional mesh.  The area to be
00267 covered is specified by intersecting the area between two lines with
00268 the parameter space.  If part of a column has already been covered,
00269 one can further restrict the area by specifying a pair of ``clipping
00270 points'' on each vertical line; the area to be covered is then
00271 restricted to lie above the line joining the bottom two corners and
00272 below the line joining the top two corners.  The fields of the
00273 structure are:
00274 
00275 \begin{description}
00276 \item[\texttt{REAL4 domain[2]}] The region in $x$ spanned by the
00277 column.  We require that \verb@domain[1]@$>$\verb@domain[0]@.
00278 
00279 \item[\texttt{REAL4 leftRange[2]}] The values $y_1(x)$, $y_2(x)$ (in
00280 that order) of the boundary functions at $x=$\verb@domain[0]@.
00281 
00282 \item[\texttt{REAL4 rightRange[2]}] The values of $y_1(x)$, $y_2(x)$
00283 (in that order) of the boundary functions at $x=$\verb@domain[1]@.
00284 
00285 \item[\texttt{REAL4 leftClip[2]}] The $y$ values of the bottom and top
00286 corners (in that order) of the clipping boundary at
00287 $x=$\verb@domain[0]@.
00288 
00289 \item[\texttt{REAL4 rightClip[2]}] The $y$ values of the bottom and
00290 top corners (in that order) of the clipping boundary at
00291 $x=$\verb@domain[1]@.
00292 
00293 \item[\texttt{BOOLEAN tooWide}] This is set to 1 if the
00294 column-placement routine determines that the region is too wide to be
00295 covered with a single column of tiles.
00296 \end{description}
00297 
00298 ******************************************************* </lalLaTeX> */
00299 
00300 typedef struct tagTwoDColumnParamStruc {
00301   REAL4 domain[2];
00302   REAL4 leftRange[2];  
00303   REAL4 rightRange[2];
00304   REAL4 leftClip[2];
00305   REAL4 rightClip[2];
00306   BOOLEAN tooWide;
00307 } TwoDColumnParamStruc;
00308 
00309 
00310 /* <lalLaTeX>
00311 \vfill{\footnotesize\input{TwoDMeshHV}}
00312 </lalLaTeX> */
00313 
00314 
00315 /* Function prototypes. */
00316 
00317 /* <lalLaTeX>
00318 \newpage\input{TwoDMeshC}
00319 </lalLaTeX> */
00320 void
00321 LALCreateTwoDMesh( LALStatus          *status,
00322                    TwoDMeshNode       **mesh,
00323                    TwoDMeshParamStruc *params );
00324 
00325 void
00326 LALDestroyTwoDMesh( LALStatus    *status,
00327                     TwoDMeshNode **mesh,
00328                     UINT4        *nFree );
00329 
00330 void
00331 LALRefineTwoDMesh( LALStatus    *status,
00332                    TwoDMeshNode *coarseMesh,
00333                    TwoDMeshNode *fineMesh );
00334 
00335 /* <lalLaTeX>
00336 \newpage\input{TwoDMeshInternalC}
00337 </lalLaTeX> */
00338 void
00339 LALTwoDMesh( LALStatus            *status,
00340              TwoDMeshNode         **tail,
00341              TwoDMeshParamStruc   *params );
00342 
00343 void
00344 LALTwoDColumn( LALStatus            *status,
00345                TwoDMeshNode         **tail,
00346                TwoDColumnParamStruc *columnParams,
00347                TwoDMeshParamStruc   *params );
00348 
00349 void
00350 LALTwoDNodeCopy( LALStatus    *status,
00351                  TwoDMeshNode **new,
00352                  TwoDMeshNode *old );
00353 
00354 
00355 void
00356 LALGetNearestMetric( LALStatus *status, REAL4 metric[3], REAL4 position[2], void *params );
00357 
00358 void
00359 LALInterpolateMetricGrid( LALStatus *status, REAL4 metric[3], REAL4 position[2], void *params );
00360 
00361 /* <lalLaTeX>
00362 \newpage\input{TwoDMeshRangesC}
00363 </lalLaTeX> */
00364 void
00365 LALInterpolateRangePolygon( LALStatus *status, REAL4 range[2], REAL4 x, void *params );
00366 
00367 void
00368 LALInterpolateRangeGrid( LALStatus *status, REAL4 range[2], REAL4 x, void *params );
00369 
00370 #ifdef __cplusplus
00371 #pragma {
00372 }
00373 #endif
00374 
00375 #endif /* _TWODMESH_H */

Generated on Sat Sep 6 03:07:45 2008 for LAL by  doxygen 1.5.2