public Dictionary <long, HashSet <long> > BuildGraph(SpeedRoadSectionMgr secmgr) { Dictionary <long, HashSet <long> > graph = new Dictionary <long, HashSet <long> >(); foreach (var item in map) { graph[item.Key] = item.Value.GetNeighbors(secmgr); } return(graph); }
List <Vector3> ObtainRingPoints(string secs, SpeedRoadSectionMgr secmgr) { var arr = secs.Split(','); foreach (var item in arr) { lstSections.Add(secmgr.GetSection(int.Parse(item))); } return(SortSections(lstSections)); }
public HashSet <long> GetNeighbors(SpeedRoadSectionMgr secmgr) { HashSet <long> result = new HashSet <long>(); foreach (var item in lstSections) { HashSet <long> r = item.GetCrossings(); result.UnionWith(r); } result.Remove(Fid); return(result); }
void Init(ref GameObject obj, Feature fea, SpeedRoadSectionMgr secmgr) { fid = fea.GetFID(); // 构建顶点数组 var lstpts = ObtainRingPoints(fea.GetFieldAsString("sections"), secmgr); Geometry geo = fea.GetGeometryRef(); Vector3 pt = new Vector3((float)geo.GetX(0), 0, (float)geo.GetY(0)); lstpts.Add(pt); // 构建索引数组 // 3 * (lstpts.Count); List <int> idx = new List <int>(); for (int i = 0; i < lstpts.Count - 2; i++) { idx.Add(lstpts.Count - 1); idx.Add(i); idx.Add(i + 1); } idx.Add(lstpts.Count - 1); idx.Add(lstpts.Count - 2); idx.Add(0); Mesh msh = new Mesh(); msh.vertices = lstpts.ToArray(); msh.triangles = idx.ToArray(); msh.RecalculateNormals(); msh.RecalculateBounds(); obj.AddComponent(typeof(MeshRenderer)); MeshFilter filter = obj.AddComponent(typeof(MeshFilter)) as MeshFilter; filter.mesh = msh; obj.GetComponent <MeshRenderer>().material.color = new Color(0, 1, 0, 0.5f); obj.name = fid.ToString(); GameObject fidmesh = GameObject.Instantiate(SpeedRoad.prefab); fidmesh.transform.parent = obj.transform; fidmesh.transform.localPosition = pt + Vector3.up * 2; fidmesh.name = "fid"; m_textMeshPro = fidmesh.AddComponent <TextMeshPro>(); m_textMeshPro.fontSize = 48; m_textMeshPro.color = Color.black; m_textMeshPro.alignment = TextAlignmentOptions.Center; m_textMeshPro.enableWordWrapping = false; m_textMeshPro.SetText(obj.name); }
public void LoadFile(string fname, Transform par, SpeedRoadSectionMgr secmgr) { parent = par; DataSource ds = Ogr.Open(fname, 0); Assert.IsNotNull(ds); Assert.IsTrue(ds.GetLayerCount() > 0); Layer layer = ds.GetLayerByIndex(0); layer.ResetReading(); Feature feat; while ((feat = layer.GetNextFeature()) != null) { GameObject obj = Instantiate(SpeedRoad.prefab); obj.transform.parent = parent; SpeedRoadCrossing crossing = new SpeedRoadCrossing(ref obj, feat, secmgr); map[crossing.Fid] = crossing; } }
public SpeedRoadCrossing(ref GameObject obj, Feature fea, SpeedRoadSectionMgr secmgr) { Assert.IsTrue(fea.GetGeometryRef().GetGeometryType() == wkbGeometryType.wkbPoint); Init(ref obj, fea, secmgr); }