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.
191 lines
4.1 KiB
191 lines
4.1 KiB
10 months ago
|
#include "stdafx.h"
|
||
|
#include "Path.h"
|
||
|
#include<cmath>
|
||
|
#include<vector>
|
||
|
#include<queue>
|
||
|
#include<map>
|
||
|
#include<iostream>
|
||
|
#include<fstream>
|
||
|
#include<sstream>
|
||
|
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<int> 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;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 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<vector<pair<int,int> > >& resClip,
|
||
|
vector<vector<int> >& resBranchPoint,
|
||
|
vector<int>& startBranchPoint,
|
||
|
vector<int>& endBranchPoint,bool basic=false){
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
};
|