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)
{
startStand = cuMap.GetStand(cus[0].StartPoint);
startStand = cuMap.GetOnlyVertice(cus[0].StartPoint);
while (startStand)
startStand = linkCurve(startStand, cus, false);
}

@ -27,7 +27,8 @@ export interface Route
}
/**
* 线,使.
* 线
*
*/
export class CurveMap
{
@ -42,24 +43,24 @@ export class CurveMap
线.
使,使x.
*/
_NodeMap = new Map<Vector3, Vertice>();
_VerticeMap = new Map<Vector3, Vertice>();
_Vertices: Vertice[] = [];
/**
*
*/
get Stands(): Vertice[]
{
let stands: Vertice[] = [];
this._NodeMap.forEach(s => stands.push(s));
return stands;
return this._Vertices;
}
AddCurveToMap(curve: Curve, isArc: boolean = curve instanceof Arc, removeDuplicate: boolean = false)
{
let sp = curve.StartPoint;
let ep = curve.EndPoint;
let startS = this.GetStand(sp);
let endS = this.GetStand(ep);
let startS = this.GetOnlyVertice(sp);
let endS = this.GetOnlyVertice(ep);
//在面域分析中,路线指向同一个顶点已经没有意义了
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);
if (this._NodeMap.has(gp))
return this._NodeMap.get(gp);
if (this._VerticeMap.has(gp))
return this._VerticeMap.get(gp);
let stand = { position: gp, routes: [] };
this._NodeMap.set(p, stand);
return stand;
let vertice: Vertice = { position: gp, routes: [] };
this._VerticeMap.set(p, vertice);
this._Vertices.push(vertice);
return vertice;
}
_LookupTable: { [key: string]: Vector3; } = {};
@ -114,10 +116,10 @@ export class CurveMap
/**
* .
*/
GenerateP(v: Vector3): Vector3
GenerateP(p: Vector3): Vector3
{
let key = "";
let els = v.toArray();
let els = p.toArray();
for (let n of els)
{
let valueQuantized = Math.round(n * this.multiplier);
@ -145,8 +147,8 @@ export class CurveMap
key += hashpart[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 { arrayLast, arrayRemove, arrayRemoveIf } from "../Common/ArrayExt";
import { arrayLast, arrayRemoveIf, arrayRemoveOnce } from "../Common/ArrayExt";
import { Arc } from "../DatabaseServices/Entity/Arc";
import { Curve } from "../DatabaseServices/Entity/Curve";
import { Polyline } from "../DatabaseServices/Entity/Polyline";
@ -10,7 +10,13 @@ import { angle } from "./GeUtils";
//区域的路线表 表示了一个区域
type RegionRouteS = Route[][];
//区域搜索算法
/**
,
=
,
CurveMapCurveMap
*/
export class RegionParse
{
//区域列表 通常是外轮廓
@ -24,18 +30,20 @@ export class RegionParse
private _CurveCount: number;
/**
* @param {Curve[]} cuList .
* @param cuList .
* @param [numDimensions=3] :
* @param [removeDuplicate=true] (true,)
*/
constructor(cuList: Curve[], public numDimensions = 3, private removeDuplicate = true)
{
//需要搜索的站
let vertices = this.GenerateNodeMap(cuList);
let vertices = this.GenerateVerticeMap(cuList);
//移除细丝
while (true)
{
let v = vertices.find(v => v.routes.length < 2);
if (v) vertices = this.RemoveFilamentAt(v, vertices);
if (v) this.RemoveFilamentAt(v, vertices);
else break;
}
let lowerVertice: Vertice;
@ -46,8 +54,8 @@ export class RegionParse
let maxWalk = ClosedWalkFrom(lowerVertice, this._CurveCount, WalkType.Max);
this.RemoveEdge(minWalk[0]);
vertices = this.RemoveFilamentAt(minWalk[0].from, vertices);
vertices = this.RemoveFilamentAt(minWalk[0].to, vertices);
this.RemoveFilamentAt(minWalk[0].from, vertices);
this.RemoveFilamentAt(minWalk[0].to, vertices);
minWalk = ReduceWalk(minWalk);
maxWalk = ReduceWalk(maxWalk);
@ -92,7 +100,7 @@ export class RegionParse
let current = v;
while (current && current.routes.length < 2)
{
vertices = arrayRemove(vertices, current);
vertices = arrayRemoveOnce(vertices, current);
let r = current.routes[0];
if (r)
{
@ -102,7 +110,6 @@ export class RegionParse
else
current = undefined;
}
return vertices;
}
RemoveEdge(r: Route)
@ -134,7 +141,7 @@ export class RegionParse
* 线. 线. 使,使x.
* @returns
*/
private GenerateNodeMap(curveList: Curve[]): Array<Vertice>
private GenerateVerticeMap(curveList: Curve[]): Array<Vertice>
{
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;
for (let r of s.routes)
{
if (r.length < minLength)
minLength = r.length;
}
for (let r of s.routes)
for (let r of v.routes)
if (r.length < minLength) minLength = r.length;
for (let r of v.routes)
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;
}
@ -222,8 +225,6 @@ export class RegionParse
/**
* 线使
* @param cu
* @returns true if cueve used
*/
GetCueveUsed(cu: Curve): boolean
{

@ -84,7 +84,7 @@ export class LinkSelf
let cu = breakCus[i];
if (this.GetCurveUse(cu)) continue;
let cuIndex = this.GetCurveIndex(cu);
let stand = cuMap.GetStand(cu.EndPoint);
let stand = cuMap.GetOnlyVertice(cu.EndPoint);
let routeCus = new Set<Curve>();
@ -92,7 +92,7 @@ export class LinkSelf
{
//缓存走过的节点
let ways: Vertice[] = [];
ways.push(cuMap.GetStand(cu.StartPoint));
ways.push(cuMap.GetOnlyVertice(cu.StartPoint));
if (equalv3(route.curve.EndPoint, stand.position))
continue; //如果方向相反,那么退出计算 (不符合)
@ -148,7 +148,7 @@ export class LinkSelf
while (true)
{
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++)
@ -200,7 +200,7 @@ export class LinkSelf
{
let routes2 = routes.concat();//复制数组保证函数有唯一结果
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;
}
@ -280,9 +280,9 @@ export class LinkSelf
let cuMap = new CurveMap();
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); //从大到小
});

Loading…
Cancel
Save