Search in sources :

Example 1 with HitState

use of au.gov.asd.tac.constellation.graph.interaction.framework.HitState in project constellation by constellation-app.

the class GraphRendererDropTarget method drop.

@Override
public void drop(final DropTargetDropEvent dtde) {
    BiConsumer<Graph, DropInfo> dropHandler = null;
    // Accept the drop, work out whether any graph dropper will handle it, and if so mark the drop as complete.
    dtde.acceptDrop(dtde.getDropAction());
    final Collection<? extends GraphDropper> droppers = Lookup.getDefault().lookupAll(GraphDropper.class);
    for (final GraphDropper dropper : droppers) {
        dropHandler = dropper.drop(dtde);
        if (dropHandler != null) {
            break;
        }
    }
    dtde.dropComplete(dropHandler != null);
    // (Note this has to be in a new thread because hit testing is done on the EDT, which we need to wait for the results of, but we are already on the EDT).
    if (dropHandler != null) {
        BiConsumer<Graph, DropInfo> resultDropHandler = dropHandler;
        final Thread computeDrop = new Thread(() -> {
            final Vector3f dropGraphLocation = processor.windowToGraphCoordinates(processor.getDisplayCamera(), dropLocation);
            final BlockingQueue<HitState> hitTestQueue = new ArrayBlockingQueue<>(1);
            manager.addOperation(processor.hitTestPoint(dropLocation.x, dropLocation.y, hitTestQueue));
            HitState hitState;
            while (true) {
                try {
                    hitState = hitTestQueue.take();
                    break;
                } catch (InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }
            }
            final DropInfo dropInfo = new DropInfo(dropGraphLocation, hitState.getCurrentHitId(), hitState.getCurrentHitType().equals(HitType.VERTEX), hitState.getCurrentHitType().equals(HitType.TRANSACTION));
            resultDropHandler.accept(graph, dropInfo);
        });
        computeDrop.setName("Graph Renderer Drop Target");
        computeDrop.start();
    }
}
Also used : DropInfo(au.gov.asd.tac.constellation.graph.visual.dragdrop.GraphDropper.DropInfo) HitState(au.gov.asd.tac.constellation.graph.interaction.framework.HitState) Graph(au.gov.asd.tac.constellation.graph.Graph) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) GraphDropper(au.gov.asd.tac.constellation.graph.visual.dragdrop.GraphDropper)

Example 2 with HitState

use of au.gov.asd.tac.constellation.graph.interaction.framework.HitState in project constellation by constellation-app.

the class HitTester method display.

@Override
public void display(final GLAutoDrawable drawable, final Matrix44f modelViewProjectionMatrix) {
    final GL3 gl = drawable.getGL().getGL3();
    if (needsResize) {
        gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, hitTestDepthBufferName[0]);
        gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT32, width, height);
        gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, hitTestRboName[0]);
        gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_R32F, width, height);
        gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, 0);
        needsResize = false;
    }
    if (!notificationQueues.isEmpty()) {
        final int x = hitTestRequest.getX();
        final int y = hitTestRequest.getY();
        // Windows-DPI-Scaling
        // 
        // If JOGL is ever fixed or another solution is found, either change
        // needsManualDPIScaling to return false (so there is effectively no
        // DPI scaling here) or to remove dpiScaleY below.
        float dpiScaleY = 1.0F;
        if (GLTools.needsManualDPIScaling()) {
            dpiScaleY = parent.getDPIScaleY();
        }
        final int surfaceHeight = (int) (drawable.getSurfaceHeight() * dpiScaleY);
        // Allocate 3 floats for RGB values.
        FloatBuffer fbuf = Buffers.newDirectFloatBuffer(3);
        gl.glBindFramebuffer(GL.GL_READ_FRAMEBUFFER, hitTestFboName[0]);
        gl.glReadBuffer(HIT_TEST_BUFFER_NAME);
        gl.glReadPixels(x, surfaceHeight - y, 1, 1, GL.GL_RGB, GL.GL_FLOAT, fbuf);
        // There are enough colors in the buffer that we only need worry about
        // r component for now. That gives us 2**22 distinct values.
        final int r = (int) (fbuf.get(0));
        final int id;
        final HitType currentHitType;
        if (r == 0) {
            currentHitType = HitType.NO_ELEMENT;
            id = -1;
        } else {
            currentHitType = r > 0 ? HitType.VERTEX : HitType.TRANSACTION;
            id = r > 0 ? r - 1 : -r - 1;
        }
        final HitState hitState = hitTestRequest.getHitState();
        hitState.setCurrentHitId(id);
        hitState.setCurrentHitType(currentHitType);
        if (hitTestRequest.getFollowUpOperation() != null) {
            hitTestRequest.getFollowUpOperation().accept(hitState);
        }
        synchronized (this.notificationQueues) {
            while (!notificationQueues.isEmpty()) {
                final Queue<HitState> queue = notificationQueues.remove();
                if (queue != null) {
                    queue.add(hitState);
                }
            }
        }
    }
}
Also used : HitState(au.gov.asd.tac.constellation.graph.interaction.framework.HitState) HitType(au.gov.asd.tac.constellation.graph.interaction.framework.HitState.HitType) FloatBuffer(java.nio.FloatBuffer) GL3(com.jogamp.opengl.GL3)

Aggregations

HitState (au.gov.asd.tac.constellation.graph.interaction.framework.HitState)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 HitType (au.gov.asd.tac.constellation.graph.interaction.framework.HitState.HitType)1 GraphDropper (au.gov.asd.tac.constellation.graph.visual.dragdrop.GraphDropper)1 DropInfo (au.gov.asd.tac.constellation.graph.visual.dragdrop.GraphDropper.DropInfo)1 Vector3f (au.gov.asd.tac.constellation.utilities.graphics.Vector3f)1 GL3 (com.jogamp.opengl.GL3)1 FloatBuffer (java.nio.FloatBuffer)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1