Changeset 2562


Ignore:
Timestamp:
04/05/07 18:08:08 (13 years ago)
Author:
sorber
Message:

Some cleanup to both files.

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

Legend:

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

    r2559 r2562  
    8787  protected double curveLength; 
    8888 
    89   /** Whether the head node should be highlighted */ 
    90   protected boolean highlightHead; 
    91  
    92   /** Whether the tail node should be highlighted */ 
    93   protected boolean highlightTail; 
    94  
    9589  /** Whether there is a higlighted node */ 
    9690  protected boolean highlightNode; 
     
    110104  public OverlayNodedObject(OverlayTransform overlay) {  
    111105    super(overlay);  
    112     setHighlightHead(false); 
    113     setHighlightTail(false); 
    114106    turnOffHighlighting(); 
    115107  } 
     
    131123    computeGridParameters(); 
    132124    computeLength(); 
    133     setHighlightHead(false); 
    134     setHighlightTail(false); 
    135125    turnOffHighlighting(); 
    136126  } 
     
    146136    computeGridParameters(); 
    147137    computeLength(); 
    148     setHighlightHead(false); 
    149     setHighlightTail(false); 
    150138    turnOffHighlighting(); 
    151139  } 
     
    193181     
    194182    // fill nodes range samples 
    195     float r = color.getRed() / 255f; 
    196     float g = color.getGreen() / 255f; 
    197     float b = color.getBlue() / 255f; 
    198  
    199     if (selected) { 
    200       r = 1.0f; 
    201       g = 1.0f; 
    202       b = 0.0f; 
    203     } 
     183    Color col = selected ? GLOW_COLOR : color;  
     184    float r = col.getRed() / 255f; 
     185    float g = col.getGreen() / 255f; 
     186    float b = col.getBlue() / 255f; 
    204187 
    205188    Arrays.fill(rangeSamples[0], 0, maxNodes, r); 
     
    345328 
    346329    // construct range samples; 
    347     Color col = Color.YELLOW; 
    348  
     330    Color col = GLOW_COLOR; 
    349331    float r = col.getRed() / 255f; 
    350332    float g = col.getGreen() / 255f; 
     
    416398  public boolean hasEndpoint2() { return true; } 
    417399 
    418   /** True iff the head node is highlighted. */ 
    419   public boolean isHighlightHead() { return highlightHead; } 
    420   // TODO get rid of this ACS 
    421  
    422   /** True iff the tail node is highlighted. */ 
    423   public boolean isHighlightTail() { return highlightTail; } 
    424   // TODO get rid of this ACS 
    425  
    426400  /** True iff there is a highlighted node. */ 
    427401  public boolean isHighlightNode() { return highlightNode; } 
     
    464438   */ 
    465439  public void setActiveDisplay (DisplayImpl d) { display = d; } 
    466    
    467   /** Toggle highlight head of polyline. */ 
    468   public void setHighlightHead(boolean b) { highlightHead = b; } 
    469  
    470   /** Toggle highlight tail of polyline. */ 
    471   public void setHighlightTail(boolean b) { highlightTail = b; } 
    472440 
    473441  /** Highlight a node. */  
  • trunk/loci/visbio/overlays/PolylineTool.java

    r2524 r2562  
    4848  protected static final int EXTEND_ON_TAIL = 8; 
    4949  protected static final int BEG_EXTEND = 9; 
    50    
    5150 
    5251  /** Maximum distance (in pixels) mouse can be from a node to be considered 
     
    9998    DisplayImpl display = (DisplayImpl) e.getDisplay(); 
    10099 
    101     deselectAll();  
    102  
    103100    if (overlay.hasToolChanged()) { 
    104101      releaseLine(); 
     
    107104 
    108105    if (mode == WAIT) { 
     106      deselectAll(); 
    109107      line =  new OverlayPolyline(overlay, dx, dy, dx, dy); 
     108      line.setDrawing(true); 
     109      line.setSelected(true); 
    110110      configureOverlay(line); 
    111111      overlay.addObject(line, pos); 
     
    230230      line.setNodeCoords(selectedNode, dx, dy); 
    231231 
    232       int ndx = 0; // index of head 
    233       double[] dPxlDbl = {(double) px, (double) py}; 
    234       float[] nDom = line.getNodeCoords(ndx); 
    235       double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
    236       int[] nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
    237       double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
    238       double dist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     232      // determine if near head 
     233      double dist = getDistanceToNode(0, px, py, display); 
    239234       
    240       // if near ndx, highlight selected node differently  
     235      // if near, highlight head node  
    241236      if (dist < THRESH) { 
    242237        line.setHighlightNode(selectedNode, CON); 
     
    334329    } 
    335330    else if (mode == EXTEND || mode == EXTEND_ON_TAIL) { 
    336       float[][] lastSeg = {line.getNodeCoords(line.getNumNodes()-1), 
    337         line.getNodeCoords(line.getNumNodes() - 2)}; 
    338       double[][] lastSegD = {{(double) lastSeg[0][0], (double) lastSeg[0][1]}, 
    339         {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
    340       double lastSegLength = MathUtil.getDistance(lastSegD[0], lastSegD[1]); 
    341  
     331      // update curve length 
     332      double lastSegLength = getLastSegmentLength(); 
    342333      line.setLastNode(dx, dy); 
    343  
    344       float[][] newLastSeg = {line.getNodeCoords(line.getNumNodes() -1), 
    345         line.getNodeCoords(line.getNumNodes() - 2)}; 
    346       double[][] newLastSegD = {{(double) lastSeg[0][0], (double) 
    347         lastSeg[0][1]}, {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
    348       double newLastSegLength = MathUtil.getDistance(newLastSegD[0],  
    349           newLastSegD[1]); 
    350  
     334      double newLastSegLength = getLastSegmentLength(); 
    351335      double delta = newLastSegLength - lastSegLength; 
    352       //System.out.println("lastSegLength = " + lastSegLength); // TEMP 
    353       //System.out.println("newLastSegLength = " + newLastSegLength); 
    354       //System.out.println("delta =  " + delta); 
    355  
    356336      line.setCurveLength(line.getCurveLength() + delta);      
    357337       
    358       // determine if near head:  
    359       int ndx = 0; // index of head 
    360       double[] dPxlDbl = {(double) px, (double) py}; 
    361       float[] nDom = line.getNodeCoords(ndx); 
    362       double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
    363       int[] nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
    364       double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
    365       double hdist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     338      // determine if near head  
     339      double hdist = getDistanceToNode(0, px, py, display); 
     340      // determine if near last node placed  
     341      double ldist = getDistanceToNode(line.getNumNodes() - 2, px, py, display); 
    366342       
    367       // determine if near last node placed  
    368       ndx = line.getNumNodes() - 2; 
    369       dPxlDbl = new double[] {(double) px, (double) py}; 
    370       nDom = line.getNodeCoords(ndx); 
    371       nDomDbl = new double[] {(double) nDom[0], (double) nDom[1]}; 
    372       nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
    373       nPxlDbl = new double[] {(double) nPxl[0], (double) nPxl[1]}; 
    374       double ldist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
    375  
    376343      // if near ndx, highlight selected node differently  
    377344      int flag = -1;  
     
    382349      else if (hdist < THRESH) flag = 0; 
    383350 
    384        
    385351      if (flag == 0) { 
    386352        line.setActiveDisplay(display); 
     
    399365    } 
    400366    else if (mode == BEG_EXTEND) { 
    401       float[][] lastSeg = {line.getNodeCoords(line.getNumNodes() -1), line.getNodeCoords(line.getNumNodes() - 2)}; 
    402       double[][] lastSegD = {{(double) lastSeg[0][0], (double) lastSeg[0][1]}, 
    403         {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
    404       double lastSegLength = MathUtil.getDistance(lastSegD[0], lastSegD[1]); 
    405  
     367      // update curve length 
     368      double lastSegLength = getLastSegmentLength(); 
    406369      line.setLastNode(dx, dy); 
    407  
    408       float[][] newLastSeg = {line.getNodeCoords(line.getNumNodes() -1), 
    409         line.getNodeCoords(line.getNumNodes() - 2)}; 
    410       double[][] newLastSegD = {{(double) lastSeg[0][0], (double) 
    411         lastSeg[0][1]}, {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
    412       double newLastSegLength = MathUtil.getDistance(newLastSegD[0],  
    413           newLastSegD[1]); 
    414  
     370      double newLastSegLength = getLastSegmentLength(); 
    415371      double delta = newLastSegLength - lastSegLength; 
    416  
    417       line.setCurveLength(line.getCurveLength() + delta);  
    418        
    419       // determine if near head:  
    420       int ndx = 0; // index of head 
    421       double[] dPxlDbl = {(double) px, (double) py}; 
    422       float[] nDom = line.getNodeCoords(ndx); 
    423       double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
    424       int[] nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
    425       double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
    426       double hdist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
    427        
     372      line.setCurveLength(line.getCurveLength() + delta);      
     373 
     374      // determine if near head  
     375      double hdist = getDistanceToNode(0, px, py, display); 
    428376      // determine if near last node placed  
    429       ndx = line.getNumNodes() - 2; 
    430       dPxlDbl = new double[] {(double) px, (double) py}; 
    431       nDom = line.getNodeCoords(ndx); 
    432       nDomDbl = new double[] {(double) nDom[0], (double) nDom[1]}; 
    433       nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
    434       nPxlDbl = new double[] {(double) nPxl[0], (double) nPxl[1]}; 
    435       double ldist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
    436  
     377      double ldist = getDistanceToNode(line.getNumNodes() - 2, px, py, display); 
     378 
     379      // highlight first or last visible node if near 
    437380      if (hdist < THRESH) { 
    438381        line.setActiveDisplay(display); 
     
    441384      } 
    442385      
    443       // if you've dragged far enough from last node placed 
     386      // switch modes if you've dragged far enough from last node placed 
    444387      if (ldist > 10.0) { 
    445388        mode = EXTEND; 
     
    449392      line.setLastNode(dx, dy); 
    450393      // determine if near head:  
    451       int ndx = 0; // index of head 
    452       double[] dPxlDbl = {(double) px, (double) py}; 
    453       float[] nDom = line.getNodeCoords(ndx); 
    454       double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
    455       int[] nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
    456       double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
    457       double dist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
    458        
     394      double dist = getDistanceToNode(0, px, py, display); 
     395      
    459396      // if near ndx, highlight selected node differently  
    460397      if (dist > THRESH) { 
     
    464401    } 
    465402    else if (mode == SELECT) { 
     403      // get distance btw. pointer and selectedNode 
    466404      float[] nodeFlt = line.getNodeCoords (selectedNode);  
    467405      double[] nodeDbl = {(double) nodeFlt[0], (double) nodeFlt[1]}; 
     
    484422  // -- Helper methods --  
    485423   
     424  /** Gets distance to the node specified, handling awkward casts */ 
     425  private double getDistanceToNode(int ndx, int px, int py,  
     426    DisplayImpl display) { 
     427    double[] dPxlDbl = {(double) px, (double) py}; 
     428    float[] nDom = line.getNodeCoords(ndx); 
     429    double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
     430    int[] nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
     431    double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
     432    double dist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     433    return dist; 
     434  } 
     435 
     436  /** Determines length of last line segment */  
     437  private double getLastSegmentLength() { 
     438    float[][] lastSeg = {line.getNodeCoords(line.getNumNodes() -1),  
     439      line.getNodeCoords(line.getNumNodes() - 2)}; 
     440    double[][] lastSegD = {{(double) lastSeg[0][0], (double) lastSeg[0][1]}, 
     441      {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
     442    return MathUtil.getDistance(lastSegD[0], lastSegD[1]); 
     443  } 
     444 
    486445  /** Ends drawing of the current line */ 
    487446  private void releaseLine() { 
Note: See TracChangeset for help on using the changeset viewer.