Browse Source

code check - OK

VSbuild_required
郑敬润 1 year ago
parent
commit
cc7e7b90eb
  1. 1
      WireRouting_DLL/Astar.cpp
  2. 2
      WireRouting_DLL/Astar.h
  3. 33
      WireRouting_DLL/BVH.cpp
  4. 3
      WireRouting_DLL/BranchTree.cpp
  5. 2
      WireRouting_DLL/BranchTree.h
  6. 4
      WireRouting_DLL/Clip.cpp
  7. 6
      WireRouting_DLL/Clip.h
  8. 2
      WireRouting_DLL/Connector.h
  9. 4
      WireRouting_DLL/Const.cpp
  10. 114
      WireRouting_DLL/Const.h
  11. 4
      WireRouting_DLL/Geometry.cpp
  12. 6
      WireRouting_DLL/Geometry.h
  13. 8
      WireRouting_DLL/Intersection.cpp
  14. 5
      WireRouting_DLL/Intersection.h
  15. 3
      WireRouting_DLL/KDtree.cpp
  16. 2
      WireRouting_DLL/KDtree.h
  17. 2
      WireRouting_DLL/Path.cpp
  18. 2
      WireRouting_DLL/Path.h
  19. 22
      WireRouting_DLL/ReadXML.cpp

1
WireRouting_DLL/Astar.cpp

@ -1,7 +1,6 @@
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include "Astar.h"
BranchTree branchTree;
Astar astar;
void DSU::init(int cnt)

2
WireRouting_DLL/Astar.h

@ -23,8 +23,6 @@
using namespace std;
extern ASTAR_API BranchTree branchTree;
struct ASTAR_API DSU
{
int f[N];

33
WireRouting_DLL/BVH.cpp

@ -189,6 +189,31 @@ bool BVH::TriSegIntersection(Point3 &P0, Point3 &P1, Point3 &P2, Point3 &A, Poin
}
}
/*
bool BVH::TriSegIntersection(Triangle t,Point3 A,Point3 B,int mood)
{
P P0=t.p[0],P1=t.p[1],P2=t.p[2];
Vector3 n=Cross(P1-P0,P2-P0);
if(dcmp(Dot(n,B-A))==0){
if(mood)cout<<"平行"<<endl;
return false;//线段 AB 和平面 P0P1P2 平行或共面
}
else
{
double t=Dot(n,P0-A)/Dot(n,B-A);
if(dcmp(t)<0||dcmp(t-1)>0){
if(mood)cout<<"交点不在AB上"<<t<<endl;
return false;//交点不在线段 AB 上
}
if(dcmp(t)==0)t=0;
if(dcmp(t-1)==0)t=1;
P p=A+(B-A)*t;
p.print("p");
return PointInTri(p,P0,P1,P2);//判断交点是否在三角形 P0-P1-P2 内
}
}
*/
bool BVH::TriSegIntersection(Triangle &t, Point3 &A, Point3 &B)
{
P P0 = t.p[0], P1 = t.p[1], P2 = t.p[2];
@ -228,6 +253,14 @@ bool BVH::query(int x, int l, int r, P &A, P &B)
return false;
}
/*
bool BVH::iscollect(P A,P B,int mood){
if(mood==0)return query(1,0,trinum,A,B);
for(int i=0;i<=trinum;i++)
if(TriSegIntersection(tri[i],A,B))return true;
return false;
}
*/
bool BVH::iscollect(P &A, P &B)
{
return false;

3
WireRouting_DLL/BranchTree.cpp

@ -1,6 +1,8 @@
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include "BranchTree.h"
BranchTree branchTree;
void Edge::clear()
{
to = 0;
@ -21,6 +23,7 @@ BranchTree::BranchTree()
pclipSet = &clipSet;
}
// 初始化
void BranchTree::init()
{
for (int i = 1; i <= cnt; i++)

2
WireRouting_DLL/BranchTree.h

@ -74,3 +74,5 @@ struct BRANCH_TREE_API BranchTree
// 添加一条路径,返回去除环路的路径
Path addPath(Path &path);
};
extern BRANCH_TREE_API BranchTree branchTree;

4
WireRouting_DLL/Clip.cpp

@ -1,7 +1,7 @@
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include "Clip.h"
KDtree kdtree;
ClipSet clipSet;
Clip::Clip()
{
@ -12,6 +12,7 @@ Clip::Clip()
used = 0;
}
// 清除所有通过卡箍的线和通道信息
void Clip::clear()
{
diaset.clear();
@ -96,6 +97,7 @@ void ClipSet::addwire(P &p, double d)
c[id].addwire(d);
}
// 获取指向编号为id的卡箍的指针
Clip *ClipSet::getClipPointer(int id, int bundleNodeID)
{
if (bundleNodeID != -1)

6
WireRouting_DLL/Clip.h

@ -20,8 +20,6 @@
#include <sstream>
using namespace std;
extern KDtree CLIP_API kdtree;
// 卡箍信息
struct CLIP_API Clip
{
@ -99,4 +97,6 @@ struct CLIP_API ClipSet
2
*/
void print();
};
};
extern ClipSet CLIP_API clipSet;

2
WireRouting_DLL/Connector.h

@ -31,5 +31,5 @@ struct CONNECTOR_API Connector
Connector();
};
extern Connector CONNECTOR_API connectors[];
extern Connector CONNECTOR_API connectors[M];
extern int CONNECTOR_API connectorNum;

4
WireRouting_DLL/Const.cpp

@ -3,7 +3,3 @@
double MAXX = -1e9, MINX = 1e9, MAXY = -1e9, MINY = 1e9, MAXZ = -1e9, MINZ = 1e9; // 卡箍的坐标范围
double Ycenter, Zcenter; // 飞机在Y,Z两轴的中心
vector<Vec3f> vertices;
vector<Vec3u> indices;
Mesh mesh;
int intersection_model = 0;

114
WireRouting_DLL/Const.h

@ -11,7 +11,6 @@
#endif
#include "Point.h"
// #include "Geometry.h"
#include "Intersection.h"
#include <cmath>
@ -35,14 +34,15 @@ static const double MAXDia = 50; // 卡箍能容纳的最大直径
static const int maxCap = 50; // 卡箍能容纳的最大线缆数
static const double pi = acos(-1.0); // Π
static const double minAngle = pi / 144; // 判断平行和垂直的偏差阈值
// static const double minDis=30; //
// static const double minDis=30; //*
static const double R = 2000; // 飞机横截面的近似半径
static const double MARGIN = 1000; // 布线的空间范围,从STL模型向外延申的长度
//----------------------mark----------------------
static const int MAXBranchPointNumOnSegment = 4; // 分支上的最大分支点数
static const int MAXPointNum = N + MAXBranchPointNumOnSegment * N; // 最大分支点数加最大卡箍数
static const double segmentLength = 400; // 卡箍到卡箍之间的最长距离
static const double MinClipToBranchPointDistance = 1; // 卡箍到分支点的最短距离
static const double MinBranchPointDistance = 1; // 分支点到分支点的最短距离
static const double segmentLength = 3000; // *卡箍到卡箍之间的最长距离(搜索半径)(目前2000-3000较好)
static const double MinClipToBranchPointDistance = 11; // 卡箍到分支点的最短距离
static const double MinBranchPointDistance = 11; // 分支点到分支点的最短距离
// X,Y,Z的正方向
static const P DX = P(1, 0, 0);
static const P DY = P(0, 1, 0);
@ -51,21 +51,23 @@ static const P DZ = P(0, 0, 1);
CONST_API extern double MAXX, MINX, MAXY, MINY, MAXZ, MINZ; // 卡箍的坐标范围,初值-1e9~1e9
CONST_API extern double Ycenter, Zcenter; // 飞机在Y,Z两轴的中心
extern vector<Vec3f> CONST_API vertices;
extern vector<Vec3u> CONST_API indices;
extern Mesh CONST_API mesh;
extern int CONST_API intersection_model;
inline bool inmid(double x, double y, double z, double margin = MARGIN)
// static const double intersection_distance = 100;
static int intersection_model = 0; //是否判断求交
// 判断y是否在[x-margin,z+margin]的范围内
inline bool inmid(const double x, const double y, const double z, const double margin = MARGIN)
{
return y >= x - margin && y <= z + margin;
}
inline bool inbox(P &p)
inline bool inbox(const P &p)
{
return inmid(MINX, p.x, MAXX) && inmid(MINY, p.y, MAXY) && inmid(MINZ, p.z, MAXZ);
}
inline int dcmp(double d)
// 将d与0比较,返回正负
inline int dcmp(const double d)
{
if (d < -eps)
return -1;
@ -74,17 +76,36 @@ inline int dcmp(double d)
return 0;
}
inline double distan1(P &p1, P &p2)
// 空间两点距离
inline double distan1(const P &p1, const P &p2)
{
double x = p1.x - p2.x, y = p1.y - p2.y, z = p1.z - p2.z;
return sqrt(x * x + y * y + z * z);
}
/*
inline double distan2(P &p1,P &p2){
static double penalty_par=1;
if(intersection_model==1)
{
LineSegment lineSegment(Vec3f(p1.x, p1.y, p1.z),Vec3f(p2.x, p2.y, p2.z));
static BVH_intersection bvh(mesh);
bool hit = bvh.intersectWithLineSegment(lineSegment);
if(hit==0)
penalty_par=1;
else
penalty_par=100;
}
double x=p1.x-p2.x,y=p1.y-p2.y,z=p1.z-p2.z;
return sqrt(x*x+y*y+z*z)*penalty_par;
}
*/
inline double Dot(const Vector3 &A, const Vector3 &B) { return A.x * B.x + A.y * B.y + A.z * B.z; }
inline double Length(const Vector3 &A) { return sqrt(Dot(A, A)); }
inline double Angle(const Vector3 &A, const Vector3 &B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
inline double DistanceToPlane(const Point3 &p, const Point3 &p0, const Vector3 &n) { return fabs(Dot(p - p0, n)); } // 如果不取绝对值,得到的是有向距离
inline int ParallelorVertical(P &p1, P &p2)
inline int ParallelorVertical(const P &p1, const P &p2)
{
double angel = Angle(p1, p2);
if (angel <= minAngle || angel >= pi - minAngle)
@ -93,53 +114,62 @@ inline int ParallelorVertical(P &p1, P &p2)
return 2;
return 0;
}
inline Point3 GetPlaneProjection(Point3 &p, Point3 &p0, Vector3 &n)
inline Point3 GetPlaneProjection(const Point3 &p, const Point3 &p0, const Vector3 &n)
{
return p - n * Dot(p - p0, n);
}
inline Point3 LinePlaneIntersection(Point3 &p1, Point3 &p2, Point3 &p0, Vector3 &n)
inline Point3 LinePlaneIntersection(const Point3 &p1, const Point3 &p2, const Point3 &p0, const Vector3 &n)
{
Vector3 v = p2 - p1;
double t = (Dot(n, p0 - p1) / Dot(n, p2 - p1));
return p1 + v * t;
double t = (Dot(n, p0 - p1) / Dot(n, p2 - p1)); // 判断分母是否为 0
return p1 + v * t; // 如果是线段,判断 t 是不是在 0 和 1 之间
}
inline Vector3 Cross(Vector3 A, Vector3 B)
inline Vector3 Cross(const Vector3 A, const Vector3 B)
{
return Vector3(A.y * B.z - A.z * B.y, A.z * B.x - A.x * B.z, A.x * B.y - A.y * B.x);
}
inline double Area2(Point3 &A, Point3 &B, Point3 &C)
{
return Length(Cross(B - A, C - A));
}
inline double get_penalty_par_distance(double len)
inline double Area2(const Point3 &A, const Point3 &B, const Point3 &C) { return Length(Cross(B - A, C - A)); }
inline double get_penalty_par_distance(const double len)
{
static const double intersection_distance = 60;
static const double intersection_distance = 180;
if (len <= intersection_distance)
return 1;
else if (len <= intersection_distance * 1.5)
return 3;
return 1.4;
else if (len <= intersection_distance * 3)
return 10;
return 2.6;
else if (len <= intersection_distance * 5)
return 20;
return 6;
else if (len <= intersection_distance * 10)
return 50;
return 15;
else if (len <= intersection_distance * 25)
return 200;
return 30;
else
return 40;
}
/*考虑了连线方向,卡箍方向,连线长度的综合权值函数
A或者B type!=0inOut没有意义
inOut1=0沿A的dirinOut1=1A的dir
inOut2=0沿B的dirinOut2=1B的dir
*/
inline double distan(P A, P B, int inOut1, int inOut2)
{
static double penalty_par_intersection = 1;
static double penalty_par_distance = 1;
double angel = Angle(A - B, DX);
if (angel > pi / 2)
angel = pi - angel;
angel = min(angel, pi / 2 - angel);
double len = distan1(A, B);
// 求交判断并赋值惩罚参数
if (intersection_model == 1)
{
@ -149,9 +179,11 @@ inline double distan(P A, P B, int inOut1, int inOut2)
if (hit == 0)
penalty_par_intersection = 1;
else
penalty_par_intersection = 100;
penalty_par_distance = get_penalty_par_distance(len);
penalty_par_intersection = 100; //*原400
// cout << "out: len:" << len << " intersection_distance" << intersection_distance << endl;
}
penalty_par_distance = get_penalty_par_distance(len);
double len1 = sqrt((A.y - Ycenter) * (A.y - Ycenter) + (A.z - Zcenter) * (A.z - Zcenter));
double len2 = sqrt((B.y - Ycenter) * (B.y - Ycenter) + (B.z - Zcenter) * (B.z - Zcenter));
if (len1 < R || len2 < R)
@ -167,27 +199,37 @@ inline double distan(P A, P B, int inOut1, int inOut2)
angel3 = pi - angel3;
angel = min(angel1, min(angel2, angel3));
}
P C;
if (inOut1)
A.reverse();
C.x = A.dx;
C.y = A.dy;
C.z = A.dz;
double angel2 = Angle(B - A, C);
if (A.isend == 1 || A.type != 0)
angel2 = 0;
if (inOut2)
B.reverse();
C.x = B.dx;
C.y = B.dy;
C.z = B.dz;
double angel3 = Angle(B - A, C);
if (B.isend == 1 || B.type != 0)
angel3 = 0;
double orign_distance = len * (angel * 4 + 1) + 300 * 600 * (angel2 + angel3) / len;
return orign_distance * penalty_par_intersection * penalty_par_distance;
}
/*考虑了连线方向,卡箍方向,连线长度的综合权值函数
A和B自动选择最合适的dir
*/
//----------------------mark----------------------
// 多线缆bug:距离太短可能无法生成分离点导致
inline double distan(P A, P B)
{
static double penalty_par_intersection = 1;
@ -205,9 +247,11 @@ inline double distan(P A, P B)
if (hit == 0)
penalty_par_intersection = 1;
else
penalty_par_intersection = 100;
penalty_par_distance = get_penalty_par_distance(len);
penalty_par_intersection = 100; //*原400
// cout << "no_out: len:" << len << " intersection_distance" << intersection_distance << endl;
}
penalty_par_distance = get_penalty_par_distance(len);
double len1 = sqrt((A.y - Ycenter) * (A.y - Ycenter) + (A.z - Zcenter) * (A.z - Zcenter));
double len2 = sqrt((B.y - Ycenter) * (B.y - Ycenter) + (B.z - Zcenter) * (B.z - Zcenter));
if (len1 < R || len2 < R)
@ -239,10 +283,12 @@ inline double distan(P A, P B)
angel3 = min(angel3, pi - angel3);
if (B.isend == 1 || B.type != 0)
angel3 = 0;
double orign_distance = len * (angel * 4 + 1) + 300 * 600 * (angel2 + angel3) / len;
return orign_distance * penalty_par_intersection * penalty_par_distance;
}
// 打印路径信息
inline void printPath(vector<P> vecp)
{
for (int j = 0; j < vecp.size(); j++)

4
WireRouting_DLL/Geometry.cpp

@ -1,6 +1,10 @@
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include "Geometry.h"
vector<Vec3f> vertices;
vector<Vec3u> indices;
Mesh mesh;
AABB::AABB()
{
min = Vec3f(1e5, 1e5, 1e5);

6
WireRouting_DLL/Geometry.h

@ -99,9 +99,13 @@ public:
}
};
typedef Vec3<float> Vec3f;
typedef Vec3<unsigned int> Vec3u;
extern vector<Vec3f> GEOMETRY_API vertices;
extern vector<Vec3u> GEOMETRY_API indices;
class GEOMETRY_API Mesh
{
public:
@ -109,6 +113,8 @@ public:
std::vector<Vec3u> indices;
};
extern Mesh GEOMETRY_API mesh;
class GEOMETRY_API AABB
{
public:

8
WireRouting_DLL/Intersection.cpp

@ -58,9 +58,11 @@ size_t BVH_intersection::dfsBuild(vector<size_t> &indicesList, AABB aabb, size_t
nowIdx++;
if (indicesList.size() == 1)
{
// leaf
nodes[nodeIdx] = BVHNode(0, indicesList[0], 0, aabb); // VS2008
return nodeIdx;
}
// longest axis
int longAxis = -1;
float longAxisLen = -1;
for (int i = 0; i < 3; ++i)
@ -72,6 +74,7 @@ size_t BVH_intersection::dfsBuild(vector<size_t> &indicesList, AABB aabb, size_t
longAxis = i;
}
}
// split indices list
const size_t k = indicesList.size() / 2;
nth(indicesList, k - 1, longAxis);
vector<size_t> leftIndices(indicesList.begin(), indicesList.begin() + k);
@ -112,6 +115,7 @@ AABB BVH_intersection::computeAABB(const vector<size_t> &indices)
bool BVH_intersection::recursiveLineSegIntersection(const LineSegment &lineSegment, size_t nodeIdx) const
{
// segment-box intersection test
const AABB &aabb = nodes[nodeIdx].boundingBox;
const Vec3f &dir = lineSegment.getDir();
bool hit = false;
@ -137,6 +141,7 @@ bool BVH_intersection::recursiveLineSegIntersection(const LineSegment &lineSegme
{
if (nodes[nodeIdx].left == 0)
{
// leaf
Vec3u face = mesh.indices[nodes[nodeIdx].right];
TriangleSegmentIntersectRes res = triangleSegmentIntersection(lineSegment, mesh.vertices[face[0]], mesh.vertices[face[1]],
mesh.vertices[face[2]]);
@ -146,6 +151,7 @@ bool BVH_intersection::recursiveLineSegIntersection(const LineSegment &lineSegme
}
else
{
// check children
return recursiveLineSegIntersection(lineSegment, nodes[nodeIdx].left) ||
recursiveLineSegIntersection(lineSegment, nodes[nodeIdx].right);
}
@ -153,6 +159,8 @@ bool BVH_intersection::recursiveLineSegIntersection(const LineSegment &lineSegme
return false;
}
// implement nth, without std::nth_element
// kth is 0-based
void BVH_intersection::nth(vector<size_t> &indicesList, size_t kth, int longAxis)
{
recursiveChoose(indicesList, 0, indicesList.size() - 1, kth, longAxis);

5
WireRouting_DLL/Intersection.h

@ -27,9 +27,8 @@ struct INTERSECTION_API TriangleSegmentIntersectRes
TriangleSegmentIntersectRes(bool h, float tt);
};
extern TriangleSegmentIntersectRes
INTERSECTION_API
triangleSegmentIntersection(const LineSegment &segment, const Vec3f &a, const Vec3f &b, const Vec3f &c);
extern TriangleSegmentIntersectRes INTERSECTION_API
triangleSegmentIntersection(const LineSegment &segment, const Vec3f &a, const Vec3f &b, const Vec3f &c);
class INTERSECTION_API BVHNode
{

3
WireRouting_DLL/KDtree.cpp

@ -1,6 +1,8 @@
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include "KDtree.h"
KDtree kdtree;
bool cmp0(const point &a, const point &b)
{
return a.x[0] < b.x[0];
@ -192,6 +194,7 @@ void KDtree::build()
build(root, 1, n, 0);
}
// 返回离s最近的k个点的编号
vector<int> KDtree::search_by_k(P &s, int k)
{
X = s.x;

2
WireRouting_DLL/KDtree.h

@ -82,3 +82,5 @@ struct KD_TREE_API KDtree
// 返回距离s点d以内的所有点的编号
vector<int> search_by_dis(P &s, double d);
};
extern KDtree KD_TREE_API kdtree;

2
WireRouting_DLL/Path.cpp

@ -1,7 +1,6 @@
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include "Path.h"
ClipSet clipSet;
P dirP(P &A)
{
@ -24,6 +23,7 @@ int Path::size()
return points.size();
}
// 把路径中经过的卡箍和分支点都标记成使用过的状态
void Path::markPoint()
{
for (int i = 0; i < points.size(); i++)

2
WireRouting_DLL/Path.h

@ -22,8 +22,6 @@
#include <cassert>
using namespace std;
extern ClipSet PATH_API clipSet;
extern P PATH_API dirP(P &A);
// 简单的路径信息,路径规划的直接结果

22
WireRouting_DLL/ReadXML.cpp

@ -47,16 +47,18 @@ Bund::Bund()
dia = length = 0;
}
void init_readxml()
{
wire_node.clear();
wire_pairs.clear();
mp.clear();
wiremap.clear();
pinidmap.clear();
pinmap.clear();
cnt = 0;
}
// void init_readxml()
// {
// wire_node.clear();
// wire_pairs.clear();
// mp.clear();
// wiremap.clear();
// pinidmap.clear();
// pinmap.clear();
// cnt = 0;
// }
//
// void producePin(TiXmlElement* pin){

Loading…
Cancel
Save