@@ -180,14 +180,14 @@ var
180180 end;
181181 connectA, connectB: TIntegerArray;
182182begin
183- doors := Self.FindDoors(red.ClusterEx (1), map);
183+ doors := Self.FindDoors(red.Cluster (1), map);
184184 SetLength(connectedDoors, Length(doors));
185185 with white.Bounds() do
186186 SetLength(connectionMap, X2, Y2);
187187
188188 minLen := Self.MinimumTiles * RSTranslator.TileArea;
189189
190- for cluster in white.ClusterEx (1).SortBySize(True) do
190+ for cluster in white.Cluster (1).SortBySize(True) do
191191 begin
192192 if Length(cluster) <= minLen then Continue; //remove very small spaces
193193
@@ -244,7 +244,7 @@ begin
244244
245245 nodes := [];
246246 for tpa in skeleton.Partition(Self.Spacing) do
247- nodes += tpa.ClusterEx (1.5).Means();
247+ nodes += tpa.Cluster (1.5).Means();
248248
249249 for d in connectA do
250250 begin
@@ -299,172 +299,6 @@ begin
299299 SetLength(Result.Names, Length(Result.Nodes));
300300end;
301301
302- function TWebGraphGenerator._BuildGraph2(map: TImage; white, red: TPointArray): TWebGraph;
303- var
304- a, b, i, j, n, d, len, hi: Integer;
305- atpa, parts: T2DPointArray;
306- skeleton, nodes, tpa, doorsInTpa, doorNodes: TPointArray;
307- bounds: TBox;
308- p, q: TPoint;
309- nodesTree, skeletonTree: TSlackTree;
310- jInRange, nInRange: Boolean;
311- connectionMap: array of TIntegerMatrix;
312- doors: TRSDoorArray;
313- door: TRSDoor;
314- doorPaths: T2DIntegerArray;
315- connectedDoors: array of record
316- After, Before: Boolean;
317- end;
318- connectA, connectB: TIntegerArray;
319- dists: TDoubleArray;
320- begin
321- atpa := white.ClusterEx(1).SortBySize(True);
322- doors := Self.FindDoors(red.ClusterEx(1), map);
323- SetLength(connectedDoors, Length(doors));
324- with white.Bounds() do
325- SetLength(connectionMap, X2, Y2);
326-
327- for i := 0 to High(atpa) do
328- begin
329- if Length(atpa[i]) <= Self.MinimumTiles * RSTranslator.TileArea then
330- Continue; //remove very small spaces
331-
332- connectA := [];
333- connectB := [];
334-
335- hi := High(connectedDoors);
336- for d := 0 to hi do
337- begin
338- if connectedDoors[d].After and connectedDoors[d].Before then
339- begin
340- Result.Doors += doors[d];
341- Delete(doors, d, 1);
342- Delete(connectedDoors, d, 1);
343- hi -= 1;
344- d -= 1;
345- Continue;
346- end;
347-
348- if not connectedDoors[d].After and atpa[i].Contains(doors[d].After) then
349- connectA += d;
350- if not connectedDoors[d].Before and atpa[i].Contains(doors[d].Before) then
351- connectB += d;
352- end;
353-
354- bounds := atpa[i].Bounds();
355- if Max(bounds.Width, bounds.Height) < Self.NodeRadius then
356- begin
357- Result.Nodes += atpa[i].Median(); //mark spaces less than NodeRadius with a single node and continue
358-
359- for d in connectA do
360- begin
361- Result.Nodes += doors[d].After;
362- connectedDoors[d].After := True;
363- SetLength(Result.Paths, Length(Result.Nodes));
364- Result.Paths[High(Result.Nodes)-1] := [High(Result.Nodes)];
365- Result.Paths[High(Result.Nodes)] := [High(Result.Nodes)-1];
366- end;
367-
368- for d in connectB do
369- begin
370- Result.Nodes += doors[d].Before;
371- connectedDoors[d].Before := True;
372- SetLength(Result.Paths, Length(Result.Nodes));
373- Result.Paths[High(Result.Nodes)-1] := [High(Result.Nodes)];
374- Result.Paths[High(Result.Nodes)] := [High(Result.Nodes)-1];
375- end;
376-
377- Continue;
378- end;
379-
380- skeleton := atpa[i].Erode(1).Skeleton(2, 6);
381-
382- if skeleton = [] then
383- begin
384- Result.Nodes += atpa[i].Median();
385-
386- for d in connectA do
387- begin
388- Result.Nodes += doors[d].After;
389- connectedDoors[d].After := True;
390- SetLength(Result.Paths, Length(Result.Nodes));
391- Result.Paths[High(Result.Nodes)-1] := [High(Result.Nodes)];
392- Result.Paths[High(Result.Nodes)] := [High(Result.Nodes)-1];
393- end;
394-
395- for d in connectB do
396- begin
397- Result.Nodes += doors[d].Before;
398- connectedDoors[d].Before := True;
399- SetLength(Result.Paths, Length(Result.Nodes));
400- Result.Paths[High(Result.Nodes)-1] := [High(Result.Nodes)];
401- Result.Paths[High(Result.Nodes)] := [High(Result.Nodes)-1];
402- end;
403-
404- Continue;
405- end;
406-
407- nodes := [];
408-
409- for tpa in skeleton.Partition(Self.Spacing) do
410- for tpa in tpa.ClusterEx(1.5) do
411- nodes += tpa.Mean();
412-
413- for d in connectA do
414- begin
415- nodes += doors[d].After;
416- connectedDoors[d].After := True;
417- end;
418-
419- for d in connectB do
420- begin
421- nodes += doors[d].Before;
422- connectedDoors[d].Before := True;
423- end;
424-
425- nodesTree.Init(nodes);
426- len := Length(Result.Nodes);
427- SetLength(Result.Nodes, len + Length(nodes));
428- SetLength(Result.Paths, Length(Result.Nodes));
429-
430- for j := 0 to High(nodesTree.Data) do
431- begin
432- p := nodesTree.Data[j].Split;
433- tpa := nodesTree.KNearest(p, Self.MaxConnections, True);
434-
435- for q in tpa do
436- begin
437- if Max(Abs(p.X - q.X), Abs(p.Y - q.Y)) > Self.Spacing * 2 then Continue;
438-
439- if map.ColorsInLine(p, q, [$0, $FF, $333333]) then
440- if map.ColorsInLineEx(p, q, [$0, $FF, $333333]) then
441- if atpa[i].ExtractBox(TBox.Create(Min(p.X, q.X), Min(p.Y, q.Y), Max(p.X, q.X), Max(p.Y, q.Y))).AStar(p, q, True) = [] then
442- Continue;
443-
444- connectionMap[q.X, q.Y] += j;
445- end;
446- end;
447-
448- for j := 0 to High(nodesTree.Data) do
449- begin
450- p := nodesTree.Data[j].Split;
451- Result.Nodes[j+len] := p;
452- for n in connectionMap[p.X, p.Y] do
453- begin
454- Result.Nodes[n+len] := nodesTree.Data[n].Split;
455-
456- if not Result.Paths[j+len].Contains(n+len) then
457- Result.Paths[j+len] += n+len;
458- if not Result.Paths[n+len].Contains(j+len) then
459- Result.Paths[n+len] += j+len;
460- end;
461- end;
462- end;
463-
464- SetLength(Result.Paths, Length(Result.Nodes));
465- SetLength(Result.Names, Length(Result.Nodes));
466- end;
467-
468302
469303function TWebGraphGenerator.BuildGraph(name: String; map: TImage): TWebGraph;
470304var
@@ -483,16 +317,16 @@ begin
483317
484318 gray := map.FindColor($333333, 0);
485319
486- whiteClusters := white.ClusterEx (1);
487- grayClusters := gray.ClusterEx (1);
320+ whiteClusters := white.Cluster (1);
321+ grayClusters := gray.Cluster (1);
488322
489323 for i := 0 to High(whiteClusters) do
490324 begin
491325 if Length(whiteClusters[i]) <= 6 then Continue;
492326
493327 graySubset := gray.ExtractBox(whiteclusters[i].Bounds().Expand(80));
494328 merged := whiteclusters[i] + graySubset;
495- mergedClusters := merged.ClusterEx (1);
329+ mergedClusters := merged.Cluster (1);
496330
497331 for j := 0 to high(mergedClusters) do
498332 if mergedClusters[j].Contains(whiteClusters[i][0]) then
0 commit comments