public ForceDirectedGraphForm() { InitializeComponent(); this.DoubleBuffered = true; this.Width = (width + 1) * 20; this.Height = (height + 1) * 20 + 100; this.MaximumSize = new Size(this.Width, this.Height); this.MaximizeBox = false; tbStiffness.Text = "81.76"; tbRepulsion.Text = "40000.0"; tbDamping.Text = "0.5"; panelTop = 0; panelBottom = pDrawPanel.Size.Height; panelLeft = 0; panelRight = pDrawPanel.Size.Width; m_fdgBoxes = new Dictionary <Node, GridBox>(); m_fdgLines = new Dictionary <Edge, GridLine>(); m_fdgGraph = new Graph(); m_fdgPhysics = new ForceDirected2D(m_fdgGraph, 81.76f, 40000.0f, 0.5f); m_fdgRenderer = new Renderer(this, m_fdgPhysics); pDrawPanel.Paint += new PaintEventHandler(DrawPanel_Paint); timer.Interval = 30; timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Start(); }
public ForceDirectedGraphForm() { InitializeComponent(); this.DoubleBuffered = true; this.Width = (width + 1) * 20; this.Height = (height + 1) * 20 + 100; this.MaximumSize = new Size(this.Width, this.Height); this.MaximizeBox = false; tbStiffness.Text = "81.76"; tbRepulsion.Text = "40000.0"; tbDamping.Text = "0.5"; panelTop = 0; panelBottom = pDrawPanel.Size.Height; panelLeft = 0; panelRight = pDrawPanel.Size.Width; m_fdgBoxes = new Dictionary<Node, GridBox>(); m_fdgLines = new Dictionary<Edge, GridLine>(); m_fdgGraph = new Graph(); m_fdgPhysics = new ForceDirected2D(m_fdgGraph,81.76f,40000.0f, 0.5f); m_fdgRenderer = new Renderer(this, m_fdgPhysics); pDrawPanel.Paint += new PaintEventHandler(DrawPanel_Paint); timer.Interval = 30; timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Start(); }
public ForceDirectedManager() { _graph = new Graph(); _physics = new ForceDirected2D(_graph, Stiffness, Repulsion, Damping); _nodeToDisplay = new Dictionary <Node, Transform>(); _displayToNode = new Dictionary <Transform, Node>(); }
void Start() { _graph = new Graph(); _physics = new ForceDirected2D(_graph, Stiffness, Repulsion, Damping); _nodes = new Dictionary <Node, GameObject>(); for (int i = 0; i < NumNodesToCreate; i++) { var visualNode = Instantiate(NodeTemplate, transform); var nodeData = new NodeData() { label = "Node" + i, mass = 1, initialPostion = new FDGVector3(0, 0, 0) }; var node = _graph.CreateNode(nodeData); _nodes[node] = visualNode; } for (int i = 0; i < NumRandomEdges; i++) { var n1 = Random.Range(0, NumNodesToCreate - 1); var n2 = Random.Range(0, NumNodesToCreate - 1); var node1 = _graph.GetNode("Node" + n1); var node2 = _graph.GetNode("Node" + n2); var edgeData = new EdgeData() { length = Random.Range(.1f, 3) }; _graph.CreateEdge(node1, node2, edgeData); } // add force simulation }
//public static Transform Reference; public ForceDirectedPetri(Dictionary <PetrinetCondition, Valuation> conds, Dictionary <HardwareRequirements, Valuation> hard, ForceLayoutSettings settings, Vector3 bottomLeft, Vector3 topRight, Transform reference) { bottomLeft = reference.InverseTransformPoint(bottomLeft); topRight = reference.InverseTransformPoint(topRight); _bottomLeft = new Vector2(Mathf.Min(bottomLeft.x, topRight.x), Mathf.Min(bottomLeft.z, topRight.z)); _topRight = new Vector2(Mathf.Max(bottomLeft.x, topRight.x), Mathf.Max(bottomLeft.z, topRight.z)); _bottomLeft *= .8f; _topRight *= .8f; _layoutSettings = settings; _graph = new Graph(); _physics = new ForceDirected2D(_graph, _layoutSettings.Stiffness, _layoutSettings.Repulsion, _layoutSettings.Damping); _condToNodes = new Dictionary <PetrinetCondition, CondNode>(); _hardwareNodes = new Dictionary <HardwareRequirements, HardwareNode>(); _petriNodes = new List <PetriNode>(); PetriNode.Reference = reference; //Reference = reference; Func <Vector3, bool> withinBoundaries = delegate(Vector3 pos) { return(_bottomLeft.x <= pos.x && pos.x <= _topRight.x && _bottomLeft.y <= pos.z && pos.z <= _topRight.y); }; foreach (var condRadius in conds) { var condNode = new CondNode(condRadius.Key, condRadius.Value.Radius, condRadius.Value.Weight); if (!withinBoundaries(condNode.Visual.position)) { Debug.LogWarning(condNode.Visual.name + " not within boundaries"); } _petriNodes.Add(condNode); _graph.AddNode(condNode); _condToNodes[condRadius.Key] = condNode; } foreach (var hardwareRadius in hard) { var hardwareNode = new HardwareNode(hardwareRadius.Key, hardwareRadius.Value.Radius, hardwareRadius.Value.Weight); if (!withinBoundaries(hardwareNode.Visual.position)) { Debug.LogWarning(hardwareNode.Visual.name + " not within boundaries"); } _petriNodes.Add(hardwareNode); _graph.AddNode(hardwareNode); _hardwareNodes[hardwareRadius.Key] = hardwareNode; foreach (var transition in hardwareRadius.Key.gameObject.GetComponents <PetrinetTransition>()) { transition.In.ForEach(cond => AddEdge(_condToNodes[cond], hardwareNode)); transition.Out.ForEach(cond => AddEdge(hardwareNode, _condToNodes[cond])); } } foreach (var condNode in _condToNodes) { if (condNode.Key.Type == PetrinetCondition.ConditionType.Place) { condNode.Value.Kids = condNode.Key.GetComponentsInChildren <HardwareRequirements>() .Select(kid => _hardwareNodes[kid])//kid => kid.HardwareRequirements.transform) //.Distinct()/ .ToList(); condNode.Value.Kids.ForEach(kid => AddEdge(condNode.Value, kid)); } } }