atPMatch.c
This file contains routines that try to match up items
in two different CHAINs, which might have very different
coordinate systems.
DESCRIPTION:
This function is based on the algorithm described in Valdes et al.,
PASP 107, 1119 (1995). It tries to
a. match up objects in the two chains
a. find a coordinate transformation that takes coords in
objects in chainA and changes to those in chainB.
Actually, this is a top-level "driver" routine that calls smaller
functions to perform actual tasks. It mostly creates the proper
inputs and outputs for the smaller routines.
Only the affine elemnts of the TRANS are set. The higer-order distortion
and color terms are all set to 0.
RETURN:
SH_SUCCESS if all goes well
SH_GENERIC_ERROR if an error occurs
SIGNATURE:
int
atFindTrans
(
CHAIN *chainA, /* I: match this set of objects with chain B */
char *xnameA, /* I: name of the field in CHAIN A with X coord */
char *ynameA, /* I: name of the field in CHAIN A with Y coord */
char *magnameA, /* I: name of the field in CHAIN A with "mag" */
CHAIN *chainB, /* I: match this set of objects with chain A */
char *xnameB, /* I: name of the field in CHAIN B with X coord */
char *ynameB, /* I: name of the field in CHAIN B with Y coord */
char *magnameB, /* I: name of the field in CHAIN B with "mag" */
float radius, /* I: max radius in triangle-space allowed for */
/* a pair of triangles to match */
int nobj, /* I: max number of bright stars to use in creating */
/* triangles for matching from each list */
float maxdist, /* I: after initial guess at coord transform */
/* accept as valid pairs which are at most */
/* this far apart in coord system B */
float scale, /* I: expected relative scale factor */
/* if -1, any scale factor is allowed */
TRANS *trans /* O: place into this TRANS structure's fields */
/* the coeffs which convert coords of chainA */
/* into coords of chainB system. */
)
DESCRIPTION:
Given a CHAIN of structures, each of which has an element containing
something used as an "x" coordinate, and an element for something
used as a "y" coordinate, apply the given TRANS to each item in
the CHAIN, modifying the "x" and "y" values.
Only the affine terms of the TRANS structure are used. The higher-order
distortion and color terms are ignfored. Thus:
x' = a + bx + cx
y' = d + ex + fy
Actually, this is a top-level "driver" routine that calls smaller
functions to perform actual tasks. It mostly creates the proper
inputs and outputs for the smaller routines.
RETURN:
SH_SUCCESS if all goes well
SH_GENERIC_ERROR if an error occurs
SIGNATURE:
int
atApplyTrans
(
CHAIN *chain, /* I/O: modify x,y coords of objects in this CHAIN */
char *xname, /* I: name of the field in CHAIN with X coord */
char *yname, /* I: name of the field in CHAIN with Y coord */
TRANS *trans /* I: use this TRANS to transform the coords of */
/* items in the CHAIN */
)
DESCRIPTION:
Given 2 CHAINs of structures, the items on each of which have
an element containing something used as an "x" coordinate,
and an element for something used as a "y" coordinate,
and which have ALREADY been transformed so that the "x"
and "y" coordinates of each CHAIN are close to each other
(i.e. matching items from each CHAIN have very similar "x" and "y")
this routine attempts to find all instances of matching items
from the 2 CHAINs.
We consider a "match" to be the closest coincidence of centers
which are within "radius" pixels of each other.
Use a slow, but sure, algorithm.
We will match objects from A --> B. It is possible to have several
As that match to the same B:
A1 -> B5 and A2 -> B5
This function finds such multiple-match items and deletes all but
the closest of the matches.
place the elems of A that are matches into output chain J
B that are matches into output chain K
A that are not matches into output chain L
B that are not matches into output chain M
RETURN:
SH_SUCCESS if all goes well
SH_GENERIC_ERROR if an error occurs
SIGNATURE:
int
atMatchChains
(
CHAIN *chainA, /* I: first input chain of items to be matched */
char *xnameA, /* I: name of field in items in listA which */
/* contain the "x" coordinates */
char *ynameA, /* I: name of field in items in listA which */
/* contain the "y" coordinates */
CHAIN *chainB, /* I: second chain of items to be matched */
char *xnameB, /* I: name of field in items in listB which */
/* contain the "x" coordinates */
char *ynameB, /* I: name of field in items in listB which */
/* contain the "y" coordinates */
float radius, /* I: maximum radius for items to be a match */
CHAIN **chainJ, /* O: output chain of all items in A that match */
CHAIN **chainK, /* O: output chain of all items in B that match */
CHAIN **chainL, /* O: chain of items from A that didn't match */
CHAIN **chainM /* O: chain of items from B that didn't match */
)