You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.3 KiB

#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<vector<pair<int,int> > >& resClip,
vector<vector<int> >& resBranchPoint,
vector<int>& startBranchPoint,
vector<int>& endBranchPoint,
bool basic){
if(head==NULL)return;
BundleNode *pbn=head;
vector<pair<int,int> > partClip;
vector<int> 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);
}
}
}