Exemplo n.º 1
0
    protected int xAddNode(GeoNode node)
    {
        int i = nodes.Count;

        nodes.Add(node);
        return(i);
    }
Exemplo n.º 2
0
            public Runtime(
                Level level,
                Model3D mdl,
                GeoRoot root
#if DEBUG
                , ushort[] counter = null
                , System.Text.StringBuilder log = null
#endif
                ) : base(Instance, level.rom)
            {
                if (null == (object)level || null == (object)mdl || null == (object)root)
                {
                    throw new System.ArgumentNullException();
                }
                this._zbuf    = true;
                this.lvl      = level;
                this.mdl      = mdl;
                this.rootNode = root;

                this.nodeCurrent = null;
#if DEBUG
                this.counter = counter ?? new ushort[259];
                this.log     = log ?? new System.Text.StringBuilder();
#endif
            }
Exemplo n.º 3
0
        private void TraceNodes(List <GeoNode> visitedNodes, double curLength)
        {
            if (curLength > _minHalfLength)
            {
                GeoPath path = new GeoPath {
                    Nodes = visitedNodes, Length = (float)curLength
                };
                HalfPaths.Add(path);
                //NewLoop?.Invoke(new Tuple<GeoPath, GeoPath>(path, path));
                return;
            }
            GeoNode nodeFrom     = visitedNodes.Last();
            var     nodesToVisit = nodeFrom?.NeighbourNodes;

            foreach (var nodeTo in nodesToVisit)
            {
                if (visitedNodes.FirstOrDefault(n => n.Id == nodeTo.NodeId) == null)
                {
                    var nodeToFull      = _nodesCache[nodeTo.NodeId];
                    var newVisitedNodes = visitedNodes.ToList();
                    newVisitedNodes.Add(nodeToFull);
                    var dist = nodeTo.Distance;
                    TraceNodes(newVisitedNodes, curLength + dist);
                }
            }
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------


        /// <summary>
        /// Handles the MouseDoubleClick event of the DataGridGeoData control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param>
        private void DataGridGeoData_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            GeoNode gn = (sender as DataGrid).SelectedItem as GeoNode;

            JumpToGeoNode(gn);

            e.Handled = true;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Jumps to geo node.
        /// </summary>
        /// <param name="gn">The gn.</param>
        private void JumpToGeoNode(GeoNode gn)
        {
            this.mcMapControl.Position = gn.Position;
            this.mcMapControl.Zoom     = this.settings.MapZoomLevel;

            CreateGeoNodeMarker(gn);

            this.tiMap.IsSelected = true;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates the geo node marker.
        /// </summary>
        /// <param name="gn">The gn.</param>
        private void CreateGeoNodeMarker(GeoNode gn)
        {
            GMapMarker Marker = new GMapMarker(gn.Position)
            {
                Offset = new Point(-10, -10),
                ZIndex = int.MaxValue,
                Shape  = new GeoNodeMarker(gn),
                Tag    = gn
            };

            this.mcMapControl.Markers.Add(Marker);
        }
Exemplo n.º 7
0
                public GeoNode Create(Runtime rt, GeoParent parent)
                {
                    var node = new GeoNode(parent)
                    {
                        MinDistance = minDistance,
                        MaxDistance = maxDistance,
                        Local       = parent.Cursor,
                        ZTest       = rt._zbuf,
                    };

                    this = reset;
                    return(node);
                }
Exemplo n.º 8
0
    public GeoQuad(Vector3 pA, Vector3 pB, Vector3 pC1, Vector3 pC2) : base()
    {
        triTreeRootSize = 2;
        trianglePairs   = new int[1][] { new int[2] {
                                             0, 1
                                         } };
        triangleToPairsMap = new int[2] {
            0, 0
        };

        // 0 A
        GeoNode node = new GeoNode();

        node.position = pA;
        node.adjacency.Add(new int[2] {
            2, 3
        });
        nodes.Add(node);

        // 1 B
        node          = new GeoNode();
        node.position = pB;
        node.adjacency.Add(new int[2] {
            2, 3
        });
        nodes.Add(node);

        // 2 C1
        node          = new GeoNode();
        node.position = pC1;
        node.adjacency.Add(new int[3] {
            0, 1, 3
        });
        nodes.Add(node);

        // 3 C2
        node          = new GeoNode();
        node.position = pC2;
        node.adjacency.Add(new int[3] {
            0, 1, 2
        });
        nodes.Add(node);

        xAddTriTreeNode(new int[3] {
            0, 2, 3
        });
        xAddTriTreeNode(new int[3] {
            2, 1, 3
        });
    }
Exemplo n.º 9
0
            public Runtime(Runtime copy)
                : base(copy)
            {
                this.lvl         = copy.lvl;
                this.mdl         = copy.mdl;
                this.rootNode    = copy.rootNode;
                this.nodeCurrent = copy.nodeCurrent;
                this._zbuf       = copy._zbuf;
                this.persistant  = copy.persistant;
#if !NO_GEO_MAT
                this.material = copy.material;
#endif
#if DEBUG
                this.counter = copy.counter;
                this.log     = copy.log;
#endif
            }
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------


        /// <summary>
        /// Initializes a new instance of the <see cref="GeoNodeMarker"/> class.
        /// </summary>
        public GeoNodeMarker(GeoNode gn)
        {
            InitializeComponent();

            this.popup = new Popup
            {
                Placement = PlacementMode.Mouse,
                Child     = new Label
                {
                    Background      = Brushes.Yellow,
                    Foreground      = Brushes.Black,
                    BorderBrush     = Brushes.Black,
                    BorderThickness = new Thickness(2),
                    Padding         = new Thickness(3),
                    FontSize        = 14,
                    FontFamily      = new FontFamily("Courier New"),
                    Content         = $"[{gn.Tag}/{gn.Value}]: {(gn.Name.IsNotEmpty() ? gn.Name : "Unknown")}"
                }
            };

            MouseEnter += MarkerControl_MouseEnter;
            MouseLeave += MarkerControl_MouseLeave;
        }
Exemplo n.º 11
0
        public void SaveNodesToShape(string shapeFileName, Dictionary <long, GeoNode> allNodesCache, List <GeoNode> nodesToSave)
        {
            string firstNameAttribute = "a";
            string lastNameAttribute  = "b";

            //create geometry factory
            IGeometryFactory geomFactory = NtsGeometryServices.Instance.CreateGeometryFactory();


            IList <Feature> features = new List <Feature>();

            for (int i = 0; i < nodesToSave.Count - 1; i++)
            {
                GeoNode node1 = nodesToSave[i];
                GeoNode node2 = nodesToSave[i + 1];
                //var ngbGeoNode = allNodesCache[ngb.NodeId];
                var             line = geomFactory.CreateLineString(new[] { new Coordinate(node1.Longitude, node1.Latitude), new Coordinate(node2.Longitude, node2.Latitude) });
                AttributesTable t1   = new AttributesTable();
                t1.AddAttribute(firstNameAttribute, node1.OSMId);
                t1.AddAttribute(lastNameAttribute, node2.OSMId);

                Feature feat = new Feature(line, t1);
                features.Add(feat);
            }
            var dirName = Path.GetDirectoryName(shapeFileName);

            if (!Directory.Exists(dirName))
            {
                Directory.CreateDirectory(dirName);
            }
            var writer = new ShapefileDataWriter(shapeFileName)
            {
                Header = ShapefileDataWriter.GetHeader(features[0], features.Count)
            };

            writer.Write(features);
        }
Exemplo n.º 12
0
    protected void BuildIcosahedron()
    {
        const float A = 0.5f;
        const float B = 0.30901699437f;         // 1/(1+Sqrt(5))

        Vector3[] icoverts = new Vector3[12]
        {
            new Vector3(0f, -B, -A), new Vector3(0f, -B, A), new Vector3(0f, B, -A), new Vector3(0f, B, A),
            new Vector3(-A, 0f, -B), new Vector3(-A, 0f, B), new Vector3(A, 0f, -B), new Vector3(A, 0f, B),
            new Vector3(-B, -A, 0f), new Vector3(-B, A, 0f), new Vector3(B, -A, 0f), new Vector3(B, A, 0f)
        };

        int[][] icotris = new int[20][]
        { new int[3] {
              2, 9, 11
          }, new int[3] {
              3, 11, 9
          }, new int[3] {
              3, 5, 1
          }, new int[3] {
              3, 1, 7
          }, new int[3] {
              2, 6, 0
          },
          new int[3] {
              2, 0, 4
          }, new int[3] {
              1, 8, 10
          }, new int[3] {
              0, 10, 8
          }, new int[3] {
              9, 4, 5
          }, new int[3] {
              8, 5, 4
          },
          new int[3] {
              11, 7, 6
          }, new int[3] {
              10, 6, 7
          }, new int[3] {
              3, 9, 5
          }, new int[3] {
              3, 7, 11
          }, new int[3] {
              2, 4, 9
          },
          new int[3] {
              2, 11, 6
          }, new int[3] {
              0, 8, 4
          }, new int[3] {
              0, 6, 10
          }, new int[3] {
              1, 5, 8
          }, new int[3] {
              1, 10, 7
          } };

        int[][] icoadj = new int[12][]
        { new int[5] {
              8, 2, 4, 10, 6
          }, new int[5] {
              8, 10, 3, 5, 7
          }, new int[5] {
              0, 9, 11, 4, 6
          }, new int[5] {
              7, 9, 11, 5, 1
          },
          new int[5] {
              0, 9, 2, 5, 8
          }, new int[5] {
              8, 1, 3, 4, 9
          }, new int[5] {
              0, 2, 11, 10, 7
          }, new int[5] {
              11, 1, 10, 3, 6
          },
          new int[5] {
              0, 1, 10, 4, 5
          }, new int[5] {
              3, 2, 11, 4, 5
          }, new int[5] {
              8, 1, 6, 0, 7
          }, new int[5] {
              9, 2, 3, 6, 7
          } };

        for (int i = 0; i < icoverts.Length; i++)
        {
            GeoNode node = new GeoNode();
            node.position = icoverts[i].normalized;
            node.adjacency.Add(icoadj[i]);
            nodes.Add(node);
        }

        for (int i = 0; i < icotris.Length; i++)
        {
            xAddTriTreeNode(icotris[i]);
        }
    }
Exemplo n.º 13
0
    protected void Subdivide(int treeNodeIndex, int levelLimit, int _callLevel = 0)
    {
        Utils.Assert(treeNodeIndex >= 0, "Geosphere.GeoSurface.Subdivide: treeNodeIndex must be >= 0");

        if (tritree[treeNodeIndex].children[0] < 0)
        {
            int[] subNodes         = new int[3];
            int   subdivisionLevel = tritree[treeNodeIndex].level;

            if (subdivisionLevel >= levelLimit)
            {
                return;
            }

            for (int i = 0; i < 3; i++)
            {
                int v1 = tritree[treeNodeIndex].vertices[i];
                int v2 = tritree[treeNodeIndex].vertices[(i + 1) % 3];

                int v12 = xFindNodesCommonAdjacency(v1, v2, subdivisionLevel + 1);

                if (v12 < 0)
                {
                    GeoNode newnode = new GeoNode();
                    newnode.position  = NormalizePoint(0.5f * (nodes[v1].position + nodes[v2].position));
                    newnode.elevation = 0f;
                    newnode.adjacency = new List <int[]>();
                    v12 = xAddNode(newnode);

                    xConnectNodes(v12, v1, subdivisionLevel + 1);
                    xConnectNodes(v12, v2, subdivisionLevel + 1);
                }

                subNodes[i] = v12;
            }

            xConnectNodes(subNodes[0], subNodes[1], subdivisionLevel + 1);
            xConnectNodes(subNodes[1], subNodes[2], subdivisionLevel + 1);
            xConnectNodes(subNodes[2], subNodes[0], subdivisionLevel + 1);

            //      /\
            //     /  \
            //    /----\
            //   / \  / \
            //  /___\/___\

            xAddTriTreeNode(new int[3] {
                tritree[treeNodeIndex].vertices[0], subNodes[0], subNodes[2]
            }, treeNodeIndex);
            xAddTriTreeNode(new int[3] {
                tritree[treeNodeIndex].vertices[1], subNodes[1], subNodes[0]
            }, treeNodeIndex);
            xAddTriTreeNode(new int[3] {
                tritree[treeNodeIndex].vertices[2], subNodes[2], subNodes[1]
            }, treeNodeIndex);
            xAddTriTreeNode(new int[3] {
                subNodes[0], subNodes[1], subNodes[2]
            }, treeNodeIndex);
        }

        Utils.Assert(_callLevel + 1 <= levelLimit, "Geosphere.GeoSurface.Subdivide: Recoursive call level (" + (_callLevel + 1) + ") can't be greater than levelLimit (" + levelLimit + ")");
        foreach (int childNode in tritree[treeNodeIndex].children)
        {
            Subdivide(childNode, levelLimit, _callLevel + 1);
        }
    }
Exemplo n.º 14
0
 private double GetDistanceBetweenNodes(GeoNode node1, GeoNode node2)
 {
     return(Haversine.Calculate(node1.Latitude, node1.Longitude, node2.Latitude, node2.Longitude));
 }
Exemplo n.º 15
0
 public GeoNode FillNode(GeoNode node)
 {
     return(_liteDB.GetNodeById(node.Id));
 }