Skip to content

Commit

Permalink
Fix selection rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
eduramiba committed Jun 11, 2024
1 parent 80a486f commit 765c724
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ enum GraphSelectionMode {
SIMPLE_MOUSE_SELECTION,
RECTANGLE_SELECTION
}

boolean someNodesOrEdgesSelection();

boolean isNodeSelected(Node node);

int getSelectedNodesCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public GraphSelectionImpl() {
this.selectionMode = GraphSelectionMode.SIMPLE_MOUSE_SELECTION;
}

@Override
public boolean someNodesOrEdgesSelection() {
return !nodes.isEmpty() || !edges.isEmpty();
}

@Override
public boolean isNodeSelected(Node node) {
return nodes.contains(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,9 @@ private void updateData(final GraphIndexImpl graphIndex, final GraphRenderingOpt
graphIndex.indexEdges();

//Selection:
final boolean someEdgesSelection = graphSelection.getSelectedEdgesCount() > 0;
final boolean someNodesSelection = graphSelection.getSelectedNodesCount() > 0;
final boolean someSelection = graphSelection.someNodesOrEdgesSelection();
final float lightenNonSelectedFactor = renderingOptions.getLightenNonSelectedFactor();
final boolean hideNonSelected = someEdgesSelection && (renderingOptions.isHideNonSelected() || lightenNonSelectedFactor >= 1);
final boolean hideNonSelected = someSelection && (renderingOptions.isHideNonSelected() || lightenNonSelectedFactor >= 1);
final boolean edgeSelectionColor = renderingOptions.isEdgeSelectionColor();
final float edgeBothSelectionColor = Float.intBitsToFloat(renderingOptions.getEdgeBothSelectionColor().getRGB());
final float edgeInSelectionColor = Float.intBitsToFloat(renderingOptions.getEdgeInSelectionColor().getRGB());
Expand All @@ -246,13 +245,13 @@ private void updateData(final GraphIndexImpl graphIndex, final GraphRenderingOpt
int attribsIndex = 0;
attribsIndex = updateUndirectedData(
graph,
someEdgesSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray,
graphSelection, someNodesSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor,
someSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray,
graphSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor,
attribs, attribsIndex
);
updateDirectedData(
graph, someEdgesSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray,
graphSelection, someNodesSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor,
graph, someSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray,
graphSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor,
attribs, attribsIndex
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected int setupShaderProgramForRenderingLayerUndirected(final GL2ES2 gl,
final RenderingLayer layer,
final VizEngine engine,
final float[] mvpFloats) {
final boolean someSelection = engine.getLookup().lookup(GraphSelection.class).getSelectedEdgesCount() > 0;
final boolean someSelection = engine.getLookup().lookup(GraphSelection.class).someNodesOrEdgesSelection();
final boolean renderingUnselectedEdges = layer.isBack();
if (!someSelection && renderingUnselectedEdges) {
return 0;
Expand Down Expand Up @@ -133,7 +133,7 @@ protected int setupShaderProgramForRenderingLayerUndirected(final GL2ES2 gl,
);

if (someSelection) {
if (someNodesSelection && edgeSelectionColor) {
if (someSelection && edgeSelectionColor) {
lineModelUndirected.useProgram(
gl,
mvpFloats,
Expand Down Expand Up @@ -175,7 +175,7 @@ protected int setupShaderProgramForRenderingLayerDirected(final GL2ES2 gl,
final RenderingLayer layer,
final VizEngine engine,
final float[] mvpFloats) {
final boolean someSelection = engine.getLookup().lookup(GraphSelection.class).getSelectedEdgesCount() > 0;
final boolean someSelection = engine.getLookup().lookup(GraphSelection.class).someNodesOrEdgesSelection();
final boolean renderingUnselectedEdges = layer.isBack();
if (!someSelection && renderingUnselectedEdges) {
return 0;
Expand Down Expand Up @@ -222,7 +222,7 @@ protected int setupShaderProgramForRenderingLayerDirected(final GL2ES2 gl,
);

if (someSelection) {
if (someNodesSelection && edgeSelectionColor) {
if (someSelection && edgeSelectionColor) {
lineModelDirected.useProgram(
gl,
mvpFloats,
Expand Down Expand Up @@ -262,15 +262,15 @@ protected int setupShaderProgramForRenderingLayerDirected(final GL2ES2 gl,

protected int updateDirectedData(
final Graph graph,
final boolean someEdgesSelection, final boolean hideNonSelected, final int visibleEdgesCount, final Edge[] visibleEdgesArray, final GraphSelection graphSelection, final boolean someNodesSelection, final boolean edgeSelectionColor, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor,
final boolean someSelection, final boolean hideNonSelected, final int visibleEdgesCount, final Edge[] visibleEdgesArray, final GraphSelection graphSelection, final boolean edgeSelectionColor, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor,
final float[] attribs, int index
) {
return updateDirectedData(graph, someEdgesSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray, graphSelection, someNodesSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor, attribs, index, null);
return updateDirectedData(graph, someSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray, graphSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor, attribs, index, null);
}

protected int updateDirectedData(
final Graph graph,
final boolean someEdgesSelection, final boolean hideNonSelected, final int visibleEdgesCount, final Edge[] visibleEdgesArray, final GraphSelection graphSelection, final boolean someNodesSelection, final boolean edgeSelectionColor, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor,
final boolean someSelection, final boolean hideNonSelected, final int visibleEdgesCount, final Edge[] visibleEdgesArray, final GraphSelection graphSelection, final boolean edgeSelectionColor, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor,
final float[] attribs, int index, final FloatBuffer directBuffer
) {
checkBufferIndexing(directBuffer, attribs, index);
Expand All @@ -281,11 +281,11 @@ protected int updateDirectedData(
return index;
}

saveSelectionState(someNodesSelection, edgeSelectionColor, graphSelection, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor);
saveSelectionState(this.someSelection, edgeSelectionColor, graphSelection, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor);

int newEdgesCountUnselected = 0;
int newEdgesCountSelected = 0;
if (someEdgesSelection) {
if (someSelection) {
if (hideNonSelected) {
for (int j = 0; j < visibleEdgesCount; j++) {
final Edge edge = visibleEdgesArray[j];
Expand Down Expand Up @@ -387,15 +387,15 @@ protected int updateDirectedData(

protected int updateUndirectedData(
final Graph graph,
final boolean someEdgesSelection, final boolean hideNonSelected, final int visibleEdgesCount, final Edge[] visibleEdgesArray, final GraphSelection graphSelection, final boolean someNodesSelection, final boolean edgeSelectionColor, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor,
final boolean someSelection, final boolean hideNonSelected, final int visibleEdgesCount, final Edge[] visibleEdgesArray, final GraphSelection graphSelection, final boolean edgeSelectionColor, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor,
final float[] attribs, int index
) {
return updateUndirectedData(graph, someEdgesSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray, graphSelection, someNodesSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor, attribs, index, null);
return updateUndirectedData(graph, someSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray, graphSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor, attribs, index, null);
}

protected int updateUndirectedData(
final Graph graph,
final boolean someEdgesSelection, final boolean hideNonSelected, final int visibleEdgesCount, final Edge[] visibleEdgesArray, final GraphSelection graphSelection, final boolean someNodesSelection, final boolean edgeSelectionColor, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor,
final boolean someSelection, final boolean hideNonSelected, final int visibleEdgesCount, final Edge[] visibleEdgesArray, final GraphSelection graphSelection, final boolean edgeSelectionColor, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor,
final float[] attribs, int index, final FloatBuffer directBuffer
) {
checkBufferIndexing(directBuffer, attribs, index);
Expand All @@ -406,12 +406,12 @@ protected int updateUndirectedData(
return index;
}

saveSelectionState(someNodesSelection, edgeSelectionColor, graphSelection, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor);
saveSelectionState(someSelection, edgeSelectionColor, graphSelection, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor);

int newEdgesCountUnselected = 0;
int newEdgesCountSelected = 0;
//Undirected edges:
if (someEdgesSelection) {
if (someSelection) {
if (hideNonSelected) {
for (int j = 0; j < visibleEdgesCount; j++) {
final Edge edge = visibleEdgesArray[j];
Expand Down Expand Up @@ -522,20 +522,20 @@ private void checkBufferIndexing(final FloatBuffer directBuffer, final float[] a
}
}

private boolean someNodesSelection;
private boolean someSelection;
private boolean edgeSelectionColor;
private GraphSelection graphSelection;
private float edgeBothSelectionColor;
private float edgeOutSelectionColor;
private float edgeInSelectionColor;

private void saveSelectionState(final boolean someNodesSelection1, final boolean edgeSelectionColor1, final GraphSelection graphSelection1, final float edgeBothSelectionColor1, final float edgeOutSelectionColor1, final float edgeInSelectionColor1) {
this.someNodesSelection = someNodesSelection1;
this.edgeSelectionColor = edgeSelectionColor1;
this.graphSelection = graphSelection1;
this.edgeBothSelectionColor = edgeBothSelectionColor1;
this.edgeOutSelectionColor = edgeOutSelectionColor1;
this.edgeInSelectionColor = edgeInSelectionColor1;
private void saveSelectionState(final boolean someSelection, final boolean edgeSelectionColor, final GraphSelection graphSelection, final float edgeBothSelectionColor, final float edgeOutSelectionColor, final float edgeInSelectionColor) {
this.someSelection = someSelection;
this.edgeSelectionColor = edgeSelectionColor;
this.graphSelection = graphSelection;
this.edgeBothSelectionColor = edgeBothSelectionColor;
this.edgeOutSelectionColor = edgeOutSelectionColor;
this.edgeInSelectionColor = edgeInSelectionColor;
}

protected void fillUndirectedEdgeAttributesDataBase(final float[] buffer, final Edge edge, final int index) {
Expand Down Expand Up @@ -579,7 +579,7 @@ protected void fillUndirectedEdgeAttributesDataWithSelection(final float[] buffe

//Color:
if (selected) {
if (someNodesSelection && edgeSelectionColor) {
if (someSelection && edgeSelectionColor) {
boolean sourceSelected = graphSelection.isNodeSelected(source);
boolean targetSelected = graphSelection.isNodeSelected(target);

Expand All @@ -593,7 +593,7 @@ protected void fillUndirectedEdgeAttributesDataWithSelection(final float[] buffe
buffer[index + 7] = Float.intBitsToFloat(edge.getRGBA());//Color
}
} else {
if (someNodesSelection && edge.alpha() <= 0) {
if (someSelection && edge.alpha() <= 0) {
if (graphSelection.isNodeSelected(source)) {
buffer[index + 7] = Float.intBitsToFloat(target.getRGBA());//Color
} else {
Expand Down Expand Up @@ -650,7 +650,7 @@ protected void fillDirectedEdgeAttributesDataWithSelection(final float[] buffer,

//Color:
if (selected) {
if (someNodesSelection && edgeSelectionColor) {
if (someSelection && edgeSelectionColor) {
boolean sourceSelected = graphSelection.isNodeSelected(source);
boolean targetSelected = graphSelection.isNodeSelected(target);

Expand All @@ -664,7 +664,7 @@ protected void fillDirectedEdgeAttributesDataWithSelection(final float[] buffer,
buffer[index + 6] = Float.intBitsToFloat(edge.getRGBA());//Color
}
} else {
if (someNodesSelection && edge.alpha() <= 0) {
if (someSelection && edge.alpha() <= 0) {
if (graphSelection.isNodeSelected(source)) {
buffer[index + 6] = Float.intBitsToFloat(target.getRGBA());//Color
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected int setupShaderProgramForRenderingLayer(final GL2ES2 gl,
final VizEngine engine,
final float[] mvpFloats,
final boolean isRenderingOutsideCircle) {
final boolean someSelection = engine.getLookup().lookup(GraphSelection.class).getSelectedNodesCount() > 0;
final boolean someSelection = engine.getLookup().lookup(GraphSelection.class).someNodesOrEdgesSelection();
final boolean renderingUnselectedNodes = layer.isBack();
if (!someSelection && renderingUnselectedNodes) {
return 0;
Expand Down Expand Up @@ -222,7 +222,7 @@ protected void updateData(final float zoom,
spatialIndex.indexNodes();

//Selection:
final boolean someSelection = selection.getSelectedNodesCount() > 0;
final boolean someSelection = selection.someNodesOrEdgesSelection();
final float lightenNonSelectedFactor = renderingOptions.getLightenNonSelectedFactor();
final boolean hideNonSelected = someSelection && (renderingOptions.isHideNonSelected() || lightenNonSelectedFactor >= 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ private void updateData(final GraphIndexImpl graphIndex, final GraphRenderingOpt
graphIndex.indexEdges();

//Selection:
final boolean someEdgesSelection = graphSelection.getSelectedEdgesCount() > 0;
final boolean someNodesSelection = graphSelection.getSelectedNodesCount() > 0;
final boolean someSelection = graphSelection.someNodesOrEdgesSelection();
final float lightenNonSelectedFactor = renderingOptions.getLightenNonSelectedFactor();
final boolean hideNonSelected = someEdgesSelection && (renderingOptions.isHideNonSelected() || lightenNonSelectedFactor >= 1);
final boolean hideNonSelected = someSelection && (renderingOptions.isHideNonSelected() || lightenNonSelectedFactor >= 1);
final boolean edgeSelectionColor = renderingOptions.isEdgeSelectionColor();
final float edgeBothSelectionColor = Float.intBitsToFloat(renderingOptions.getEdgeBothSelectionColor().getRGB());
final float edgeInSelectionColor = Float.intBitsToFloat(renderingOptions.getEdgeInSelectionColor().getRGB());
Expand All @@ -184,12 +183,12 @@ private void updateData(final GraphIndexImpl graphIndex, final GraphRenderingOpt

updateUndirectedData(
graph,
someEdgesSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray, graphSelection, someNodesSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor,
someSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray, graphSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor,
attributesBufferBatch, 0, attribsDirectBuffer
);
updateDirectedData(
graph,
someEdgesSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray, graphSelection, someNodesSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor,
someSelection, hideNonSelected, visibleEdgesCount, visibleEdgesArray, graphSelection, edgeSelectionColor, edgeBothSelectionColor, edgeOutSelectionColor, edgeInSelectionColor,
attributesBufferBatch, 0, attribsDirectBuffer
);
}
Expand Down
Loading

0 comments on commit 765c724

Please sign in to comment.