/**
   * Set <CODE>Vector</CODE> of <CODE>String</CODE>s describing the cursor location from the cursor
   * location; this is invoked when the cursor location changes or the cursor display status changes
   */
  public void setCursorStringVector() {
    synchronized (cursorStringVector) {
      cursorStringVector.removeAllElements();
      float[][] cursor = new float[3][1];
      double[] cur = getCursor();
      cursor[0][0] = (float) cur[0];
      cursor[1][0] = (float) cur[1];
      cursor[2][0] = (float) cur[2];
      Enumeration maps = display.getMapVector().elements();
      while (maps.hasMoreElements()) {
        try {
          ScalarMap map = (ScalarMap) maps.nextElement();
          DisplayRealType dreal = map.getDisplayScalar();
          DisplayTupleType tuple = dreal.getTuple();
          int index = dreal.getTupleIndex();
          if (tuple != null
              && (tuple.equals(Display.DisplaySpatialCartesianTuple)
                  || (tuple.getCoordinateSystem() != null
                      && tuple
                          .getCoordinateSystem()
                          .getReference()
                          .equals(Display.DisplaySpatialCartesianTuple)))) {
            float[] fval = new float[1];
            if (tuple.equals(Display.DisplaySpatialCartesianTuple)) {
              fval[0] = cursor[index][0];
            } else {
              float[][] new_cursor = tuple.getCoordinateSystem().fromReference(cursor);
              fval[0] = new_cursor[index][0];
            }
            float[] dval = map.inverseScaleValues(fval);
            RealType real = (RealType) map.getScalar();

            // WLH 31 Aug 2000
            Real r = new Real(real, dval[0]);
            Unit overrideUnit = map.getOverrideUnit();
            Unit rtunit = real.getDefaultUnit();
            // units not part of Time string
            // DRM 2003-08-19: don't check for equality since toString
            // may be different
            if (overrideUnit != null
                && // !overrideUnit.equals(rtunit) &&
                (!Unit.canConvert(rtunit, CommonUnit.secondsSinceTheEpoch)
                    || rtunit.getAbsoluteUnit().equals(rtunit))) {
              dval[0] = (float) overrideUnit.toThis((double) dval[0], rtunit);
              r = new Real(real, dval[0], overrideUnit);
            }
            String valueString = r.toValueString();

            // WLH 27 Oct 2000
            String s = map.getScalarName() + " = " + valueString;
            // String s = real.getName() + " = " + valueString;

            cursorStringVector.addElement(s);
          } // end if (tuple != null && ...)
        } catch (VisADException e) {
        }
      } // end while(maps.hasMoreElements())
    } // end synchronized (cursorStringVector)
    render_trigger();
  }
Exemple #2
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((x == null) ? 0 : x.hashCode());
   result = prime * result + ((y == null) ? 0 : y.hashCode());
   result = prime * result + ((z == null) ? 0 : z.hashCode());
   return result;
 }
Exemple #3
0
  /**
   * Does the pattern match the given value
   *
   * @param value value to check
   * @return Pattern matches value
   */
  public boolean match(Data value) throws Exception {
    if (value instanceof Real && isNumericRange()) {
      Real[] range = getNumericRange();
      Real r = (Real) value;
      if (r.__ge__(range[0]) == 0) return false;
      if (r.__le__(range[1]) == 0) return false;
      return true;
    }

    String stringValue = value.toString();
    return StringUtil.stringMatch(stringValue, pattern, true, true);
  }
Exemple #4
0
 /** evaluate the bracket function; e.g., A1[5] or A1[A2] */
 public static Data brackets(visad.Field f, Real r) {
   Data value = null;
   try {
     RealType rt = (RealType) r.getType();
     value = f.getSample((int) r.getValue());
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return value;
 }
  public AbstractNode F() throws IOException {
    AbstractNode abstractNode = null;
    if (look.tag == '(') {
      match('(');
      abstractNode = E();
      match(')');
    } else if (look.tag == Tag.ID) {
      Id word = (Id) look;
      String workLex = word.lexeme;
      stackMachine.postfixTokenStack.push(word);
      match(Tag.ID);
      abstractNode =
          threeAddressCodeGenerator.insertAndGetLeaf(
              word); // insert leaf to  processed symbols if not exists
      postFix.append(workLex);
      // System.out.print(workLex);

    } else if (look.tag == Tag.NUM) {
      Num num = (Num) look;
      String IntNum = num.tostring();
      match(Tag.NUM);
      stackMachine.postfixTokenStack.push(num);
      abstractNode =
          threeAddressCodeGenerator.insertAndGetLeaf(
              num); // insert leaf to  processed symbols if not exists
      postFix.append(IntNum);
      // System.out.print(IntNum);
    } else if (look.tag == Tag.FLOAT) {
      Real real = (Real) look;
      String floatNum = real.tostring();
      match(Tag.FLOAT);
      stackMachine.postfixTokenStack.push(real);
      abstractNode =
          threeAddressCodeGenerator.insertAndGetLeaf(
              real); // insert leaf to  processed symbols if not exists
      postFix.append(floatNum);
      // System.out.print(floatNum);
    } else if (skipId != null && skipFlag == 1) {
      Id word = (Id) skipId;
      String workLex = word.lexeme;
      stackMachine.postfixTokenStack.push(word);
      match(Tag.ID);
      abstractNode =
          threeAddressCodeGenerator.insertAndGetLeaf(
              word); // insert leaf to  processed symbols if not exists
      postFix.append(workLex);
      skipId = null;
      // System.out.print(workLex);
    } else {
      throw new Error("Syntax Error");
    }
    return abstractNode;
  }
Exemple #6
0
  @Override
  public Response serve() {
    Frame fr = DKV.get(data_key.value()).get();
    if (fr == null) return RequestServer._http404.serve();
    // Build a frame with the selected Vecs
    Frame fr2 = new Frame(new String[0], new Vec[0]);
    int[] idxs = vecs.value();
    for (int idx : idxs) // The selected frame columns
    fr2.add(fr._names[idx], fr._vecs[idx]);
    // Add the class-vec last
    Vec cvec = class_vec.value();
    fr2.add(fr._names[class_vec._colIdx.get()], cvec);
    domain = cvec.domain(); // Class/enum/factor names
    mtrys = features.value() == null ? (int) (Math.sqrt(idxs.length) + 0.5) : features.value();

    DRF drf =
        DRF.start(
            DRF.makeKey(),
            fr2,
            depth.value(),
            ntrees.value(),
            mtrys,
            sample_rate.value(),
            seed.value());

    drf.get(); // Block for result
    cm = drf.cm(); // Get CM result

    return new Response(Response.Status.done, this, -1, -1, null);
  }
 /**
  * Build a {@PListObject} from a string that matches one of the tags defined in {@link Constants}.
  *
  * @param tag
  * @param value can be null if tag equals {@link Constants#TAG_BOOL_FALSE} or {@link
  *     Constants#TAG_BOOL_TRUE}.
  * @throws Exception
  * @todo replace with factory for PListObject
  */
 public PListObject buildObject(java.lang.String tag, java.lang.String value) throws Exception {
   if (null == tag) {
     throw new Exception("Cannot add a child with a null tag to a PList.");
   }
   PListObject ret = null;
   if (tag.equalsIgnoreCase(Constants.TAG_INTEGER)) {
     ret = new Integer();
     ((Integer) ret).setValue(value);
   } else if (tag.equalsIgnoreCase(Constants.TAG_STRING)) {
     ret = new String();
     ((String) ret).setValue(value);
   } else if (tag.equalsIgnoreCase(Constants.TAG_REAL)) {
     ret = new Real();
     ((Real) ret).setValue(value);
   } else if (tag.equalsIgnoreCase(Constants.TAG_DATE)) {
     ret = new Date();
     ((Date) ret).setValue(value);
   } else if (tag.equalsIgnoreCase(Constants.TAG_BOOL_FALSE)) {
     ret = new False();
   } else if (tag.equalsIgnoreCase(Constants.TAG_BOOL_TRUE)) {
     ret = new True();
   } else if (tag.equalsIgnoreCase(Constants.TAG_DATA)) {
     ret = new Data();
     ((Data) ret).setValue(value.trim(), true);
   } else if (tag.equalsIgnoreCase(Constants.TAG_DICT)) {
     ret = new Dict();
   } else if (tag.equalsIgnoreCase(Constants.TAG_PLIST_ARRAY)) {
     ret = new Array();
   }
   return ret;
 }
Exemple #8
0
  /**
   * The animation changed. Handle the change.
   *
   * @param evt The event
   */
  private void handleAnimationPropertyChange(PropertyChangeEvent evt) {
    //        System.err.println ("Handlechange:" +evt.getPropertyName());
    if (evt.getPropertyName().equals(Animation.ANI_VALUE)) {
      debug("handleAnimationPropertyChange value :" + evt.getPropertyName());
      Real eventValue = (Real) evt.getNewValue();
      // if there's nothing to do, return;
      if ((eventValue == null) || eventValue.isMissing()) {
        return;
      }

      /** The Animation associated with this widget */
      DateTime time = null;
      try {
        time = new DateTime(eventValue);
      } catch (VisADException ve) {;
      }
      final DateTime theDateTime = time;
      final int theIndex = ((anime != null) ? anime.getCurrent() : -1);
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              boolean oldValue = ignoreTimesCbxEvents;
              try {
                ignoreTimesCbxEvents = true;
                //                        synchronized (timesCbxMutex) {
                xcnt++;

                timesCbx.setSelectedItem(theDateTime);
                //                        }
                if ((boxPanel != null) && (theIndex >= 0)) {
                  boxPanel.setOnIndex(theIndex);
                }
                timesCbx.repaint();
              } finally {
                ignoreTimesCbxEvents = oldValue;
              }
            }
          });
      shareValue();
    } else if (evt.getPropertyName().equals(Animation.ANI_SET)) {
      if (ignoreAnimationSetChange) {
        return;
      }
      updateIndicatorInner((Set) evt.getNewValue(), true);
    }
  }
Exemple #9
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (!(obj instanceof DefaultVector)) return false;
   DefaultVector other = (DefaultVector) obj;
   if (x == null) {
     if (other.x != null) return false;
   } else if (!x.equals(other.x)) return false;
   if (y == null) {
     if (other.y != null) return false;
   } else if (!y.equals(other.y)) return false;
   if (z == null) {
     if (other.z != null) return false;
   } else if (!z.equals(other.z)) return false;
   return true;
 }
  @Test
  public void matrixRemove() {
    VectorSpace<Vector<Real>, Real> space = provider.getVectorSpaceOver(RealField.getInstance(), 3);

    Matrix<Real> M = space.matrix(3, 3, Real.valueOf(1, 1, 2, 1, 2, 1, 2, 1, 1));

    M = M.remove(0, 0);

    assertEquals(2, M.rowsCount());
    assertEquals(2, M.columnsCount());

    System.out.println(M);

    assertEquals(Real.valueOf(2), M.get(0, 0));
    assertEquals(Real.valueOf(1), M.get(1, 0));
    assertEquals(Real.valueOf(1), M.get(0, 1));
    assertEquals(Real.valueOf(1), M.get(1, 1));
  }
Exemple #11
0
 /** evaluate the dot operator */
 public static Data dot(TupleIface t, Real r) {
   Data d = null;
   try {
     d = t.getComponent((int) r.getValue());
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return d;
 }
Exemple #12
0
 /** evaluate the extract function */
 public static Data extract(visad.Field f, Real r) {
   Data d = null;
   try {
     d = f.extract((int) r.getValue());
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return d;
 }
  @Test(expected = ArithmeticException.class)
  public void matrixInversNotExists() {
    VectorSpace<Vector<Real>, Real> space = provider.getVectorSpaceOver(RealField.getInstance(), 3);

    Matrix<Real> X =
        space.matrix(
            3,
            3,
            Real.valueOf(
                1, 3, 3, 1, 3, 3, // two equal rows => zero determinant
                1, 3, 4));

    X.inverse();
  }
Exemple #14
0
 /**
  * Add to the properties list
  *
  * @param comps List of label/widgets
  * @param compMap Optional mapping to hold components for later access
  */
 protected void getPropertiesComponents(List comps, Hashtable compMap) {
   super.getPropertiesComponents(comps, compMap);
   startTextFld = new JTextField(startText, 5);
   endTextFld = new JTextField(endText, 5);
   comps.add(GuiUtils.rLabel("Start Label:"));
   comps.add(GuiUtils.left(startTextFld));
   comps.add(GuiUtils.rLabel("End Label:"));
   comps.add(GuiUtils.left(endTextFld));
   maxDistanceFld = null;
   tvm = null;
   if (viewDescriptor != null) {
     VMManager vmManager = control.getControlContext().getIdv().getVMManager();
     List vms = vmManager.getViewManagers(TransectViewManager.class);
     tvm = (TransectViewManager) VMManager.findViewManagerInList(viewDescriptor, vms);
     if ((tvm != null) && (maxDataDistance != null)) {
       maxDistanceFld =
           new JTextField(maxDataDistance.getValue() + " [" + maxDataDistance.getUnit() + "]", 15);
       maxDistanceFld.setToolTipText("Maximum distance shown. e.g.: value[unit]");
       comps.add(GuiUtils.rLabel("Max distance:"));
       comps.add(GuiUtils.left(maxDistanceFld));
     }
   }
 }
Exemple #15
0
 /**
  * Check if we need to show/hide the max data distance box
  *
  * @throws RemoteException On badness
  * @throws VisADException On badness
  */
 public void checkBoxVisibility() throws VisADException, RemoteException {
   if (maxDistanceBox == null) {
     return;
   }
   if ((maxDataDistance == null) || !super.isVisible()) {
     maxDistanceBox.setVisible(false);
   } else {
     double km = maxDataDistance.getValue(CommonUnit.meter) / 1000.0;
     if (km > 2000) {
       maxDistanceBox.setVisible(false);
     } else {
       if (control != null) {
         maxDistanceBox.setVisible(control.shouldBeVisible(this));
       }
     }
   }
 }
  @Test
  public void testNumbers() {

    Real a = Real.valueOf(1.2);
    Real b = Real.valueOf(1.2);
    Real c = Real.valueOf(2.4);

    assertEquals(c, a.plus(b));

    BigInt i = BigInt.valueOf(10);
    BigInt j = BigInt.valueOf(12);

    assertEquals(Real.valueOf(11.2), a.plus(i));
    assertEquals(j, i.times(a));
  }
    public void detectCopyRoots(final VirtualFile[] roots, final boolean clearState) {
      final Getter<Boolean> cancelGetter =
          new Getter<Boolean>() {
            public Boolean get() {
              return myVcs.getProject().isDisposed();
            }
          };

      for (final VirtualFile vcsRoot : roots) {
        final List<Real> foundRoots =
            ForNestedRootChecker.getAllNestedWorkingCopies(vcsRoot, myVcs, false, cancelGetter);
        if (foundRoots.isEmpty()) {
          myLonelyRoots.add(vcsRoot);
        }
        // filter out bad(?) items
        for (Real foundRoot : foundRoots) {
          final SVNURL repoRoot = foundRoot.getInfo().getRepositoryRootURL();
          if (repoRoot == null) {
            LOG.info(
                "Error: cannot find repository URL for versioned folder: "
                    + foundRoot.getFile().getPath());
          } else {
            myRepositoryRoots.register(repoRoot);
            myTopRoots.add(
                new RootUrlInfo(
                    repoRoot,
                    foundRoot.getInfo().getURL(),
                    SvnFormatSelector.getWorkingCopyFormat(foundRoot.getInfo().getFile()),
                    foundRoot.getFile(),
                    vcsRoot));
          }
        }
      }

      if (!SvnConfiguration.getInstance(myVcs.getProject()).DETECT_NESTED_COPIES) {
        myApplier.apply(myVcs, myTopRoots, myLonelyRoots);
      } else {
        addNestedRoots(clearState);
      }
    }
  public synchronized void drag_direct(VisADRay ray, boolean first, int mouseModifiers) {
    if (barbValues == null || ref == null || shadow == null) return;

    if (first) {
      stop = false;
    } else {
      if (stop) return;
    }

    // modify direction if mshift != 0
    // modify speed if mctrl != 0
    // modify speed and direction if neither
    int mshift = mouseModifiers & InputEvent.SHIFT_MASK;
    int mctrl = mouseModifiers & InputEvent.CTRL_MASK;

    float o_x = (float) ray.position[0];
    float o_y = (float) ray.position[1];
    float o_z = (float) ray.position[2];
    float d_x = (float) ray.vector[0];
    float d_y = (float) ray.vector[1];
    float d_z = (float) ray.vector[2];

    if (pickCrawlToCursor) {
      if (first) {
        offset_count = OFFSET_COUNT_INIT;
      } else {
        if (offset_count > 0) offset_count--;
      }
      if (offset_count > 0) {
        float mult = ((float) offset_count) / ((float) OFFSET_COUNT_INIT);
        o_x += mult * offsetx;
        o_y += mult * offsety;
        o_z += mult * offsetz;
      }
    }

    if (first || refirst) {
      point_x = barbValues[2];
      point_y = barbValues[3];
      point_z = 0.0f;
      line_x = 0.0f;
      line_y = 0.0f;
      line_z = 1.0f; // lineAxis == 2 in DataRenderer.drag_direct
    } // end if (first || refirst)

    float[] x = new float[3]; // x marks the spot
    // DirectManifoldDimension = 2
    // intersect ray with plane
    float dot = (point_x - o_x) * line_x + (point_y - o_y) * line_y + (point_z - o_z) * line_z;
    float dot2 = d_x * line_x + d_y * line_y + d_z * line_z;
    if (dot2 == 0.0) return;
    dot = dot / dot2;
    // x is intersection
    x[0] = o_x + dot * d_x;
    x[1] = o_y + dot * d_y;
    x[2] = o_z + dot * d_z;
    /*
    System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
    */
    try {

      Tuple data = (Tuple) link.getData();
      int n = ((TupleType) data.getType()).getNumberOfRealComponents();
      Real[] reals = new Real[n];

      int k = 0;
      int m = data.getDimension();
      for (int i = 0; i < m; i++) {
        Data component = data.getComponent(i);
        if (component instanceof Real) {
          reals[k++] = (Real) component;
        } else if (component instanceof RealTuple) {
          for (int j = 0; j < ((RealTuple) component).getDimension(); j++) {
            reals[k++] = (Real) ((RealTuple) component).getComponent(j);
          }
        }
      }

      if (first || refirst) {
        // get first Data flow vector
        for (int i = 0; i < 3; i++) {
          int j = flowToComponent[i];
          data_flow[i] = (j >= 0) ? (float) reals[j].getValue() : 0.0f;
        }

        if (coord != null) {
          float[][] ds = {{data_flow[0]}, {data_flow[1]}, {data_flow[2]}};
          ds = coord.toReference(ds);
          data_flow[0] = ds[0][0];
          data_flow[1] = ds[1][0];
          data_flow[2] = ds[2][0];
        }

        data_speed =
            (float)
                Math.sqrt(
                    data_flow[0] * data_flow[0]
                        + data_flow[1] * data_flow[1]
                        + data_flow[2] * data_flow[2]);
        float barb0 = barbValues[2] - barbValues[0];
        float barb1 = barbValues[3] - barbValues[1];
        /*
        System.out.println("data_flow = " + data_flow[0] + " " + data_flow[1] +
                           " " + data_flow[2]);
        System.out.println("barbValues = " + barbValues[0] + " " + barbValues[1] +
                           "   " + barbValues[2] + " " + barbValues[3]);
        System.out.println("data_speed = " + data_speed);
        */
      } // end if (first || refirst)

      // convert x to a flow vector, and from spatial to earth
      if (getRealVectorTypes(which_barb) instanceof EarthVectorType) {
        // don't worry about vector magnitude -
        // data_speed & display_speed take care of that
        float eps = 0.0001f; // estimate derivative with a little vector
        float[][] spatial_locs = {
          {barbValues[0], barbValues[0] + eps * (x[0] - barbValues[0])},
          {barbValues[1], barbValues[1] + eps * (x[1] - barbValues[1])},
          {0.0f, 0.0f}
        };
        /*
        System.out.println("spatial_locs = " + spatial_locs[0][0] + " " +
                           spatial_locs[0][1] + " " + spatial_locs[1][0] + " " +
                           spatial_locs[1][1]);
        */
        float[][] earth_locs = spatialToEarth(spatial_locs);
        // WLH - 18 Aug 99
        if (earth_locs == null) return;
        /*
        System.out.println("earth_locs = " + earth_locs[0][0] + " " +
                           earth_locs[0][1] + " " + earth_locs[1][0] + " " +
                           earth_locs[1][1]);
        */
        x[2] = 0.0f;
        x[0] =
            (earth_locs[1][1] - earth_locs[1][0])
                * ((float) Math.cos(Data.DEGREES_TO_RADIANS * earth_locs[0][0]));
        x[1] = earth_locs[0][1] - earth_locs[0][0];
        /*
        System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
        */
      } else { // if (!(getRealVectorTypes(which_barb) instanceof EarthVectorType))
        // convert x to vector
        x[0] -= barbValues[0];
        x[1] -= barbValues[1];

        // adjust for spatial map scalings but don't worry about vector
        // magnitude - data_speed & display_speed take care of that
        // also, spatial is Cartesian
        double[] ranges = getRanges();
        for (int i = 0; i < 3; i++) {
          x[i] /= ranges[i];
        }
        /*
        System.out.println("ranges = " + ranges[0] + " " + ranges[1] +
                           " " + ranges[2]);
        System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
        */
      }

      // WLH 6 August 99
      x[0] = -x[0];
      x[1] = -x[1];
      x[2] = -x[2];

      /* may need to do this for performance
            float[] xx = {x[0], x[1], x[2]};
            addPoint(xx);
      */

      float x_speed = (float) Math.sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
      /* WLH 16 April 2002 - from Ken
            if (x_speed < 0.000001f) x_speed = 0.000001f;
      */
      if (x_speed < 0.01f) x_speed = 0.01f;
      if (first || refirst) {
        display_speed = x_speed;
      }
      refirst = false;

      if (mshift != 0) {
        // only modify data_flow direction
        float ratio = data_speed / x_speed;
        x[0] *= ratio;
        x[1] *= ratio;
        x[2] *= ratio;
        /*
        System.out.println("direction, ratio = " + ratio + " " +
                           data_speed + " " + x_speed);
        System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
        */
      } else if (mctrl != 0) {
        // only modify data_flow speed
        float ratio = x_speed / display_speed;
        if (data_speed < EPS) {
          data_flow[0] = 2.0f * EPS;
          refirst = true;
        }
        x[0] = ratio * data_flow[0];
        x[1] = ratio * data_flow[1];
        x[2] = ratio * data_flow[2];
        /*
        System.out.println("speed, ratio = " + ratio + " " +
                           x_speed + " " + display_speed);
        System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
        */
      } else {
        // modify data_flow speed and direction
        float ratio = data_speed / display_speed;
        /*
        System.out.println("data_speed = " + data_speed +
                           " display_speed = " + display_speed +
                           " ratio = " + ratio + " EPS = " + EPS);
        System.out.println("x = " + x[0] + " " + x[1] +" " + x[2] +
                           " x_speed = " + x_speed);
          data_speed = 21.213203 display_speed = 0.01 ratio = 2121.3203 EPS = 0.2
          x = 1.6170928E-4 1.6021729E-4 -0.0 x_speed = 0.01
          wind = (0.3430372, 0.33987218) at (-35.0, 5.0)
        */
        if (data_speed < EPS) {
          data_flow[0] = 2.0f * EPS;
          x[0] = data_flow[0];
          x[1] = data_flow[1];
          x[2] = data_flow[2];
          refirst = true;
        } else {
          x[0] *= ratio;
          x[1] *= ratio;
          x[2] *= ratio;
        }
      }

      if (coord != null) {
        float[][] xs = {{x[0]}, {x[1]}, {x[2]}};
        xs = coord.fromReference(xs);
        x[0] = xs[0][0];
        x[1] = xs[1][0];
        x[2] = xs[2][0];
      }

      // now replace flow values
      Vector vect = new Vector();
      for (int i = 0; i < 3; i++) {
        int j = flowToComponent[i];
        if (j >= 0) {
          RealType rtype = (RealType) reals[j].getType();
          reals[j] = new Real(rtype, (double) x[i], rtype.getDefaultUnit(), null);

          // WLH 31 Aug 2000
          Real r = reals[j];
          Unit overrideUnit = null;
          if (directMap[i] != null) {
            overrideUnit = directMap[i].getOverrideUnit();
          }
          Unit rtunit = rtype.getDefaultUnit();
          // units not part of Time string
          if (overrideUnit != null
              && !overrideUnit.equals(rtunit)
              && !RealType.Time.equals(rtype)) {
            double d = (float) overrideUnit.toThis((double) x[0], rtunit);
            r = new Real(rtype, d, overrideUnit);
            String valueString = r.toValueString();
            vect.addElement(rtype.getName() + " = " + valueString);
          } else {
            // create location string
            vect.addElement(rtype.getName() + " = " + x[i]);
          }
        }
      }
      getDisplayRenderer().setCursorStringVector(vect);

      Data newData = null;
      // now build new RealTuple or Flat Tuple
      if (data instanceof RealTuple) {
        newData =
            new RealTuple(
                ((RealTupleType) data.getType()), reals, ((RealTuple) data).getCoordinateSystem());
      } else {
        Data[] new_components = new Data[m];
        k = 0;
        for (int i = 0; i < m; i++) {
          Data component = data.getComponent(i);
          if (component instanceof Real) {
            new_components[i] = reals[k++];
          } else if (component instanceof RealTuple) {
            Real[] sub_reals = new Real[((RealTuple) component).getDimension()];
            for (int j = 0; j < ((RealTuple) component).getDimension(); j++) {
              sub_reals[j] = reals[k++];
            }
            new_components[i] =
                new RealTuple(
                    ((RealTupleType) component.getType()),
                    sub_reals,
                    ((RealTuple) component).getCoordinateSystem());
          }
        }
        newData = new Tuple(new_components, false);
      }
      ref.setData(newData);
    } catch (VisADException e) {
      // do nothing
      System.out.println("drag_direct " + e);
      e.printStackTrace();
    } catch (RemoteException e) {
      // do nothing
      System.out.println("drag_direct " + e);
      e.printStackTrace();
    }
  }
Exemple #19
0
 public static Vector of(double x, double y, double z) {
   return of(Real.of(x), Real.of(y), Real.of(z));
 }
  @Test
  public void matrixLU() {
    VectorSpace<Vector<Real>, Real> space = provider.getVectorSpaceOver(RealField.getInstance(), 3);

    // http://en.wikipedia.org/wiki/LU_decomposition
    Matrix<Real> A =
        space.matrix(
            2,
            2,
            Real.valueOf(
                4, 3,
                6, 3));

    Matrix<Real> U = space.matrix(2, 2, Real.valueOf(4, 3, 0, -1.5));

    Matrix<Real> L = space.matrix(2, 2, Real.valueOf(1, 0, 1.5, 1));

    LuDecomposition<Real> lud = LuDecomposition.decompose(A);

    assertEquals("Incorrect 2x2 L", L, lud.getL());
    assertEquals("Incorrect 2x2 U", U, lud.getU());

    assertEquals(A, L.times(U));
    assertEquals(A, lud.getL().times(lud.getU()));

    A = space.matrix(3, 3, Real.valueOf(6, -2, 0, 9, -1, 1, 3, 7, 5));

    U =
        space.matrix(
            3,
            3,
            new Real[] {
              Real.valueOf(6), Real.valueOf(-2), Real.valueOf(0),
              Real.valueOf(0), Real.valueOf(2), Real.valueOf(1),
              Real.valueOf(0), Real.valueOf(0), Real.valueOf(1)
            });

    L =
        space.matrix(
            3,
            3,
            new Real[] {
              Real.valueOf(1), Real.valueOf(0), Real.valueOf(0),
              Real.valueOf(3, 2), Real.valueOf(1), Real.valueOf(0),
              Real.valueOf(1, 2), Real.valueOf(4), Real.valueOf(1)
            });

    assertEquals("wrong test data", A, L.times(U));

    lud = LuDecomposition.decompose(A);

    assertEquals("Incorrect decomposition product", A, lud.getL().times(lud.getU()));

    assertEquals("Incorrect 3x3 L", L, lud.getL());
    assertEquals("Incorrect 3x3 U", U, lud.getU());

    Matrix<Real> N = space.matrix(3, 3, Real.valueOf(1, 1, 2, 1, 2, 1, 2, 1, 1));

    lud = LuDecomposition.decompose(N);

    assertEquals(N, lud.getL().times(lud.getU()));
  }
  @Test
  public void matrix() {

    VectorSpace<Vector<Real>, Real> space = provider.getVectorSpaceOver(RealField.getInstance(), 3);

    //		Vector<Real> v1 = space.vector(1,1,2);
    //		Vector<Real> v2 = space.vector(1,2,1);
    //		Vector<Real> v3 = space.vector(2,1,1);

    Matrix<Real> M = space.matrix(3, 3, Real.valueOf(1, 1, 2, 1, 2, 1, 2, 1, 1));

    Vector<Real> v4 = space.vector(2, 2, 4);
    //		Vector<Real> v5 = space.vector(2,4,2);
    //		Vector<Real> v6 = space.vector(4,2,2);

    Matrix<Real> N = space.matrix(3, 3, Real.valueOf(2, 2, 4, 2, 4, 2, 4, 2, 2));

    // determinant
    Real det = M.determinant();

    assertEquals(Real.valueOf(-4), det);

    assertEquals(Real.valueOf(4), M.trace());

    // transpose
    assertEquals(M, M.transpose());

    // multiplication
    assertEquals(N, M.times(Real.valueOf(2.0)));

    // addition
    assertEquals(N, M.plus(M));

    // vector x matrix
    Vector<Real> v7 = space.vector(12, 10, 10);
    assertEquals(v7, M.rightTimes(v4));

    // Matrix equality
    Matrix<Real> P = space.matrix(3, 3, Real.valueOf(1, 1, 2, 1, 2, 1, 2, 1, 1));
    assertEquals(M, P);

    // Matrix multiplication
    Matrix<Real> Q = space.matrix(3, 3, Real.valueOf(12, 10, 10, 10, 12, 10, 10, 10, 12));
    assertEquals(Q, M.times(N));

    // Adjoint
    Matrix<Real> A = space.matrix(3, 3, Real.valueOf(1, 1, -3, 1, -3, 1, -3, 1, 1));
    assertEquals(A, M.adjoint());

    // Identity Multiplication
    Matrix<Real> I = space.identity(3);
    assertEquals(I, I.times(I));

    assertEquals(I.getRow(1), I.getColumn(1));

    Matrix<Real> X = space.matrix(3, 3, Real.valueOf(1, 3, 3, 1, 4, 3, 1, 3, 4));

    // Identity relation M  = M.I and M = I.M
    assertEquals(X, X.times(I));
    assertEquals(X, I.times(X));

    Matrix<Real> XInv = space.matrix(3, 3, Real.valueOf(7, -3, -3, -1, 1, 0, -1, 0, 1));

    // inverse
    assertEquals(XInv, X.inverse());

    // Invertion relation I = M.M^-1
    assertEquals(I, X.times(X.inverse()));

    // transpose of the transpose is it self

    assertTrue(M == M.transpose().transpose());
  }
Exemple #22
0
  /**
   * Handle glyph moved
   *
   * @throws RemoteException On badness
   * @throws VisADException On badness
   */
  public void updateLocation() throws VisADException, RemoteException {
    super.updateLocation();
    if (points.size() < 2) {
      return;
    }
    if (showText) {
      setText(startTextDisplayable, 0, startText, startTextType);
      setText(endTextDisplayable, 1, endText, endTextType);
    }

    checkBoxVisibility();
    if ((maxDataDistance == null) || (maxDistanceBox == null)) {
      return;
    }
    double km = maxDataDistance.getValue(CommonUnit.meter) / 1000.0;
    if (km > 2000) {
      return;
    }

    EarthLocation p1 = (EarthLocation) points.get(0);
    EarthLocation p2 = (EarthLocation) points.get(1);

    MathType mathType = RealTupleType.LatitudeLongitudeAltitude;

    Bearing baseBearing =
        Bearing.calculateBearing(
            p1.getLatitude().getValue(),
            p1.getLongitude().getValue(),
            p2.getLatitude().getValue(),
            p2.getLongitude().getValue(),
            null);

    double baseAngle = baseBearing.getAngle();

    LatLonPointImpl[] llps =
        new LatLonPointImpl[] {
          Bearing.findPoint(
              p1.getLatitude().getValue(),
              p1.getLongitude().getValue(),
              baseAngle + 90.0,
              km,
              null),
          Bearing.findPoint(
              p2.getLatitude().getValue(),
              p2.getLongitude().getValue(),
              baseAngle + 90.0,
              km,
              null),
          Bearing.findPoint(
              p2.getLatitude().getValue(), p2.getLongitude().getValue(), baseAngle - 90, km, null),
          Bearing.findPoint(
              p1.getLatitude().getValue(), p1.getLongitude().getValue(), baseAngle - 90, km, null),
          Bearing.findPoint(
              p1.getLatitude().getValue(), p1.getLongitude().getValue(), baseAngle + 90.0, km, null)
        };

    float[][] lineVals = getPointValues();
    float alt = lineVals[2][0];
    lineVals = new float[3][llps.length];
    for (int i = 0; i < lineVals[0].length; i++) {
      lineVals[0][i] = (float) llps[i].getLatitude();
      lineVals[1][i] = (float) llps[i].getLongitude();
    }

    float[][] tmp = new float[3][];

    for (int i = 0; i < lineVals[0].length - 1; i++) {
      tmp[0] =
          Misc.merge(
              tmp[0],
              Misc.interpolate(
                  2 + getNumInterpolationPoints(), lineVals[0][i], lineVals[0][i + 1]));
      tmp[1] =
          Misc.merge(
              tmp[1],
              Misc.interpolate(
                  2 + getNumInterpolationPoints(), lineVals[1][i], lineVals[1][i + 1]));
    }

    tmp[2] = new float[tmp[0].length];
    lineVals = tmp;

    for (int i = 0; i < lineVals[0].length; i++) {
      lineVals[2][i] = alt;
    }

    Data theData = new Gridded3DSet(mathType, lineVals, lineVals[0].length);
    maxDistanceBox.setData(theData);
  }