Changeset 2534


Ignore:
Timestamp:
04/02/07 18:38:07 (13 years ago)
Author:
sorber
Message:

Began overlay statistics save/export feature. Made a small side-effect fix to OverlayNodedObject.getNodes().

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

Legend:

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

    r2524 r2534  
    205205    float length = (float) Math.sqrt(xx * xx + yy * yy); 
    206206 
    207     return "Arrow coordinates = (" + x1 + ", " + y1 + ")\n" + 
     207    return "Arrow tip coordinates = (" + x1 + ", " + y1 + ")\n" + 
    208208      "Angle = " + angle + "; Length = " + length; 
     209  } 
     210 
     211  /** Gets this object's statistics in array */ 
     212  public OverlayStat[] getStatisticsArray() { 
     213    float xx = x2 - x1; 
     214    float yy = y2 - y1; 
     215    float angle = (float) (180 * Math.atan(xx / yy) / Math.PI); 
     216    if (yy < 0) angle += 180; 
     217    if (angle < 0) angle += 360; 
     218    float length = (float) Math.sqrt(xx * xx + yy * yy); 
     219     
     220    String coords = "(" + x1 + ", " + y1 + ")"; 
     221    OverlayStat[] stats = { 
     222      new OverlayStat("Tip coordinates", coords), 
     223      new OverlayStat("Angle", "" + angle), 
     224      new OverlayStat("Length", "" + length), 
     225    }; 
     226 
     227    return stats; 
    209228  } 
    210229 
  • trunk/loci/visbio/overlays/OverlayBox.java

    r2524 r2534  
    129129      "Width = " + width + "; Height = " + height + "\n" + 
    130130      "Area = " + area + "; Perimeter = " + perim; 
     131  } 
     132 
     133  /** Gets this object's statistics in array */ 
     134  public OverlayStat[] getStatisticsArray() { 
     135    float xx = x2 - x1; 
     136    float yy = y2 - y1; 
     137    float width = xx < 0 ? -xx : xx; 
     138    float height = yy < 0 ? -yy : yy; 
     139    float centerX = x1 + xx / 2; 
     140    float centerY = y1 + yy / 2; 
     141    float area = width * height; 
     142    float perim = width + width + height + height; 
     143 
     144    String coords = "(" + x1 + ", " + y1 + ")-(" + x2 + ", " + y2 + ")"; 
     145    String center = "(" + centerX + ", " + centerY + ")"; 
     146     
     147    OverlayStat[] stats = { 
     148      new OverlayStat("Coordinates", coords), 
     149      new OverlayStat("Center", "" + center), 
     150      new OverlayStat("Width", "" + width), 
     151      new OverlayStat("Height", "" + height), 
     152      new OverlayStat("Area", "" + area), 
     153      new OverlayStat("Perimeter", "" + perim) 
     154    }; 
     155 
     156    return stats; 
    131157  } 
    132158 
  • trunk/loci/visbio/overlays/OverlayIO.java

    r2429 r2534  
    163163          if (numberOfNodedObjectsRead == loadedNodedObjects.size()) { 
    164164            String s = "more \"Noded Object\" (Freeforms, Polylines) node" 
    165               + " lists" + "than Noded Objects (" + numberOfNodedObjectsRead 
     165              + " lists " + "than Noded Objects (" + numberOfNodedObjectsRead 
    166166              + ") specified in table"; 
    167167            displayErrorMsg(owner, lineNum, s); 
    168168            return null; 
    169169          } 
    170  
    171170          // store nodes of previously read freeform 
    172171          if (nodesChanged) { 
     
    367366    int[] lengths = trans.getLengths(); 
    368367    Vector[] overlays = trans.overlays; 
    369     Vector savedNodedObjects = new Vector(); 
    370368    int freeformCount = 0; 
    371369    int polylineCount = 0; 
     370 
     371    Vector lines = new Vector(); 
     372    Vector markers = new Vector(); 
     373    Vector freeforms = new Vector(); 
     374    Vector texts = new Vector(); 
     375    Vector ovals = new Vector(); 
     376    Vector boxes = new Vector(); 
     377    Vector arrows = new Vector(); 
     378    Vector polylines = new Vector(); 
    372379 
    373380    // file header 
     
    392399      for (int j=0; j<overlays[i].size(); j++) { 
    393400        OverlayObject obj = (OverlayObject) overlays[i].elementAt(j); 
    394         if (obj instanceof OverlayNodedObject) savedNodedObjects.add(obj); 
     401         
     402        if (obj instanceof OverlayLine) lines.add(obj); 
     403        if (obj instanceof OverlayFreeform) freeforms.add(obj); 
     404        if (obj instanceof OverlayMarker) markers.add(obj); 
     405        if (obj instanceof OverlayText) texts.add(obj); 
     406        if (obj instanceof OverlayOval) ovals.add(obj); 
     407        if (obj instanceof OverlayBox) boxes.add(obj); 
     408        if (obj instanceof OverlayArrow) arrows.add(obj); 
     409        if (obj instanceof OverlayPolyline) polylines.add(obj); 
     410 
    395411        out.print(obj.toString()); 
    396412        out.print("\t"); 
     
    415431      } 
    416432    } 
    417  
     433    out.println (); 
     434 
     435    // print stats by object type 
     436    Vector[] vectors = {lines, freeforms, markers, texts, ovals, boxes,  
     437      arrows, polylines}; 
     438    String[] titles = {"Line", "Freeform", "Marker", "Text", "Oval", "Box", 
     439      "Arrow", "Polyline"}; 
     440    for (int v=0; v<vectors.length; v++) { 
     441      out.println("# " + titles[v] + " Statistics"); 
     442      for (int i=0; i<vectors[v].size(); i++) { 
     443        OverlayObject obj = (OverlayObject) vectors[v].get(i); 
     444        int index = i + 1; 
     445        out.println("# " + titles[v] + " " + index); 
     446        OverlayStat[] stats = obj.getStatisticsArray(); 
     447        for (int j=0; j<stats.length; j++) { 
     448          out.println("#\t" + stats[j].getName() + "\t" + stats[j].getValue()); 
     449        } 
     450      } 
     451      out.println(); 
     452    } 
     453    
    418454    // nodes of noded objects, one node per line 
    419     for (int i=0; i<savedNodedObjects.size(); i++) { 
    420       OverlayNodedObject ono = (OverlayNodedObject) savedNodedObjects.get(i); 
     455    for (int i=0; i<freeforms.size() + polylines.size(); i++) { 
     456      // get the noded object from the appropriate Vector 
     457      OverlayNodedObject ono; 
     458      if (i < freeforms.size()) { 
     459        ono = (OverlayNodedObject) freeforms.get(i); 
     460      } 
     461      else { 
     462        ono = (OverlayNodedObject) polylines.get(i - freeforms.size()); 
     463      } 
     464 
    421465      out.println(); 
    422466      float xx1, xx2, yy1, yy2; 
     
    431475      else if (ono instanceof OverlayPolyline) k = ++polylineCount; 
    432476 
    433       out.println("# " + ono + " " + k + " (" + xx1 + "," + yy1 + ")(" + xx2 + 
    434           "," + yy2 + ")"); 
     477      out.println("# " + ono + " " + k + " nodes:"); 
    435478 
    436479      out.println("X\tY"); 
     
    754797        state = TABLE; event = IGNORE; 
    755798      } 
    756       else if (input.matches("^\\s*#\\s*[Ff][Rr][Ee][Ee][Ff][Oo][Rr][Mm].*") ||  
    757           input.matches("^\\s*#\\s*[Pp][Oo][Ll][Yy][Ll][Ii][Nn][Ee].*")) { 
     799      else if (input.matches("# Freeform \\d+ nodes:") 
     800          || input.matches("# Polyline \\d+ nodes:")) 
     801      { 
    758802        state = NODES; event = INIT; 
    759803      } 
     
    773817        state = NODES; event = IGNORE; 
    774818      } 
    775       else if (input.matches("^\\s*#\\s*[Ff][Rr][Ee][Ee][Ff][Oo][Rr][Mm].*") ||  
    776           input.matches("^\\s*#\\s*[Pp][Oo][Ll][Yy][Ll][Ii][Nn][Ee].*")) { 
     819      else if (input.matches("# Freeform \\d+ nodes:") ||  
     820          input.matches("# Polyline \\d+ nodes:")) { 
    777821        state = NODES; event = INIT; 
    778822      } 
  • trunk/loci/visbio/overlays/OverlayLine.java

    r2524 r2534  
    100100  } 
    101101 
     102  /** Gets this object's statistics in array */ 
     103  public OverlayStat[] getStatisticsArray() { 
     104    float xx = x2 - x1; 
     105    float yy = y2 - y1; 
     106    float length = (float) Math.sqrt(xx * xx + yy * yy); 
     107     
     108    String coords = "(" + x1 + ", " + y1 + ")-(" + x2 + ", " + y2 + ")"; 
     109    OverlayStat[] stats = { 
     110      new OverlayStat("Coordinates", coords), 
     111      new OverlayStat("Length", "" + length), 
     112    }; 
     113 
     114    return stats; 
     115  } 
     116 
    102117  /** True iff this overlay has an endpoint coordinate pair. */ 
    103118  public boolean hasEndpoint() { return true; } 
  • trunk/loci/visbio/overlays/OverlayMarker.java

    r2528 r2534  
    217217    return "Marker coordinates = (" + x1 + ", " + y1 + ")"; 
    218218  } 
     219   
     220  /** Gets this object's statistics in array */ 
     221  public OverlayStat[] getStatisticsArray() { 
     222    String coords = "(" + x1 + ", " + y1 + ")"; 
     223    OverlayStat[] stats = { new OverlayStat("Coordinates", coords) }; 
     224    return stats; 
     225  } 
    219226 
    220227  /** True iff this overlay has an endpoint coordinate pair. */ 
  • trunk/loci/visbio/overlays/OverlayNodedObject.java

    r2524 r2534  
    305305    float delta = GLOW_WIDTH * scl; 
    306306 
     307    /* 
     308    // compute angle bisectors at each node 
     309    for (int i=0; i<numNodes; i++) { 
     310      if (i == 0){ 
     311      } 
     312      if (i == numNodes - 1){ 
     313      } 
     314      else { 
     315        float[] v1 = {nodes[0][i] - nodes[0][i-1], nodes[1][i] - nodes[1][i-1]}; 
     316        float[] v2 = {nodes[0][i+1] - nodes[0][i], nodes[1][i+1] - nodes[1][i]}; 
     317 
     318 
     319    }*/ 
     320 
    307321    Gridded2DSet[] segments = new Gridded2DSet[numNodes-1]; 
    308322    for (int i=0; i<numNodes - 1; i++) { 
     
    337351    float b = col.getBlue() / 255f; 
    338352 
    339  
    340353    float[][] rangeSamples = new float[4][4*(numNodes-1)]; 
    341354    Arrays.fill(rangeSamples[0], r); 
     
    357370 
    358371    return field; 
    359  
    360372  } 
    361373 
     
    386398      "Curve Length = " + (float) curveLength + "\n"; 
    387399  } 
     400   
     401  /** Gets this object's statistics in array */ 
     402  public OverlayStat[] getStatisticsArray() { 
     403    String bounds = "(" + x1 + ", " + y1 + ")-(" + x2 + ", " + y2 + ")"; 
     404    OverlayStat[] stats = { 
     405      new OverlayStat("Bounds", bounds), 
     406      new OverlayStat("Length (standard)", "" + curveLength), 
     407    }; 
     408 
     409    return stats; 
     410  } 
    388411 
    389412  /** True iff this overlay has an endpoint coordinate pair. */ 
     
    476499 
    477500  /** Returns the node array */ 
    478   public float[][] getNodes() { return nodes; } 
     501  public float[][] getNodes() {  
     502    float[][] copy = new float[2][numNodes]; 
     503    for (int i=0; i<2; i++) 
     504      System.arraycopy(nodes[i], 0, copy[i], 0, numNodes);  
     505    return copy; 
     506  } 
    479507 
    480508  /** Returns the number of real nodes in the array */ 
  • trunk/loci/visbio/overlays/OverlayObject.java

    r2524 r2534  
    9797  /** Computes the shortest distance from this overlay to the given point. */ 
    9898  public abstract double getDistance(double x, double y); 
     99 
     100  /** Gets an array of OverlayStats statistics about this overlay. */ 
     101  public abstract OverlayStat[] getStatisticsArray(); 
    99102 
    100103  /** Retrieves useful statistics about this overlay. */ 
     
    342345    y2 = Math.max(y2, y); 
    343346  } 
    344  
    345347}// end class 
  • trunk/loci/visbio/overlays/OverlayOval.java

    r2524 r2534  
    257257  } 
    258258 
     259 /** Gets this object's statistics in array */ 
     260  public OverlayStat[] getStatisticsArray() { 
     261    float xx = x2 - x1; 
     262    float yy = y2 - y1; 
     263    float centerX = x1 + xx / 2; 
     264    float centerY = y1 + yy / 2; 
     265    float radiusX = (xx < 0 ? -xx : xx) / 2; 
     266    float radiusY = (yy < 0 ? -yy : yy) / 2; 
     267    float major, minor; 
     268    if (radiusX > radiusY) { 
     269      major = radiusX; 
     270      minor = radiusY; 
     271    } 
     272    else { 
     273      major = radiusY; 
     274      minor = radiusX; 
     275    } 
     276    float eccen = (float) Math.sqrt(1 - (minor * minor) / (major * major)); 
     277    float area = (float) (Math.PI * major * minor); 
     278 
     279    // ellipse circumference approximation algorithm due to Ramanujan found at 
     280    // http://mathforum.org/dr.math/faq/formulas/faq.ellipse.circumference.html 
     281    float mm = (major - minor) / (major + minor); 
     282    float q = 3 * mm * mm; 
     283    float circum = (float) (Math.PI * 
     284      (major + minor) * (1 + q / (10 + Math.sqrt(4 - q)))); 
     285 
     286    String coords = "(" + x1 + ", " + y1 + ")"; 
     287    OverlayStat[] stats = {  
     288      new OverlayStat("Coordinates", coords), 
     289      new OverlayStat("Center", "(" + centerX + ", " + centerY + ")"), 
     290      new OverlayStat("Radius", "(" + radiusX + ", " + radiusY + ")"), 
     291      new OverlayStat("Major Axis Length", "" + major), 
     292      new OverlayStat("Minor Axis Length", "" + minor), 
     293      new OverlayStat("Area", "" + area), 
     294      new OverlayStat("Eccentricity", "" + eccen), 
     295      new OverlayStat("Circumference (approximate)", "" + circum)  
     296    }; 
     297    return stats; 
     298  } 
     299 
    259300  /** True iff this overlay has an endpoint coordinate pair. */ 
    260301  public boolean hasEndpoint() { return true; } 
  • trunk/loci/visbio/overlays/OverlayText.java

    r2524 r2534  
    127127  } 
    128128 
     129  /** Gets this object's statistics in array */ 
     130  public OverlayStat[] getStatisticsArray() { 
     131    String coords = "(" + x1 + ", " + y1 + ")"; 
     132    OverlayStat[] stats = { new OverlayStat("Coordinates", coords) }; 
     133    return stats; 
     134  } 
     135 
    129136  /** True iff this overlay has an endpoint coordinate pair. */ 
    130137  public boolean hasEndpoint() { return true; } 
Note: See TracChangeset for help on using the changeset viewer.