#include "stdafx.h" #include "Path.h" #include #include #include #include #include #include #include using namespace std; //使用链表存储通道数据结构,BundleNode是链表节点 struct BundleNode{ Clip *pc; //指向卡箍 BranchPoint *pb; //指向分支点 Connector *pcn; //指向连接器 int type; //0代表卡箍,1代表分支点,2代表连接器 BundleNode *pre,*next; //链表中的上下节点 int inOut; //卡箍方向是正向为0,反向为1 int rev; //通道节点自创建起是否反向过 int bundleID; //BundleNode所属的BundleID int id; //BundleNode自身的id vector vb; //指向属于本通道段的分支点集合 BundleNode(){ pre=next=NULL; pc=NULL;pb=NULL;pcn=NULL; type=0;inOut=0; bundleID=0; id=0; } P coord(){ if(type==0)return pc->coord; return pb->coord; } }bdNode[MAXPointNum]; int bdNodeNum=0; //用数组维护BundleNode信息 //包含线束捆(通道)信息 struct Bundle{ int id; //bundle的编号 int length; //总点数 bool abandoned; //代表这个bundle已经被合并 BundleNode *head,*tail; //通道的头尾节点 void init(){ length=0; abandoned=false; head=tail=NULL; } Bundle(){ init(); } //创建一个分支点,初始化其除了链表指针外的其他信息 static BundleNode* 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(Path& path,int bundleID){ init(); this->id=bundleID; this->length=path.size(); BundleNode * pre; for(int i=0;itail=pbn; if(i==0)this->head=pbn; else { pre->next=pbn; pbn->pre=pre; } pre=pbn; } } //如果首个节点是分支点,返回分支点的标号,否则返回0 int startBranchPoint(){ if(head==NULL)return 0; if(head->type==0||head->type==2)return 0; return head->pb->id; } //如果尾部节点是分支点,返回分支点的标号,否则返回0 int endBranchPoint(){ if(tail==NULL)return 0; if(tail->type==0||tail->type==2)return 0; return tail->pb->id; } //更新输出信息 void updateOutput(vector > >& resClip, vector >& resBranchPoint, vector& startBranchPoint, vector& endBranchPoint,bool basic=false){ 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;ivb.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); } } } };