Search in sources :

Example 11 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class MarkerCache method styleMarkers.

public void styleMarkers(final Graph graph, final MarkerState markerState) {
    assert !SwingUtilities.isEventDispatchThread();
    // update style based on graph attributes
    if (graph != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int elementMixColorAttributeId = VisualConcept.GraphAttribute.MIX_COLOR.get(readableGraph);
            final ConstellationColor mixColor = elementMixColorAttributeId != Graph.NOT_FOUND ? readableGraph.getObjectValue(elementMixColorAttributeId, 0) : null;
            synchronized (lock) {
                forEach((marker, elementList) -> {
                    if (marker != null) {
                        final Set<String> labels = new HashSet<>();
                        final Set<ConstellationColor> colors = new HashSet<>();
                        boolean selected = false;
                        boolean dimmed = false;
                        boolean hidden = false;
                        // get relevent attribute ids
                        int elementVisibilityAttributeId;
                        int elementDimmedAttributeId;
                        int elementSelectedAttributeId;
                        int elementLabelAttributeId;
                        int elementColorAttributeId;
                        for (final GraphElement element : elementList) {
                            switch(element.getType()) {
                                case VERTEX:
                                    if (markerState.getLabel() == null) {
                                        elementLabelAttributeId = GraphConstants.NOT_FOUND;
                                    } else {
                                        elementLabelAttributeId = markerState.getLabel().getVertexAttribute() == null ? GraphConstants.NOT_FOUND : markerState.getLabel().getVertexAttribute().get(readableGraph);
                                    }
                                    if (markerState.getColorScheme() == null) {
                                        elementColorAttributeId = GraphConstants.NOT_FOUND;
                                    } else {
                                        elementColorAttributeId = markerState.getColorScheme().getVertexAttribute() == null ? GraphConstants.NOT_FOUND : markerState.getColorScheme().getVertexAttribute().get(readableGraph);
                                    }
                                    elementSelectedAttributeId = VisualConcept.VertexAttribute.SELECTED.get(readableGraph);
                                    elementDimmedAttributeId = VisualConcept.VertexAttribute.DIMMED.get(readableGraph);
                                    elementVisibilityAttributeId = VisualConcept.VertexAttribute.VISIBILITY.get(readableGraph);
                                    break;
                                case TRANSACTION:
                                    if (markerState.getLabel() == null) {
                                        elementLabelAttributeId = GraphConstants.NOT_FOUND;
                                    } else {
                                        elementLabelAttributeId = markerState.getLabel().getTransactionAttribute() == null ? GraphConstants.NOT_FOUND : markerState.getLabel().getTransactionAttribute().get(readableGraph);
                                    }
                                    if (markerState.getColorScheme() == null) {
                                        elementColorAttributeId = GraphConstants.NOT_FOUND;
                                    } else {
                                        elementColorAttributeId = markerState.getColorScheme().getTransactionAttribute() == null ? GraphConstants.NOT_FOUND : markerState.getColorScheme().getTransactionAttribute().get(readableGraph);
                                    }
                                    elementSelectedAttributeId = VisualConcept.TransactionAttribute.SELECTED.get(readableGraph);
                                    elementDimmedAttributeId = VisualConcept.TransactionAttribute.DIMMED.get(readableGraph);
                                    elementVisibilityAttributeId = VisualConcept.TransactionAttribute.VISIBILITY.get(readableGraph);
                                    break;
                                default:
                                    if (marker.isCustom()) {
                                        colors.add(MarkerUtilities.value(MarkerUtilities.DEFAULT_CUSTOM_COLOR));
                                        selected |= marker.isSelected();
                                        dimmed |= marker.isDimmed();
                                    }
                                    continue;
                            }
                            final int elementId = element.getId();
                            // get label
                            if (elementLabelAttributeId != GraphConstants.NOT_FOUND) {
                                labels.add(readableGraph.getStringValue(elementLabelAttributeId, elementId));
                            }
                            // get color
                            if (elementColorAttributeId != GraphConstants.NOT_FOUND) {
                                switch(markerState.getColorScheme()) {
                                    case COLOR:
                                    case OVERLAY:
                                        colors.add(readableGraph.getObjectValue(elementColorAttributeId, elementId));
                                        break;
                                    case BLAZE:
                                        // give the blazes a color and default to the color scheme for non blazed nodes
                                        if (readableGraph.getObjectValue(elementColorAttributeId, elementId) != null) {
                                            colors.add(((Blaze) readableGraph.getObjectValue(elementColorAttributeId, elementId)).getColor());
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }
                            // get selected
                            if (elementSelectedAttributeId != GraphConstants.NOT_FOUND && readableGraph.getBooleanValue(elementSelectedAttributeId, elementId)) {
                                selected |= true;
                            }
                            // get dimming
                            if (elementDimmedAttributeId != GraphConstants.NOT_FOUND && readableGraph.getBooleanValue(elementDimmedAttributeId, elementId)) {
                                dimmed |= true;
                            }
                            // get visibility
                            if (elementVisibilityAttributeId != GraphConstants.NOT_FOUND && readableGraph.getFloatValue(elementVisibilityAttributeId, elementId) <= 0) {
                                hidden |= true;
                            }
                        }
                        // update label
                        if (labels.isEmpty()) {
                            marker.setId(null);
                        } else if (labels.size() == 1) {
                            marker.setId(labels.iterator().next());
                        } else {
                            marker.setId(MULTIPLE_VALUES);
                        }
                        // update color
                        if (colors.isEmpty()) {
                            marker.setColor(MarkerUtilities.DEFAULT_COLOR);
                        } else if (colors.size() == 1) {
                            marker.setColor(MarkerUtilities.color(colors.iterator().next()));
                        } else {
                            marker.setColor(MarkerUtilities.color(mixColor));
                        }
                        // update selection
                        marker.setSelected(selected);
                        // update dimming
                        marker.setDimmed(dimmed);
                        // update visibility
                        if ((markerState.isShowSelectedOnly() && !marker.isSelected()) || (!markerState.isShowPointMarkers() && marker instanceof ConstellationPointMarker) || (!markerState.isShowLineMarkers() && marker instanceof ConstellationLineMarker) || (!markerState.isShowPolygonMarkers() && marker instanceof ConstellationPolygonMarker) || (!markerState.isShowMultiMarkers() && marker instanceof ConstellationMultiMarker) || (!markerState.isShowClusterMarkers() && marker instanceof ConstellationClusterMarker)) {
                            marker.setHidden(true);
                        } else {
                            marker.setHidden(hidden);
                        }
                    }
                });
            }
        } finally {
            readableGraph.release();
        }
    }
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ConstellationMultiMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMultiMarker) ConstellationLineMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationLineMarker) DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint) ConstellationClusterMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationClusterMarker) ConstellationPolygonMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker) ConstellationPointMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker) HashSet(java.util.HashSet)

Example 12 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class ThiessenPolygonsLayer method update.

@Override
public PImage update() {
    // update on screen markers
    final ScreenPosition topLeft = map.getScreenPosition(map.getTopLeftBorder());
    final ScreenPosition bottomRight = map.getScreenPosition(map.getBottomRightBorder());
    final List<Marker> onScreenMarkers = map.getMarkers().stream().filter(marker -> {
        final ScreenPosition markerPosition = map.getScreenPosition(marker.getLocation());
        return !marker.isHidden() && markerPosition != null && markerPosition.x > topLeft.x && markerPosition.y > topLeft.y && markerPosition.x < bottomRight.x && markerPosition.y < bottomRight.y;
    }).collect(Collectors.toList());
    onScreenMarkerCount = onScreenMarkers.size();
    if (onScreenMarkers.isEmpty()) {
        return null;
    }
    // map markers to screen positions
    final Map<Marker, ScreenPosition> positionMap = onScreenMarkers.stream().collect(Collectors.toMap(marker -> marker, marker -> map.getScreenPosition(marker.getLocation()), (marker1, marker2) -> marker1));
    // map markers to colors
    final ConstellationColor[] palette = ConstellationColor.createPalette(onScreenMarkerCount);
    final Map<Marker, Integer> paletteMap = new HashMap<>();
    onScreenMarkers.forEach(marker -> paletteMap.put(marker, MarkerUtilities.color(palette[onScreenMarkers.indexOf(marker)])));
    final int width = renderer.width - 5;
    final int height = renderer.height - 5;
    final PImage voronoiImage = renderer.createImage(width, height, PConstants.ARGB);
    voronoiImage.loadPixels();
    for (int pixelIndex = 0; pixelIndex < voronoiImage.pixels.length; pixelIndex++) {
        // find the closest marker to this pixel
        final ScreenPosition pixelPosition = pixelPosition(pixelIndex, width, height);
        Marker closestMarker = null;
        for (final Marker marker : onScreenMarkers) {
            if (closestMarker == null) {
                closestMarker = marker;
            } else {
                final ScreenPosition markerPosition = positionMap.get(marker);
                final ScreenPosition closestMarkerPosition = positionMap.get(closestMarker);
                if (markerPosition != null && closestMarkerPosition != null && euclidianDistance((int) pixelPosition.x, (int) pixelPosition.y, (int) markerPosition.x, (int) markerPosition.y) < euclidianDistance((int) pixelPosition.x, (int) pixelPosition.y, (int) closestMarkerPosition.x, (int) closestMarkerPosition.y)) {
                    closestMarker = marker;
                }
            }
        }
        // color this pixel based on its closest marker
        if (closestMarker != null && paletteMap.get(closestMarker) != null) {
            voronoiImage.pixels[pixelIndex] = paletteMap.get(closestMarker);
        }
    }
    voronoiImage.updatePixels();
    return voronoiImage;
}
Also used : PConstants(processing.core.PConstants) List(java.util.List) MarkerUtilities(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerUtilities) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) Map(java.util.Map) ServiceProvider(org.openide.util.lookup.ServiceProvider) ScreenPosition(de.fhpotsdam.unfolding.utils.ScreenPosition) HashMap(java.util.HashMap) Marker(de.fhpotsdam.unfolding.marker.Marker) PImage(processing.core.PImage) Collectors(java.util.stream.Collectors) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) PImage(processing.core.PImage) HashMap(java.util.HashMap) Marker(de.fhpotsdam.unfolding.marker.Marker) ScreenPosition(de.fhpotsdam.unfolding.utils.ScreenPosition)

Example 13 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class BlazeBatcher method bufferBlaze.

private void bufferBlaze(final int pos, final FloatArray colorBuffer, final IntArray infoBuffer, final VisualAccess access) {
    if (access.isBlazed(pos)) {
        final ConstellationColor blazeColor = access.getBlazeColor(pos);
        final int blazeAngle = access.getBlazeAngle(pos);
        final float visibility = access.getVertexVisibility(pos);
        colorBuffer.add(blazeColor.getRed(), blazeColor.getGreen(), blazeColor.getBlue(), visibility);
        infoBuffer.add(pos, -1, blazeAngle, 0);
    }
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor)

Example 14 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class ConnectionLabelBatcher method setLabelColors.

public GLRenderableUpdateTask setLabelColors(final VisualAccess access) {
    final int numConnectionLabels = Math.min(LabelUtilities.MAX_LABELS_TO_DRAW, access.getConnectionAttributeLabelCount());
    for (int i = 0; i < numConnectionLabels; i++) {
        final ConstellationColor labelColor = access.getConnectionLabelColor(i);
        attributeLabelInfoReference.setRow(labelColor.getRed(), labelColor.getGreen(), labelColor.getBlue(), attributeLabelInfoReference.get(i, 3), i);
    }
    return gl -> attributeLabelInfo.set(attributeLabelInfoReference);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) GL3(com.jogamp.opengl.GL3) TextureUnits(au.gov.asd.tac.constellation.visual.opengl.renderer.TextureUnits) SharedDrawable(au.gov.asd.tac.constellation.visual.opengl.utilities.SharedDrawable) FloatBuffer(java.nio.FloatBuffer) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) ConnectionGlyphStream(au.gov.asd.tac.constellation.visual.opengl.utilities.glyphs.ConnectionGlyphStream) LabelUtilities(au.gov.asd.tac.constellation.visual.opengl.utilities.LabelUtilities) IOException(java.io.IOException) ArrayList(java.util.ArrayList) GLRenderableUpdateTask(au.gov.asd.tac.constellation.visual.opengl.renderer.GLRenderable.GLRenderableUpdateTask) VisualAccess(au.gov.asd.tac.constellation.utilities.visual.VisualAccess) IntBuffer(java.nio.IntBuffer) VisualGraphDefaults(au.gov.asd.tac.constellation.graph.visual.framework.VisualGraphDefaults) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera) Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) ConnectionGlyphStreamContext(au.gov.asd.tac.constellation.visual.opengl.utilities.glyphs.ConnectionGlyphStreamContext) GL(com.jogamp.opengl.GL)

Example 15 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class IconBatcher method bufferColorInfo.

private int bufferColorInfo(final int pos, final FloatBuffer colorBuffer, final VisualAccess access) {
    ConstellationColor color = access.getVertexColor(pos);
    colorBuffer.put(color.getRed());
    colorBuffer.put(color.getGreen());
    colorBuffer.put(color.getBlue());
    colorBuffer.put(access.getVertexVisibility(pos));
    return pos;
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor)

Aggregations

ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)67 ArrayList (java.util.ArrayList)13 Test (org.testng.annotations.Test)11 Color (java.awt.Color)9 BitSet (java.util.BitSet)9 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)8 IOException (java.io.IOException)7 Graph (au.gov.asd.tac.constellation.graph.Graph)6 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)6 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)6 List (java.util.List)6 File (java.io.File)5 HashMap (java.util.HashMap)5 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)4 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)4 Camera (au.gov.asd.tac.constellation.utilities.camera.Camera)4 Matrix44f (au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)4 VisualAccess (au.gov.asd.tac.constellation.utilities.visual.VisualAccess)4 GLRenderableUpdateTask (au.gov.asd.tac.constellation.visual.opengl.renderer.GLRenderable.GLRenderableUpdateTask)4 TextureUnits (au.gov.asd.tac.constellation.visual.opengl.renderer.TextureUnits)4