#include "stdafx.h" #include "BasicEdge.h" #include #include #include #include #include #include #include using namespace std; struct Edge { vector wirenames; vector d; int to; double dis; void clear() { to = 0; dis = 0; wirenames.clear(); d.clear(); } }; // 分支树结构,把各种路径信息处理成分支信息,并输出给CATIA struct BranchTree { ClipSet *pclipSet; // 指向卡箍集 double dia; // 临时变量 vector edge[N]; // 边 P points[MAXPointNum]; // 点 int f[N], sz[N]; // 并查集信息 int pre[N], vis[N], st[N]; bool endpoint[N], hashuan; // Bundle bundles[N]; // vector bundlesOfClip[N]; bool record; vector pathpoints; map nodeid; // 给点映射内部编号 int cnt, bfs; // 点的总数,以及bfs的次数 // int bundleid,branchPointNum; BranchTree() { cnt = 0; bfs = 0; hashuan = 0; record = 0; // branchPointNum=0; dia = 0; // bundleid=0; pclipSet = &clipSet; } // 初始化 void init() { for (int i = 1; i <= cnt; i++) { edge[i].clear(); } nodeid.clear(); cnt = bfs = hashuan = record = 0; } void startRecord() { record = 1; } void endRecord() { record = 0; pathpoints.clear(); } inline int getid(P &p) { if (nodeid[p] == 0) { nodeid[p] = ++cnt; f[cnt] = cnt; sz[cnt] = 1; vis[cnt] = pre[cnt] = 0; endpoint[cnt] = 0; points[cnt] = p; } return nodeid[p]; } int getrt(int x) { if (x != f[x]) return f[x] = getrt(f[x]); return x; } inline void merge(int x, int y) { if (x != f[x]) x = getrt(x); if (y != f[y]) y = getrt(y); f[x] = y; sz[y] += sz[x]; } bool check(P &p) { int id = getid(p); for (int i = 0; i < pathpoints.size(); i++) { if (getrt(id) == getrt(pathpoints[i])) return false; } return true; } inline void addEdge(int x, int y, vector namelist) { if (record) pathpoints.push_back(x); for (int i = 0; i < edge[x].size(); i++) { if (edge[x][i].to == y) { Edge &e = edge[x][i]; e.d.push_back(dia); e.wirenames.insert(e.wirenames.begin(), namelist.begin(), namelist.end()); } } for (int i = 0; i < edge[y].size(); i++) { if (edge[y][i].to == x) { Edge &e = edge[y][i]; e.d.push_back(dia); e.wirenames.insert(e.wirenames.begin(), namelist.begin(), namelist.end()); return; } } Edge e; e.to = y; e.wirenames.insert(e.wirenames.begin(), namelist.begin(), namelist.end()); e.d.push_back(dia); edge[x].push_back(e); e.to = x; edge[y].push_back(e); merge(x, y); pclipSet->addwire(points[y], dia); } inline bool hasEdge(int x, int y) { for (int i = 0; i < edge[x].size(); i++) { if (edge[x][i].to == y) { return true; } } return false; } inline vector BFS(int u, int v) { // cout< path; queue q; q.push(u); vis[u] = bfs; pre[u] = 0; while (!q.empty()) { int x = q.front(); q.pop(); for (int i = 0; i < edge[x].size(); i++) { int y = edge[x][i].to; if (vis[y] == bfs) continue; pre[y] = x; vis[y] = bfs; q.push(y); } if (vis[v] == bfs) break; } int top = 0; int tag = v; while (pre[tag]) { // cout< 0; i--) { path.push_back(st[i]); } // cout< &path, vector namelist) { for (int i = 1; i < path.size(); i++) { // cout< pathid; pathid.push_back(0); for (int i = 0; i < path.points.size(); i++) { P p = path.points[i]; int id = getid(p); pathid.push_back(id); } map cross2; for (int i = 1; i <= path.points.size(); i++) { int id = pathid[i]; int rt = getrt(id); if (sz[rt] != 1) { cross2[rt] = i; } } for (int i = 1; i <= path.points.size(); i++) { int id = pathid[i]; int rt = getrt(id); if (cross2[rt] != 0) { int en = cross2[rt]; if (en != i) { vector tempPath = BFS(pathid[i], pathid[en]); newPath(tempPath, path.wirelist); Path path3; for (int j = 0; j < tempPath.size(); j++) { path3.points.push_back(points[tempPath[j]]); } path3.processDir(); path3.inOut[0] = path.inOut[i - 1]; path3.inOut[path3.size() - 1] = path.inOut[en - 1]; for (int j = 0; j < path3.size(); j++) { path2.points.push_back(path3.points[j]); path2.inOut.push_back(path3.inOut[j]); } // if(testhuan())cout<<"BFS"<