Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

58
LINES

< > BotCompany Repo | #1034998 // G22SkeletonWalker [abandoned]

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (6291L) is out of date.

1  
srecord noeq G22SkeletonWalker<Img extends WidthAndHeight>(IImageRegion<Img> region) is Steppable {
2  
  event foundLink(Pt a, Pt b);
3  
  
4  
  settable int minDist = 3;
5  
  
6  
  // point to "registered" point close by
7  
  new Map<Pt> ptMap;
8  
  
9  
  // TEMPORARY DATA
10  
  
11  
  bool initialized;
12  
  
13  
  // each pair is (registered point, point-to-explore)
14  
  new LinkedList<Pair<Pt>> queue;
15  
  
16  
  public bool step() {
17  
    // find first pixel
18  
    if (!initialized) {
19  
      set initialized;
20  
      Pt p = region.firstPixel();
21  
      if (p == null) false;
22  
      queue.add(pair(null, p));
23  
    }
24  
      
25  
    if (empty(queue)) false;
26  
    
27  
    Pair<Pt> pair = popFirst(queue);
28  
    Pt prev = pair.a, p = pair.b;
29  
    
30  
    Pt mapped = lookupOrKeep(ptMap, p);
31  
    bool seen = ptMap.containsKey(p);
32  
    Pt mapTo = p;
33  
    
34  
    if (prev != null) {
35  
      if (distantEnough(prev, mapped))
36  
        foundLink(prev, mapped);
37  
      else
38  
        mapTo = prev;
39  
    }
40  
    
41  
    if (!seen) {
42  
      ptMap.put(p, mapTo);
43  
      Pt linkFrom = mapTo;
44  
      for (int dir = 1; dir <= 8; dir++) {
45  
        Pt p2 = ptPlus(p, onePathDirection(dir));
46  
        if (region.contains(p2))
47  
          queue.add(pair(linkFrom, p2));
48  
      }
49  
    }
50  
    
51  
    true;
52  
  }
53  
  
54  
  bool distantEnough(Pt a, Pt b) {
55  
    ret a != null && b != null
56  
      && (absDiff(a.x, b.x) >= minDist || absDiff(a.y, b.y) >= minDist);
57  
  }
58  
}

Author comment

Began life as a copy of #1030913

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034998
Snippet name: G22SkeletonWalker [abandoned]
Eternal ID of this version: #1034998/12
Text MD5: 2d007aeccf66b0be991ea79f8a288675
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-22 21:03:04
Source code size: 1396 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 175 / 282
Version history: 11 change(s)
Referenced in: [show references]