Changeset 2719


Ignore:
Timestamp:
05/01/07 18:52:22 (13 years ago)
Author:
sorber
Message:

Added Dr. Inman's smoothing algorithm (ticket #116) for OverlayFreeforms.
Increased resume drawing threshhold for OverlayFreeforms.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/overlays/FreeformTool.java

    r2667 r2719  
    6464  protected static final double RECONNECT_THRESH = 1.0; 
    6565 
     66  /** How close mouse must be to end node to resume drawing */ 
     67  protected static final double RESUME_THRESH = 10.0; 
     68 
     69  /** Smoothing factor for "single exponential smoothing" */ 
     70  protected static final float S = 0.35f; 
     71 
    6672  /** Constant for "erase" mode. */ 
    6773  protected static final int ERASE = -1; 
     
    120126    double dpx = (double) px; 
    121127    double dpy = (double) py; 
    122      
    123     // -- main 
     128 
    124129    // find closest freeform 
    125130    double maxThresh = ERASE_THRESH;  
     
    144149          setMode(ERASE); 
    145150        } 
    146         else if (dist < DRAW_THRESH) { 
     151        else if (dist < RESUME_THRESH) { 
    147152          // resume drawing 
    148153          if (seg == 0) freeform.reverseNodes(); 
     
    244249        double[] drag = {dpx, dpy}; 
    245250 
    246         // DISTANCE computation  
    247251        // compare pair of ints with pair of floats 
    248252        double hdist = MathUtil.getDistance(drag, headPxlDbl); 
     
    281285 
    282286        if (distPxl > DRAW_THRESH) { 
    283           freeform.setNextNode(dx, dy); 
     287          float[] s = smooth(new float[]{dx, dy}, new float[] {lastX, lastY}); 
     288          freeform.setNextNode(s[0], s[1]); 
    284289          double len = freeform.getCurveLength(); 
    285           freeform.setCurveLength(len + dist); 
     290          double[] sDbl = {(double) s[0], (double) s[1]}; 
     291          double delta = MathUtil.getDistance(sDbl, last); 
     292          freeform.setCurveLength(len + delta); 
    286293          // I debated whether to call setBoundaries with every mouseDrag. 
    287294          // This is an efficient 
    288295          // method, but updating realtime for erasing requires an O(n) 
    289296          // scan of the nodes every time a node is deleted. 
    290           freeform.setBoundaries(dx, dy); 
     297          freeform.setBoundaries(s[0], s[1]); 
    291298        } 
    292299        // mode remains DRAW 
     
    397404        if (dragDist > DRAW_THRESH) { 
    398405          // first drag only 
     406          float[] s = smooth (new float[] {dx, dy}, prvCrdsFlt); 
    399407          if (tendril.tip < 0) { 
    400             freeform.insertNode(tendril.stop, dx, dy); 
     408            freeform.insertNode(tendril.stop, s[0], s[1]); 
    401409            tendril.stop++; 
    402410            tendril.tip = tendril.start + 1; 
     
    404412          else { // later drags 
    405413            freeform.insertNode(tendril.tip+1, prvCrdsFlt[0], prvCrdsFlt[1]); 
    406             freeform.insertNode(tendril.tip+1, dx, dy); 
     414            freeform.insertNode(tendril.tip+1, s[0], s[1]); 
    407415            tendril.tip++; 
    408416            tendril.stop += 2; 
     
    485493 
    486494  // -- Helper methods for mouse methods 
     495   
     496  /** Calculates smoothed coordinates using "single exponential smoothing" 
     497   *  as described in Littlewood and Inman, _Computer-assisted DNA length 
     498   *  measurements..._. Nucleic Acids Research, V 10 No. 5. (1982) p. 1694  
     499   */ 
     500  private float[] smooth (float[] un, float[] cn1) { 
     501    float[] cn = new float[2]; 
     502    for (int i=0; i<2; i++) { 
     503      cn[i] = S * un[i] + (1 - S) * cn1[i]; 
     504    } 
     505    return cn; 
     506  } 
    487507   
    488508  /** Slices a freeform in two. */ 
Note: See TracChangeset for help on using the changeset viewer.