#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier #include "Bundle.h" BundleNode bdNode[MAXPointNum]; int bdNodeNum = 0; // 用数组维护BundleNode信息 BundleNode::BundleNode() { pre = next = NULL; pc = NULL; pb = NULL; pcn = NULL; type = 0; inOut = 0; bundleID = 0; id = 0; } P BundleNode::coord() { if (type == 0) return pc->coord; return pb->coord; } void Bundle::init() { length = 0; abandoned = false; head = tail = NULL; } Bundle::Bundle() { init(); } // 创建一个分支点,初始化其除了链表指针外的其他信息 BundleNode *Bundle::createBundleNode(P &tp, int inOut, int bundleID) { bdNodeNum++; BundleNode *pbn = &bdNode[bdNodeNum]; pbn->id = bdNodeNum; pbn->bundleID = bundleID; pbn->inOut = inOut; pbn->rev = 0; pbn->pre = NULL; pbn->next = NULL; if (tp.type == 0) { // 点是卡箍 pbn->type = 0; pbn->pc = clipSet.getClipPointer(tp.ref, bdNodeNum); } else if (tp.type == 1 || tp.type == 2) { // 点是分支点 pbn->type = 1; pbn->pb = branchPointSet.getBranchPointPointer(tp.ref); } else if (tp.type == 3) { pbn->type = 2; pbn->pcn = &connectors[tp.ref]; connectors[tp.ref].bundleNodeID = bdNodeNum; } return pbn; } // 根据简单路径构建一个Bundle Bundle::Bundle(Path &path, int bundleID) { init(); this->id = bundleID; this->length = path.size(); BundleNode *pre = nullptr; for (int i = 0; i < path.size(); i++) { P tp = path.points[i]; BundleNode *pbn = Bundle::createBundleNode(tp, path.inOut[i], bundleID); if (i == path.size() - 1) this->tail = pbn; if (i == 0) this->head = pbn; else { pre->next = pbn; pbn->pre = pre; } pre = pbn; } } // 如果首个节点是分支点,返回分支点的标号,否则返回0 int Bundle::startBranchPoint() { if (head == NULL) return 0; if (head->type == 0 || head->type == 2) return 0; return head->pb->id; } // 如果尾部节点是分支点,返回分支点的标号,否则返回0 int Bundle::endBranchPoint() { if (tail == NULL) return 0; if (tail->type == 0 || tail->type == 2) return 0; return tail->pb->id; } // 更新输出信息 void Bundle::updateOutput(vector>> &resClip, vector> &resBranchPoint, vector &startBranchPoint, vector &endBranchPoint, bool basic) { if (head == NULL) return; BundleNode *pbn = head; vector> partClip; vector partBranchPoint; int partStart = this->startBranchPoint(); int partEnd = this->endBranchPoint(); while (pbn != NULL) { if (pbn->type == 0) { // 卡箍 int cid = pbn->pc->id; if ((pbn->pc->used == true) || basic) { partClip.push_back(make_pair(cid, pbn->inOut)); for (int i = 0; i < pbn->vb.size(); i++) { int bid = pbn->vb[i]; BranchPoint *pb = branchPointSet.getBranchPointPointer(bid); if ((pb->used == true) || basic) partBranchPoint.push_back(bid); } } else { if (partClip.size() != 0) { resClip.push_back(partClip); resBranchPoint.push_back(partBranchPoint); startBranchPoint.push_back(partStart); endBranchPoint.push_back(partEnd); } partClip.clear(); partBranchPoint.clear(); } } else if (pbn->type == 2) { // 连接器 int cnid = pbn->pcn->ID; partClip.push_back(make_pair(cnid, -1)); } pbn = pbn->next; } if (!basic) { if (partClip.size() != 0) { resClip.push_back(partClip); resBranchPoint.push_back(partBranchPoint); startBranchPoint.push_back(partStart); endBranchPoint.push_back(partEnd); } } else { if (partClip.size() > 5) { resClip.push_back(partClip); resBranchPoint.push_back(partBranchPoint); startBranchPoint.push_back(partStart); endBranchPoint.push_back(partEnd); } } }