Search in sources :

Example 1 with DoubleInterval

use of maspack.util.DoubleInterval in project artisynth_core by artisynth.

the class FemBeamColored method prerender.

@Override
public void prerender(RenderList list) {
    // Synchronize color bar/values in case they are changed
    ColorBar cbar = (ColorBar) (renderables().get("colorBar"));
    cbar.setColorMap(fem.getColorMap());
    DoubleInterval range = fem.getStressPlotRange();
    cbar.updateLabels(range.getLowerBound(), range.getUpperBound());
    super.prerender(list);
}
Also used : DoubleInterval(maspack.util.DoubleInterval) ColorBar(artisynth.core.renderables.ColorBar)

Example 2 with DoubleInterval

use of maspack.util.DoubleInterval in project artisynth_core by artisynth.

the class HueColorMap method setHueRange.

/**
 * Sets the hue range.  Normally, these values are in the range
 * [0, 1]; however, the hues support wrapping.  If maxHue is less
 * than minHue, colors will be interpolated backwards.
 * <p>
 * Examples:<br>
 * [0, 1/6] will interpolate from red to yellow <br>
 * [1/6, 0] will interpolate from yellow to red <br>
 * [5/6, 7/6] will interpolate from violet to yellow <br>
 */
public void setHueRange(double minHue, double maxHue) {
    myMinHue = minHue;
    myMaxHue = maxHue;
    if (myHueRange == null) {
        myHueRange = new DoubleInterval();
    }
    myHueRange.set(minHue, maxHue);
}
Also used : DoubleInterval(maspack.util.DoubleInterval)

Example 3 with DoubleInterval

use of maspack.util.DoubleInterval in project artisynth_core by artisynth.

the class SetHandler method getNumericRange.

public static NumericInterval getNumericRange(Property prop) {
    NumericInterval nrange = null;
    PropertyInfo info = prop.getInfo();
    if (info.isReadOnly()) {
        return null;
    }
    Class<?> type = info.getValueClass();
    if (type == double.class || type == float.class || type == Double.class || type == Float.class) {
        Object value = prop.get();
        // i.e., if the value is not Void
        if (value instanceof Number) {
            double x = ((Number) value).doubleValue();
            if (info.hasRestrictedRange()) {
                Range range = prop.getRange();
                NumericInterval defaultRange = info.getDefaultNumericRange();
                if (range instanceof NumericInterval) {
                    nrange = new DoubleInterval((NumericInterval) range);
                    if (!nrange.isBounded()) {
                        if (defaultRange != null) {
                            nrange.intersect(defaultRange);
                        }
                    }
                    nrange = SliderRange.estimateBoundsIfNecessary(nrange, x);
                } else if (defaultRange != null) {
                    nrange = SliderRange.estimateBoundsIfNecessary(defaultRange, x);
                }
            }
            if (nrange == null) {
                // try to calculate range a from the value
                if (x == -1) {
                    nrange = new DoubleInterval(-1, 1);
                } else {
                    // interval is unbounded
                    nrange = new DoubleInterval();
                    nrange = SliderRange.estimateBoundsIfNecessary(nrange, x);
                }
            }
        }
    } else if (type == int.class || type == Integer.class) {
        Object value = prop.get();
        // i.e., if the value is not Void
        if (value instanceof Number) {
            int x = ((Number) value).intValue();
            if (info.hasRestrictedRange()) {
                Range range = prop.getRange();
                NumericInterval defaultRange = info.getDefaultNumericRange();
                if (range instanceof NumericInterval) {
                    nrange = new IntegerInterval((NumericInterval) range);
                    if (!nrange.isBounded()) {
                        if (defaultRange != null) {
                            nrange.intersect(defaultRange);
                        }
                    }
                    nrange = SliderRange.estimateBoundsIfNecessary(nrange, x);
                } else if (defaultRange != null) {
                    nrange = SliderRange.estimateBoundsIfNecessary(defaultRange, x);
                }
            }
        }
    }
    return nrange;
}
Also used : IntegerInterval(maspack.util.IntegerInterval) DoubleInterval(maspack.util.DoubleInterval) PropertyInfo(maspack.properties.PropertyInfo) EnumRange(maspack.util.EnumRange) StringRange(maspack.util.StringRange) Range(maspack.util.Range) NumericInterval(maspack.util.NumericInterval)

Example 4 with DoubleInterval

use of maspack.util.DoubleInterval in project artisynth_core by artisynth.

the class DoubleFieldSlider method updateInternalValue.

protected boolean updateInternalValue(Object value) {
    if (super.updateInternalValue(value)) {
        if (value instanceof Number && mySliderRange != null) {
            double newValue = ((Number) value).doubleValue();
            int sliderValue = toSliderValue(newValue);
            int halfPixel = halfPixelValue();
            if (myAutoRangingP) {
                double max = mySliderRange.getUpperBound();
                double min = mySliderRange.getLowerBound();
                // adjust the upper or lower slider bounds, if necessary
                DoubleInterval newRange = null;
                if (newValue > max) {
                    newRange = new DoubleInterval(min, newValue);
                } else if (newValue < min) {
                    newRange = new DoubleInterval(newValue, max);
                }
                if (newRange != null) {
                    newRange = SliderRange.roundBoundsTo125(newRange);
                    // make sure hard range OK
                    newRange.intersect(getRange());
                    setSliderRange(newRange);
                }
                // and if this widget does not have hard bounds
                if (!myRange.isBounded() && mySlider != null) {
                    if (sliderValue < halfPixel && newValue > min) {
                        double newMax = SliderRange.roundUp125(min + 4 * (newValue - min));
                        setSliderRange(new DoubleInterval(min, newMax));
                    }
                }
            }
            if (sliderValue < -halfPixel || sliderValue > SLIDER_INTERNAL_RANGE + halfPixel) {
                mySlider.setBackground(Color.GRAY);
            } else {
                mySlider.setBackground(null);
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : DoubleInterval(maspack.util.DoubleInterval)

Example 5 with DoubleInterval

use of maspack.util.DoubleInterval in project artisynth_core by artisynth.

the class DoubleIntervalField method textToValue.

@Override
public Object textToValue(String[] text, boolean[] corrected, StringHolder errMsg) {
    DoubleInterval tmp = new DoubleInterval();
    if ((LabeledTextField.isBlank(text[0]) || LabeledTextField.isBlank(text[1]))) {
        return setVoidIfPossible(errMsg);
    }
    try {
        tmp.setLowerBound(DoubleField.parseDouble(text[0]));
        corrected[0] = false;
    } catch (Exception e) {
        return illegalValue("Improperly formed number for minimum", errMsg);
    }
    try {
        tmp.setUpperBound(DoubleField.parseDouble(text[1]));
        corrected[1] = false;
    } catch (Exception e) {
        return illegalValue("Improperly formed number for maximum", errMsg);
    }
    return validValue(tmp, errMsg);
}
Also used : DoubleInterval(maspack.util.DoubleInterval)

Aggregations

DoubleInterval (maspack.util.DoubleInterval)22 NumericInterval (maspack.util.NumericInterval)3 Property (maspack.properties.Property)2 IntegerInterval (maspack.util.IntegerInterval)2 BooleanSelector (maspack.widgets.BooleanSelector)2 DoubleIntervalField (maspack.widgets.DoubleIntervalField)2 AddComponentsCommand (artisynth.core.gui.editorManager.AddComponentsCommand)1 PropertyField (artisynth.core.gui.widgets.PropertyField)1 Point (artisynth.core.mechmodels.Point)1 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)1 NumericProbeVariable (artisynth.core.probes.NumericProbeVariable)1 ColorBar (artisynth.core.renderables.ColorBar)1 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 BoxLayout (javax.swing.BoxLayout)1