Changeset 32875
- Timestamp:
- Dec 7, 2011, 3:51:28 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.astro/mkclusters.c
r32867 r32875 2 2 3 3 typedef 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 9 10 } Object; 10 11 … … 23 24 // static int NOBJECT = 0; 24 25 25 void add_to_group (int Nobj, float scale ) {26 void add_to_group (int Nobj, float scale, int Nfriends) { 26 27 27 28 int j; … … 37 38 CHECK_REALLOCATE (group[Ngroup].entry, int, group[Ngroup].NENTRY, group[Ngroup].Nentry, 100); 38 39 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++) { 41 43 if (object[Nobj].dist[j] > scale) continue; 42 44 … … 46 48 47 49 // found a friend : 48 add_to_group (Nnew, scale); 50 object[Nobj].Nfriend ++; 51 add_to_group (Nnew, scale, Nfriends); 49 52 } 50 53 return; … … 68 71 } 69 72 73 void 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 70 89 int mkclusters (int argc, char **argv) { 71 90 … … 73 92 Vector *index1, *index2, *distance; 74 93 75 if (argc != 5) goto usage;94 if (argc != 6) goto usage; 76 95 77 96 if ((index1 = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) goto escape; … … 79 98 if ((distance = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) goto escape; 80 99 float scale = atof (argv[4]); 100 int Nfriends = atoi (argv[5]); 81 101 82 102 // XXX enforce matching lengths on the three vectors … … 102 122 object[i].Ndist = 0; 103 123 object[i].group = -1; // unassigned 124 object[i].Nfriend = 0; // no friends yet 104 125 } 105 126 … … 133 154 } 134 155 156 for (i = 0; i < Nobject; i++) { 157 sortfriends (object[i].dist, object[i].friend, object[i].Ndist); 158 } 159 135 160 // generate the set of groups. each group is a list of friends and their friends 136 161 Ngroup = 0; … … 155 180 Nnew = index1->elements.Int[i]; 156 181 if (object[Nnew].group == -1) { 157 add_to_group (Nnew, scale );182 add_to_group (Nnew, scale, Nfriends); 158 183 // fprintf (stderr, "new group %d part 1 with %d elements\n", Ngroup, group[Ngroup].Nentry); 159 184 found = TRUE; … … 162 187 Nnew = index2->elements.Int[i]; 163 188 if (object[Nnew].group == -1) { 164 add_to_group (Nnew, scale );189 add_to_group (Nnew, scale, Nfriends); 165 190 // fprintf (stderr, "new group %d part 1 with %d elements\n", Ngroup, group[Ngroup].Nentry); 166 191 found = TRUE;
Note:
See TracChangeset
for help on using the changeset viewer.
