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.
130 lines
2.2 KiB
130 lines
2.2 KiB
9 months ago
|
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
|
||
|
#include "Path.h"
|
||
|
|
||
|
|
||
9 months ago
|
P dirP(P &A)
|
||
|
{
|
||
9 months ago
|
P B;
|
||
9 months ago
|
B.x = A.dx;
|
||
|
B.y = A.dy;
|
||
|
B.z = A.dz;
|
||
9 months ago
|
return B;
|
||
|
}
|
||
|
|
||
9 months ago
|
Path::Path()
|
||
|
{
|
||
|
dia = 0;
|
||
9 months ago
|
}
|
||
|
|
||
9 months ago
|
// 返回path中点的数量
|
||
|
int Path::size()
|
||
|
{
|
||
9 months ago
|
assert(inOut.size() == points.size());
|
||
|
return points.size();
|
||
|
}
|
||
|
|
||
9 months ago
|
// 把路径中经过的卡箍和分支点都标记成使用过的状态
|
||
9 months ago
|
void Path::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;
|
||
9 months ago
|
}
|
||
9 months ago
|
else if (tp.type == 0)
|
||
|
{
|
||
|
clipSet.c[tp.ref].used = true;
|
||
9 months ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
9 months ago
|
// 固定所有经过的分支点
|
||
|
void Path::fixBranchPoint()
|
||
|
{
|
||
|
for (int i = 0; i < points.size(); i++)
|
||
|
{
|
||
|
P &tp = points[i];
|
||
|
if (tp.type == 1)
|
||
|
{
|
||
|
BranchPoint *pb = branchPointSet.getBranchPointPointer(tp.ref);
|
||
9 months ago
|
pb->fix();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
9 months ago
|
// 检查路径合法性
|
||
|
void Path::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);
|
||
9 months ago
|
}
|
||
9 months ago
|
if (points[i].type != 0)
|
||
|
{
|
||
|
assert(inOut[i] < 0);
|
||
9 months ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
9 months ago
|
// 将路径中的点翻转成正常反向,并生成inOut数组
|
||
|
void Path::processDir()
|
||
|
{
|
||
|
for (int j = 0; j < points.size(); j++)
|
||
|
{
|
||
|
if (points[j].type != 0)
|
||
|
{
|
||
9 months ago
|
inOut.push_back(-1);
|
||
|
continue;
|
||
|
}
|
||
9 months ago
|
double reverse = 0;
|
||
|
P dir = dirP(points[j]);
|
||
|
if (j != 0)
|
||
|
{
|
||
|
reverse += pi / 2 - Angle(points[j] - points[j - 1], dir);
|
||
9 months ago
|
}
|
||
9 months ago
|
if (j != points.size() - 1)
|
||
|
{
|
||
|
reverse += pi / 2 - Angle(points[j + 1] - points[j], dir);
|
||
9 months ago
|
}
|
||
9 months ago
|
if (reverse < 0)
|
||
|
{
|
||
|
// points[j].reverse();
|
||
9 months ago
|
inOut.push_back(1);
|
||
|
}
|
||
9 months ago
|
else
|
||
|
inOut.push_back(0);
|
||
9 months ago
|
}
|
||
|
}
|
||
|
|
||
9 months ago
|
// 在路径确定后,处理一些能在pass层面处理的信息
|
||
|
void Path::postProcess()
|
||
|
{
|
||
9 months ago
|
this->fixBranchPoint();
|
||
9 months ago
|
// this->processDir();
|
||
9 months ago
|
this->markPoint();
|
||
|
}
|
||
|
|
||
9 months ago
|
// 翻转整条路径
|
||
|
void Path::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;
|
||
9 months ago
|
points[i].reverse();
|
||
9 months ago
|
}
|
||
9 months ago
|
}
|
||
|
}
|