Changeset 2623


Ignore:
Timestamp:
04/13/07 15:10:48 (13 years ago)
Author:
curtis
Message:

Migrate pixelToDomain and related functions into
visad.util.CursorUtil from loci.visbio.util.DisplayUtil.

Location:
trunk/loci/visbio
Files:
8 edited

Legend:

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

    r2282 r2623  
    2626import loci.visbio.data.TransformEvent; 
    2727import loci.visbio.util.MathUtil; 
    28 import loci.visbio.util.DisplayUtil; 
    2928import java.awt.event.InputEvent; 
    3029import java.util.Vector; 
    3130import visad.DisplayEvent; 
    3231import visad.DisplayImpl; 
     32import visad.util.CursorUtil; 
    3333 
    3434/** FreeformTool is the tool for creating freeform objects. */ 
     
    231231        double[] tailDbl = {(double) tail[0], (double) tail[1]}; 
    232232        //double[] drag = {(double) dx, (double) dy}; 
    233         int[] headPxl = DisplayUtil.domainToPixel(display, headDbl); 
    234         int[] tailPxl = DisplayUtil.domainToPixel(display, tailDbl); 
     233        int[] headPxl = CursorUtil.domainToPixel(display, headDbl); 
     234        int[] tailPxl = CursorUtil.domainToPixel(display, tailDbl); 
    235235        double[]  headPxlDbl = new double[] {(double) headPxl[0],  
    236236          (double) headPxl[1]}; 
     
    269269 
    270270        double[] last = new double[]{(double) lastX, (double) lastY}; 
    271         int[] lastPxl = DisplayUtil.domainToPixel(display, last); 
     271        int[] lastPxl = CursorUtil.domainToPixel(display, last); 
    272272 
    273273        double dxPxl = dpx - (double) lastPxl[0]; 
     
    305305        double[] begDbl = {(double) beg[0], (double) beg[1]}; 
    306306        double[] endDbl = {(double) end[0], (double) end[1]}; 
    307         int[] begPxl = DisplayUtil.domainToPixel(display, begDbl); 
    308         int[] endPxl = DisplayUtil.domainToPixel(display, endDbl); 
     307        int[] begPxl = CursorUtil.domainToPixel(display, begDbl); 
     308        int[] endPxl = CursorUtil.domainToPixel(display, endDbl); 
    309309        double[] begPxlDbl = {(double) begPxl[0], (double) begPxl[1]}; 
    310310        double[] endPxlDbl = {(double) endPxl[0], (double) endPxl[1]}; 
     
    364364 
    365365      double[] prvCrdsDbl= {(double) prvCrdsFlt[0], (double) prvCrdsFlt[1]}; 
    366       int[] prvCrdsPxl = DisplayUtil.domainToPixel(display, prvCrdsDbl); 
     366      int[] prvCrdsPxl = CursorUtil.domainToPixel(display, prvCrdsDbl); 
    367367      double[] prvCrdsPxlDbl = {(double) prvCrdsPxl[0], (double) prvCrdsPxl[1]}; 
    368368       
     
    792792    double[][] nodesDbl = new double[nodes.length][nodes[0].length]; 
    793793    for (int j=0; j<nodes[0].length; j++) { 
    794       int[] c = DisplayUtil.domainToPixel(d, new double[]{ 
     794      int[] c = CursorUtil.domainToPixel(d, new double[]{ 
    795795        (double) nodes[0][j], (double) nodes[1][j]}); 
    796796      nodesDbl[0][j] = (double) c[0]; 
  • trunk/loci/visbio/overlays/OverlayNodedObject.java

    r2581 r2623  
    2828import java.util.Arrays; 
    2929import loci.visbio.util.MathUtil; 
    30 import loci.visbio.util.DisplayUtil; 
    3130import visad.*; 
     31import visad.util.CursorUtil; 
    3232 
    3333/** 
     
    717717  /** Returns a scaling value [domain length units/pixel] */ 
    718718  protected float getScalingValue(DisplayImpl d) { 
    719     double[] oDom = DisplayUtil.pixelToDomain(d, 0, 0); 
    720     double[] pDom = DisplayUtil.pixelToDomain(d, 1, 0); 
     719    double[] oDom = CursorUtil.pixelToDomain(d, 0, 0); 
     720    double[] pDom = CursorUtil.pixelToDomain(d, 1, 0); 
    721721    double scl = MathUtil.getDistance(oDom, pDom);  
    722722    return (float) scl; 
  • trunk/loci/visbio/overlays/OverlayTransform.java

    r2594 r2623  
    3535import loci.visbio.data.*; 
    3636import loci.visbio.state.Dynamic; 
    37 import loci.visbio.util.DisplayUtil; 
    3837import loci.visbio.util.ObjectUtil; 
    3938import loci.visbio.view.DisplayWindow; 
     
    4140import org.apache.poi.hssf.usermodel.HSSFWorkbook; 
    4241import visad.*; 
     42import visad.util.CursorUtil; 
    4343 
    4444/** A set of overlays on top another transform. */ 
     
    721721      if (tool != null) { 
    722722        int px = e.getX(), py = e.getY(); 
    723         double[] coords = DisplayUtil.pixelToDomain(display, px, py); 
     723        double[] coords = CursorUtil.pixelToDomain(display, px, py); 
    724724        tool.mouseMoved(e, px, py, 
    725725          (float) coords[0], (float) coords[1], pos, e.getModifiers()); 
     
    737737      if (tool != null) { 
    738738        int px = e.getX(), py = e.getY(); 
    739         double[] coords = DisplayUtil.pixelToDomain(display, px, py); 
     739        double[] coords = CursorUtil.pixelToDomain(display, px, py); 
    740740        tool.mouseDown(e, px, py, 
    741741          (float) coords[0], (float) coords[1], pos, e.getModifiers()); 
     
    750750      if (tool != null) { 
    751751        int px = e.getX(), py = e.getY(); 
    752         double[] coords = DisplayUtil.pixelToDomain(display, px, py); 
     752        double[] coords = CursorUtil.pixelToDomain(display, px, py); 
    753753        tool.mouseDrag(e, px, py, 
    754754          (float) coords[0], (float) coords[1], pos, e.getModifiers()); 
     
    899899    if (tool != null) { 
    900900      int px = e.getX(), py = e.getY(); 
    901       double[] coords = DisplayUtil.pixelToDomain(display, px, py); 
     901      double[] coords = CursorUtil.pixelToDomain(display, px, py); 
    902902      tool.mouseUp(e, px, py, 
    903903        (float) coords[0], (float) coords[1], pos, e.getModifiers()); 
  • trunk/loci/visbio/overlays/PolylineTool.java

    r2581 r2623  
    2828import java.util.Vector; 
    2929import loci.visbio.data.TransformEvent; 
    30 import loci.visbio.util.DisplayUtil; 
    3130import loci.visbio.util.MathUtil; 
    3231import visad.DisplayEvent; 
    3332import visad.DisplayImpl; 
     33import visad.util.CursorUtil; 
    3434 
    3535/** FreeformTool is the tool for creating freeform objects. */ 
     
    412412      float[] nodeFlt = line.getNodeCoords (selectedNode);  
    413413      double[] nodeDbl = {(double) nodeFlt[0], (double) nodeFlt[1]}; 
    414       int[] nodePxl = DisplayUtil.domainToPixel(display, nodeDbl);  
     414      int[] nodePxl = CursorUtil.domainToPixel(display, nodeDbl);  
    415415      double[] nodePxlDbl = {(double) nodePxl[0], (double) nodePxl[1]}; 
    416416      double dist = MathUtil.getDistance(movePxl, nodePxlDbl);  
     
    457457    float[] nDom = line.getNodeCoords(ndx); 
    458458    double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
    459     int[] nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
     459    int[] nPxl = CursorUtil.domainToPixel(display, nDomDbl); 
    460460    double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
    461461    double dist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     
    534534        float[] c = pln.getNodeCoords(j); 
    535535        double[] cDbl = {c[0], c[1]}; // auto cast 
    536         int[] cPxl = DisplayUtil.domainToPixel(display, cDbl); 
     536        int[] cPxl = CursorUtil.domainToPixel(display, cDbl); 
    537537        double[] cPxlDbl = {(double) cPxl[0], (double) cPxl[1]}; 
    538538        double dist = MathUtil.getDistance (cPxlDbl, p); 
     
    553553    double[][] nodesDbl = new double[nodes.length][nodes[0].length]; 
    554554    for (int j=0; j<nodes[0].length; j++) { 
    555       int[] c = DisplayUtil.domainToPixel(d, new double[]{ 
     555      int[] c = CursorUtil.domainToPixel(d, new double[]{ 
    556556        (double) nodes[0][j], (double) nodes[1][j]}); 
    557557      nodesDbl[0][j] = (double) c[0]; 
  • trunk/loci/visbio/overlays/TransientSelectBox.java

    r2477 r2623  
    2727import java.rmi.RemoteException; 
    2828import java.util.Arrays; 
    29 import loci.visbio.util.DisplayUtil; 
    3029import visad.*; 
     30import visad.util.CursorUtil; 
    3131 
    3232/** 
     
    102102     * 4------3 
    103103     */ 
    104     double[] d1 = DisplayUtil.pixelToDomain(getActiveDisplay(), x1, y1); 
    105     double[] d2 = DisplayUtil.pixelToDomain(getActiveDisplay(), x2, y1); 
    106     double[] d3 = DisplayUtil.pixelToDomain(getActiveDisplay(), x2, y2); 
    107     double[] d4 = DisplayUtil.pixelToDomain(getActiveDisplay(), x1, y2); 
     104    double[] d1 = CursorUtil.pixelToDomain(getActiveDisplay(), x1, y1); 
     105    double[] d2 = CursorUtil.pixelToDomain(getActiveDisplay(), x2, y1); 
     106    double[] d3 = CursorUtil.pixelToDomain(getActiveDisplay(), x2, y2); 
     107    double[] d4 = CursorUtil.pixelToDomain(getActiveDisplay(), x1, y2); 
    108108 
    109109    float[] f1 = {(float) d1[0], (float) d1[1]}; 
     
    188188     */ 
    189189 
    190     double[] p0 = DisplayUtil.pixelToDomain(getActiveDisplay(), x1, y1); 
    191     double[] p1 = DisplayUtil.pixelToDomain(getActiveDisplay(), x2, y1); 
    192     double[] p2 = DisplayUtil.pixelToDomain(getActiveDisplay(), x2, y2); 
    193     double[] p3 = DisplayUtil.pixelToDomain(getActiveDisplay(), x1, y2); 
     190    double[] p0 = CursorUtil.pixelToDomain(getActiveDisplay(), x1, y1); 
     191    double[] p1 = CursorUtil.pixelToDomain(getActiveDisplay(), x2, y1); 
     192    double[] p2 = CursorUtil.pixelToDomain(getActiveDisplay(), x2, y2); 
     193    double[] p3 = CursorUtil.pixelToDomain(getActiveDisplay(), x1, y2); 
    194194 
    195195    double[][] ret = {  {p0[0], p0[1]}, 
  • trunk/loci/visbio/util/DisplayUtil.java

    r2331 r2623  
    332332  } 
    333333 
    334   /** 
    335    * Gets scale values (multiplier and offset) for the X, Y and Z maps 
    336    * corresponding to the given RealTypes (or the first ScalarMaps to 
    337    * X, Y and Z if types is null). If no mapping to a spatial axis is 
    338    * found, that component of the array will be null. 
    339    * 
    340    * @return Scale array of size [3][2], with the first dimension 
    341    * corresponding to X, Y or Z, and the second giving multiplier and offset. 
    342    * For example, cursor_x = scale[0][0] * domain_x + scale[0][1]. 
    343    */ 
    344   public static double[][] getScaleValues(DisplayImpl d, RealType[] types) { 
    345     // locate x, y and z mappings 
    346     Vector maps = d.getMapVector(); 
    347     int numMaps = maps.size(); 
    348     ScalarMap mapX = null, mapY = null, mapZ = null; 
    349     for (int i=0; i<numMaps; i++) { 
    350       if (mapX != null && mapY != null && mapZ != null) break; 
    351       ScalarMap map = (ScalarMap) maps.elementAt(i); 
    352       if (types == null) { 
    353         DisplayRealType drt = map.getDisplayScalar(); 
    354         if (drt.equals(Display.XAxis)) mapX = map; 
    355         else if (drt.equals(Display.YAxis)) mapY = map; 
    356         else if (drt.equals(Display.ZAxis)) mapZ = map; 
    357       } 
    358       else { 
    359         ScalarType st = map.getScalar(); 
    360         if (st.equals(types[0])) mapX = map; 
    361         if (st.equals(types[1])) mapY = map; 
    362         if (st.equals(types[2])) mapZ = map; 
    363       } 
    364     } 
    365  
    366     // get scale values 
    367     double[][] scale = new double[3][]; 
    368     double[] dummy = new double[2]; 
    369     if (mapX == null) scale[0] = null; 
    370     else { 
    371       scale[0] = new double[2]; 
    372       mapX.getScale(scale[0], dummy, dummy); 
    373     } 
    374     if (mapY == null) scale[1] = null; 
    375     else { 
    376       scale[1] = new double[2]; 
    377       mapY.getScale(scale[1], dummy, dummy); 
    378     } 
    379     if (mapZ == null) scale[2] = null; 
    380     else { 
    381       scale[2] = new double[2]; 
    382       mapZ.getScale(scale[2], dummy, dummy); 
    383     } 
    384     return scale; 
    385   } 
    386  
    387   /** Converts the given cursor coordinates to domain coordinates. */ 
    388   public static double[] cursorToDomain(DisplayImpl d, 
    389     RealType[] types, double[] cursor) 
    390   { 
    391     if (d == null) return null; 
    392     double[][] scale = getScaleValues(d, types); 
    393     double[] domain = new double[3]; 
    394     for (int i=0; i<3; i++) { 
    395       domain[i] = scale[i] == null ? 0 : 
    396         (cursor[i] - scale[i][1]) / scale[i][0]; 
    397     } 
    398     return domain; 
    399   } 
    400  
    401   /** Converts the given domain coordinates to cursor coordinates. */ 
    402   public static double[] domainToCursor(DisplayImpl d, 
    403     RealType[] types, double[] domain) 
    404   { 
    405     if (d == null) return null; 
    406     double[][] scale = getScaleValues(d, types); 
    407     double[] cursor = new double[3]; 
    408     for (int i=0; i<3; i++) { 
    409       cursor[i] = scale[i] == null ? 0 : 
    410         scale[i][0] * domain[i] + scale[i][1]; 
    411     } 
    412     return cursor; 
    413   } 
    414  
    415   /** Converts the given cursor coordinates to domain coordinates. */ 
    416   public static double[] cursorToDomain(DisplayImpl d, double[] cursor) { 
    417     return cursorToDomain(d, null, cursor); 
    418   } 
    419  
    420   /** Converts the given domain coordinates to cursor coordinates. */ 
    421   public static double[] domainToCursor(DisplayImpl d, double[] domain) { 
    422     return domainToCursor(d, null, domain); 
    423   } 
    424  
    425   /** Converts the given pixel coordinates to cursor coordinates. */ 
    426   public static double[] pixelToCursor(DisplayImpl d, int x, int y) { 
    427     if (d == null) return null; 
    428     MouseBehavior mb = d.getDisplayRenderer().getMouseBehavior(); 
    429     VisADRay ray = mb.findRay(x, y); 
    430     return ray.position; 
    431   } 
    432  
    433   /** Converts the given cursor coordinates to pixel coordinates. */ 
    434   public static int[] cursorToPixel(DisplayImpl d, double[] cursor) { 
    435     if (d == null) return null; 
    436     MouseBehavior mb = d.getDisplayRenderer().getMouseBehavior(); 
    437     return mb.getScreenCoords(cursor); 
    438   } 
    439  
    440   /** Converts the given pixel coordinates to domain coordinates. */ 
    441   public static double[] pixelToDomain(DisplayImpl d, int x, int y) { 
    442     return cursorToDomain(d, pixelToCursor(d, x, y)); 
    443   } 
    444  
    445   /** Converts the given domain coordinates to pixel coordinates. */ 
    446   public static int[] domainToPixel(DisplayImpl d, double[] domain) { 
    447     return cursorToPixel(d, domainToCursor(d, domain)); 
    448   } 
    449  
    450334  /** Redraws exception messages in a display's bottom left-hand corner. */ 
    451335  public static void redrawMessages(DisplayImpl d) { 
     
    479363      //canvas.getGraphicsContext3D().flush(true); 
    480364    } 
    481   } 
    482  
    483   public static double[][] domainToPixel (DisplayImpl d, float[][] nodes) { 
    484     double[][] ret = new double[2][nodes[0].length]; 
    485     for (int i=0; i<nodes[0].length; i++) { 
    486        int[] coords = domainToPixel (d, new double[]{nodes[0][i], nodes[1][i]}); 
    487        ret[0][i] = coords[0]; 
    488        ret[1][i] = coords[1]; 
    489     } 
    490     return ret; 
    491365  } 
    492366 
  • trunk/loci/visbio/view/StackLink.java

    r1989 r2623  
    3232import org.w3c.dom.Element; 
    3333import visad.*; 
     34import visad.util.CursorUtil; 
    3435 
    3536/** 
     
    652653    RealType yType = it.getYType(); 
    653654    RealType zType = it.getZType(); 
    654     double[] domain = DisplayUtil.cursorToDomain(display, 
     655    double[] domain = CursorUtil.cursorToDomain(display, 
    655656      new RealType[] {xType, yType, zType}, cur); 
    656657 
  • trunk/loci/visbio/view/TransformLink.java

    r2594 r2623  
    3333import org.w3c.dom.Element; 
    3434import visad.*; 
     35import visad.util.CursorUtil; 
    3536import visad.util.Util; 
    3637 
     
    531532    RealType xType = it.getXType(); 
    532533    RealType yType = it.getYType(); 
    533     double[] domain = DisplayUtil.cursorToDomain(display, 
     534    double[] domain = CursorUtil.cursorToDomain(display, 
    534535      new RealType[] {xType, yType, null}, cur); 
    535536 
Note: See TracChangeset for help on using the changeset viewer.