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