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.
119 lines
2.2 KiB
119 lines
2.2 KiB
#include "stdafx.h"
|
|
#include "BranchPoint.h"
|
|
#include<cmath>
|
|
#include<vector>
|
|
#include<queue>
|
|
#include<map>
|
|
#include<iostream>
|
|
#include<fstream>
|
|
#include<sstream>
|
|
#include<algorithm>
|
|
using namespace std;
|
|
|
|
//简单的路径信息,路径规划的直接结果
|
|
struct Path{
|
|
vector<string> wirelist; //路径中的线缆名
|
|
vector<P> points; //路径上的点,包括卡箍和分支点
|
|
vector<int> inOut; //卡箍方向是正向为0,反向为1,分支点为-1
|
|
double dia; //路径直径
|
|
Path(){
|
|
dia=0;
|
|
}
|
|
|
|
//返回path中点的数量
|
|
inline int size(){
|
|
assert(inOut.size()==points.size());
|
|
return points.size();
|
|
}
|
|
|
|
//把路径中经过的卡箍和分支点都标记成使用过的状态
|
|
void markPoint(){
|
|
for(int i=0;i<points.size();i++){
|
|
P& tp=points[i];
|
|
if(tp.type==1||tp.type==2){
|
|
BranchPoint *pb=branchPointSet.getBranchPointPointer(tp.ref);
|
|
pb->used=true;
|
|
pb->pc1->used=true;
|
|
pb->pc2->used=true;
|
|
|
|
}
|
|
else if(tp.type==0){
|
|
clipSet.c[tp.ref].used=true;
|
|
}
|
|
}
|
|
}
|
|
|
|
//固定所有经过的分支点
|
|
void fixBranchPoint(){
|
|
for(int i=0;i<points.size();i++){
|
|
P& tp=points[i];
|
|
if(tp.type==1){
|
|
BranchPoint *pb=branchPointSet.getBranchPointPointer(tp.ref);
|
|
pb->fix();
|
|
}
|
|
}
|
|
}
|
|
|
|
//检查路径合法性
|
|
void illegalCheck(){
|
|
map<P,int>vis;
|
|
for(int i=0;i<points.size();i++){
|
|
assert(vis[points[i]]==0);
|
|
vis[points[i]]=1;
|
|
if(i==0||i==points.size()-1){
|
|
assert(points[i].type==3);
|
|
}
|
|
if(points[i].type!=0){
|
|
assert(inOut[i]<0);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//将路径中的点翻转成正常反向,并生成inOut数组
|
|
void processDir(){
|
|
for(int j=0;j<points.size();j++){
|
|
if(points[j].type!=0){
|
|
inOut.push_back(-1);
|
|
continue;
|
|
}
|
|
double reverse=0;
|
|
P dir=dirP(points[j]);
|
|
if(j!=0){
|
|
reverse+=pi/2-Angle(points[j]-points[j-1],dir);
|
|
}
|
|
if(j!=points.size()-1){
|
|
reverse+=pi/2-Angle(points[j+1]-points[j],dir);
|
|
}
|
|
|
|
if(reverse<0){
|
|
//points[j].reverse();
|
|
inOut.push_back(1);
|
|
}
|
|
else inOut.push_back(0);
|
|
}
|
|
}
|
|
|
|
|
|
//在路径确定后,处理一些能在pass层面处理的信息
|
|
void postProcess(){
|
|
this->fixBranchPoint();
|
|
//this->processDir();
|
|
this->markPoint();
|
|
}
|
|
|
|
|
|
|
|
//翻转整条路径
|
|
void reverse(){
|
|
std::reverse(points.begin(),points.end());
|
|
assert(inOut.size()==points.size());
|
|
for(int i=0;i<points.size();i++){
|
|
if(inOut[i]!=-1){
|
|
inOut[i]=inOut[i]^1;
|
|
points[i].reverse();
|
|
}
|
|
|
|
}
|
|
}
|
|
};
|