use of au.gov.asd.tac.constellation.plugins.arrangements.SetRadiusForArrangement in project constellation by constellation-app.
the class ArrangeInSpherePlugin method edit.
@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final SetRadiusForArrangement radiusSetter = new SetRadiusForArrangement(wg);
radiusSetter.setRadii();
final Arranger arranger = new SphereArranger();
final SelectedInclusionGraph selectedGraph = new SelectedInclusionGraph(wg, SelectedInclusionGraph.Connections.NONE);
arranger.setMaintainMean(!selectedGraph.isArrangingAll());
arranger.arrange(selectedGraph.getInclusionGraph());
selectedGraph.retrieveCoords();
}
use of au.gov.asd.tac.constellation.plugins.arrangements.SetRadiusForArrangement in project constellation by constellation-app.
the class CircleArranger method arrange.
@Override
public void arrange(final GraphWriteMethods wg) throws InterruptedException {
final int vxCount = wg.getVertexCount();
if (vxCount < 2) {
// Graphs of size 0 or 1 are already in a circle.
return;
}
final SetRadiusForArrangement radiusSetter = new SetRadiusForArrangement(wg);
radiusSetter.setRadii();
final float[] oldMean = maintainMean ? ArrangementUtilities.getXyzMean(wg) : null;
// Get required attributes.
final int xAttr = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.X.getName());
final int yAttr = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Y.getName());
final int zAttr = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Z.getName());
final int nradiusAttr = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.NODE_RADIUS.getName());
// Use these if they exist.
final int x2Attr = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.X2.getName());
final int y2Attr = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Y2.getName());
final int z2Attr = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Z2.getName());
final boolean xyz2 = x2Attr != Graph.NOT_FOUND && y2Attr != Graph.NOT_FOUND && z2Attr != Graph.NOT_FOUND;
// Determine the circumference of the circle, given that nodes may have different radii.
float circleCircumference = 0;
float maxRadius = 0;
// Use radius to the corners rather than the sides.
final float sqrt2 = (float) Math.sqrt(2);
for (int position = 0; position < vxCount; position++) {
final int vxId = wg.getVertex(position);
final float nradius = (nradiusAttr != Graph.NOT_FOUND ? wg.getFloatValue(nradiusAttr, vxId) : 1) * sqrt2;
circleCircumference += 2F * nradius;
maxRadius = Math.max(maxRadius, nradius);
}
// If there's a really big node, make the circle bigger.
circleCircumference = Math.max(circleCircumference, 2 * maxRadius * sqrt2 * (float) Math.PI);
// Now arrange the vertices on the circumference, positioned by their fraction of
// the space they each take up.
final float circleRadius = circleCircumference / (2F * (float) Math.PI);
float angle = 0;
for (int position = 0; position < vxCount; position++) {
final int vxId = wg.getVertex(position);
final float nradius = (nradiusAttr != Graph.NOT_FOUND ? wg.getFloatValue(nradiusAttr, vxId) : 1) * sqrt2;
// What fraction of the circumference is this?
// And therefore, what is the angle subtended?
// (if the circumference is 0 then we divide by 1 to avoid dividing by 0 (nradius will be 0 anyway))
final float arcfrac = (2F * nradius) / (circleCircumference != 0 ? circleCircumference : 1);
final float arclen = 2F * (float) Math.PI * arcfrac;
final float subtends = arclen;
final float positionOnCircle = angle + subtends / 2F;
// Calculate the x & y position for each vertex.
final float x = circleRadius * (float) (Math.sin(positionOnCircle));
final float y = circleRadius * (float) (Math.cos(positionOnCircle));
final float z = 0;
wg.setFloatValue(xAttr, vxId, x);
wg.setFloatValue(yAttr, vxId, y);
wg.setFloatValue(zAttr, vxId, z);
if (xyz2) {
wg.setFloatValue(x2Attr, vxId, x);
wg.setFloatValue(y2Attr, vxId, y);
wg.setFloatValue(z2Attr, vxId, z);
}
angle += subtends;
}
if (maintainMean) {
ArrangementUtilities.moveMean(wg, oldMean);
}
}
use of au.gov.asd.tac.constellation.plugins.arrangements.SetRadiusForArrangement in project constellation by constellation-app.
the class ArrangeInCirclePlugin method edit.
@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final SetRadiusForArrangement radiusSetter = new SetRadiusForArrangement(wg);
radiusSetter.setRadii();
final Arranger arranger = new CircleArranger();
final SelectedInclusionGraph selectedGraph = new SelectedInclusionGraph(wg, SelectedInclusionGraph.Connections.NONE);
arranger.setMaintainMean(!selectedGraph.isArrangingAll());
arranger.arrange(selectedGraph.getInclusionGraph());
selectedGraph.retrieveCoords();
}
use of au.gov.asd.tac.constellation.plugins.arrangements.SetRadiusForArrangement in project constellation by constellation-app.
the class ArrangeInScatter3dGeneralPlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final SetRadiusForArrangement radiusSetter = new SetRadiusForArrangement(graph);
radiusSetter.setRadii();
final Map<String, PluginParameter<?>> pp = parameters.getParameters();
final Scatter3dChoiceParameters scatter3dParams = Scatter3dChoiceParameters.getDefaultParameters();
final String xDimensionName = pp.get(SCATTER_3D_X_ATTRIBUTE).getStringValue();
final String yDimensionName = pp.get(SCATTER_3D_Y_ATTRIBUTE).getStringValue();
final String zDimensionName = pp.get(SCATTER_3D_Z_ATTRIBUTE).getStringValue();
if (StringUtils.isAnyBlank(new String[] { xDimensionName, yDimensionName, zDimensionName })) {
interaction.notify(PluginNotificationLevel.FATAL, "You must supply all 3 attribute names for Scatter 3D");
return;
}
scatter3dParams.setXDimension(xDimensionName);
scatter3dParams.setYDimension(yDimensionName);
scatter3dParams.setZDimension(zDimensionName);
scatter3dParams.setLogarithmicX(pp.get(SCATTER_3D_X_LOGARITHMIC).getBooleanValue());
scatter3dParams.setLogarithmicY(pp.get(SCATTER_3D_Y_LOGARITHMIC).getBooleanValue());
scatter3dParams.setLogarithmicZ(pp.get(SCATTER_3D_Z_LOGARITHMIC).getBooleanValue());
scatter3dParams.setDoNotScale(pp.get(SCATTER_3D_DO_NOT_SCALE).getBooleanValue());
final SelectedInclusionGraph selectedGraph = new SelectedInclusionGraph(graph, SelectedInclusionGraph.Connections.NONE);
selectedGraph.addAttributeToCopy(new GraphAttribute(graph, graph.getAttribute(GraphElementType.VERTEX, xDimensionName)));
selectedGraph.addAttributeToCopy(new GraphAttribute(graph, graph.getAttribute(GraphElementType.VERTEX, yDimensionName)));
selectedGraph.addAttributeToCopy(new GraphAttribute(graph, graph.getAttribute(GraphElementType.VERTEX, zDimensionName)));
final Scatter3dArranger arranger = new Scatter3dArranger(scatter3dParams);
arranger.arrange(selectedGraph.getInclusionGraph());
selectedGraph.retrieveCoords();
}
use of au.gov.asd.tac.constellation.plugins.arrangements.SetRadiusForArrangement in project constellation by constellation-app.
the class SpectralArrangementPlugin method edit.
@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
interaction.setProgress(0, 0, "Arranging...", true);
if (graph.getVertexCount() > 0) {
final SetRadiusForArrangement radiusSetter = new SetRadiusForArrangement(graph);
radiusSetter.setRadii();
final Arranger inner = new SpectralArranger();
final Arranger outer = new GridArranger();
final GraphTaxonomyArranger arranger = new GraphComponentArranger(inner, outer, Connections.LINKS);
arranger.setSingletonArranger(new GridArranger());
arranger.setDoubletArranger(new GridArranger());
arranger.setInteraction(interaction);
arranger.setMaintainMean(true);
final SelectedInclusionGraph selectedGraph = new SelectedInclusionGraph(graph, Connections.LINKS);
arranger.arrange(selectedGraph.getInclusionGraph());
selectedGraph.retrieveCoords();
}
interaction.setProgress(1, 0, "Finished", true);
}
Aggregations