Esempio n. 1
0
        public static float CalculateDistance(Node n1, Node n2)
        {
            Point3D p1 = new Point3D(n1.X, n1.Y, n1.Z);
                Point3D p2 = new Point3D(n2.X, n2.Y, n2.Z);

                return (float)Math.Sqrt((Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2) + Math.Pow(p2.Z - p1.Z, 2)));
        }
Esempio n. 2
0
        private void ReadNodes(ref Stream s, HeaderStruct header)
        {
            BinaryReader br = new BinaryReader(s);

                int size = Marshal.SizeOf(typeof(NodeStruct));
                int nsize = Marshal.SizeOf(typeof(NeighborStruct));

                byte[] buffer = new byte[size];
                byte[] neighbor = new byte[nsize];

                List<Neighbor> nList;
                Node n;
                for (int i = 0; i < header.pathNodeCount; i++)
                {
                    br.Read(buffer, 0, size);

                    n = new Node(Functions.ByteArrayToStructure<NodeStruct>(buffer));

                    nList = new List<Neighbor>();
                    for (int j = 0; j < 50; j++)
                    {
                        br.Read(neighbor, 0, nsize);

                        NeighborStruct neighborData = Functions.ByteArrayToStructure<NeighborStruct>(neighbor);
                        if (neighborData.id == -1) continue;
                        nList.Add(new Neighbor(neighborData));
                    }
                    n.Neighbors = nList;

                    _nodes.Add(n);
                }

                ConnectNodes();
        }
Esempio n. 3
0
 private void OnNodeRemoved(Node node,List<Node>neighbors)
 {
     if (NodeRemoved != null)
         {
             NodeRemoved(this, new PathModifiedEventArgs(node,neighbors));
         }
 }
Esempio n. 4
0
 private void OnNodeAdded(Node node)
 {
     if (NodeAdded != null)
         {
             NodeAdded(this, new PathModifiedEventArgs(node,new List<Node>()));
         }
 }
Esempio n. 5
0
        public void RemoveNode(Node node)
        {
            //OnNodeRemoved(node);
                List<Node> neighbors = new List<Node>();

                node.DisconnectAll();
                foreach (Node n in Nodes)
                {
                    if (n.Neighbors.RemoveAll(x => x.Node == node) > 0)
                    {
                        neighbors.Add(n);
                    }
                }
                Nodes.Remove(node);
                UpdateNodes();
                OnNodeRemoved(node, neighbors);
        }
Esempio n. 6
0
 public void NodeTwoWayDisconnect(Node n1, Node n2)
 {
     n1.DisconnectNodeTwoWay(n2);
 }
Esempio n. 7
0
 public void NodeSingleDisconnect(Node n1, Node n2)
 {
     n1.DisconnectNode(n2);
 }
Esempio n. 8
0
 public void ConnectToNodeAsWarp(Node target)
 {
     ConnectToNode(target);
     foreach (Neighbor n in Neighbors)
     {
         if (n.Node == target)
         {
             n.Warp = true;
             n.Distance = 0.0f;
             return;
         }
     }
 }
Esempio n. 9
0
        public ObservableCollection<Node> GetInaccessibleNodes(Node n)
        {
            if (n == null) return new ObservableCollection<Node>();

                ObservableCollection<Node> unreachableNodes = new ObservableCollection<Node>();

                IEnumerable<Node> connectedNodes = n.ConnectedNodes;

                var query = Nodes.Select(x => x).Where(y => connectedNodes.Contains(y) == false);
                foreach (Node node in query)
                {
                    unreachableNodes.Add(node);
                }

                return unreachableNodes;
        }
Esempio n. 10
0
 public void AddNode(Node node)
 {
     Nodes.Add(node);
         UpdateNodes();
         OnNodeAdded(node);
 }
Esempio n. 11
0
 public void UnsubscribeToNode(Node target)
 {
     target.PropertyChanged -= NodePropertyChanged;
 }
Esempio n. 12
0
 public void SubscribeToNode(Node target)
 {
     target.PropertyChanged += NodePropertyChanged;
 }
Esempio n. 13
0
 public void DisconnectNodeTwoWay(Node target)
 {
     target.DisconnectNode(this);
     DisconnectNode(target);
 }
Esempio n. 14
0
 public void DisconnectNode(Node target)
 {
     Neighbors.RemoveAll(x => x.Node == target);
     //UnsubscribeToNode(target);
     target.PropertyChanged -= NodePropertyChanged;
     NotifyPropertyChanged("Neighbors");
 }
Esempio n. 15
0
 public void ConnectToNodeTwoWay(Node target)
 {
     ConnectToNode(target);
     target.ConnectToNode(this);
 }
Esempio n. 16
0
        public ObservableCollection<Node> GetNonNeighbors(Node n)
        {
            if (n == null) return new ObservableCollection<Node>();

                ObservableCollection<Node> nonNeighbors = new ObservableCollection<Node>();

                List<Node> neighborNodes = new List<Node>();
                neighborNodes.Add(n);
                foreach (Neighbor neighbor in n.Neighbors)
                {
                    neighborNodes.Add(neighbor.Node);
                }

                var query = Nodes.Select(x => x).Where(y => neighborNodes.Contains(y) == false);
                foreach (Node node in query)
                {
                    nonNeighbors.Add(node);
                }
                return nonNeighbors;
        }
Esempio n. 17
0
 public PathModifiedEventArgs(Node node, List<Node> neighbors)
 {
     _node = node;
     _neighbors = neighbors;
 }
Esempio n. 18
0
        ///<summary>
        ///Connects this node to the target node - distance calculations are also stored
        ///</summary>
        public void ConnectToNode(Node target)
        {
            if (this == target) throw new Exception("Cannot connect node to itself");

            //return if this target node is already in the neighbors list
            foreach (Neighbor neighbor in Neighbors)
            {
                if (neighbor.Node == target) return;
            }
            Neighbors.Add(new Neighbor() { Node = target, Distance = Path.CalculateDistance(this, target) });
            //SubscribeToNode(target);
            target.PropertyChanged += NodePropertyChanged;
            NotifyPropertyChanged("Neighbors");
        }