Search in sources :

Example 1 with ConstellationPointMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker in project constellation by constellation-app.

the class PointMarkerErrorLayer method update.

@Override
public PImage update() {
    if (map.getMarkers().isEmpty()) {
        return null;
    }
    markerCount = map.getMarkers().size();
    final int width = renderer.width - 5;
    final int height = renderer.height - 5;
    // get on screen markers
    final ScreenPosition topLeft = map.getScreenPosition(map.getTopLeftBorder());
    final ScreenPosition bottomRight = map.getScreenPosition(map.getBottomRightBorder());
    final List<ConstellationAbstractMarker> markers = renderer.getMarkerCache().getAllMarkers().stream().filter(marker -> {
        final ScreenPosition markerPosition = map.getScreenPosition(marker.getLocation());
        return markerPosition != null && markerPosition.x > topLeft.x && markerPosition.y > topLeft.y && markerPosition.x < bottomRight.x && markerPosition.y < bottomRight.y;
    }).collect(Collectors.toList());
    // create error region data from markers
    final PGraphics errorRegionImage = renderer.createGraphics(width, height, PConstants.JAVA2D);
    errorRegionImage.beginDraw();
    errorRegionImage.stroke(STROKE_COLOR);
    errorRegionImage.fill(ERROR_REGION_COLOR);
    if (graph != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int vertexPrecisionAttributeId = SpatialConcept.VertexAttribute.PRECISION.get(readableGraph);
            final int transactionPrecisionAttributeId = SpatialConcept.TransactionAttribute.PRECISION.get(readableGraph);
            for (final ConstellationAbstractMarker marker : markers) {
                if (!(marker instanceof ConstellationPointMarker)) {
                    continue;
                }
                float minimumPrecision = DEFAULT_PRECISION;
                final Set<GraphElement> elements = renderer.getMarkerCache().get(marker);
                for (final GraphElement element : elements) {
                    final float elementPrecision;
                    switch(element.getType()) {
                        case VERTEX:
                            if (vertexPrecisionAttributeId != Graph.NOT_FOUND) {
                                elementPrecision = readableGraph.getFloatValue(vertexPrecisionAttributeId, element.getId());
                                minimumPrecision = Math.max(elementPrecision, minimumPrecision);
                            } else {
                                elementPrecision = DEFAULT_PRECISION;
                                minimumPrecision = DEFAULT_PRECISION;
                            }
                            break;
                        case TRANSACTION:
                            elementPrecision = transactionPrecisionAttributeId != Graph.NOT_FOUND ? readableGraph.getFloatValue(transactionPrecisionAttributeId, element.getId()) : DEFAULT_PRECISION;
                            break;
                        default:
                            elementPrecision = DEFAULT_PRECISION;
                            break;
                    }
                    minimumPrecision = Math.max(elementPrecision, minimumPrecision);
                }
                // don't bother drawing if there isn't a precision
                if (minimumPrecision == 0) {
                    continue;
                }
                final Location errorRegionRadiusLocation = new Location(marker.getLocation().getLat() - Haversine.kilometersToDecimalDegrees(minimumPrecision), marker.getLocation().getLon() - Haversine.kilometersToDecimalDegrees(minimumPrecision));
                final List<Location> errorRegionLocations = MarkerUtilities.generateCircle(marker.getLocation(), errorRegionRadiusLocation);
                final List<MapPosition> errorRegionPositions = errorRegionLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
                errorRegionImage.beginShape();
                errorRegionPositions.forEach(position -> errorRegionImage.vertex(position.x, position.y));
                errorRegionImage.endShape(PConstants.CLOSE);
            }
        } finally {
            readableGraph.release();
        }
    }
    errorRegionImage.endDraw();
    return errorRegionImage;
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) MarkerUtilities(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerUtilities) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphElement(au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement) Set(java.util.Set) SpatialConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept) PGraphics(processing.core.PGraphics) PImage(processing.core.PImage) ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) Collectors(java.util.stream.Collectors) Graph(au.gov.asd.tac.constellation.graph.Graph) PConstants(processing.core.PConstants) List(java.util.List) Location(de.fhpotsdam.unfolding.geo.Location) Haversine(au.gov.asd.tac.constellation.utilities.geospatial.Distance.Haversine) ServiceProvider(org.openide.util.lookup.ServiceProvider) ConstellationPointMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker) ScreenPosition(de.fhpotsdam.unfolding.utils.ScreenPosition) MapPosition(de.fhpotsdam.unfolding.utils.MapPosition) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) PGraphics(processing.core.PGraphics) ScreenPosition(de.fhpotsdam.unfolding.utils.ScreenPosition) GraphElement(au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement) ConstellationPointMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker) MapPosition(de.fhpotsdam.unfolding.utils.MapPosition) Location(de.fhpotsdam.unfolding.geo.Location)

Example 2 with ConstellationPointMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker 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)

Aggregations

ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2 ConstellationPointMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 SpatialConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept)1 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)1 Haversine (au.gov.asd.tac.constellation.utilities.geospatial.Distance.Haversine)1 ConstellationAbstractMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker)1 ConstellationClusterMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationClusterMarker)1 ConstellationLineMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationLineMarker)1 ConstellationMultiMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMultiMarker)1 ConstellationPolygonMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker)1 GraphElement (au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement)1 MarkerUtilities (au.gov.asd.tac.constellation.views.mapview.utilities.MarkerUtilities)1 Location (de.fhpotsdam.unfolding.geo.Location)1 MapPosition (de.fhpotsdam.unfolding.utils.MapPosition)1 ScreenPosition (de.fhpotsdam.unfolding.utils.ScreenPosition)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1