Changeset 2909


Ignore:
Timestamp:
06/26/07 17:38:20 (12 years ago)
Author:
sorber
Message:

Added comments to several files in overlays package.
Added overlays/test folder; moved test and dummy classes inside.
Added test overlays data to test folder.

Location:
trunk/loci/visbio/overlays
Files:
13 added
3 deleted
5 edited

Legend:

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

    r2903 r2909  
    3737 * 
    3838 * The section of the freeform represented by a freeform extension is actually a 
    39  * loop, not a single line, like a giant 'loopie' on your shoelace.  
     39 * loop, but it's thin (both sides overlap exactly) so it appears like a single 
     40 * line.  
    4041 * The loop has two parts, between start and tip and between tip and stop. 
    4142 * If an edit is completed, half of the freeform extension is deleted along 
     
    169170  } 
    170171 
    171   /** Computes distance between drag and tip of extension. **/ 
     172  /** Computes distance between mouse drag and tip of extension. **/ 
    172173  public double computeDragDist(DisplayImpl display, int px, int py) { 
    173174    // coords of this mouseDrag event 
     
    181182    return dragDist; 
    182183  } 
    183  
    184184 
    185185  /** Extends the tip of the freeform extension by "one" node. */ 
  • trunk/loci/visbio/overlays/FreeformTool.java

    r2903 r2909  
    260260      } 
    261261 
     262      // if close, connect freeforms together 
    262263      if (minDist < DRAW_THRESH) { 
    263264        connectFreeforms(freeform, 
     
    467468          OverlayFreeform currentFreeform = (OverlayFreeform) currentObject; 
    468469          // performance opportunity: 
    469           // I removed the check on the bounding box 
     470          // check distance to bounding box first. 
    470471          // Should the getDistance method return a distance in 
    471472          // pixel coordinates? 
     
    525526  } 
    526527 
    527   // -- Inner Classes --  
     528  // -- Inner Class --  
    528529 
    529530  /**  
  • trunk/loci/visbio/overlays/OverlayNodedObject.java

    r2904 r2909  
    343343  } 
    344344 
    345   /** Returns the node array */ 
     345  /** Returns a copy of the node array */ 
    346346  public float[][] getNodes() { 
    347347    synchronized(nodesSync) { 
     
    354354  } 
    355355 
    356   /** Returns the number of real nodes in the array */ 
     356  /** Returns the number of real nodes in the array. */ 
    357357  public int getNumNodes() { synchronized(nodesSync) { return numNodes; } } 
    358358 
    359   /** Returns total number of nodes in array */ 
     359  /** Returns total number of nodes in array. */ 
    360360  public int getMaxNodes() { synchronized(nodesSync) { return maxNodes; } } 
    361361 
     
    387387  } 
    388388 
    389   /** Sets the node array to that provided--for loading from saved */ 
     389  /** Sets the node array to that provided--for loading from saved. */ 
    390390  public void setNodes(float[][] nodes) { 
    391391    synchronized (nodesSync) { 
     
    398398  } 
    399399 
    400   /** Updates the coordinates of the bounding box of a noded object */ 
     400  /**  
     401   * Updates the coordinates of the bounding box of a noded object by 
     402   * checking the entire node array.  
     403   */ 
    401404  public void updateBoundingBox() { 
    402405    if (numNodes == 0) return; 
     
    418421  } 
    419422 
    420   /** Gets length of curve */ 
     423  /** Gets length of curve. */ 
    421424  public double getCurveLength() { return curveLength; } 
    422425 
     
    430433  } 
    431434 
    432   /** Sets length of curve */ 
     435  /** Sets length of curve. */ 
    433436  public void setCurveLength(double len) { curveLength = len; } 
    434437 
    435   /** Computes length of curve */ 
     438  /** Computes length of curve. */ 
    436439  public void computeLength() { 
    437440    boolean notFull = false; 
     
    454457  // -- OverlayNodedObject API Methods: node array mutators -- 
    455458  // note: call updateBoundingBox() after a series of changes to the node array 
    456    
    457459 
    458460  /** Sets coordinates of an existing node */ 
     
    538540      if (index >= 0 && index < numNodes) { 
    539541        // if array is full, make some more room. 
    540         if (numNodes >= maxNodes) { // numNodes should never exceed maxNodes but.. 
     542        if (numNodes >= maxNodes) {  
     543          // numNodes should never exceed maxNodes but I threw the > in anyway. 
    541544          maxNodes *= 2; 
    542545          resizeNodeArray(maxNodes); 
     
    622625    synchronized (nodesSync) { 
    623626      if (index >=0 && index < numNodes) { 
    624         // built-in truncation 
    625         //System.out.println("OverlayObject.deleteNode(" + index +") called. " + 
    626         //  "numNodes = " + numNodes + ", maxNodes = " + maxNodes); 
     627        // This method includes built-in truncation: it doesn't bother to 
     628        // copy the extra nodes in the node array. 
     629         
     630        // Check if this delete operation will result in two colocational nodes 
     631        // becoming adjacent in the node array.  If so, also delete one of  
     632        // these nodes. 
    627633        int offset; 
    628634        if (index > 0 && index < numNodes - 1 &&  
    629635            MathUtil.areSame(getNodeCoords(index-1), getNodeCoords(index+1)))  
    630           // colocational nodes exist 
    631636          offset = 1; 
    632637        else offset = 0; 
     
    670675   * the child objects.  
    671676   */ 
     677  // TODO -- combine this with 'split' method in polyline tool. 
    672678  private OverlayFreeform[] slice(int seg, double weight) 
    673679  { 
  • trunk/loci/visbio/overlays/OverlayUtil.java

    r2904 r2909  
    155155    float y1 = obj.getY(); 
    156156    float y2 = obj.getY2(); 
     157 
    157158    // compute corners of arrow tail 
     159    // (this paragraph copied straight from OverlayArrow) 
    158160    double xx = x2 - x1; 
    159161    double yy = y2 - y1; 
     
    174176    // arrow lengths: 
    175177    double a, b, c; 
    176     a = Math.sqrt(qx * qx + qy * qy); 
    177     b = dist; 
    178     c = Math.sqrt(a * a + b * b); 
     178    a = Math.sqrt(qx * qx + qy * qy); // 1/2 width of tail 
     179    b = dist; // length from tail to tip 
     180    c = Math.sqrt(a * a + b * b); // length of side/hypotenuse 
    179181 
    180182    double d = GLOW_WIDTH * getMultiplier(link); 
     
    300302    float y2 = obj.getY2(); 
    301303 
    302     /* 
    303     // method for doing math in pixel coordinates part 1 of 2 
    304     float[] p1 = domainToPixel(link, new float[]{obj.getX(), obj.getY()}); 
    305     float[] p2 = domainToPixel(link, new float[]{obj.getX2(), obj.getY2()}); 
    306  
    307     float x1 = p1[0]; 
    308     float x2 = p2[0]; 
    309     float y1 = p1[1]; 
    310     float y2 = p2[1]; 
    311     */ 
    312304 
    313305    float delta = GLOW_WIDTH * getMultiplier(link); 
     
    333325                            {c1[1], c2[1], c3[1], c4[1]}}; 
    334326 
    335     /* 
    336     // method for doing math in pixel coordinates part 2 of 2 
    337     float[][] setSamplesPxl = {{c1[0], c2[0], c3[0], c4[0]}, 
    338                             {c1[1], c2[1], c3[1], c4[1]}}; 
    339  
    340     float[][] setSamples = pixelToDomain(link, setSamplesPxl); 
    341     */ 
    342327 
    343328    // construct range samples; 
     
    388373    float yy2 = y1 - size - delta; 
    389374 
    390     float dx = 0.0001f; // TEMP 
    391  
     375    // construct a cross shape, or if the marker is really small compared 
     376    // to the desired width (delta) of the selection layer, a box instead 
    392377    SampledSet domainSet = null; 
    393378    int samplesLength = 4; 
     
    410395      // using a UnionSet for now--couldn't get a single 
    411396      // Gridded2D set to appear as a cross 
     397 
     398      // left branch 
    412399      float[][] setSamples1 = { 
    413400        {xx1, x1-delta, xx1, x1 - delta}, 
     
    415402      }; 
    416403 
     404      // vertical part  
    417405      float[][] setSamples2 = { 
    418406        {x1 - delta, x1 + delta, x1 - delta, x1 + delta}, 
     
    420408      }; 
    421409 
     410      // right branch 
    422411      float[][] setSamples3 = { 
    423412        {x1 + delta, xx2, x1 + delta, xx2}, 
     
    440429 
    441430      /* 
     431      float dx = 0.0001; 
     432      // here's the code for creating a cross-shaped Gridded2DSet,  
     433      // which doesn't quite work 
    442434      setSamples = new float[][]{ 
    443435        {xx1, x1 - delta, x1 - delta + dx, x1 + delta - dx, x1 + delta, xx2, 
     
    447439      };*/ 
    448440 
    449       // Run this example by curtis: 
    450441      // Start with this: 
    451442      /* 
     
    501492    OverlayNodedObject ono = (OverlayNodedObject) obj; 
    502493 
     494    // This method builds a UnionSet of Gridded2DSets to highlight an Overlay 
     495    // Freeform or OverlayPolyline, plus (sometimes) a translucent circle over 
     496    // one of the nodes of the freeform or polyline to indicate that the mouse 
     497    // pointer is nearby.  It constructs a separate Gridded2DSet for 
     498    // each segment of the freeform or polyline, and an additional Gridded2DSet 
     499    // for the circle. 
     500 
    503501    float delta = GLOW_WIDTH * getMultiplier(link); 
    504502    float[][] nodes = ono.getNodes(); 
    505     // OverlayNodedObject.printThread("OU.getNodedLayer()"); 
    506503    int numNodes = ono.getNumNodes(); 
    507504    boolean hlt = ono.isHighlightNode(); 
     
    523520    samples = sets.size() * 4; 
    524521 
    525     //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
    526      
    527522    int hlen = hlt ? len : 0; 
    528523    float[][] rangeSamples = new float[4][samples+hlen]; 
     
    892887    int len = nodes[0].length; 
    893888 
    894     // Create two arrays to store the gridpoints: one to the right of the curve 
    895     // and another to the left (supposing the curve is oriented in order of 
    896     // increasing node indices, i.e., the first node is nodes[][0], the last 
    897     // is nodes[][nodes.length-1]) 
     889    // Create two arrays to store the gridpoints: one to the 'right' 
     890    // of the curve and another to the 'left' (supposing the curve is oriented 
     891    // in order of increasing node indices, i.e., the first node is nodes[][0], 
     892    // the last is nodes[][nodes.length-1]).   
    898893    float[][] right = new float[2][len]; // store the gridpts 
    899894    float[][] left = new float[2][len];  
     
    901896    if (len <=1) return null; 
    902897 
     898    // The senses of left and right remain the same except when the curve  
     899    // doubles back on itself, i.e., when two consecutive segments form an  
     900    // angle of 180 degrees.  Then the flag 'orientationChanged' switches. 
    903901    boolean orientationChanged = false; // if this is true, right and left 
    904902    // must be switched 
     903     
     904 
     905    // This loop computes the points to use in the Gridded2DSets.  The sets 
     906    // are constructed separately since each sets corner points are shared 
     907    // by two other sets (the front points of one set are the rear points of the 
     908    // next, etc.) 
    905909    for (int i=0; i<len; i++) { 
     910      // Each iteration of this loop computes a new pair of points 
     911      // rigthPt and leftPt.  The points are computed differently 
     912      // depending on whether the index i points to  
     913      // 1) the first node 
     914      // 2) the last node 
     915      // 3) some interior node 
    906916      float[] rightPt = new float[2]; 
    907917      float[] leftPt = new float[2]; 
    908918       
    909919      // System.out.println("index = " + i); 
    910       if (i==0) { // Case 1: the first node 
     920      if (i==0) {  
     921        // Case 1: the first node 
     922        // Just compute points a distance 'width' from the first node, 
     923        // in the direction perpendicular to the first segment 
    911924        
    912925        float[] p1 = new float[] {nodes[0][0], nodes[1][0]}; // first node  
     
    923936        // System.out.print("left pt: "); print(leftPt); 
    924937      } 
    925       else if (i == len - 1) { // Case 2: the last node 
    926  
     938      else if (i == len - 1) {  
     939        // Case 2: the last node 
     940        // Just compute points a distance 'width' from the last node, 
     941        // in the direction perpendicular to the last segment 
     942         
    927943        float[] p1 = new float[] {nodes[0][i-1], nodes[1][i-1]}; // penultimate 
    928944        // node 
    929945        float[] p2 = new float[] {nodes[0][i], nodes[1][i]}; // last node  
    930946 
    931         boolean anti = false; 
     947        // Test if the last segment doubles back on the second to last segment 
     948        boolean anti = false; // for 'antiparallel' 
    932949        if (len >= 3) { 
    933           // test if antiparallel 
    934950          float[] p0 = new float[] {nodes[0][i-2], nodes[1][i-2]}; // 3rd 2 last 
    935951          float[] v1 = MathUtil.unit(MathUtil.vector(p1, p0)); 
     
    944960        if (anti) vPerp = 
    945961          MathUtil.getRightPerpendicularVector2D(p1, p2); 
    946         // reversed p1 and p2 above! 
     962        // p1 and p2 above have been switched above to obtain a reflection  
    947963        else vPerp = MathUtil.getRightPerpendicularVector2D(p2, p1); 
    948964 
     
    963979        // System.out.println("orientation changed = "  + orientationChanged); 
    964980      } 
    965       else { // Case 3: all interior nodes 
     981      else {  
     982        // Case 3: all interior nodes 
     983        // Compute points a perpendicular distance 'width' away from the curve 
     984        // as in cases 1 and 2.  This time, however, the points lie on the  
     985        // the line bisecting the angle formed by adjacent segments. 
    966986 
    967987        float[] p1 = {nodes[0][i-1], nodes[1][i-1]}; 
     
    974994        // System.out.print("p3: "); print(p3); 
    975995 
     996        // Test if the line doubles back on itself 
    976997        // check if p2-p3 and p3-p2 are antiparallel 
    977         // have to correct the strategy in this case 
    978998        float[] v1 = MathUtil.unit(MathUtil.vector(p2, p1)); 
    979999        float[] v2 = MathUtil.unit(MathUtil.vector(p3, p2)); 
     
    9961016          float sin = Math.abs(MathUtil.cross2D(bisector, 
    9971017                MathUtil.unit(MathUtil.vector(p2, p1)))); 
    998           if (sin < 0.1f) sin = 0.1f; // keep a lower bound on this for safety  
    999           // (the value of sin could become really small) 
     1018          if (sin < 0.1f) sin = 0.1f; // keep a lower bound on this value to 
     1019          // prevent 1/sin from becoming too large 
    10001020           
    10011021          // compute offset distance from curve 
    10021022          float offset = width / sin; 
    10031023 
    1004           float[] a = MathUtil.add(p2, MathUtil.scalarMultiply(bisector, offset)); 
    1005           float[] b = MathUtil.add(p2, MathUtil.scalarMultiply(bisectorReflected, 
     1024          float[] a = MathUtil.add(p2, MathUtil.scalarMultiply(bisector, 
    10061025                offset)); 
     1026          float[] b = MathUtil.add(p2, 
     1027              MathUtil.scalarMultiply(bisectorReflected, offset)); 
     1028 
    10071029          rightPt = orientationChanged ? b : a; 
    10081030          leftPt = orientationChanged ? a : b; 
     
    10481070    Vector sets = new Vector(100); 
    10491071    for (int i=0; i<len-1; i++) { 
     1072      // This loop constructs Gridded2D sets, one for each segment of a noded 
     1073      // object (implied here by the arrays right and left). 
     1074      // For each segment (between indices 'i' and 'i+1'),  
     1075      // try to construct a trapezoidal set: 
    10501076      float[][] setSamples = { 
    10511077        {right[0][i], right[0][i+1], left[0][i], left[0][i+1]}, 
     
    10591085      } 
    10601086      catch (VisADException ex) { 
    1061         // If samples form an invalid set, the grid is bow-tie shaped.   
     1087        // If samples form an invalid set, the grid is most likely  
     1088        // bow-tie shaped.   
    10621089        // "Uncross" the box just by switching the order of the two 
    1063         // left points 
     1090        // left points. 
     1091 
     1092        // System.out.println("formed 1 invalid set"); 
    10641093        setSamples = new float[][]{ 
    10651094          {right[0][i], right[0][i+1], left[0][i+1], left[0][i]}, 
     
    10731102        } 
    10741103        catch (VisADException ex2) { 
    1075           // make a plain rectangular set, disregarding left and right 
    1076           // arrays 
     1104          // If the uncrossed samples still form an invalid set, give up 
     1105          // trying to make a trapezoidal set. 
     1106          // Make a plain rectangular set, disregarding left and right 
     1107          // arrays. Instead use the node array and calculate the corners of the 
     1108          // set using perpendiculars to the line segment under consideration. 
     1109          // System.out.println("formed 2 invalid sets"); 
    10771110          float[] p1 = {nodes[0][i], nodes[1][i]}; 
    10781111          float[] p2 = {nodes[0][i+1], nodes[1][i+1]}; 
     
    11251158  } 
    11261159 
    1127   /** Casts an array of floats to doubles. */ 
     1160  /**  
     1161   * Casts and converts an array of floats in domain coordinates to doubles in 
     1162   * pixel coordinates.  
     1163   */ 
    11281164  public static double[][] floatsToPixelDoubles(DisplayImpl d, float[][] nodes) { 
    11291165    double[][] nodesDbl = new double[nodes.length][nodes[0].length]; 
     
    11401176  public static void print(float[][] points) { 
    11411177    for (int i=0; i<points[0].length; i++) { 
    1142       System.out.println("[" + points[0][i] + "," + points[1][i] + "]"); 
     1178      print(points[0][i], points[1][i]); 
    11431179    } 
    11441180  } 
     
    11491185  } 
    11501186 
     1187  /** Prints a point. */ 
    11511188  public static void print(float[] p) { 
    11521189    print(p[0], p[1]);  
  • trunk/loci/visbio/overlays/PolylineTool.java

    r2904 r2909  
    388388  } 
    389389 
    390   // TODO -- combine this method with the similar one for freeforms, 
     390  // TODO -- replace this method with the similar one for freeforms, 
    391391  // currently located in OverlayNodedObject.java 
     392  // Determine some way of combining the two. 
    392393  /** Splits an overlay polyline in two */ 
    393394  private void split (OverlayPolyline line, int selectedNode) { 
     
    427428  } 
    428429 
    429   /** Gets distance to the node specified, handling awkward casts. */ 
     430  /**  
     431   * Gets distance to the node specified in pixel coordinates, handling 
     432   * awkward casts.  
     433   */  
    430434  private double getDistanceToNode(int ndx, int px, int py, 
    431435    DisplayImpl display) { 
     
    477481   *  in the objects array, item 1 the index of the nearest node in the nearest 
    478482   *  polyline */ 
     483  // TODO can this make use of or be replaced by the OverlayNodedObject instance 
     484  // method with the same name? 
    479485  private int[] getNearestNode(DisplayImpl display, 
    480486      OverlayObject[] objects, int px, int py, double threshold) { 
Note: See TracChangeset for help on using the changeset viewer.