Author: paperwing
Date: 2012-03-28 17:29:09 -0700 (Wed, 28 Mar 2012)
New Revision: 28688
Added:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithm.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithmTask.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutContext.java
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/GridLayoutAlgorithmTask.java
Log:
refs #812 Grid layout basic algorithm completed; now available from the menu.
This layout arranges nodes in an evenly-spaced 3D grid.
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
2012-03-29 00:08:29 UTC (rev 28687)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
2012-03-29 00:29:09 UTC (rev 28688)
@@ -3,6 +3,7 @@
import java.util.Properties;
import org.cytoscape.paperwing.internal.cytoscape.view.WindNetworkViewFactory;
+import org.cytoscape.paperwing.internal.layouts.BoxLayoutAlgorithm;
import org.cytoscape.paperwing.internal.layouts.GridLayoutAlgorithm;
import org.cytoscape.paperwing.internal.layouts.SphericalLayoutAlgorithm;
import org.cytoscape.paperwing.internal.task.TaskFactoryListener;
@@ -117,5 +118,15 @@
gridLayoutAlgorithmProps.setProperty("title",
gridLayoutAlgorithm.toString());
gridLayoutAlgorithmProps.setProperty("menuGravity","10.49");
registerService(bc, gridLayoutAlgorithm,
CyLayoutAlgorithm.class, gridLayoutAlgorithmProps);
+
+ BoxLayoutAlgorithm boxLayoutAlgorithm = new
BoxLayoutAlgorithm();
+ Properties boxLayoutAlgorithmProps = new Properties();
+ boxLayoutAlgorithmProps.setProperty("preferredMenu","Layout.3D
Layouts");
+
boxLayoutAlgorithmProps.setProperty("preferredTaskManager","menu");
+ boxLayoutAlgorithmProps.setProperty("title",
boxLayoutAlgorithm.toString());
+ boxLayoutAlgorithmProps.setProperty("menuGravity","10.51");
+ registerService(bc, boxLayoutAlgorithm,
CyLayoutAlgorithm.class, boxLayoutAlgorithmProps);
+
+
}
}
Added:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithm.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithm.java
(rev 0)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithm.java
2012-03-29 00:29:09 UTC (rev 28688)
@@ -0,0 +1,25 @@
+package org.cytoscape.paperwing.internal.layouts;
+
+import org.cytoscape.view.layout.AbstractLayoutAlgorithm;
+import org.cytoscape.view.layout.CyLayoutContext;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.undo.UndoSupport;
+
+public class BoxLayoutAlgorithm extends
AbstractLayoutAlgorithm<BoxLayoutContext> {
+
+ public BoxLayoutAlgorithm() {
+ super("box", "Box Layout", false);
+ }
+
+ @Override
+ public TaskIterator createTaskIterator(BoxLayoutContext context) {
+ return new TaskIterator(
+ new BoxLayoutAlgorithmTask(getName(), context));
+ }
+
+ @Override
+ public BoxLayoutContext createLayoutContext() {
+ return new BoxLayoutContext(supportsSelectedOnly(),
supportsNodeAttributes(), supportsEdgeAttributes());
+ }
+}
Property changes on:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithm.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithmTask.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithmTask.java
(rev 0)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithmTask.java
2012-03-29 00:29:09 UTC (rev 28688)
@@ -0,0 +1,156 @@
+package org.cytoscape.paperwing.internal.layouts;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.cytoscape.model.CyEdge.Type;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.paperwing.internal.cytoscape.view.WindNetworkView;
+import org.cytoscape.paperwing.internal.geometric.Vector3;
+import org.cytoscape.paperwing.internal.tools.LayoutToolkit;
+import org.cytoscape.paperwing.internal.tools.NetworkToolkit;
+import org.cytoscape.view.layout.AbstractBasicLayoutTask;
+import org.cytoscape.view.layout.AbstractLayoutAlgorithmContext;
+import org.cytoscape.view.layout.LayoutNode;
+import org.cytoscape.view.layout.LayoutPartition;
+import org.cytoscape.view.layout.PartitionUtil;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.presentation.property.BasicVisualLexicon;
+import org.cytoscape.work.TaskMonitor;
+
+public class BoxLayoutAlgorithmTask extends AbstractBasicLayoutTask {
+
+ private BoxLayoutContext context;
+
+ public BoxLayoutAlgorithmTask(String name,
+ BoxLayoutContext context) {
+ super(name, context);
+ this.context = context;
+ }
+
+ @Override
+ protected void doLayout(TaskMonitor taskMonitor) {
+
+ // Break graph into partitions
+ List<LayoutPartition> layoutPartitions =
PartitionUtil.partition(networkView, false, null);
+ int numPartitions = layoutPartitions.size();
+
+ Collection<Collection<View<CyNode>>> partitions = new
HashSet<Collection<View<CyNode>>>(layoutPartitions.size());
+
+ Collection<View<CyNode>> partitionNodeViews;
+
+ for (LayoutPartition partition : layoutPartitions) {
+ partitionNodeViews = new HashSet<View<CyNode>>();
+
+ for (LayoutNode layoutNode : partition.getNodeList()) {
+ View<CyNode> nodeView =
layoutNode.getNodeView();
+ partitionNodeViews.add(nodeView);
+ }
+
+ partitions.add(partitionNodeViews);
+ }
+
+ for (Collection<View<CyNode>> partition : partitions) {
+ arrangeAsBox(partition, 270);
+ }
+
+ LayoutToolkit.arrangePartitions(partitions);
+ }
+
+ private void arrangeAsBox(Collection<View<CyNode>> nodeViews, double
nodeSpacing) {
+ int nodeCount = nodeViews.size();
+ int nodesPerFace = (int) Math.ceil(nodeCount / 6.0);
+
+ int sideLength = (int) Math.ceil(Math.sqrt(nodesPerFace));
+ double halfSideLength = sideLength / 2.0;
+
+ Vector3 center = LayoutToolkit.findCenter(nodeViews);
+
+ // The position of the top-left corner of a face
+ Vector3 faceCorner;
+ // A unit vector pointing rightwards from the current corner
+ Vector3 faceRight = new Vector3();
+ // A unit vector pointing downwards from the current corner
+ Vector3 faceDown = new Vector3();
+
+ int count = 0;
+ for (View<CyNode> nodeView : nodeViews) {
+ int face = count / nodesPerFace;
+
+ switch (face) {
+ // Front face (positive z direction)
+ case 0:
+ faceCorner =
center.plus(-halfSideLength * nodeSpacing,
+ halfSideLength *
nodeSpacing,
+ halfSideLength *
nodeSpacing);
+ faceRight.set(1, 0, 0);
+ faceDown.set(0, -1, 0);
+ break;
+ // Back face (negative z direction)
+ case 1:
+ faceCorner = center.plus(halfSideLength
* nodeSpacing,
+ halfSideLength *
nodeSpacing,
+ -halfSideLength *
nodeSpacing);
+ faceRight.set(-1, 0, 0);
+ faceDown.set(0, -1, 0);
+ break;
+ // Left face (negative x direction)
+ case 2:
+ faceCorner =
center.plus(-halfSideLength * nodeSpacing,
+ halfSideLength *
nodeSpacing,
+ -halfSideLength *
nodeSpacing);
+ faceRight.set(0, 0, 1);
+ faceDown.set(0, -1, 0);
+ break;
+ // Right face (positive x direction)
+ case 3:
+ faceCorner = center.plus(halfSideLength
* nodeSpacing,
+ halfSideLength *
nodeSpacing,
+ halfSideLength *
nodeSpacing);
+ faceRight.set(0, 0, -1);
+ faceDown.set(0, -1, 0);
+ break;
+ // Top face (positive y direction)
+ case 4:
+ faceCorner =
center.plus(-halfSideLength * nodeSpacing,
+ halfSideLength *
nodeSpacing,
+ -halfSideLength *
nodeSpacing);
+ faceRight.set(1, 0, 0);
+ faceDown.set(0, 0, 1);
+ break;
+ // Bottom face (negative y direction)
+ case 5:
+ faceCorner =
center.plus(-halfSideLength * nodeSpacing,
+ -halfSideLength *
nodeSpacing,
+ halfSideLength *
nodeSpacing);
+ faceRight.set(1, 0, 0);
+ faceDown.set(0, 0, -1);
+ break;
+ default:
+ throw new
IllegalStateException("Current node cannot be allocated to a face of the
arrangement cube.");
+ }
+
+ // The row that this node belongs to on the current face
+ int row = (count % nodesPerFace) % sideLength + 1;
+
+ // The column that this node belongs to on the current
face
+ int column = (count % nodesPerFace) / sideLength + 1;
+
+
nodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION,
+ faceCorner.x() + faceRight.x() *
nodeSpacing * column + faceDown.x() * nodeSpacing * row);
+
nodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION,
+ faceCorner.y() + faceRight.y() *
nodeSpacing * column + faceDown.y() * nodeSpacing * row);
+
nodeView.setVisualProperty(BasicVisualLexicon.NODE_Z_LOCATION,
+ faceCorner.z() + faceRight.z() *
nodeSpacing * column + faceDown.z() * nodeSpacing * row);
+
+ count++;
+ }
+ }
+}
Property changes on:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutAlgorithmTask.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutContext.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutContext.java
(rev 0)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutContext.java
2012-03-29 00:29:09 UTC (rev 28688)
@@ -0,0 +1,19 @@
+package org.cytoscape.paperwing.internal.layouts;
+
+import java.util.Set;
+
+import org.cytoscape.view.layout.AbstractLayoutAlgorithmContext;
+import org.cytoscape.work.Tunable;
+import org.cytoscape.work.TunableValidator;
+
+public class BoxLayoutContext extends AbstractLayoutAlgorithmContext
implements TunableValidator {
+
+ public BoxLayoutContext(boolean supportsSelectedOnly, Set<Class<?>>
supportedNodeAttributes, Set<Class<?>> supportedEdgeAttributes) {
+ super(supportsSelectedOnly, supportedNodeAttributes,
supportedEdgeAttributes);
+ }
+
+ @Override //TODO how to validate these values?
+ public ValidationState getValidationState(final Appendable errMsg) {
+ return ValidationState.OK;
+ }
+}
Property changes on:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/BoxLayoutContext.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/GridLayoutAlgorithmTask.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/GridLayoutAlgorithmTask.java
2012-03-29 00:08:29 UTC (rev 28687)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/GridLayoutAlgorithmTask.java
2012-03-29 00:29:09 UTC (rev 28688)
@@ -58,98 +58,39 @@
}
for (Collection<View<CyNode>> partition : partitions) {
- arrangeAsBox(partition, 270);
+ arrangeAsGrid(partition, 130);
}
LayoutToolkit.arrangePartitions(partitions);
}
- private void arrangeAsBox(Collection<View<CyNode>> nodeViews, double
nodeSpacing) {
- int nodeCount = nodeViews.size();
- int nodesPerFace = (int) Math.ceil(nodeCount / 6.0);
+ private void arrangeAsGrid(Collection<View<CyNode>> nodeViews, double
spacing) {
- int sideLength = (int) Math.ceil(Math.sqrt(nodesPerFace));
- double halfSideLength = sideLength / 2.0;
+ int cubeLength = (int) Math.ceil(Math.pow(nodeViews.size(),
1.0/3));
+ // System.out.println("cubeLength: " + cubeLength);
+
+ // Average position of all nodes
Vector3 center = LayoutToolkit.findCenter(nodeViews);
- // The position of the top-left corner of a face
- Vector3 faceCorner;
- // A unit vector pointing rightwards from the current corner
- Vector3 faceRight = new Vector3();
- // A unit vector pointing downwards from the current corner
- Vector3 faceDown = new Vector3();
-
int count = 0;
- for (View<CyNode> nodeView : nodeViews) {
- int face = count / nodesPerFace;
- switch (face) {
- // Front face (positive z direction)
- case 0:
- faceCorner =
center.plus(-halfSideLength * nodeSpacing,
- halfSideLength *
nodeSpacing,
- halfSideLength *
nodeSpacing);
- faceRight.set(1, 0, 0);
- faceDown.set(0, -1, 0);
- break;
- // Back face (negative z direction)
- case 1:
- faceCorner = center.plus(halfSideLength
* nodeSpacing,
- halfSideLength *
nodeSpacing,
- -halfSideLength *
nodeSpacing);
- faceRight.set(-1, 0, 0);
- faceDown.set(0, -1, 0);
- break;
- // Left face (negative x direction)
- case 2:
- faceCorner =
center.plus(-halfSideLength * nodeSpacing,
- halfSideLength *
nodeSpacing,
- -halfSideLength *
nodeSpacing);
- faceRight.set(0, 0, 1);
- faceDown.set(0, -1, 0);
- break;
- // Right face (positive x direction)
- case 3:
- faceCorner = center.plus(halfSideLength
* nodeSpacing,
- halfSideLength *
nodeSpacing,
- halfSideLength *
nodeSpacing);
- faceRight.set(0, 0, -1);
- faceDown.set(0, -1, 0);
- break;
- // Top face (positive y direction)
- case 4:
- faceCorner =
center.plus(-halfSideLength * nodeSpacing,
- halfSideLength *
nodeSpacing,
- -halfSideLength *
nodeSpacing);
- faceRight.set(1, 0, 0);
- faceDown.set(0, 0, 1);
- break;
- // Bottom face (negative y direction)
- case 5:
- faceCorner =
center.plus(-halfSideLength * nodeSpacing,
- -halfSideLength *
nodeSpacing,
- halfSideLength *
nodeSpacing);
- faceRight.set(1, 0, 0);
- faceDown.set(0, 0, -1);
- break;
- default:
- throw new
IllegalStateException("Current node cannot be allocated to a face of the
arrangement cube.");
- }
+ for (View<CyNode> nodeView : nodeViews) {
+ int x = count % cubeLength;
+ int y = count / cubeLength % cubeLength;
+ int z = count / cubeLength / cubeLength;
- // The row that this node belongs to on the current face
- int row = (count % nodesPerFace) % sideLength + 1;
+ // TODO: Need to set offset so that total average node
position is preserved
+ Vector3 offset = new Vector3(x * spacing, y * spacing,
z * spacing);
+ double halfCubeActualLength = (double) (cubeLength - 1)
/ 2 * spacing;
+ offset.subtractLocal(halfCubeActualLength,
halfCubeActualLength, halfCubeActualLength);
+
+ Vector3 nodeNewPosition = offset.plus(center);
+
nodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION,
nodeNewPosition.x());
+
nodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION,
nodeNewPosition.y());
+
nodeView.setVisualProperty(BasicVisualLexicon.NODE_Z_LOCATION,
nodeNewPosition.z());
- // The column that this node belongs to on the current
face
- int column = (count % nodesPerFace) / sideLength + 1;
-
-
nodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION,
- faceCorner.x() + faceRight.x() *
nodeSpacing * column + faceDown.x() * nodeSpacing * row);
-
nodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION,
- faceCorner.y() + faceRight.y() *
nodeSpacing * column + faceDown.y() * nodeSpacing * row);
-
nodeView.setVisualProperty(BasicVisualLexicon.NODE_Z_LOCATION,
- faceCorner.z() + faceRight.z() *
nodeSpacing * column + faceDown.z() * nodeSpacing * row);
-
+ // System.out.println(new Vector3(x, y, z));
count++;
}
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.