Search in sources :

Example 1 with SetBooleanValuesOperation

use of au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation in project constellation by constellation-app.

the class BoxSelectionPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final float mix = camera.getMix();
    final float inverseMix = 1.0F - mix;
    final Vector3f centre = new Vector3f(camera.lookAtCentre);
    final float left = box[0];
    final float right = box[1];
    final float top = box[2];
    final float bottom = box[3];
    // Look up all the required attributes.
    int xAttr = VisualConcept.VertexAttribute.X.get(graph);
    int yAttr = VisualConcept.VertexAttribute.Y.get(graph);
    int zAttr = VisualConcept.VertexAttribute.Z.get(graph);
    final int x2Attr = VisualConcept.VertexAttribute.X2.get(graph);
    final int y2Attr = VisualConcept.VertexAttribute.Y2.get(graph);
    final int z2Attr = VisualConcept.VertexAttribute.Z2.get(graph);
    final int vxSelectedAttr = VisualConcept.VertexAttribute.SELECTED.get(graph);
    final int txSelectedAttr = VisualConcept.TransactionAttribute.SELECTED.get(graph);
    final int vxVisibilityAttr = VisualConcept.VertexAttribute.VISIBILITY.get(graph);
    final int txVisibilityAttr = VisualConcept.TransactionAttribute.VISIBILITY.get(graph);
    final SetBooleanValuesOperation selectVerticesOperation = new SetBooleanValuesOperation(graph, GraphElementType.VERTEX, vxSelectedAttr);
    final SetBooleanValuesOperation selectTransactionsOperation = new SetBooleanValuesOperation(graph, GraphElementType.TRANSACTION, txSelectedAttr);
    final float visibilityHigh = camera.getVisibilityHigh();
    final float visibilityLow = camera.getVisibilityLow();
    // Get a copy of the current rotation matrix.
    final Vector3f diff = Vector3f.subtract(camera.lookAtEye, camera.lookAtCentre);
    final float cameraDistance = diff.getLength();
    // Get the inverse eye rotation to match the object frame rotation.
    final Frame frame = new Frame(camera.lookAtEye, camera.lookAtCentre, camera.lookAtUp);
    final Matrix44f objectFrameMatrix = new Matrix44f();
    frame.getMatrix(objectFrameMatrix, true);
    final Matrix44f rotationMatrixt = new Matrix44f();
    objectFrameMatrix.getRotationMatrix(rotationMatrixt);
    final Matrix44f rotationMatrixti = new Matrix44f();
    rotationMatrixti.invert(rotationMatrixt);
    final Matrix33f rotationMatrix = new Matrix33f();
    rotationMatrixti.getRotationMatrix(rotationMatrix);
    // Do the vertex positions need mixing?
    boolean requiresMix = x2Attr != Graph.NOT_FOUND && y2Attr != Graph.NOT_FOUND && z2Attr != Graph.NOT_FOUND;
    boolean requiresVertexVisibility = vxVisibilityAttr != Graph.NOT_FOUND;
    boolean requiresTransactionVisibility = txVisibilityAttr != Graph.NOT_FOUND;
    // If the mix value is either 0 or 1 then no mixing is required
    if (requiresMix && mix == 0.0F) {
        requiresMix = false;
    } else if (requiresMix && mix == 1.0F) {
        xAttr = x2Attr;
        yAttr = y2Attr;
        zAttr = z2Attr;
        requiresMix = false;
    } else {
    // Do nothing
    }
    final BitSet vxIncluded = new BitSet();
    final int vxCount = graph.getVertexCount();
    // Select the correct vertices.
    for (int position = 0; position != vxCount; position++) {
        final int vxId = graph.getVertex(position);
        if (requiresVertexVisibility) {
            final float visibility = graph.getFloatValue(vxVisibilityAttr, vxId);
            if (visibility <= 1.0F && (visibility > visibilityHigh || visibility < visibilityLow)) {
                continue;
            }
        }
        // Get the main location of the vertex.
        float x = xAttr != Graph.NOT_FOUND ? graph.getFloatValue(xAttr, vxId) : VisualGraphDefaults.getDefaultX(vxId);
        float y = yAttr != Graph.NOT_FOUND ? graph.getFloatValue(yAttr, vxId) : VisualGraphDefaults.getDefaultY(vxId);
        float z = zAttr != Graph.NOT_FOUND ? graph.getFloatValue(zAttr, vxId) : VisualGraphDefaults.getDefaultZ(vxId);
        // If mixing is required then mix the main location with the alternative location.
        if (requiresMix) {
            x = inverseMix * x + mix * graph.getFloatValue(x2Attr, vxId);
            y = inverseMix * y + mix * graph.getFloatValue(y2Attr, vxId);
            z = inverseMix * z + mix * graph.getFloatValue(z2Attr, vxId);
        }
        // Convert world coordinates to camera coordinates.
        final Vector3f sceneLocation = convertWorldToScene(x, y, z, centre, rotationMatrix, cameraDistance);
        final int rAttr = VisualConcept.VertexAttribute.NODE_RADIUS.get(graph);
        final float r = graph.getFloatValue(rAttr, vxId);
        if (sceneLocation.getZ() < 0) {
            final float leftMostPoint = (sceneLocation.getX() - r) / -sceneLocation.getZ();
            final float rightMostPoint = (sceneLocation.getX() + r) / -sceneLocation.getZ();
            final float bottomMostPoint = (sceneLocation.getY() - r) / -sceneLocation.getZ();
            final float topMostPoint = (sceneLocation.getY() + r) / -sceneLocation.getZ();
            final boolean vertexLeftOfBox = rightMostPoint < left;
            final boolean vertexRightOfBox = right < leftMostPoint;
            final boolean vertexBelowBox = topMostPoint < bottom;
            final boolean vertexAboveBox = top < bottomMostPoint;
            if (!vertexLeftOfBox && !vertexRightOfBox && !vertexBelowBox && !vertexAboveBox) {
                vxIncluded.set(vxId);
            }
        }
    }
    final BitSet txIncluded = new BitSet();
    if (vxIncluded.isEmpty()) {
        // There were no vertices in the selection box,
        // so now we check if any lines overlapped. If they do, include the vertices at the ends of
        // those lines.
        // Note: we're checking the actual connections, not what is drawn on the display.
        // This could be confusing for the user, but checking against what is actually displayed would be
        // a very different kettle of lines.
        final int linkCount = graph.getLinkCount();
        for (int position = 0; position < linkCount; position++) {
            final int linkId = graph.getLink(position);
            final int vxLo = graph.getLinkLowVertex(linkId);
            final int vxHi = graph.getLinkHighVertex(linkId);
            // Get the main location of the lo vertex.
            float xLo = xAttr != Graph.NOT_FOUND ? graph.getFloatValue(xAttr, vxLo) : VisualGraphDefaults.getDefaultX(vxLo);
            float yLo = yAttr != Graph.NOT_FOUND ? graph.getFloatValue(yAttr, vxLo) : VisualGraphDefaults.getDefaultY(vxLo);
            float zLo = zAttr != Graph.NOT_FOUND ? graph.getFloatValue(zAttr, vxLo) : VisualGraphDefaults.getDefaultZ(vxLo);
            // Get the main location of the lo vertex.
            float xHi = xAttr != Graph.NOT_FOUND ? graph.getFloatValue(xAttr, vxHi) : VisualGraphDefaults.getDefaultX(vxHi);
            float yHi = yAttr != Graph.NOT_FOUND ? graph.getFloatValue(yAttr, vxHi) : VisualGraphDefaults.getDefaultY(vxHi);
            float zHi = zAttr != Graph.NOT_FOUND ? graph.getFloatValue(zAttr, vxHi) : VisualGraphDefaults.getDefaultZ(vxHi);
            if (requiresMix) {
                xLo = inverseMix * xLo + mix * graph.getFloatValue(x2Attr, vxLo);
                yLo = inverseMix * yLo + mix * graph.getFloatValue(y2Attr, vxLo);
                zLo = inverseMix * zLo + mix * graph.getFloatValue(z2Attr, vxLo);
                xHi = inverseMix * xHi + mix * graph.getFloatValue(x2Attr, vxHi);
                yHi = inverseMix * yHi + mix * graph.getFloatValue(y2Attr, vxHi);
                zHi = inverseMix * zHi + mix * graph.getFloatValue(z2Attr, vxHi);
            }
            // Convert world coordinates to camera coordinates.
            final Vector3f worldLocationLo = new Vector3f(xLo, yLo, zLo);
            worldLocationLo.subtract(centre);
            final Vector3f lo = new Vector3f();
            lo.rotate(worldLocationLo, rotationMatrix);
            lo.setZ(lo.getZ() - cameraDistance);
            final Vector3f worldLocationHi = new Vector3f(xHi, yHi, zHi);
            worldLocationHi.subtract(centre);
            final Vector3f hi = new Vector3f();
            hi.rotate(worldLocationHi, rotationMatrix);
            hi.setZ(hi.getZ() - cameraDistance);
            // If at least one of the end-points is in front of the eye...
            if (lo.getZ() < 0 || hi.getZ() < 0) {
                // Project the 3d eye coordinates of the ends of the line onto the 2D viewing plane.
                // The algorithm to do this depends on where the points are.
                // If a point is in front of the eye (z<0), project to the z==0 plane.
                // See 2.13 Coordinate Transformations in "OpenGL 3.3 (Core Profile)".
                // If a point is behind the eye (z>0), the line connecting the points must be clipped at z==0.
                // Project x,y by using the equation for findnig where a line crosses the plane z==0.
                // See 2.19.1 Clipping Shader Varying Outputs in "OpenGL 3.3 (Core Profile)".
                final float horizontalOffsetLo;
                final float horizontalOffsetHi;
                final float verticalOffsetLo;
                final float verticalOffsetHi;
                if (lo.getZ() < 0) {
                    final float loz = -Math.abs(lo.getZ());
                    horizontalOffsetLo = lo.getX() / -loz;
                    verticalOffsetLo = lo.getY() / -loz;
                } else if (lo.getZ() > 0) {
                    horizontalOffsetLo = lo.getX() + (lo.getZ() * (hi.getX() - lo.getX())) / (lo.getZ() - hi.getZ());
                    verticalOffsetLo = lo.getY() + (lo.getZ() * (hi.getY() - lo.getY()) / (lo.getZ() - hi.getZ()));
                } else {
                    horizontalOffsetLo = lo.getX();
                    verticalOffsetLo = lo.getY();
                }
                if (hi.getZ() < 0) {
                    final float hiz = -Math.abs(hi.getZ());
                    horizontalOffsetHi = hi.getX() / -hiz;
                    verticalOffsetHi = hi.getY() / -hiz;
                } else if (hi.getZ() > 0) {
                    horizontalOffsetHi = lo.getX() + (lo.getZ() * (hi.getX() - lo.getX())) / (lo.getZ() - hi.getZ());
                    verticalOffsetHi = lo.getY() + (lo.getZ() * (hi.getY() - lo.getY()) / (lo.getZ() - hi.getZ()));
                } else {
                    horizontalOffsetHi = hi.getX();
                    verticalOffsetHi = hi.getY();
                }
                final boolean intersects = lineSegmentIntersectsRectangle(horizontalOffsetLo, verticalOffsetLo, horizontalOffsetHi, verticalOffsetHi, left, bottom, right, top);
                if (intersects) {
                    final int linkTxCount = graph.getLinkTransactionCount(linkId);
                    for (int linkPos = 0; linkPos < linkTxCount; linkPos++) {
                        final int txId = graph.getLinkTransaction(linkId, linkPos);
                        txIncluded.set(txId);
                    }
                }
            }
        }
    }
    final int txCount = graph.getTransactionCount();
    if (txIncluded.isEmpty()) {
        if (isAdd) {
            if (vxSelectedAttr != Graph.NOT_FOUND) {
                for (int vxId = vxIncluded.nextSetBit(0); vxId >= 0; vxId = vxIncluded.nextSetBit(vxId + 1)) {
                    if (!graph.getBooleanValue(vxSelectedAttr, vxId)) {
                        selectVerticesOperation.setValue(vxId, true);
                    }
                }
            }
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < txCount; position++) {
                    final int txId = graph.getTransaction(position);
                    if (vxIncluded.get(graph.getTransactionSourceVertex(txId)) && vxIncluded.get(graph.getTransactionDestinationVertex(txId)) && !graph.getBooleanValue(txSelectedAttr, txId)) {
                        if (requiresTransactionVisibility) {
                            float visibility = graph.getFloatValue(txVisibilityAttr, txId);
                            if (visibility <= 1.0F && (visibility > visibilityHigh || visibility < visibilityLow)) {
                                continue;
                            }
                        }
                        selectTransactionsOperation.setValue(txId, true);
                    }
                }
            }
        } else if (isToggle) {
            if (vxSelectedAttr != Graph.NOT_FOUND) {
                for (int vertex = vxIncluded.nextSetBit(0); vertex >= 0; vertex = vxIncluded.nextSetBit(vertex + 1)) {
                    selectVerticesOperation.setValue(vertex, !graph.getBooleanValue(vxSelectedAttr, vertex));
                }
            }
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < txCount; position++) {
                    final int txId = graph.getTransaction(position);
                    if (vxIncluded.get(graph.getTransactionSourceVertex(txId)) && vxIncluded.get(graph.getTransactionDestinationVertex(txId))) {
                        if (requiresTransactionVisibility) {
                            float visibility = graph.getFloatValue(txVisibilityAttr, txId);
                            if (visibility <= 1.0F && (visibility > visibilityHigh || visibility < visibilityLow)) {
                                continue;
                            }
                        }
                        selectTransactionsOperation.setValue(txId, !graph.getBooleanValue(txSelectedAttr, txId));
                    }
                }
            }
        } else {
            if (vxSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < vxCount; position++) {
                    final int vxId = graph.getVertex(position);
                    final boolean included = vxIncluded.get(vxId);
                    if (included != graph.getBooleanValue(vxSelectedAttr, vxId)) {
                        selectVerticesOperation.setValue(vxId, included);
                    }
                }
            }
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < txCount; position++) {
                    final int txId = graph.getTransaction(position);
                    boolean included = vxIncluded.get(graph.getTransactionSourceVertex(txId)) && vxIncluded.get(graph.getTransactionDestinationVertex(txId));
                    if (requiresTransactionVisibility) {
                        float visibility = graph.getFloatValue(txVisibilityAttr, txId);
                        if (visibility <= 1.0F && (visibility > visibilityHigh || visibility < visibilityLow)) {
                            included = false;
                        }
                    }
                    if (included != graph.getBooleanValue(txSelectedAttr, txId)) {
                        selectTransactionsOperation.setValue(txId, included);
                    }
                }
            }
        }
    } else {
        // TODO: figure out if we also want to select the associated vertices.
        if (isAdd) {
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int txId = txIncluded.nextSetBit(0); txId >= 0; txId = txIncluded.nextSetBit(txId + 1)) {
                    if (!graph.getBooleanValue(txSelectedAttr, txId)) {
                        selectTransactionsOperation.setValue(txId, true);
                    }
                }
            }
        } else if (isToggle) {
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int txId = txIncluded.nextSetBit(0); txId >= 0; txId = txIncluded.nextSetBit(txId + 1)) {
                    selectTransactionsOperation.setValue(txId, !graph.getBooleanValue(txSelectedAttr, txId));
                }
            }
        } else {
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < txCount; position++) {
                    final int txId = graph.getTransaction(position);
                    final boolean included = txIncluded.get(txId);
                    if (included != graph.getBooleanValue(txSelectedAttr, txId)) {
                        selectTransactionsOperation.setValue(txId, included);
                    }
                }
            }
            // Deselect any selected vertices.
            if (vxSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < vxCount; position++) {
                    final int vxId = graph.getVertex(position);
                    final boolean selected = graph.getBooleanValue(vxSelectedAttr, vxId);
                    if (selected) {
                        selectVerticesOperation.setValue(vxId, false);
                    }
                }
            }
        }
    }
    graph.executeGraphOperation(selectVerticesOperation);
    graph.executeGraphOperation(selectTransactionsOperation);
}
Also used : SetBooleanValuesOperation(au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation) Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame) Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) Matrix33f(au.gov.asd.tac.constellation.utilities.graphics.Matrix33f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) BitSet(java.util.BitSet)

Example 2 with SetBooleanValuesOperation

use of au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation in project constellation by constellation-app.

the class FreeformSelectionPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final float mix = camera.getMix();
    final float inverseMix = 1.0F - mix;
    final Vector3f centre = new Vector3f(camera.lookAtCentre);
    final float left = box[0];
    final float right = box[1];
    final float top = box[2];
    final float bottom = box[3];
    // Look up all the required attributes.
    int xAttr = VisualConcept.VertexAttribute.X.get(graph);
    int yAttr = VisualConcept.VertexAttribute.Y.get(graph);
    int zAttr = VisualConcept.VertexAttribute.Z.get(graph);
    final int x2Attr = VisualConcept.VertexAttribute.X2.get(graph);
    final int y2Attr = VisualConcept.VertexAttribute.Y2.get(graph);
    final int z2Attr = VisualConcept.VertexAttribute.Z2.get(graph);
    final int vxSelectedAttr = VisualConcept.VertexAttribute.SELECTED.get(graph);
    final int txSelectedAttr = VisualConcept.TransactionAttribute.SELECTED.get(graph);
    final int vxVisibilityAttr = VisualConcept.VertexAttribute.VISIBILITY.get(graph);
    final int txVisibilityAttr = VisualConcept.TransactionAttribute.VISIBILITY.get(graph);
    final SetBooleanValuesOperation selectVerticesOperation = new SetBooleanValuesOperation(graph, GraphElementType.VERTEX, vxSelectedAttr);
    final SetBooleanValuesOperation selectTransactionsOperation = new SetBooleanValuesOperation(graph, GraphElementType.TRANSACTION, txSelectedAttr);
    final float visibilityHigh = camera.getVisibilityHigh();
    final float visibilityLow = camera.getVisibilityLow();
    // Get a copy of the current rotation matrix.
    final Vector3f diff = Vector3f.subtract(camera.lookAtEye, camera.lookAtCentre);
    final float cameraDistance = diff.getLength();
    // Get the inverse eye rotation to match the object frame rotation.
    final Frame frame = new Frame(camera.lookAtEye, camera.lookAtCentre, camera.lookAtUp);
    final Matrix44f objectFrameMatrix = new Matrix44f();
    frame.getMatrix(objectFrameMatrix, true);
    final Matrix44f rotationMatrixt = new Matrix44f();
    objectFrameMatrix.getRotationMatrix(rotationMatrixt);
    final Matrix44f rotationMatrixti = new Matrix44f();
    rotationMatrixti.invert(rotationMatrixt);
    final Matrix33f rotationMatrix = new Matrix33f();
    rotationMatrixti.getRotationMatrix(rotationMatrix);
    // Do the vertex positions need mixing?
    boolean requiresMix = x2Attr != Graph.NOT_FOUND && y2Attr != Graph.NOT_FOUND && z2Attr != Graph.NOT_FOUND;
    final boolean requiresVertexVisibility = vxVisibilityAttr != Graph.NOT_FOUND;
    final boolean requiresTransactionVisibility = txVisibilityAttr != Graph.NOT_FOUND;
    // If the mix value is either 0 or 1 then no mixing is required
    if (requiresMix && mix == 0.0F) {
        requiresMix = false;
    } else if (requiresMix && mix == 1.0F) {
        xAttr = x2Attr;
        yAttr = y2Attr;
        zAttr = z2Attr;
        requiresMix = false;
    } else {
    // Do nothing
    }
    final BitSet vxIncluded = new BitSet();
    final int vxCount = graph.getVertexCount();
    // Select the correct vertices.
    for (int position = 0; position != vxCount; position++) {
        final int vxId = graph.getVertex(position);
        if (requiresVertexVisibility) {
            final float visibility = graph.getFloatValue(vxVisibilityAttr, vxId);
            if (visibility <= 1.0F && (visibility > visibilityHigh || visibility < visibilityLow)) {
                continue;
            }
        }
        // Get the main location of the vertex.
        float x = xAttr != Graph.NOT_FOUND ? graph.getFloatValue(xAttr, vxId) : VisualGraphDefaults.getDefaultX(vxId);
        float y = yAttr != Graph.NOT_FOUND ? graph.getFloatValue(yAttr, vxId) : VisualGraphDefaults.getDefaultY(vxId);
        float z = zAttr != Graph.NOT_FOUND ? graph.getFloatValue(zAttr, vxId) : VisualGraphDefaults.getDefaultZ(vxId);
        // If mixing is required then mix the main location with the alternative location.
        boolean mixed = false;
        if (requiresMix) {
            x = inverseMix * x + mix * graph.getFloatValue(x2Attr, vxId);
            y = inverseMix * y + mix * graph.getFloatValue(y2Attr, vxId);
            z = inverseMix * z + mix * graph.getFloatValue(z2Attr, vxId);
            mixed = true;
        }
        // Convert world coordinates to camera coordinates.
        final Vector3f sceneLocation = convertWorldToScene(x, y, z, centre, rotationMatrix, cameraDistance);
        final int rAttr = VisualConcept.VertexAttribute.NODE_RADIUS.get(graph);
        final float r = graph.getFloatValue(rAttr, vxId);
        if (sceneLocation.getZ() < 0) {
            final float leftMostPoint = (sceneLocation.getX() - r) / -sceneLocation.getZ();
            final float rightMostPoint = (sceneLocation.getX() + r) / -sceneLocation.getZ();
            final float bottomMostPoint = (sceneLocation.getY() - r) / -sceneLocation.getZ();
            final float topMostPoint = (sceneLocation.getY() + r) / -sceneLocation.getZ();
            final boolean vertexLeftOfFreeform = rightMostPoint < left;
            final boolean vertexRightOfFreeform = right < leftMostPoint;
            final boolean vertexBelowFreeform = topMostPoint < bottom;
            final boolean vertexAboveFreeform = top < bottomMostPoint;
            if (!vertexLeftOfFreeform && !vertexRightOfFreeform && !vertexBelowFreeform && !vertexAboveFreeform && inFreeformPolygons(leftMostPoint, topMostPoint)) {
                vxIncluded.set(vxId);
            }
        }
    }
    final BitSet txIncluded = new BitSet();
    if (vxIncluded.isEmpty()) {
        final int linkCount = graph.getLinkCount();
        for (int position = 0; position < linkCount; position++) {
            final int linkId = graph.getLink(position);
            final int vxLo = graph.getLinkLowVertex(linkId);
            final int vxHi = graph.getLinkHighVertex(linkId);
            // Get the main location of the lo vertex.
            float xLo = xAttr != Graph.NOT_FOUND ? graph.getFloatValue(xAttr, vxLo) : VisualGraphDefaults.getDefaultX(vxLo);
            float yLo = yAttr != Graph.NOT_FOUND ? graph.getFloatValue(yAttr, vxLo) : VisualGraphDefaults.getDefaultY(vxLo);
            float zLo = zAttr != Graph.NOT_FOUND ? graph.getFloatValue(zAttr, vxLo) : VisualGraphDefaults.getDefaultZ(vxLo);
            // Get the main location of the lo vertex.
            float xHi = xAttr != Graph.NOT_FOUND ? graph.getFloatValue(xAttr, vxHi) : VisualGraphDefaults.getDefaultX(vxHi);
            float yHi = yAttr != Graph.NOT_FOUND ? graph.getFloatValue(yAttr, vxHi) : VisualGraphDefaults.getDefaultY(vxHi);
            float zHi = zAttr != Graph.NOT_FOUND ? graph.getFloatValue(zAttr, vxHi) : VisualGraphDefaults.getDefaultZ(vxHi);
            if (requiresMix) {
                xLo = inverseMix * xLo + mix * graph.getFloatValue(x2Attr, vxLo);
                yLo = inverseMix * yLo + mix * graph.getFloatValue(y2Attr, vxLo);
                zLo = inverseMix * zLo + mix * graph.getFloatValue(z2Attr, vxLo);
                xHi = inverseMix * xHi + mix * graph.getFloatValue(x2Attr, vxHi);
                yHi = inverseMix * yHi + mix * graph.getFloatValue(y2Attr, vxHi);
                zHi = inverseMix * zHi + mix * graph.getFloatValue(z2Attr, vxHi);
            }
            // Convert world coordinates to camera coordinates.
            final Vector3f worldLocationLo = new Vector3f(xLo, yLo, zLo);
            worldLocationLo.subtract(centre);
            final Vector3f lo = new Vector3f();
            lo.rotate(worldLocationLo, rotationMatrix);
            lo.setZ(lo.getZ() - cameraDistance);
            final Vector3f worldLocationHi = new Vector3f(xHi, yHi, zHi);
            worldLocationHi.subtract(centre);
            final Vector3f hi = new Vector3f();
            hi.rotate(worldLocationHi, rotationMatrix);
            hi.setZ(hi.getZ() - cameraDistance);
            // If at least one of the end-points is in front of the eye...
            if (lo.getZ() < 0 || hi.getZ() < 0) {
                final float horizontalOffsetLo;
                final float horizontalOffsetHi;
                final float verticalOffsetLo;
                final float verticalOffsetHi;
                if (lo.getZ() < 0) {
                    final float loz = -Math.abs(lo.getZ());
                    horizontalOffsetLo = lo.getX() / -loz;
                    verticalOffsetLo = lo.getY() / -loz;
                } else if (lo.getZ() > 0) {
                    horizontalOffsetLo = lo.getX() + (lo.getZ() * (hi.getX() - lo.getX())) / (lo.getZ() - hi.getZ());
                    verticalOffsetLo = lo.getY() + (lo.getZ() * (hi.getY() - lo.getY()) / (lo.getZ() - hi.getZ()));
                } else {
                    horizontalOffsetLo = lo.getX();
                    verticalOffsetLo = lo.getY();
                }
                if (hi.getZ() < 0) {
                    final float hiz = -Math.abs(hi.getZ());
                    horizontalOffsetHi = hi.getX() / -hiz;
                    verticalOffsetHi = hi.getY() / -hiz;
                } else if (hi.getZ() > 0) {
                    horizontalOffsetHi = lo.getX() + (lo.getZ() * (hi.getX() - lo.getX())) / (lo.getZ() - hi.getZ());
                    verticalOffsetHi = lo.getY() + (lo.getZ() * (hi.getY() - lo.getY()) / (lo.getZ() - hi.getZ()));
                } else {
                    horizontalOffsetHi = hi.getX();
                    verticalOffsetHi = hi.getY();
                }
                final boolean intersects = lineSegmentIntersectsRectangle(horizontalOffsetLo, verticalOffsetLo, horizontalOffsetHi, verticalOffsetHi, left, bottom, right, top);
                if (intersects) {
                    final int linkTxCount = graph.getLinkTransactionCount(linkId);
                    for (int linkPos = 0; linkPos < linkTxCount; linkPos++) {
                        final int txId = graph.getLinkTransaction(linkId, linkPos);
                        txIncluded.set(txId);
                    }
                }
            }
        }
    }
    final int txCount = graph.getTransactionCount();
    if (txIncluded.isEmpty()) {
        if (isAdd) {
            if (vxSelectedAttr != Graph.NOT_FOUND) {
                for (int vxId = vxIncluded.nextSetBit(0); vxId >= 0; vxId = vxIncluded.nextSetBit(vxId + 1)) {
                    if (!graph.getBooleanValue(vxSelectedAttr, vxId)) {
                        selectVerticesOperation.setValue(vxId, true);
                    }
                }
            }
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < txCount; position++) {
                    final int txId = graph.getTransaction(position);
                    if (vxIncluded.get(graph.getTransactionSourceVertex(txId)) && vxIncluded.get(graph.getTransactionDestinationVertex(txId)) && !graph.getBooleanValue(txSelectedAttr, txId)) {
                        if (requiresTransactionVisibility) {
                            final float visibility = graph.getFloatValue(txVisibilityAttr, txId);
                            if (visibility <= 1.0F && (visibility > visibilityHigh || visibility < visibilityLow)) {
                                continue;
                            }
                        }
                        selectTransactionsOperation.setValue(txId, true);
                    }
                }
            }
        } else if (isToggle) {
            if (vxSelectedAttr != Graph.NOT_FOUND) {
                for (int vertex = vxIncluded.nextSetBit(0); vertex >= 0; vertex = vxIncluded.nextSetBit(vertex + 1)) {
                    selectVerticesOperation.setValue(vertex, !graph.getBooleanValue(vxSelectedAttr, vertex));
                }
            }
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < txCount; position++) {
                    final int txId = graph.getTransaction(position);
                    if (vxIncluded.get(graph.getTransactionSourceVertex(txId)) && vxIncluded.get(graph.getTransactionDestinationVertex(txId))) {
                        if (requiresTransactionVisibility) {
                            final float visibility = graph.getFloatValue(txVisibilityAttr, txId);
                            if (visibility <= 1.0F && (visibility > visibilityHigh || visibility < visibilityLow)) {
                                continue;
                            }
                        }
                        selectTransactionsOperation.setValue(txId, !graph.getBooleanValue(txSelectedAttr, txId));
                    }
                }
            }
        } else {
            if (vxSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < vxCount; position++) {
                    final int vxId = graph.getVertex(position);
                    final boolean included = vxIncluded.get(vxId);
                    if (included != graph.getBooleanValue(vxSelectedAttr, vxId)) {
                        selectVerticesOperation.setValue(vxId, included);
                    }
                }
            }
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < txCount; position++) {
                    final int txId = graph.getTransaction(position);
                    boolean included = vxIncluded.get(graph.getTransactionSourceVertex(txId)) && vxIncluded.get(graph.getTransactionDestinationVertex(txId));
                    if (requiresTransactionVisibility) {
                        final float visibility = graph.getFloatValue(txVisibilityAttr, txId);
                        if (visibility <= 1.0F && (visibility > visibilityHigh || visibility < visibilityLow)) {
                            included = false;
                        }
                    }
                    if (included != graph.getBooleanValue(txSelectedAttr, txId)) {
                        selectTransactionsOperation.setValue(txId, included);
                    }
                }
            }
        }
    } else {
        if (isAdd) {
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int txId = txIncluded.nextSetBit(0); txId >= 0; txId = txIncluded.nextSetBit(txId + 1)) {
                    if (!graph.getBooleanValue(txSelectedAttr, txId)) {
                        selectTransactionsOperation.setValue(txId, true);
                    }
                }
            }
        } else if (isToggle) {
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int txId = txIncluded.nextSetBit(0); txId >= 0; txId = txIncluded.nextSetBit(txId + 1)) {
                    selectTransactionsOperation.setValue(txId, !graph.getBooleanValue(txSelectedAttr, txId));
                }
            }
        } else {
            if (txSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < txCount; position++) {
                    final int txId = graph.getTransaction(position);
                    final boolean included = txIncluded.get(txId);
                    if (included != graph.getBooleanValue(txSelectedAttr, txId)) {
                        selectTransactionsOperation.setValue(txId, included);
                    }
                }
            }
            // Deselect any selected vertices.
            if (vxSelectedAttr != Graph.NOT_FOUND) {
                for (int position = 0; position < vxCount; position++) {
                    final int vxId = graph.getVertex(position);
                    final boolean selected = graph.getBooleanValue(vxSelectedAttr, vxId);
                    if (selected) {
                        selectVerticesOperation.setValue(vxId, false);
                    }
                }
            }
        }
    }
    graph.executeGraphOperation(selectVerticesOperation);
    graph.executeGraphOperation(selectTransactionsOperation);
}
Also used : SetBooleanValuesOperation(au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation) Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame) Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) Matrix33f(au.gov.asd.tac.constellation.utilities.graphics.Matrix33f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) BitSet(java.util.BitSet)

Example 3 with SetBooleanValuesOperation

use of au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation in project constellation by constellation-app.

the class SelectAllPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    Properties properties = new Properties();
    int vxSelected = VisualConcept.VertexAttribute.SELECTED.get(graph);
    if (vxSelected != Graph.NOT_FOUND) {
        SetBooleanValuesOperation selectVerticesOperation = new SetBooleanValuesOperation(graph, GraphElementType.VERTEX, vxSelected);
        int vertexCount = graph.getVertexCount();
        for (int position = 0; position < vertexCount; position++) {
            int vertex = graph.getVertex(position);
            selectVerticesOperation.setValue(vertex, true);
        }
        graph.executeGraphOperation(selectVerticesOperation);
        properties.setProperty("vsize", String.valueOf(selectVerticesOperation.size()));
    }
    int txSelected = VisualConcept.TransactionAttribute.SELECTED.get(graph);
    if (txSelected != Graph.NOT_FOUND) {
        SetBooleanValuesOperation selectTransactionsOperation = new SetBooleanValuesOperation(graph, GraphElementType.TRANSACTION, txSelected);
        int transactionCount = graph.getTransactionCount();
        for (int position = 0; position < transactionCount; position++) {
            int transaction = graph.getTransaction(position);
            selectTransactionsOperation.setValue(transaction, true);
        }
        graph.executeGraphOperation(selectTransactionsOperation);
        properties.setProperty("tsize", String.valueOf(selectTransactionsOperation.size()));
    }
    ConstellationLogger.getDefault().pluginProperties(this, properties);
}
Also used : SetBooleanValuesOperation(au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation) Properties(java.util.Properties)

Aggregations

SetBooleanValuesOperation (au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation)3 Frame (au.gov.asd.tac.constellation.utilities.graphics.Frame)2 Matrix33f (au.gov.asd.tac.constellation.utilities.graphics.Matrix33f)2 Matrix44f (au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)2 Vector3f (au.gov.asd.tac.constellation.utilities.graphics.Vector3f)2 BitSet (java.util.BitSet)2 Properties (java.util.Properties)1