use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class NewLineRenderable method update.
@Override
public void update(final GLAutoDrawable drawable) {
final Camera camera = parent.getDisplayCamera();
NewLineModel updatedModel = modelQueue.peek();
while (updatedModel != null && updatedModel.getCamera() != camera) {
modelQueue.remove();
updatedModel = modelQueue.peek();
}
if (updatedModel != null) {
updatedModel = modelQueue.remove();
NewLineModel nextModel = modelQueue.peek();
while (nextModel != null && nextModel.getCamera() == camera) {
updatedModel = modelQueue.remove();
nextModel = modelQueue.peek();
}
modelQueue.addFirst(updatedModel);
}
model = updatedModel;
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class BBoxf method getGraphBoundingBoxMix.
/**
* Get the bounding box of this graph.
* <p>
* Takes mixing into account.
*
* @param rg The graph to create a bounding box from.
* @param selectedOnly True to only include selected vertices, false to
* include all vertices.
*
* @return The bounding box of the relevant vertices.
*/
public static BBoxf getGraphBoundingBoxMix(final GraphReadMethods rg, final boolean selectedOnly) {
int xId = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.X.getName());
int yId = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Y.getName());
int zId = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Z.getName());
final int x2Id = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.X2.getName());
final int y2Id = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Y2.getName());
final int z2Id = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Z2.getName());
final int selectedId = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.SELECTED.getName());
final int visualStateId = VisualConcept.GraphAttribute.CAMERA.get(rg);
final Camera visualState = rg.getObjectValue(visualStateId, 0);
final float mix = visualState.getMix();
final float inverseMix = 1.0F - mix;
boolean requiresMix = x2Id != Graph.NOT_FOUND && y2Id != Graph.NOT_FOUND && z2Id != Graph.NOT_FOUND;
if (requiresMix) {
if (mix == 0.0F) {
requiresMix = false;
} else if (mix == 1.0F) {
xId = x2Id;
yId = y2Id;
zId = z2Id;
requiresMix = false;
} else {
// Do nothing
}
}
final int vxCount = rg.getVertexCount();
final BBoxf box = new BBoxf();
for (int position = 0; position < vxCount; position++) {
final int vxId = rg.getVertex(position);
final boolean selected = rg.getBooleanValue(selectedId, vxId);
if (!selectedOnly || selected) {
float x = rg.getFloatValue(xId, vxId);
float y = rg.getFloatValue(yId, vxId);
float z = rg.getFloatValue(zId, vxId);
if (requiresMix) {
x = inverseMix * x + mix * rg.getFloatValue(x2Id, vxId);
y = inverseMix * y + mix * rg.getFloatValue(y2Id, vxId);
z = inverseMix * z + mix * rg.getFloatValue(z2Id, vxId);
}
box.add(x, y, z);
}
}
return box;
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class CameraIOProvider method readObject.
/**
* Deserialise an object from a JsonNode.
* <p>
* Refer to base class for detailed description.
*
* @param attributeId The id of the attribute being read.
* @param elementId The id of the element being read.
* @param jnode The JsonNode to read from.
* @param graph The graph that the resulting object will be placed in. Provided in case
* the object requires some graph data.
* @param vertexMap (not used) A mapping from a vertex id in the file to the vertex id
* in the graph.
* @param transactionMap (not used) A mapping from a transaction id in the file to the
* transaction id in the graph.
* @param byteReader (not used) The byte reader containing ancillary data (e.g. images)
* that doesn't easily fit into a JSON document.
* @param cache (not used) a cache that can be used to dedup identical instances of the
* same immutable objects.
* @throws java.io.IOException If there's a problem reading the document.
*/
@Override
public void readObject(int attributeId, int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, ImmutableObjectCache cache) {
if (!jnode.isNull()) {
final Camera camera = new Camera();
final Vector3f lookAtEye = getVector(jnode, LOOK_AT_EYE);
final Vector3f lookAtCentre = getVector(jnode, LOOK_AT_CENTRE);
final Vector3f lookAtUp = getVector(jnode, LOOK_AT_UP);
final Vector3f lookAtRotation = getVector(jnode, LOOK_AT_ROTATION);
final Vector3f lookAtPreviousEye = getVector(jnode, LOOK_AT_PREVIOUS_EYE);
final Vector3f lookAtPreviousCentre = getVector(jnode, LOOK_AT_PREVIOUS_CENTRE);
final Vector3f lookAtPreviousUp = getVector(jnode, LOOK_AT_PREVIOUS_UP);
final Vector3f lookAtPreviousRotation = getVector(jnode, LOOK_AT_PREVIOUS_ROTATION);
// In case the look_at objects aren't there, or they're there but aren't valid numbers...
boolean eyeIsOk = lookAtEye != null && lookAtCentre != null && lookAtUp != null && lookAtRotation != null && lookAtPreviousEye != null && lookAtPreviousCentre != null && lookAtPreviousUp != null && lookAtPreviousRotation != null;
if (eyeIsOk) {
eyeIsOk = lookAtEye.isValid() && lookAtCentre.isValid() && lookAtUp.isValid() && lookAtRotation.isValid() && lookAtPreviousEye != null && lookAtPreviousCentre.isValid() && lookAtPreviousUp.isValid() && lookAtPreviousRotation.isValid();
}
if (eyeIsOk) {
camera.lookAtEye.set(lookAtEye);
camera.lookAtCentre.set(lookAtCentre);
camera.lookAtUp.set(lookAtUp);
camera.lookAtRotation.set(lookAtRotation);
camera.lookAtPreviousEye.set(lookAtPreviousEye);
camera.lookAtPreviousCentre.set(lookAtPreviousCentre);
camera.lookAtPreviousUp.set(lookAtPreviousUp);
camera.lookAtPreviousRotation.set(lookAtPreviousRotation);
getBoundingBox(camera.boundingBox, jnode, BOUNDING_BOX);
}
camera.setObjectFrame(getFrame(jnode, FRAME));
camera.setVisibilityLow((float) jnode.get(VISIBILITY_LOW).doubleValue());
camera.setVisibilityHigh((float) jnode.get(VISIBILITY_HIGH).doubleValue());
camera.setMixRatio((int) jnode.get(MIX_RATIO).doubleValue());
graph.setObjectValue(attributeId, elementId, camera);
}
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class CameraIOProvider method writeObject.
/**
* Write this object to the JSON generator.
* <p>
* Refer to base class for detailed description.
*
* @param attr The attribute being written.
* @param elementId The id of the element being written.
* @param jsonGenerator The JsonGenerator used to write to the JSON document.
* @param graph The graph that the object belongs to. Provided in case the object requires some
* graph data.
* @param byteWriter (not used) For ancillary data (e.g. images) that doesn't easily
* fit into a JSON document.
* @param verbose Determines whether to write default values of attributes or not.
* @throws IOException
*/
@Override
public void writeObject(final Attribute attr, final int elementId, final com.fasterxml.jackson.core.JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) {
final Camera camera = (Camera) graph.getObjectValue(attr.getId(), elementId);
if (camera == null) {
jsonGenerator.writeNullField(attr.getName());
} else {
jsonGenerator.writeObjectFieldStart(attr.getName());
addVector(jsonGenerator, LOOK_AT_EYE, camera.lookAtEye);
addVector(jsonGenerator, LOOK_AT_CENTRE, camera.lookAtCentre);
addVector(jsonGenerator, LOOK_AT_UP, camera.lookAtUp);
addVector(jsonGenerator, LOOK_AT_ROTATION, camera.lookAtRotation);
addVector(jsonGenerator, LOOK_AT_PREVIOUS_EYE, camera.lookAtPreviousEye);
addVector(jsonGenerator, LOOK_AT_PREVIOUS_CENTRE, camera.lookAtPreviousCentre);
addVector(jsonGenerator, LOOK_AT_PREVIOUS_UP, camera.lookAtPreviousUp);
addVector(jsonGenerator, LOOK_AT_PREVIOUS_ROTATION, camera.lookAtPreviousRotation);
addFrame(jsonGenerator, FRAME, camera.getObjectFrame());
addBoundingBox(jsonGenerator, BOUNDING_BOX, camera.boundingBox);
jsonGenerator.writeNumberField(VISIBILITY_LOW, camera.getVisibilityLow());
jsonGenerator.writeNumberField(VISIBILITY_HIGH, camera.getVisibilityHigh());
jsonGenerator.writeNumberField(MIX_RATIO, camera.getMixRatio());
jsonGenerator.writeEndObject();
}
}
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class CameraIOProviderNGTest method testWriteObject.
/**
* Test of writeObject method, of class CameraIOProvider.
*/
@Test
public void testWriteObject() throws Exception {
System.out.println("CameraIOProviderNGTest.testWriteObject");
// Test case where not verbose and default graph value
resetMocking();
when(mockGraphReadMethods.isDefaultValue(attributeId, elementId)).thenReturn(true);
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, false);
Mockito.verify(mockGraphReadMethods, times(0)).getObjectValue(anyInt(), anyInt());
// Test case where not verbose and not default graph value
resetMocking();
when(mockGraphReadMethods.isDefaultValue(attributeId, elementId)).thenReturn(false);
when(mockGraphReadMethods.getObjectValue(attributeId, elementId)).thenReturn(null);
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, false);
Mockito.verify(mockGraphReadMethods, times(1)).getObjectValue(attributeId, elementId);
Mockito.verify(mockJsonGenerator, times(1)).writeNullField(attr.getName());
Mockito.verify(mockJsonGenerator, times(0)).writeArrayFieldStart(anyString());
// Test case where verbose and not default graph value
resetMocking();
when(mockGraphReadMethods.isDefaultValue(attributeId, elementId)).thenReturn(false);
when(mockGraphReadMethods.getObjectValue(attributeId, elementId)).thenReturn(null);
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, true);
Mockito.verify(mockGraphReadMethods, times(1)).getObjectValue(attributeId, elementId);
Mockito.verify(mockJsonGenerator, times(1)).writeNullField(attr.getName());
Mockito.verify(mockJsonGenerator, times(0)).writeArrayFieldStart(anyString());
// Test case where verbose and default graph value
resetMocking();
Camera camera = new Camera();
camera.setVisibilityLow(0.0f);
camera.setVisibilityHigh(1.0f);
camera.setMixRatio(2);
camera.lookAtEye.set(0.0f, 0.1f, 0.2f);
camera.lookAtCentre.set(1.0f, 1.1f, 1.2f);
camera.lookAtUp.set(2.0f, 2.1f, 2.2f);
camera.lookAtRotation.set(3.0f, 3.1f, 3.2f);
camera.lookAtPreviousEye.set(4.0f, 4.1f, 4.2f);
camera.lookAtPreviousCentre.set(5.0f, 5.1f, 5.2f);
camera.lookAtPreviousUp.set(6.0f, 6.1f, 6.2f);
camera.lookAtPreviousRotation.set(7.0f, 7.1f, 7.2f);
Frame objFrame = new Frame();
objFrame.setOrigin(new Vector3f(0.0f, 0.1f, 0.2f));
objFrame.setForwardVector(new Vector3f(1.0f, 1.1f, 1.2f));
objFrame.setUpVector(new Vector3f(2.0f, 2.1f, 2.2f));
camera.setObjectFrame(objFrame);
camera.boundingBox.set(new Vector3f(0.0f, 0.1f, 0.2f), new Vector3f(1.0f, 1.1f, 1.2f), new Vector3f(2.0f, 2.1f, 2.2f), new Vector3f(3.0f, 3.1f, 3.2f));
when(mockGraphReadMethods.isDefaultValue(attributeId, elementId)).thenReturn(true);
when(mockGraphReadMethods.getObjectValue(attributeId, elementId)).thenReturn(camera);
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, true);
Mockito.verify(mockGraphReadMethods, times(1)).getObjectValue(attributeId, elementId);
Mockito.verify(mockJsonGenerator, times(0)).writeNullField(anyString());
Mockito.verify(mockJsonGenerator, times(1)).writeObjectFieldStart(attr.getName());
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("look_at_eye");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("look_at_centre");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("look_at_up");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("look_at_rotation");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("look_at_previous_eye");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("look_at_previous_centre");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("look_at_previous_up");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("look_at_previous_rotation");
Mockito.verify(mockJsonGenerator, times(1)).writeObjectFieldStart("frame");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("origin");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("forward");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("up");
Mockito.verify(mockJsonGenerator, times(1)).writeObjectFieldStart("bounding_box");
Mockito.verify(mockJsonGenerator, times(1)).writeBooleanField("is_empty", false);
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("min");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("max");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("min2");
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart("max2");
Mockito.verify(mockJsonGenerator, times(15)).writeEndArray();
Mockito.verify(mockJsonGenerator, times(1)).writeNumberField("visibility_low", 0.0f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumberField("visibility_high", 1.0f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumberField("mix_ratio", 2);
Mockito.verify(mockJsonGenerator, times(3)).writeEndObject();
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(0.0f);
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(0.1f);
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(0.2f);
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(1.0f);
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(1.1f);
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(1.2f);
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(2.0f);
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(2.1f);
Mockito.verify(mockJsonGenerator, times(3)).writeNumber(2.2f);
Mockito.verify(mockJsonGenerator, times(2)).writeNumber(3.0f);
Mockito.verify(mockJsonGenerator, times(2)).writeNumber(3.1f);
Mockito.verify(mockJsonGenerator, times(2)).writeNumber(3.2f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(4.0f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(4.1f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(4.2f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(5.0f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(5.1f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(5.2f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(6.0f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(6.1f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(6.2f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(7.0f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(7.1f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumber(7.2f);
}
Aggregations