use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class VisualGraphUtilities method getCamera.
public static Camera getCamera(final GraphReadMethods graph) {
final int cameraAttribute = VisualConcept.GraphAttribute.CAMERA.get(graph);
final Camera camera = cameraAttribute != Graph.NOT_FOUND ? graph.getObjectValue(cameraAttribute, 0) : VisualGraphDefaults.DEFAULT_CAMERA;
return camera != null ? camera : VisualGraphDefaults.DEFAULT_CAMERA;
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class GraphVisualAccessNGTest method testGetCameraAttributeAdded.
/**
* Test of getCamera method when attribute is added, of class
* GraphVisualAccess.
*
* @throws InterruptedException
*/
@Test
public void testGetCameraAttributeAdded() throws InterruptedException {
System.out.println("getCameraAttributeAdded");
final WritableGraph wg = graph.getWritableGraph("Graph Visual Access", true);
try {
final int graphCameraAttribute = VisualConcept.GraphAttribute.CAMERA.ensure(wg);
final Camera newCamera = new Camera();
newCamera.setVisibilityHigh(0.6f);
wg.setObjectValue(graphCameraAttribute, 0, newCamera);
} finally {
wg.commit();
}
final GraphVisualAccess instance = new GraphVisualAccess(graph);
instance.beginUpdate();
instance.updateInternally();
final Camera camera = instance.getCamera();
instance.endUpdate();
assertEquals(camera.getVisibilityHigh(), 0.6f);
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class CameraIOProviderV0 method writeObject.
/**
* Write a Camera object into a JSON ObjectNode.
*
* @param attr
* @param root The Object Node to serialise into.
* @param state The Camera object to serialise.
* @param graph
*
* @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 CameraIOProviderV0 method readObject.
/**
* Create a new Camera object from a JsonNode.
*
* @param jnode The JsonNode to deserialise a Camera instance from.
* @param graph
*/
@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 GraphVisualAccessNGTest method testGetCameraAttributeNotFound.
/**
* Test of getCamera method when attribute is not found, of class
* GraphVisualAccess.
*
* @throws InterruptedException
*/
@Test
public void testGetCameraAttributeNotFound() throws InterruptedException {
System.out.println("getCameraAttributeNotFound");
final GraphVisualAccess instance = new GraphVisualAccess(graph);
instance.beginUpdate();
final Camera camera = instance.getCamera();
instance.endUpdate();
assertEquals(camera, VisualGraphDefaults.DEFAULT_CAMERA);
assertEquals(camera.getVisibilityHigh(), 1.0f);
}
Aggregations