use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.
the class RandomArranger method arrange.
@Override
public void arrange(final GraphWriteMethods wg) throws InterruptedException {
final float[] oldMean = maintainMean ? ArrangementUtilities.getXyzMean(wg) : null;
final int xId = VisualConcept.VertexAttribute.X.get(wg);
final int yId = VisualConcept.VertexAttribute.Y.get(wg);
final int zId = VisualConcept.VertexAttribute.Z.get(wg);
final int x2Id = VisualConcept.VertexAttribute.X2.ensure(wg);
final int y2Id = VisualConcept.VertexAttribute.Y2.ensure(wg);
final int z2Id = VisualConcept.VertexAttribute.Z2.ensure(wg);
final int vxCount = wg.getVertexCount();
// We want the side to be long enough that a subsequent uncollide doesn't take too long.
final float side = 4F * (float) Math.sqrt(vxCount);
final Vector3f xyz = new Vector3f();
for (int position = 0; position < vxCount; position++) {
final int vxId = wg.getVertex(position);
wg.setFloatValue(x2Id, vxId, wg.getFloatValue(xId, vxId));
wg.setFloatValue(y2Id, vxId, wg.getFloatValue(yId, vxId));
wg.setFloatValue(z2Id, vxId, wg.getFloatValue(xId, vxId));
// Arrange in a circle/sphere.
do {
xyz.set(0.5F - random.nextFloat(), 0.5F - random.nextFloat(), dimensions == 3 ? 0.5F - random.nextFloat() : 0);
} while (xyz.getLength() > 0.5F);
wg.setFloatValue(xId, vxId, side * xyz.getX());
wg.setFloatValue(yId, vxId, side * xyz.getY());
wg.setFloatValue(zId, vxId, side * xyz.getZ());
}
if (maintainMean) {
ArrangementUtilities.moveMean(wg, oldMean);
}
}
use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.
the class FlyingAnimation method animate.
@Override
public List<VisualChange> animate(GraphWriteMethods wg) {
// dont animate unless there is more than 1 node
if (wg.getVertexCount() > 1) {
if (step >= stepsPerLink) {
// Get the next p3 vertex.
final Vector3f xyz = getNextVertex(wg, camera.getMix());
// Remove the old p0 and add the new p3.
xyzQueue.removeFirst();
xyzQueue.addLast(xyz);
// The first step between p1 and p2.
step = 0;
}
// The four control points of the spline.
final Iterator<Vector3f> it = xyzQueue.iterator();
final float[] p0 = it.next().a;
final float[] p1 = it.next().a;
final float[] p2 = it.next().a;
final float[] p3 = it.next().a;
// Determine the new lookAt eye and center.
final float t = step / (float) stepsPerLink;
final float t1 = (step + 1) / (float) stepsPerLink;
final float[] eye = new float[3];
Mathf.catmullRom(eye, p0, p1, p2, p3, t);
final float[] centre = new float[3];
Mathf.catmullRom(centre, p0, p1, p2, p3, t1);
camera.lookAtEye.set(eye[0], eye[1], eye[2]);
camera.lookAtCentre.set(centre[0], centre[1], centre[2]);
step++;
}
return Arrays.asList(new VisualChangeBuilder(VisualProperty.CAMERA).forItems(1).withId(flyingAnimationId).build());
}
use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.
the class FlyingAnimation method getNextVertex.
private Vector3f getNextVertex(final GraphReadMethods rg, final float mix) {
final Vector3f xyz;
// If there is no valid graph just return a default vector
if (rg.getVertexCount() == 0) {
return new Vector3f(0, 0, 0);
}
currentVxId = getNextVertexId(rg);
float x = rg.getFloatValue(xAttr, currentVxId);
float y = rg.getFloatValue(yAttr, currentVxId);
float z = rg.getFloatValue(zAttr, currentVxId);
if (doMixing) {
final float x2 = rg.getFloatValue(x2Attr, currentVxId);
final float y2 = rg.getFloatValue(y2Attr, currentVxId);
final float z2 = rg.getFloatValue(z2Attr, currentVxId);
x = Graphics3DUtilities.mix(x, x2, mix);
y = Graphics3DUtilities.mix(y, y2, mix);
z = Graphics3DUtilities.mix(z, z2, mix);
}
final float r = rAttr != Graph.NOT_FOUND ? rg.getFloatValue(rAttr, currentVxId) : 1;
xyz = new Vector3f(x + r * 1.5F, y + r * 1.5F, z + r * 1.5F);
return xyz;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.
the class BoxSelectionPlugin method convertWorldToScene.
/*
* Takes the x,y,z coordinate of a point in the world and translates it into
* the equivilant coordinate in the current scene.
*/
private Vector3f convertWorldToScene(final float x, final float y, final float z, final Vector3f centre, final Matrix33f rotationMatrix, final float cameraDistance) {
// Convert world coordinates to camera coordinates.
final Vector3f worldLocation = new Vector3f();
final Vector3f sceneLocation = new Vector3f();
worldLocation.set(x, y, z);
worldLocation.subtract(centre);
sceneLocation.rotate(worldLocation, rotationMatrix);
sceneLocation.setZ(sceneLocation.getZ() - cameraDistance);
return sceneLocation;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f 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);
}
Aggregations