Changeset 2581


Ignore:
Timestamp:
04/06/07 16:22:41 (13 years ago)
Author:
sorber
Message:

Added feature to update polyline curve length dynamically. Made slight changes to selection behavior.

Location:
trunk/loci/visbio/overlays
Files:
2 edited

Legend:

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

    r2562 r2581  
    4545  /** Computes the top 1/2 of a unit circle. */ 
    4646  private static float[][] arc() { 
    47     int res = 16; // resolution for 1/8 of circle 
     47    int res = 8; // resolution for 1/8 of circle 
    4848    float[][] arc = new float[2][4 * res]; 
    4949    for (int i=0; i<res; i++) { 
     
    7272  /** Alpha value for highlighting */ 
    7373  protected static final float HLT_ALPHA = 0.5f; 
     74 
     75  /** Radius in pixels of circle indicating a node is selected */ 
     76  protected static final float RADIUS = 7.5f; 
    7477   
    7578  // -- Fields -- 
     
    201204      if (display != null) scale = getScalingValue(display); 
    202205      else scale = 1f; 
    203       float rad = 10.0f * scale; // 10.0 pixels wide per active display 
     206      float rad = RADIUS * scale; // 5.0 pixels wide per active display 
    204207 
    205208      // assemble highlight set samples 
  • trunk/loci/visbio/overlays/PolylineTool.java

    r2562 r2581  
    5151  /** Maximum distance (in pixels) mouse can be from a node to be considered 
    5252   *  pointing to it. */ 
    53   protected static final double THRESH = 2.0; 
     53  protected static final double THRESH = 5.0; 
    5454 
    5555  /** Color for highlighting head or tail node of polyline when 'connecting' 
     
    9797    boolean ctl = (mods & InputEvent.CTRL_MASK) != 0; 
    9898    DisplayImpl display = (DisplayImpl) e.getDisplay(); 
     99 
     100    //printMode("mouseDown"); 
    99101 
    100102    if (overlay.hasToolChanged()) { 
     
    137139          mode = ADJUST; 
    138140        } 
     141        line.setDrawing(true); 
    139142      } 
    140143      else { 
     
    152155          float[][] n2 = new float[2][numNodes2]; 
    153156  
    154           // if non-trivial polyline remains 'left' of deleted node 
     157          // if a non-trivial polyline remains 'left' of deleted node 
    155158          if (selectedNode > 1) { 
    156159            for (int i=0; i<2; i++)  
     
    164167          } 
    165168 
    166           // if non-trivial polyline remains 'right' of deleted node 
     169          // if a non-trivial polyline remains 'right' of deleted node 
    167170          if (selectedNode < numNodes - 1) { 
    168171            for (int i=0; i<2; i++) { 
     
    192195    else if (mode == EXTEND || mode == BEG_EXTEND) { 
    193196      line.setLastNode(dx, dy); 
    194       float[] c = line.getNodeCoords(line.getNumNodes()-2); 
    195       double[] cdub = {(double) c[0], (double) c[1]}; 
    196       double oldLen = line.getCurveLength(); 
    197       line.setCurveLength(oldLen + MathUtil.getDistance(cdub, 
    198             new double[]{dx, dy})); 
    199197      mode = PLACE; 
    200198    } 
     
    214212    //System.out.println("mode = " + mode); 
    215213    DisplayImpl display = (DisplayImpl) e.getDisplay(); 
     214 
     215    //printMode("mouseDrag"); 
    216216 
    217217    if (overlay.hasToolChanged()) { 
     
    256256    //System.out.println("up mode = " + mode); 
    257257    DisplayImpl display = (DisplayImpl) e.getDisplay(); 
     258    //printMode("mouseUp"); // TEMP 
    258259 
    259260    if (overlay.hasToolChanged()) { 
     
    265266      line.computeGridParameters(); 
    266267      line.computeLength(); 
     268      line.setDrawing(false); 
    267269      mode = SELECT; 
    268270    } 
     
    271273      line.computeGridParameters(); 
    272274      line.computeLength(); 
     275      line.setDrawing(false); 
    273276      mode = SELECT; 
    274277    } 
     
    283286      line.computeGridParameters(); 
    284287      line.computeLength(); 
     288      line.setDrawing(false); 
    285289      selectNode(display, line, line.getNumNodes() - 1); 
    286290      mode = SELECT; 
     
    299303    double[] movePxl = {(double) px, (double) py};  
    300304 
     305    //printMode("mouseMoved"); 
     306 
    301307    if (overlay.hasToolChanged()) { 
    302308      releaseLine(); 
     
    305311    if (mode == WAIT) { 
    306312      OverlayObject[] objects = overlay.getObjects(); 
    307       double threshold = 2.0; 
    308       int[] ndxNode =  getNearestNode(display, objects, px, py, threshold); 
     313      int[] ndxNode =  getNearestNode(display, objects, px, py, THRESH); 
    309314 
    310315      if (ndxNode != null) { 
     
    312317        int node = ndxNode[1]; 
    313318        //System.out.println("near node " + node + " of object " + obj); // TEMP  
     319        deselectAll(); 
    314320        line = (OverlayPolyline) objects[ndx]; 
    315321        selectNode(display, line, node); 
     
    320326      line.setNextNode(dx, dy); 
    321327       
     328      // keep track of curve length 
     329      // using frequent updates to curvelength in EXTEND, etc. instead 
    322330      float[] c = line.getNodeCoords(line.getNumNodes()-2); 
    323331      double[] cdub = {(double) c[0], (double) c[1]}; 
     
    394402      double dist = getDistanceToNode(0, px, py, display); 
    395403      
    396       // if near ndx, highlight selected node differently  
     404      // if not, turn off highlighting  
    397405      if (dist > THRESH) { 
    398406        line.turnOffHighlighting(); 
     
    422430  // -- Helper methods --  
    423431   
    424   /** Gets distance to the node specified, handling awkward casts */ 
     432  /** Prints current mode and mouse event type: helpful for debugging */ 
     433  private void printMode(String method) { 
     434    String m; 
     435    switch (mode) { 
     436      case ERASE          : m = "erase"; break; 
     437      case WAIT           : m = "wait"; break; 
     438      case EXTEND         : m = "extend"; break; 
     439      case ADJUST         : m = "adjust"; break; 
     440      case SELECT         : m = "select"; break; 
     441      case PLACE          : m = "place"; break; 
     442      case ADJUST_TAIL    : m = "adjust tail"; break; 
     443      case CLOSE_LOOP     : m = "close loop"; break; 
     444      case SELECTED_TAIL  : m = "selected tail"; break; 
     445      case EXTEND_ON_TAIL : m = "extend on tail"; break; 
     446      case BEG_EXTEND     : m = "begin extend"; break; 
     447      default             : m = "unknown mode"; break; 
     448    } 
     449 
     450    System.out.println(method + "\t" + m); 
     451  } 
     452 
     453  /** Gets distance to the node specified, handling awkward casts. */ 
    425454  private double getDistanceToNode(int ndx, int px, int py,  
    426455    DisplayImpl display) { 
     
    434463  } 
    435464 
    436   /** Determines length of last line segment */  
     465  /** Determines length of last line segment. */  
    437466  private double getLastSegmentLength() { 
    438467    float[][] lastSeg = {line.getNodeCoords(line.getNumNodes() -1),  
     
    463492   
    464493  private void selectNode(DisplayImpl display, OverlayPolyline pln, int node) { 
     494    line.setDrawing(false); 
     495    line.setSelected(true); 
    465496    selectedNode = node; 
    466497    pln.setHighlightNode(node, SEL); 
     
    517548    else return new int[]{nearestPline, nearestNode}; 
    518549  } 
    519    
    520  
    521    
    522550  
    523551  /** Casts an array of floats to doubles */ 
Note: See TracChangeset for help on using the changeset viewer.