Beispiel #1
0
    private Quaternion CalculateRotation(Graph.Link link)
    {
        var vec   = link.To.Coordinates - link.From.Coordinates;
        var angle = Vector2.SignedAngle(Vector2.right, vec);

        return(Quaternion.AngleAxis(angle, Vector3.forward));
    }
Beispiel #2
0
        public IActionResult DeleteLink([FromBody] Graph.Link link)
        {
            try
            {
                Startup.MainGraph.DeleteLink(link);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode(500));
            }

            return(NoContent());
        }
Beispiel #3
0
    private float CalculatePathLength(Graph.Link link)
    {
        var distanceBetweenCheckpoints = link.To.Coordinates - link.From.Coordinates;

        return(distanceBetweenCheckpoints.magnitude);
    }
        /// <summary>
        ///
        /// </summary>
        public override void Initialize()
        {
            debugFont = Game.Content.Load <DiscTexture>("conchars");

            var bounds = Game.RenderSystem.DisplayBounds;

            masterView = Game.RenderSystem.RenderWorld;


            Game.RenderSystem.RemoveLayer(masterView);

            viewLayer = new RenderLayer(Game);
            Game.RenderSystem.AddLayer(viewLayer);

            Game.RenderSystem.DisplayBoundsChanged += (s, e) =>
            {
                masterView.Resize(Game.RenderSystem.DisplayBounds.Width, Game.RenderSystem.DisplayBounds.Height);
            };

            viewLayer.SpriteLayers.Add(console.ConsoleSpriteLayer);


            Game.Keyboard.KeyDown += Keyboard_KeyDown;

            LoadContent();

            Game.Reloading += (s, e) => LoadContent();


            Game.Touch.Tap          += args => System.Console.WriteLine("You just perform tap gesture at point: " + args.Position);
            Game.Touch.DoubleTap    += args => System.Console.WriteLine("You just perform double tap gesture at point: " + args.Position);
            Game.Touch.SecondaryTap += args => System.Console.WriteLine("You just perform secondary tap gesture at point: " + args.Position);
            Game.Touch.Manipulate   += args => System.Console.WriteLine("You just perform touch manipulation: " + args.Position + "	" + args.ScaleDelta + "	" + args.RotationDelta + " " + args.IsEventBegin + " " + args.IsEventEnd);


            graph        = new GraphLayer(Game);
            graph.Camera = new GreatCircleCamera();

            Game.Mouse.Scroll += (sender, args) =>
            {
                graph.Camera.Zoom(args.WheelDelta > 0 ? -0.1f : 0.1f);
            };

            Game.Mouse.Move += (sender, args) =>
            {
                if (Game.Keyboard.IsKeyDown(Keys.LeftButton))
                {
                    graph.Camera.RotateCamera(mouseDelta);
                }
                if (Game.Keyboard.IsKeyDown(Keys.MiddleButton))
                {
                    graph.Camera.MoveCamera(mouseDelta);
                }
            };

            var g = new Graph();
            // Здесь должно быть чтение из файла и запись в узлы
            string path = @"Data/Hela_sonic_LMNA_interactions_diploid_10071362_iter_final.csv";
            Dictionary <int, Graph.Vertice> allVertices = new Dictionary <int, Graph.Vertice>();
            List <Graph.Link> allEdges = new List <Graph.Link>();
            var zone       = -1;
            var currentChr = "";
            var zoneIndex  = -1;
            var lines      = File.ReadAllLines(path);
            var index      = 0;

            foreach (var line in lines)
            {
                var info = line.Split(',');
                int id   = index++;
                Log.Message(info[0] + ' ' + id);

                var chr = info[0].Split(':')[0];
                if (!chr.Equals(currentChr))
                {
                    zoneIndex++;
                    currentChr = chr;
                    Log.Message("zone" + zoneIndex);
                }

                if (!allVertices.ContainsKey(id))
                {
                    if (zone == zoneIndex && id != 0)
                    {
                        try
                        {
                            var type = 1;
                            // var id = i;
                            var stock = id - 1;


                            Graph.Link link = new Graph.Link()
                            {
                                SourceID      = id,
                                StockID       = stock,
                                Length        = 10,
                                Force         = 0,
                                Orientation   = Vector3.Zero,
                                Weight        = graph.cfg.MaxLinkWidth,
                                LinkType      = type + 1,
                                Color         = paletteByZone.ElementAt(zone).ToVector4(),
                                Width         = 10,
                                LifeTime      = 0,
                                TotalLifeTime = 0,
                            };
                            allEdges.Add(link);
                        }

                        catch (Exception e)
                        {
                            Log.Message(e.StackTrace);
                        }
                    }
                    else
                    {
                        zone = zoneIndex;
                    }
                    Graph.Vertice node = new Graph.Vertice()
                    {
                        Position     = new Vector3(float.Parse(info[1]), float.Parse(info[2]), float.Parse(info[3])) * 1000, //gcConfig.LinkSize,
                        Velocity     = Vector3.Zero,
                        Color        = paletteByZone.ElementAt(zone).ToVector4(),                                            //to bechange
                        Size         = float.Parse(info[4]) * 1000,
                        Acceleration = Vector3.Zero,
                        Mass         = 0,
                        Information  = 1,
                        Id           = id,
                        Group        = zone,
                        Charge       = 1,
                        Cluster      = 0,
                        ColorType    = zone * 100 + graph.cfg.MinParticleRadius * 5,
                    };

                    allVertices.Add(id, node);
                }
            }
            //try
            //{
            //    for (int i = 0; i < lines.Count() - 1; i++)
            //    {
            //        var type = 1;
            //        var id = i;
            //        var stock = i + 1;


            //        Graph.Link link = new Graph.Link()
            //        {
            //            SourceID = id,
            //            StockID = stock,
            //            Length = 10,
            //            Force = 0,
            //            Orientation = Vector3.Zero,
            //            Weight = graph.cfg.MaxLinkWidth,
            //            LinkType = type + 1,
            //            Color = ColorConstant.paletteWhite.ElementAt(type + 1).ToVector4(),
            //            Width = 10,
            //            LifeTime = 0,
            //            TotalLifeTime = 0,
            //        };
            //        allEdges.Add(link);
            //    }
            //}
            //catch (Exception e)
            //{
            //    Log.Message(e.StackTrace);
            //}

            foreach (var pair in allVertices)
            {
                var node = pair.Value;
                //node.ColorType = 0;
                g.nodes.Add(node);
            }
            g.NodesCount = g.nodes.Count;
            g.links      = allEdges;

            graph.SetGraph(g);
            graph.cfg.GraphLayout = @"Graph/Signaling";
            graph.Initialize();
            graph.staticMode = true;
            graph.Pause();
            graph.AddMaxParticles();



            viewLayer.GraphLayers.Add(graph);
        }