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;
}
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();
}
}
}
Aggregations