Changeset 428 for trunk/loci/visbio/view


Ignore:
Timestamp:
06/06/05 17:39:22 (15 years ago)
Author:
curtis
Message:

Switch image stacks to run from 0 to numSlices-1, instead of -1 to 1.
Some more work on proper handling of microns.

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

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/view/StackHandler.java

    r405 r428  
    103103      RealType zType = ((ImageTransform) trans).getZType(); 
    104104      ScalarMap zMap = new ScalarMap(zType, Display.ZAxis); 
    105       zMap.setRange(-1, 1); 
    106105      display.addMap(zMap); 
    107106    } 
  • trunk/loci/visbio/view/StackLink.java

    r423 r428  
    213213      else { 
    214214        for (int i=0; i<len; i++) { 
    215           double z = len == 1 ? 0.0 : 2.0 * i / (len - 1) - 1; 
    216215          display.addReferences((DataRenderer) renderers.elementAt(i), 
    217             (DataReferenceImpl) references.elementAt(i), 
    218             new ConstantMap[] {new ConstantMap(z, Display.ZAxis)}); 
     216            (DataReferenceImpl) references.elementAt(i)); 
    219217        } 
    220218      } 
     
    365363 
    366364 
     365  // -- Internal StackLink API methods 
     366 
     367  /** 
     368   * Assigns the given data object to the given data reference, 
     369   * switching to the proper types if the flag is set. 
     370   */ 
     371  protected void setData(Data d, DataReference dataRef, 
     372    boolean autoSwitch, double zval) 
     373  { 
     374    if (autoSwitch && d instanceof FlatField && 
     375      trans instanceof ImageTransform) 
     376    { 
     377      // special case: use ImageTransform's suggested MathType instead 
     378      FlatField ff = (FlatField) d; 
     379      ImageTransform it = (ImageTransform) trans; 
     380      FunctionType ftype = it.getType(); 
     381      Unit[] units = it.getImageUnits(); 
     382      try { 
     383        d = VisUtil.switchType(ff, ftype, units);  
     384 
     385        // wrap image in another field, to assign proper Z value 
     386        RealType zbox = it.getZType(); 
     387        Unit zunit = it.getZUnit(stackAxis); 
     388        Set set = new SingletonSet(new RealTupleType(zbox), 
     389          new double[] {zval}, null, new Unit[] {zunit}, null); 
     390        FieldImpl field = new FieldImpl(new FunctionType(zbox, ftype), set); 
     391        field.setSample(0, d, false); 
     392        d = field; 
     393      } 
     394      catch (VisADException exc) { exc.printStackTrace(); } 
     395      catch (RemoteException exc) { exc.printStackTrace(); } 
     396    } 
     397    try { dataRef.setData(d); } 
     398    catch (VisADException exc) { exc.printStackTrace(); } 
     399    catch (RemoteException exc) { exc.printStackTrace(); } 
     400  } 
     401 
     402 
    367403  // -- Internal TransformLink API methods -- 
    368404 
     
    392428      int xres = it.getImageWidth(); 
    393429      int yres = it.getImageHeight(); 
    394       float zval = stackAxis < 0 ? 0 : 2f * pos[stackAxis] / (len - 1) - 1; 
     430      float zval = stackAxis < 0 ? 0.0f : (float) pos[stackAxis]; 
    395431      float[][] samps = { 
    396432        {0, xres, xres, 0, 0}, 
     
    403439      Unit[] imageUnits = it.getImageUnits(); 
    404440      Unit[] xyzUnits = {imageUnits[0], imageUnits[1], it.getZUnit(stackAxis)}; 
    405       // CTR START HERE: 
    406       //why isn't this unit assignment orienting the bounding box properly? 
    407441      try { 
    408442        RealTupleType xyz = new RealTupleType(xbox, ybox, zbox); 
     
    456490      Data thumb = th == null ? null : th.getThumb(pos); 
    457491      DataReferenceImpl sliceRef = (DataReferenceImpl) references.elementAt(s); 
    458       if (thumbs) setData(thumb, sliceRef); 
     492      if (thumbs) setData(thumb, sliceRef, true, s); 
    459493      else { 
    460494        if (!volume || collapse == null) { 
     
    469503        } 
    470504        if (volume) setData(DUMMY, sliceRef, false); 
    471         else setData(slices[s], sliceRef); 
     505        else setData(slices[s], sliceRef, true, s); 
    472506      } 
    473507    } 
     
    494528            // compile slices into a single volume and collapse 
    495529            collapse = VisUtil.collapse( 
    496               VisUtil.makeField(slices, zType, -1, 1)); 
     530              VisUtil.makeField(slices, zType, 0, len - 1)); 
    497531            cache.putData(trans, pos, "collapse", collapse); 
    498532          } 
     
    558592    double[] domain = VisUtil.cursorToDomain(display, 
    559593      new RealType[] {xType, yType, zType}, cur); 
     594    // CTR START HERE - 
     595    // 1) This cursor probe is wrong when micron values are specified. 
     596    // 2) Then, make aspect ratio automatically match micron values if present.  
     597    // 3) Fix derivative data objects (arbitrary slice, etc.) to work properly. 
     598    // 4) Test state logic a bit more. 
     599    // 5) Release! 
    560600 
    561601    // determine which slice to probe 
    562602    int index = -1; 
    563603    int len = references.size(); 
    564     if (len > 1) { 
    565       double zpos = Math.round((domain[2] + 1) * (len - 1) / 2.0); 
    566       if (zpos >= 0 && zpos < len) index = (int) zpos; 
    567     } 
    568     else if (len == 1 && Math.round(domain[2]) == 0.0) index = 0; 
     604    double zpos = Math.round(domain[2]); 
     605    if (zpos >= 0 && zpos < len) index = (int) zpos; 
    569606    if (index < 0) return; 
    570607 
     
    574611    // get data at appropriate slice 
    575612    Data data = sliceRef.getData(); 
     613 
     614    // unwrap data 
     615    if (data instanceof FieldImpl) { 
     616      try { data = ((FieldImpl) data).getSample(0); } 
     617      catch (VisADException exc) { return; } 
     618      catch (RemoteException exc) { return; } 
     619    } 
    576620    if (!(data instanceof FunctionImpl)) return; 
    577621    FunctionImpl func = (FunctionImpl) data; 
Note: See TracChangeset for help on using the changeset viewer.