Search in sources :

Example 1 with Vector3f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.

the class GatherNodesInGraphPlugin method edit.

@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final Vector3f xyzp = (Vector3f) parameters.getParameters().get(XYZ_PARAMETER_ID).getObjectValue();
    final BitSet gathers = (BitSet) parameters.getParameters().get(GATHERS_PARAMETER_ID).getObjectValue();
    final int xId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.X.getName());
    final int yId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Y.getName());
    final int zId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Z.getName());
    final int cameraAttribute = VisualConcept.GraphAttribute.CAMERA.get(wg);
    final int selectedVertexCount = gathers.cardinality();
    if (selectedVertexCount >= 1) {
        // This is where we want to rotate to: relative to the eye->centre direction.
        final Camera visualState = wg.getObjectValue(cameraAttribute, 0);
        final Vector3f xyz = Vector3f.subtract(visualState.lookAtCentre, visualState.lookAtEye);
        // Create a rotation matrix that will rotate the positions we're about to create.
        final Frame frame = new Frame(xyz, new Vector3f(0, 0, 0), visualState.lookAtUp);
        final Matrix44f rm = new Matrix44f();
        frame.getMatrix(rm, true);
        final Matrix33f rotationMatrix = new Matrix33f();
        rm.getRotationMatrix(rotationMatrix);
        // We want the grid to start at the top left and grow down and right.
        // Choose our up and left vectors accordingly.
        final Vector3f up = new Vector3f();
        up.rotate(new Vector3f(0, -1, 0), rotationMatrix);
        final Vector3f left = new Vector3f();
        left.rotate(new Vector3f(-1, 0, 0), rotationMatrix);
        // If we wanted to be consistent, we'd call the arrange by grid plugin on the selected vertices
        // and rotate the result...
        final int rowLength = (int) Math.ceil(Math.sqrt(selectedVertexCount));
        float x = xyzp.getX();
        float y = xyzp.getY();
        float z = xyzp.getZ();
        int h = 0;
        int v = 0;
        float scalingFactor = 4;
        for (int vxId = gathers.nextSetBit(0); vxId >= 0; vxId = gathers.nextSetBit(vxId + 1)) {
            if (h == 0 && v == 0) {
                // This gathers the selected nodes at the distance the first selected node as measured away from the camera/eye.
                // It does this by using a right hand triangle (hypotenuse = ray to click, adjacent = view from eye to centre,
                // opposite = pane perpendicular to eye) and the approriate triangle properties
                // 
                // Unit vector from eye to click point
                final Vector3f ray = Vector3f.subtract(xyzp, visualState.lookAtEye);
                ray.normalize();
                // Unit vector from eye to centre
                final Vector3f adjacentUnit = Vector3f.subtract(visualState.lookAtCentre, visualState.lookAtEye);
                adjacentUnit.normalize();
                // Vector from eye to node already on graph
                final Vector3f point = new Vector3f(wg.getFloatValue(xId, vxId), wg.getFloatValue(yId, vxId), wg.getFloatValue(zId, vxId));
                point.subtract(visualState.lookAtEye);
                // Determining the distance along the unit vector to the centre that the node will be
                final float adjacentLen = Vector3f.dotProduct(adjacentUnit, point);
                // Determining the length of the hypotenuse of the right hand triangle
                final float cosAngleBetweenVectors = (float) Math.cos(Vector3f.angleBetweenVectors(ray, adjacentUnit));
                // If it does equal 0 we will skip this section and have x,y,z equal the "click point" which was assigned when they were defined
                if (cosAngleBetweenVectors != 0.0) {
                    final float rayScalar = adjacentLen / cosAngleBetweenVectors;
                    ray.scale(rayScalar);
                    final Vector3f destination = Vector3f.add(visualState.lookAtEye, ray);
                    x = destination.getX();
                    y = destination.getY();
                    z = destination.getZ();
                }
            }
            wg.setFloatValue(xId, vxId, x + scalingFactor * (h * left.getX() + v * up.getX()));
            wg.setFloatValue(yId, vxId, y + scalingFactor * (h * left.getY() + v * up.getY()));
            wg.setFloatValue(zId, vxId, z + scalingFactor * (h * left.getZ() + v * up.getZ()));
            if (++h == rowLength) {
                h = 0;
                v++;
            }
        }
    }
}
Also used : 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) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 2 with Vector3f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.

the class GatherNodesPlugin method edit.

@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final int vxId = parameters.getParameters().get(VXID_PARAMETER_ID).getIntegerValue();
    final BitSet gathers = (BitSet) parameters.getParameters().get(GATHERS_PARAMETER_ID).getObjectValue();
    gathers.set(vxId);
    final int xId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.X.getName());
    final int yId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Y.getName());
    final int zId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Z.getName());
    final int cameraAttribute = VisualConcept.GraphAttribute.CAMERA.get(wg);
    final int selectedVertexCount = gathers.cardinality();
    if (selectedVertexCount > 1) {
        // This is where we want to rotate to: relative to the eye->centre direction.
        final Camera visualState = wg.getObjectValue(cameraAttribute, 0);
        final Vector3f xyz = Vector3f.subtract(visualState.lookAtCentre, visualState.lookAtEye);
        // Create a rotation matrix that will rotate the positions we're about to create.
        final Frame frame = new Frame(xyz, new Vector3f(0, 0, 0), visualState.lookAtUp);
        final Matrix44f rm = new Matrix44f();
        frame.getMatrix(rm, true);
        final Matrix33f rotationMatrix = new Matrix33f();
        rm.getRotationMatrix(rotationMatrix);
        // We want the grid to start at the top left and grow down and right.
        // Choose our up and left vectors accordingly.
        final Vector3f up = new Vector3f();
        up.rotate(new Vector3f(0, -1, 0), rotationMatrix);
        final Vector3f left = new Vector3f();
        left.rotate(new Vector3f(-1, 0, 0), rotationMatrix);
        final float x = wg.getFloatValue(xId, vxId);
        final float y = wg.getFloatValue(yId, vxId);
        final float z = wg.getFloatValue(zId, vxId);
        // If we wanted to be consistent, we'd call the arrange by grid plugin on the selected vertices
        // and rotate the result...
        final int rowLength = (int) Math.ceil(Math.sqrt(selectedVertexCount));
        // Skip the first position: when we get to vxId, we don't change it's position.
        int h = 1;
        int v = 0;
        final float scalingFactor = 4;
        for (int vertex = gathers.nextSetBit(0); vertex >= 0; vertex = gathers.nextSetBit(vertex + 1)) {
            if (vertex != vxId) {
                wg.setFloatValue(xId, vertex, x + scalingFactor * (h * left.getX() + v * up.getX()));
                wg.setFloatValue(yId, vertex, y + scalingFactor * (h * left.getY() + v * up.getY()));
                wg.setFloatValue(zId, vertex, z + scalingFactor * (h * left.getZ() + v * up.getZ()));
                if (++h == rowLength) {
                    h = 0;
                    v++;
                }
            }
        }
    }
}
Also used : 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) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 3 with Vector3f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.

the class BroccoliArranger method arrange.

public void arrange(final GraphWriteMethods wg, final int vxId) {
    set(wg);
    final Vector3f centre = getCentre();
    arrangeVertex(centre, vxId);
}
Also used : Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Example 4 with Vector3f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.

the class BroccoliArranger method arrangeVertex.

/**
 * Arrange the neighbours of the given vertex with degree 1 into a fan
 * relative to the centre.
 *
 * @param centre
 * @param vid
 */
private void arrangeVertex(final Vector3f centre, final int vxId) {
    float maxRadius = 0;
    final ArrayList<Integer> deg1 = new ArrayList<>();
    final int vncount = wg.getVertexNeighbourCount(vxId);
    for (int i = 0; i < vncount; i++) {
        final int vnId = wg.getVertexNeighbour(vxId, i);
        if (wg.getVertexNeighbourCount(vnId) == 1) {
            deg1.add(vnId);
            final float nradius = nradiusId != Graph.NOT_FOUND ? wg.getFloatValue(nradiusId, vnId) : 1;
            if (nradius > maxRadius) {
                maxRadius = nradius;
            }
        }
    }
    if (!deg1.isEmpty()) {
        final Vector3f xyz = new Vector3f(wg.getFloatValue(xId, vxId), wg.getFloatValue(yId, vxId), wg.getFloatValue(zId, vxId));
        final int size = deg1.size();
        final int sideLen = (int) Math.floor(Math.sqrt(size - 1.0)) + 1;
        final float sideLen1 = sideLen - 1F;
        // Generate a suitable up vector for lookAt.
        final Vector3f tmpv = new Vector3f();
        tmpv.crossProduct(xyz, Y_VECTOR);
        final Vector3f up = new Vector3f();
        up.crossProduct(tmpv, xyz);
        up.normalize();
        // Create a rotation matrix that will rotate the positions we're about to create
        // to the parent vertex.
        final Frame frame = new Frame(xyz, ZERO_VECTOR, up);
        final Matrix44f rm = new Matrix44f();
        frame.getMatrix(rm, true);
        final Matrix33f rotm = new Matrix33f();
        rm.getRotationMatrix(rotm);
        // Layout the degree 1 vertices on the surface of a sphere.
        for (int i = 0; i < size; i++) {
            final int vx1Id = deg1.get(i);
            // A position in the unit square.
            final float xs = sideLen1 > 0 ? (((float) i / sideLen) / sideLen1) * 2 - 1 : 0;
            final float ys = sideLen1 > 0 ? ((i % sideLen) / sideLen1) * 2 - 1 : 0;
            final Vector3f v = new Vector3f(xs, ys, 1);
            // Map the square onto the surface of the unit sphere.
            v.normalize();
            // Rotate the normalized square relative to the centre, resize it,
            // and move it to its parent.
            final Vector3f vrot = new Vector3f();
            vrot.rotate(v, rotm);
            vrot.scale(sideLen * 2 * maxRadius);
            vrot.add(xyz);
            final float x = vrot.getX();
            final float y = vrot.getY();
            final float z = vrot.getZ();
            wg.setFloatValue(xId, vx1Id, x);
            wg.setFloatValue(yId, vx1Id, y);
            wg.setFloatValue(zId, vx1Id, z);
        }
    }
}
Also used : 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) ArrayList(java.util.ArrayList)

Example 5 with Vector3f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.

the class BroccoliArranger method getCentre.

private Vector3f getCentre() {
    final BBoxf box = new BBoxf();
    for (int position = 0; position < vxCount; position++) {
        final int vxId = wg.getVertex(position);
        final float x = wg.getFloatValue(xId, vxId);
        final float y = wg.getFloatValue(yId, vxId);
        final float z = wg.getFloatValue(zId, vxId);
        box.add(x, y, z);
    }
    final float[] c = box.getCentre();
    return new Vector3f(c[BBoxf.X], c[BBoxf.Y], c[BBoxf.Z]);
}
Also used : Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) BBoxf(au.gov.asd.tac.constellation.graph.visual.graphics.BBoxf)

Aggregations

Vector3f (au.gov.asd.tac.constellation.utilities.graphics.Vector3f)85 Test (org.testng.annotations.Test)32 Frame (au.gov.asd.tac.constellation.utilities.graphics.Frame)14 Matrix44f (au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)14 Camera (au.gov.asd.tac.constellation.utilities.camera.Camera)10 Vector4f (au.gov.asd.tac.constellation.utilities.graphics.Vector4f)7 Matrix33f (au.gov.asd.tac.constellation.utilities.graphics.Matrix33f)6 Point (java.awt.Point)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 BitSet (java.util.BitSet)4 GL3 (com.jogamp.opengl.GL3)3 SetBooleanValuesOperation (au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation)2 IOException (java.io.IOException)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 HitState (au.gov.asd.tac.constellation.graph.interaction.framework.HitState)1 CreateTransactionPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.draw.CreateTransactionPlugin)1 CreateVertexPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.draw.CreateVertexPlugin)1 BoxSelectionPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.select.BoxSelectionPlugin)1 FreeformSelectionPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.select.FreeformSelectionPlugin)1 PointSelectionPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.select.PointSelectionPlugin)1