Search in sources :

Example 1 with BooleanHolder

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

the class SurfaceMeshIntersector method createContourVertices.

/**
 * Creates mesh vertices corresponding to each contour intersection point in
 * a ContactInfo structure. These vertices can then be used in the formation
 * of a CSG mesh associated with the intersection. The vertex associated
 * with each intersection point is stored in the point's
 * <code>myVertex</code> field. A single common vertex is created for points
 * which are very close together. Also, for points which are very close to
 * an original vertex on one of the intersecting meshes, the newly created
 * vertex is projected onto the original vertex and an association from the
 * original to the new vertex is recorded in a vertex-vertex
 * <code>HashMap</code> which is returned by this method. Other new vertices
 * which are not associated with original vertices are stored in the
 * argument <code>contourVtxs</code>.
 */
private HashMap<Vertex3d, Vertex3d> createContourVertices(ArrayList<IntersectionContour> contours, ArrayList<Vertex3d> contourVtxs) {
    // Create vertices for each contour ...
    boolean debug = false;
    LinkedHashMap<Vertex3d, Vertex3d> vertexMap = new LinkedHashMap<Vertex3d, Vertex3d>();
    for (IntersectionContour c : contours) {
        IntersectionPoint mip = c.get(0);
        if (c.isClosed()) {
            // If the contour is closed, back up until we find a point whose
            // preceeding point is *not* coincident. There must be such a
            // point, because otherwise the contour would consist of a single
            // set of coincident points and would have been eliminated.
            mip = backupToNonCoincident(c.get(0));
        // IntersectionPoint prev = mip.prev();
        // if (prev.distance (mip0) <= myPositionTol) {
        // do {
        // mip = prev;
        // prev = mip.prev();
        // }
        // while (prev.distance (mip0) <= myPositionTol && mip != mip0);
        // }
        }
        // Create a new vertex at the starting intersection point.
        BooleanHolder vtxIsCoincident = new BooleanHolder();
        Vertex3d newVtx = createNewVertex(mip, vertexMap, vtxIsCoincident);
        if (!vtxIsCoincident.value) {
            contourVtxs.add(newVtx);
        }
        mip.myVertex = newVtx;
        mip.effectiveFace0 = c.findSegmentFace(mip, myMesh0);
        mip.effectiveFace1 = c.findSegmentFace(mip, myMesh1);
        mip.nearEdge0 = null;
        mip.nearEdge1 = null;
        mip.clearEmptyMarks();
        for (int i = 1; i < c.size(); i++) {
            mip = mip.next();
            // Question: do we want to cluster based on lastp, or newVtx.pnt?
            if (mip.distance(newVtx.pnt) > myPositionTol) {
                if (debug) {
                    System.out.println("mip " + mip.contourIndex + " new vertex");
                }
                newVtx = createNewVertex(mip, vertexMap, vtxIsCoincident);
                if (!vtxIsCoincident.value) {
                    contourVtxs.add(newVtx);
                }
            } else {
                if (debug) {
                    System.out.println("mip " + mip.contourIndex + " old vertex");
                }
                if (vtxIsCoincident.value) {
                    mapCoincidentVertices(mip, newVtx, vertexMap);
                }
            }
            mip.myVertex = newVtx;
            mip.effectiveFace0 = c.findSegmentFace(mip, myMesh0);
            mip.effectiveFace1 = c.findSegmentFace(mip, myMesh1);
            mip.nearEdge0 = null;
            mip.nearEdge1 = null;
            mip.clearEmptyMarks();
        }
    }
    return vertexMap;
}
Also used : IntersectionPoint(maspack.collision.IntersectionPoint) BooleanHolder(maspack.util.BooleanHolder) IntersectionPoint(maspack.collision.IntersectionPoint)

Example 2 with BooleanHolder

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

the class IntegerIntervalField method textToValue.

@Override
public Object textToValue(String[] text, boolean[] corrected, StringHolder errMsg) {
    IntegerInterval tmp = new IntegerInterval();
    BooleanHolder clipped = new BooleanHolder();
    if (LabeledTextField.isBlank(text[0]) || LabeledTextField.isBlank(text[1])) {
        return setVoidIfPossible(errMsg);
    }
    try {
        tmp.setLowerBound(IntegerField.parseInt(text[0], clipped));
        corrected[0] = clipped.value;
    } catch (Exception e) {
        return illegalValue("Improperly formed number for minimum", errMsg);
    }
    try {
        tmp.setUpperBound(IntegerField.parseInt(text[1], clipped));
        corrected[1] = clipped.value;
    } catch (Exception e) {
        return illegalValue("Improperly formed number for maximum", errMsg);
    }
    return validValue(tmp, errMsg);
}
Also used : IntegerInterval(maspack.util.IntegerInterval) BooleanHolder(maspack.util.BooleanHolder) IOException(java.io.IOException)

Example 3 with BooleanHolder

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

the class IntegerMultiField method textToValue.

@Override
public Object textToValue(String[] text, boolean[] corrected, StringHolder errMsg) {
    int[] tmp = new int[myVectorSize];
    BooleanHolder clipped = new BooleanHolder();
    for (int i = 0; i < myVectorSize; i++) {
        if (LabeledTextField.isBlank(text[i])) {
            return setVoidIfPossible(errMsg);
        }
        try {
            tmp[i] = IntegerField.parseInt(text[i], clipped);
            corrected[i] = clipped.value;
        } catch (Exception e) {
            return illegalValue(e.getMessage(), errMsg);
        }
    }
    return validValue(tmp, errMsg);
}
Also used : BooleanHolder(maspack.util.BooleanHolder)

Example 4 with BooleanHolder

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

the class ComponentPropertyField method setValueFromDisplay.

protected void setValueFromDisplay() {
    if (myAlwaysParseText || !myLastText.equals(myTextField.getText()) || (myPropertySelector != null && !((String) (myPropertySelector.getValue())).equals(myLastPropName))) {
        StringHolder errMsg = new StringHolder();
        // we explicitly call fireValueCheckListeners instead of
        // checkValue since textToValue may itself throw an error
        // and we want to handle that in the same way
        BooleanHolder corrected = new BooleanHolder();
        Object value = textToValue(getText(), corrected, null);
        if (value != Property.IllegalValue) {
            value = validateValue(value, errMsg);
        }
        if (value == Property.IllegalValue) {
            focusListenerMasked = true;
            JOptionPane.showMessageDialog(this, errMsg.value, "Error", JOptionPane.ERROR_MESSAGE);
            focusListenerMasked = false;
            myTextField.setText(myLastText);
            updateDisplay();
            myLastEntryAccepted = false;
            return;
        }
        updateValue(value);
        updateDisplay();
    } else {
        setReverseTextBackground(false);
    }
    myLastEntryAccepted = true;
}
Also used : StringHolder(maspack.util.StringHolder) BooleanHolder(maspack.util.BooleanHolder)

Example 5 with BooleanHolder

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

the class ComponentPropertyField method updateDisplay.

/**
 * Override to account for property selector
 */
protected void updateDisplay(boolean forceUpdate) {
    String[] newText = null;
    Object value = getInternalValue();
    BooleanHolder corrected = new BooleanHolder();
    if (value == Property.VoidValue) {
        newText = new String[] { "", "" };
    } else {
        Object textValue = textToValue(getText(), corrected, null);
        if (forceUpdate || textValue == Property.IllegalValue || corrected.value || !valuesEqual(textValue, value)) {
            // update
            newText = valueToTextArray(value);
        }
    }
    if (newText != null) {
        myLastText = newText[0];
        myTextField.setText(newText[0]);
        if (myPropertiesAllowed) {
            myPropertyMask = true;
            myLastPropName = newText[1];
            if ("".equals(newText[1])) {
                myPropertySelector.setValue(nullString);
            } else {
                myPropertySelector.setValue(newText[1]);
            }
            myPropertyMask = false;
        } else {
            if (newText[1] != null && !"".equals(newText[1])) {
                myLastText = newText[0] + ":" + newText[1];
                myTextField.setText(myLastText);
            }
        }
    } else {
        myLastText = myTextField.getText();
        if (myPropertySelector != null) {
            String propValue = (String) (myPropertySelector.getValue());
            myLastPropName = propValue;
        }
    }
    setReverseTextBackground(false);
}
Also used : BooleanHolder(maspack.util.BooleanHolder)

Aggregations

BooleanHolder (maspack.util.BooleanHolder)5 IOException (java.io.IOException)1 IntersectionPoint (maspack.collision.IntersectionPoint)1 IntegerInterval (maspack.util.IntegerInterval)1 StringHolder (maspack.util.StringHolder)1