IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32875


Ignore:
Timestamp:
Dec 7, 2011, 3:51:28 AM (15 years ago)
Author:
eugene
Message:

allow clusters to limit entry to max Nfriends

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.astro/mkclusters.c

    r32867 r32875  
    22
    33typedef struct {
    4   int *friend;;
    5   float *dist;
    6   int Ndist;
    7   int NDIST;
    8   int group;
     4  int *friend; // indices for all tested relationships
     5  float *dist; // distance for this relationship
     6  int Ndist;   // number of tested relationships
     7  int NDIST;   // number of allocated relationships
     8  int group;   // assigned group
     9  int Nfriend; // number of friends brought into group
    910} Object;
    1011
     
    2324// static int NOBJECT = 0;
    2425
    25 void add_to_group (int Nobj, float scale) {
     26void add_to_group (int Nobj, float scale, int Nfriends) {
    2627
    2728  int j;
     
    3738  CHECK_REALLOCATE (group[Ngroup].entry, int, group[Ngroup].NENTRY, group[Ngroup].Nentry, 100);
    3839
    39   // add all friends of this object
    40   for (j = 0; j < object[Nobj].Ndist; j++) {
     40  // add all friends of this object (up to Nfriensd)
     41  // friends are already sorted by distance, so we add closest friends first
     42  for (j = 0; (object[Nobj].Nfriend < Nfriends) && (j < object[Nobj].Ndist); j++) {
    4143    if (object[Nobj].dist[j] > scale) continue;
    4244
     
    4648
    4749    // found a friend :
    48     add_to_group (Nnew, scale);
     50    object[Nobj].Nfriend ++;
     51    add_to_group (Nnew, scale, Nfriends);
    4952  }
    5053  return;
     
    6871}
    6972
     73void sortfriends (float *X, int *IDX1, int N) {
     74
     75# define SWAPFUNC(A,B){ float tmp; int itmp; \
     76  tmp  = X[A];    X[A]    = X[B];    X[B]    = tmp; \
     77  itmp = IDX1[A]; IDX1[A] = IDX1[B]; IDX1[B] = itmp; \
     78}
     79
     80# define COMPARE(A,B)(X[A] < X[B])
     81
     82  OHANA_SORT (N, COMPARE, SWAPFUNC);
     83
     84# undef SWAPFUNC
     85# undef COMPARE
     86
     87}
     88
    7089int mkclusters (int argc, char **argv) {
    7190 
     
    7392  Vector *index1, *index2, *distance;
    7493
    75   if (argc != 5) goto usage;
     94  if (argc != 6) goto usage;
    7695
    7796  if ((index1   = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) goto escape;
     
    7998  if ((distance = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) goto escape;
    8099  float scale = atof (argv[4]);
     100  int Nfriends = atoi (argv[5]);
    81101
    82102  // XXX enforce matching lengths on the three vectors
     
    102122    object[i].Ndist = 0;
    103123    object[i].group = -1; // unassigned
     124    object[i].Nfriend = 0; // no friends yet
    104125  }
    105126
     
    133154  }
    134155
     156  for (i = 0; i < Nobject; i++) {
     157    sortfriends (object[i].dist, object[i].friend, object[i].Ndist);
     158  }
     159
    135160  // generate the set of groups. each group is a list of friends and their friends
    136161  Ngroup = 0;
     
    155180    Nnew = index1->elements.Int[i];
    156181    if (object[Nnew].group == -1) {
    157       add_to_group (Nnew, scale);
     182      add_to_group (Nnew, scale, Nfriends);
    158183      // fprintf (stderr, "new group %d part 1 with %d elements\n", Ngroup, group[Ngroup].Nentry);
    159184      found = TRUE;
     
    162187    Nnew = index2->elements.Int[i];
    163188    if (object[Nnew].group == -1) {
    164       add_to_group (Nnew, scale);
     189      add_to_group (Nnew, scale, Nfriends);
    165190      // fprintf (stderr, "new group %d part 1 with %d elements\n", Ngroup, group[Ngroup].Nentry);
    166191      found = TRUE;
Note: See TracChangeset for help on using the changeset viewer.