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.

srecord noeq G22SkeletonWalker<Img extends WidthAndHeight>(IImageRegion<Img> region) is Steppable {
  event foundLink(Pt a, Pt b);
  
  settable int minDist = 3;
  
  // point to "registered" point close by
  new Map<Pt> ptMap;
  
  // TEMPORARY DATA
  
  bool initialized;
  
  // each pair is (registered point, point-to-explore)
  new LinkedList<Pair<Pt>> queue;
  
  public bool step() {
    // find first pixel
    if (!initialized) {
      set initialized;
      Pt p = region.firstPixel();
      if (p == null) false;
      queue.add(pair(null, p));
    }
      
    if (empty(queue)) false;
    
    Pair<Pt> pair = popFirst(queue);
    Pt prev = pair.a, p = pair.b;
    
    Pt mapped = lookupOrKeep(ptMap, p);
    bool seen = ptMap.containsKey(p);
    Pt mapTo = p;
    
    if (prev != null) {
      if (distantEnough(prev, mapped))
        foundLink(prev, mapped);
      else
        mapTo = prev;
    }
    
    if (!seen) {
      ptMap.put(p, mapTo);
      Pt linkFrom = mapTo;
      for (int dir = 1; dir <= 8; dir++) {
        Pt p2 = ptPlus(p, onePathDirection(dir));
        if (region.contains(p2))
          queue.add(pair(linkFrom, p2));
      }
    }
    
    true;
  }
  
  bool distantEnough(Pt a, Pt b) {
    ret a != null && b != null
      && (absDiff(a.x, b.x) >= minDist || absDiff(a.y, b.y) >= minDist);
  }
}

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: 176 / 283
Version history: 11 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)
#1034999 - G22SkeletonWalker [backup]
#1035010 - G22SkeletonToMesh [old, superceded by G22SkeletonToMesh_v2]