pull/912/head
ChenX 5 years ago
parent d8de1036ad
commit 755eb2ee0a

@ -155,7 +155,7 @@ export function curveLinkGroup(cus: Curve[]): Array<Array<Curve>>
if (cus.length > 0) if (cus.length > 0)
{ {
startStand = cuMap.GetStand(cus[0].StartPoint); startStand = cuMap.GetOnlyVertice(cus[0].StartPoint);
while (startStand) while (startStand)
startStand = linkCurve(startStand, cus, false); startStand = linkCurve(startStand, cus, false);
} }

@ -27,7 +27,8 @@ export interface Route
} }
/** /**
* 线,使. * 线
*
*/ */
export class CurveMap export class CurveMap
{ {
@ -42,24 +43,24 @@ export class CurveMap
线. 线.
使,使x. 使,使x.
*/ */
_NodeMap = new Map<Vector3, Vertice>(); _VerticeMap = new Map<Vector3, Vertice>();
_Vertices: Vertice[] = [];
/** /**
* *
*/ */
get Stands(): Vertice[] get Stands(): Vertice[]
{ {
let stands: Vertice[] = []; return this._Vertices;
this._NodeMap.forEach(s => stands.push(s));
return stands;
} }
AddCurveToMap(curve: Curve, isArc: boolean = curve instanceof Arc, removeDuplicate: boolean = false) AddCurveToMap(curve: Curve, isArc: boolean = curve instanceof Arc, removeDuplicate: boolean = false)
{ {
let sp = curve.StartPoint; let sp = curve.StartPoint;
let ep = curve.EndPoint; let ep = curve.EndPoint;
let startS = this.GetStand(sp); let startS = this.GetOnlyVertice(sp);
let endS = this.GetStand(ep); let endS = this.GetOnlyVertice(ep);
//在面域分析中,路线指向同一个顶点已经没有意义了 //在面域分析中,路线指向同一个顶点已经没有意义了
if (this._RemoveSortLine && startS === endS) if (this._RemoveSortLine && startS === endS)
@ -98,15 +99,16 @@ export class CurveMap
/** /**
* *
*/ */
GetStand(p: Vector3): Vertice GetOnlyVertice(p: Vector3): Vertice
{ {
let gp = this.GenerateP(p); let gp = this.GenerateP(p);
if (this._NodeMap.has(gp)) if (this._VerticeMap.has(gp))
return this._NodeMap.get(gp); return this._VerticeMap.get(gp);
let stand = { position: gp, routes: [] }; let vertice: Vertice = { position: gp, routes: [] };
this._NodeMap.set(p, stand); this._VerticeMap.set(p, vertice);
return stand; this._Vertices.push(vertice);
return vertice;
} }
_LookupTable: { [key: string]: Vector3; } = {}; _LookupTable: { [key: string]: Vector3; } = {};
@ -114,10 +116,10 @@ export class CurveMap
/** /**
* . * .
*/ */
GenerateP(v: Vector3): Vector3 GenerateP(p: Vector3): Vector3
{ {
let key = ""; let key = "";
let els = v.toArray(); let els = p.toArray();
for (let n of els) for (let n of els)
{ {
let valueQuantized = Math.round(n * this.multiplier); let valueQuantized = Math.round(n * this.multiplier);
@ -145,8 +147,8 @@ export class CurveMap
key += hashpart[hashmaskShifted & 1]; key += hashpart[hashmaskShifted & 1];
hashmaskShifted >>= 1; hashmaskShifted >>= 1;
}); });
this._LookupTable[key] = v; this._LookupTable[key] = p;
} }
return v; return p;
} }
} }

@ -1,5 +1,5 @@
import { Vector3 } from "three"; import { Vector3 } from "three";
import { arrayLast, arrayRemove, arrayRemoveIf } from "../Common/ArrayExt"; import { arrayLast, arrayRemoveIf, arrayRemoveOnce } from "../Common/ArrayExt";
import { Arc } from "../DatabaseServices/Entity/Arc"; import { Arc } from "../DatabaseServices/Entity/Arc";
import { Curve } from "../DatabaseServices/Entity/Curve"; import { Curve } from "../DatabaseServices/Entity/Curve";
import { Polyline } from "../DatabaseServices/Entity/Polyline"; import { Polyline } from "../DatabaseServices/Entity/Polyline";
@ -10,7 +10,13 @@ import { angle } from "./GeUtils";
//区域的路线表 表示了一个区域 //区域的路线表 表示了一个区域
type RegionRouteS = Route[][]; type RegionRouteS = Route[][];
//区域搜索算法 /**
,
=
,
CurveMapCurveMap
*/
export class RegionParse export class RegionParse
{ {
//区域列表 通常是外轮廓 //区域列表 通常是外轮廓
@ -24,18 +30,20 @@ export class RegionParse
private _CurveCount: number; private _CurveCount: number;
/** /**
* @param {Curve[]} cuList . * @param cuList .
* @param [numDimensions=3] :
* @param [removeDuplicate=true] (true,)
*/ */
constructor(cuList: Curve[], public numDimensions = 3, private removeDuplicate = true) constructor(cuList: Curve[], public numDimensions = 3, private removeDuplicate = true)
{ {
//需要搜索的站 //需要搜索的站
let vertices = this.GenerateNodeMap(cuList); let vertices = this.GenerateVerticeMap(cuList);
//移除细丝 //移除细丝
while (true) while (true)
{ {
let v = vertices.find(v => v.routes.length < 2); let v = vertices.find(v => v.routes.length < 2);
if (v) vertices = this.RemoveFilamentAt(v, vertices); if (v) this.RemoveFilamentAt(v, vertices);
else break; else break;
} }
let lowerVertice: Vertice; let lowerVertice: Vertice;
@ -46,8 +54,8 @@ export class RegionParse
let maxWalk = ClosedWalkFrom(lowerVertice, this._CurveCount, WalkType.Max); let maxWalk = ClosedWalkFrom(lowerVertice, this._CurveCount, WalkType.Max);
this.RemoveEdge(minWalk[0]); this.RemoveEdge(minWalk[0]);
vertices = this.RemoveFilamentAt(minWalk[0].from, vertices); this.RemoveFilamentAt(minWalk[0].from, vertices);
vertices = this.RemoveFilamentAt(minWalk[0].to, vertices); this.RemoveFilamentAt(minWalk[0].to, vertices);
minWalk = ReduceWalk(minWalk); minWalk = ReduceWalk(minWalk);
maxWalk = ReduceWalk(maxWalk); maxWalk = ReduceWalk(maxWalk);
@ -92,7 +100,7 @@ export class RegionParse
let current = v; let current = v;
while (current && current.routes.length < 2) while (current && current.routes.length < 2)
{ {
vertices = arrayRemove(vertices, current); vertices = arrayRemoveOnce(vertices, current);
let r = current.routes[0]; let r = current.routes[0];
if (r) if (r)
{ {
@ -102,7 +110,6 @@ export class RegionParse
else else
current = undefined; current = undefined;
} }
return vertices;
} }
RemoveEdge(r: Route) RemoveEdge(r: Route)
@ -134,7 +141,7 @@ export class RegionParse
* 线. 线. 使,使x. * 线. 线. 使,使x.
* @returns * @returns
*/ */
private GenerateNodeMap(curveList: Curve[]): Array<Vertice> private GenerateVerticeMap(curveList: Curve[]): Array<Vertice>
{ {
let curveMap = new CurveMap(this.numDimensions, true); let curveMap = new CurveMap(this.numDimensions, true);
@ -194,19 +201,15 @@ export class RegionParse
} }
//排序,根据角度逆时针排序. //排序,根据角度逆时针排序.
curveMap._NodeMap.forEach(s => for (let v of curveMap._Vertices)
{ {
let minLength = Infinity; let minLength = Infinity;
for (let r of s.routes) for (let r of v.routes)
{ if (r.length < minLength) minLength = r.length;
if (r.length < minLength) for (let r of v.routes)
minLength = r.length;
}
for (let r of s.routes)
CalcRouteAngle(r, minLength * 0.2); CalcRouteAngle(r, minLength * 0.2);
s.routes.sort((r1, r2) => r1.an - r2.an); v.routes.sort((r1, r2) => r1.an - r2.an);
}); }
return curveMap.Stands; return curveMap.Stands;
} }
@ -222,8 +225,6 @@ export class RegionParse
/** /**
* 线使 * 线使
* @param cu
* @returns true if cueve used
*/ */
GetCueveUsed(cu: Curve): boolean GetCueveUsed(cu: Curve): boolean
{ {

@ -84,7 +84,7 @@ export class LinkSelf
let cu = breakCus[i]; let cu = breakCus[i];
if (this.GetCurveUse(cu)) continue; if (this.GetCurveUse(cu)) continue;
let cuIndex = this.GetCurveIndex(cu); let cuIndex = this.GetCurveIndex(cu);
let stand = cuMap.GetStand(cu.EndPoint); let stand = cuMap.GetOnlyVertice(cu.EndPoint);
let routeCus = new Set<Curve>(); let routeCus = new Set<Curve>();
@ -92,7 +92,7 @@ export class LinkSelf
{ {
//缓存走过的节点 //缓存走过的节点
let ways: Vertice[] = []; let ways: Vertice[] = [];
ways.push(cuMap.GetStand(cu.StartPoint)); ways.push(cuMap.GetOnlyVertice(cu.StartPoint));
if (equalv3(route.curve.EndPoint, stand.position)) if (equalv3(route.curve.EndPoint, stand.position))
continue; //如果方向相反,那么退出计算 (不符合) continue; //如果方向相反,那么退出计算 (不符合)
@ -148,7 +148,7 @@ export class LinkSelf
while (true) while (true)
{ {
let oldCount = cs.length; let oldCount = cs.length;
let routes = cuMap.GetStand(isInv ? originCu.StartPoint : originCu.EndPoint).routes; let routes = cuMap.GetOnlyVertice(isInv ? originCu.StartPoint : originCu.EndPoint).routes;
//把索引相等的站点最后遍历 //把索引相等的站点最后遍历
for (let i = 0; i < routes.length; i++) for (let i = 0; i < routes.length; i++)
@ -200,7 +200,7 @@ export class LinkSelf
{ {
let routes2 = routes.concat();//复制数组保证函数有唯一结果 let routes2 = routes.concat();//复制数组保证函数有唯一结果
routes2.push(cu); routes2.push(cu);
curIndex = this.FindMinRoute(this.cuMap.GetStand(cu.EndPoint), nowIndex, cs, routes2); curIndex = this.FindMinRoute(this.cuMap.GetOnlyVertice(cu.EndPoint), nowIndex, cs, routes2);
continue; continue;
} }
@ -280,9 +280,9 @@ export class LinkSelf
let cuMap = new CurveMap(); let cuMap = new CurveMap();
breakCus.forEach(c => cuMap.AddCurveToMap(c)); breakCus.forEach(c => cuMap.AddCurveToMap(c));
//所有的站点 逆序排序. //所有的站点 逆序排序.
for (let [, stand] of cuMap._NodeMap) for (let v of cuMap._Vertices)
{ {
stand.routes.sort((r1, r2) => v.routes.sort((r1, r2) =>
{ {
return this.GetCurveIndex(r2.curve) - this.GetCurveIndex(r1.curve); //从大到小 return this.GetCurveIndex(r2.curve) - this.GetCurveIndex(r1.curve); //从大到小
}); });

Loading…
Cancel
Save