Sort and use the sorted zone property to change some if statements

This commit is contained in:
Guilhem Lavaux 2013-03-31 19:35:03 -04:00
parent 311ac50344
commit 6a15e59521
2 changed files with 38 additions and 6 deletions

View file

@ -314,6 +314,8 @@ void buildZones(PARTICLE *p, pid_t np, pid_t *&jumped,
for (pid_t i=0; i < np; i++) { for (pid_t i=0; i < np; i++) {
int h = zonenum[i]; int h = zonenum[i];
z[h].vol += 1.0/(double)p[i].dens; z[h].vol += 1.0/(double)p[i].dens;
z[h].numzones = 0;
z[h].zonelist = 0;
} }
} }
@ -373,7 +375,9 @@ void doWatershed(const std::string& zonfile2, PARTICLE *p, pid_t np, ZONE *z, in
int *zonelist, *zonelist2; int *zonelist, *zonelist2;
int nhl; int nhl;
int *links = new int[NLINKS]; int *links = new int[NLINKS];
int *iord;
float maxdenscontrast = 0; float maxdenscontrast = 0;
bool *done_zones;
ofstream zon2(zonfile2.c_str()); ofstream zon2(zonfile2.c_str());
if (!zon2) if (!zon2)
@ -387,20 +391,37 @@ void doWatershed(const std::string& zonfile2, PARTICLE *p, pid_t np, ZONE *z, in
inyet2 = new char[numZones]; inyet2 = new char[numZones];
zonelist = new int[numZones]; zonelist = new int[numZones];
zonelist2 = new int[numZones]; zonelist2 = new int[numZones];
done_zones = new bool[nzones];
fill(inyet, inyet + numZones, 0); fill(inyet, inyet + numZones, 0);
fill(inyet2, inyet2 + numZones, 0); fill(inyet2, inyet2 + numZones, 0);
fill(done_zones, done_zones + numZones, false);
sorter = new double[nzones+1];
/* Assign sorter by probability (could use volume instead) */
for (int h = 0; h < nzones; h++)
sorter[h] = (double)z[h].core;
/* Text output file */
printf("about to sort (pre-watershed sort) ...\n");FF;
iord = new int[nzones];
findrtop(sorter, numZones, iord, numZones);
delete[] sorter;
nhl = 0; nhl = 0;
for (int h = 0; h < numZones; h++) for (int ii = 0; ii < numZones; h++)
{ {
int nhlcount = 0; int nhlcount = 0;
int h = iord[ii];
float lowvol; float lowvol;
bool beaten; bool beaten;
for (int hl = 0; hl < nhl; hl++) for (int hl = 0; hl < nhl; hl++)
inyet[zonelist[hl]] = 0; inyet[zonelist[hl]] = 0;
zonelist[0] = h; zonelist[0] = h;
inyet[h] = 1; inyet[h] = 1;
nhl = 1; nhl = 1;
@ -462,7 +483,7 @@ void doWatershed(const std::string& zonfile2, PARTICLE *p, pid_t np, ZONE *z, in
for (int l = 0; l < nl; l++) for (int l = 0; l < nl; l++)
{ {
if (p[z[links[l]].core].dens < p[z[h].core].dens) if (!done_zones[links[l]]) /* Equivalent to p[z[links[l]].core].dens < p[z[h].core].dens) as zones are sorted. */
beaten = true; beaten = true;
} }
@ -496,7 +517,7 @@ void doWatershed(const std::string& zonfile2, PARTICLE *p, pid_t np, ZONE *z, in
if ((inyet[link2]+inyet2[link2]) == 0) { if ((inyet[link2]+inyet2[link2]) == 0) {
interior = false; interior = false;
if (z[h2].slv[za] <= lowvol) { if (z[h2].slv[za] <= lowvol) {
if (p[z[link2].core].dens < p[z[h].core].dens) { if (!done_zones[link2]) { // Equivalent to p[z[link2].core].dens < p[z[h].core].dens)
beaten = true; beaten = true;
break; break;
} }
@ -550,10 +571,14 @@ void doWatershed(const std::string& zonfile2, PARTICLE *p, pid_t np, ZONE *z, in
} }
/* Calculate volume */ /* Calculate volume */
z[h].voljoin = 0.; z[h].voljoin = 0.;
z[h].zonelist = new int[nhl];
z[h].numzones = nhl;
for (int q = 0; q < nhl; q++) { for (int q = 0; q < nhl; q++) {
z[h].voljoin += z[zonelist[q]].vol; z[h].voljoin += z[zonelist[q]].vol;
z[h].zonelist[q] = zonelist[q];
} }
done_zones[h] = true;
z[h].nhl = nhl; z[h].nhl = nhl;
zon2.write((char *)&nhl, sizeof(int)); zon2.write((char *)&nhl, sizeof(int));
@ -672,7 +697,7 @@ int main(int argc,char **argv)
printf("about to sort ...\n");FF; printf("about to sort ...\n");FF;
iord = (int *)malloc(nzones*sizeof(int)); iord = new int[nzones];
findrtop(sorter, nzones, iord, nzones); findrtop(sorter, nzones, iord, nzones);
delete[] sorter; delete[] sorter;
@ -694,7 +719,11 @@ int main(int argc,char **argv)
} /* h+1 to start from 1, not zero */ } /* h+1 to start from 1, not zero */
txt.close(); txt.close();
delete[] iord;
delete[] z;
delete[] p;
cout << "Done!" << endl; cout << "Done!" << endl;
return(0); return(0);
} }

View file

@ -20,6 +20,9 @@ typedef struct Zone {
float denscontrast; /* density contrast */ float denscontrast; /* density contrast */
double vol; /* Total volume of all particles in the zone */ double vol; /* Total volume of all particles in the zone */
double voljoin; /* Total volume of all particles in the joined void */ double voljoin; /* Total volume of all particles in the joined void */
int *zonelist; /* Zones bound to the void. */
int numzones; /* Number of zones bound. */
} ZONE; } ZONE;
typedef struct ZoneT { typedef struct ZoneT {