Example #1
0
/*** ConvexHull merge(ConvexHull a, ConvexHull b);
 * find the smallest convex hull that surrounds a and b.
 */
ConvexHull merge(ConvexHull a, ConvexHull b) {
    ConvexHull ret;

    pair< map<int, int>, map<int, int> > bpair = bridges(a, b);
    map<int, int> ab = bpair.first;
    map<int, int> bb = bpair.second;

    ab[-1] = 0;
    bb[-1] = 0;

    int i = -1; // XXX: i is int but refers to vector indices

    if(a.boundary[0][1] > b.boundary[0][1]) goto start_b;
    while(true) {
        for(; ab.count(i) == 0; i++) {
            ret.boundary.push_back(a[i]);
            if(i >= (int)a.boundary.size()) return ret;
        }
        if(ab[i] == 0 && i != -1) break;
        i = ab[i];
        start_b:

        for(; bb.count(i) == 0; i++) {
            ret.boundary.push_back(b[i]);
            if(i >= (int)b.boundary.size()) return ret;
        }
        if(bb[i] == 0 && i != -1) break;
        i = bb[i];
    }
    return ret;
}
void main()
{
  int i,j;
  clock_t time;
  SHEET *clay=(SHEET*)malloc(sizeof(SHEET)*N_CLAY);
  POLY *chain=(POLY*)malloc(sizeof(POLY)*N_CHAIN);
  FILE *f_filler=fopen("..//filler.lammpstrj","r");
  FILE *f_chain=fopen("..//chains.lammpstrj","r");  
  FILE *gel=fopen("percent_gel.txt","w");
  fclose(gel);
  int n_entries=0;
  clearbridges();
  systeminfo();
  while(!feof(f_filler)&&!feof(f_chain)&&n_entries<ENTRIES_BEFORESHEAR){
    time=clock();
    if(feof(f_filler)||feof(f_chain)){printf("ERROR: Two file not of same length, or reading speed not sync\n");exit(17);}
    clearinfo(clay,chain);
    readfiller(f_filler,clay);
    readchain(f_chain,chain);
    findcom(clay);
    sortchain(N_CHAIN,chain);
    bridges(clay,chain);
    findunion(clay,chain);
    groupanalyze(n_entries,clay,chain);
    n_entries++;
    printf("TIME COST: %f \n",((float)(clock()-time))/CLOCKS_PER_SEC);
    //getchar();
  }
}
Example #3
0
std::vector<Point> bridge_points(ConvexHull a, ConvexHull b) {
    vector<Point> ret;
    pair< map<int, int>, map<int, int> > indices = bridges(a, b);
    for(map<int, int>::iterator it = indices.first.begin(); it != indices.first.end(); it++) {
      ret.push_back(a[it->first]);
      ret.push_back(b[it->second]);
    }
    for(map<int, int>::iterator it = indices.second.begin(); it != indices.second.end(); it++) {
      ret.push_back(b[it->first]);
      ret.push_back(a[it->second]);
    }
    return ret;
}
Example #4
0
// times is initialized to be 1
void bridges(int a, int f, int &times) {
    dfn[a] = low[a] = times;
    for (int i = 0; i < x[a].size(); ++i) {
        if (x[a][i] == f) continue;
        if (dfn[x[a][i]] == 0) {
            bridges(x[a][i], a, ++times);
            low[a] = min(low[a], low[x[a][i]]);
            // This is a bridge
            if (low[x[a][i]] == dfn[x[a][i]]) z[x[a][i]][a] = z[a][x[a][i]] = true;
        } else {
            low[a] = min(low[a], dfn[x[a][i]]);
        }
    }
}