protected void arrangeRelatives(MapLevel level, MapLevel lastLevel) { List <GridCluster> levelClusterList = level.getGridClusters(); foreach (GridCluster clusterChild in levelClusterList) { MapPoint childPoint = clusterChild.getPoint(0); //Debug.Log("Se llama desde cluster con h=" + clusterChild.hQuad + " y v=" + clusterChild.vQuad); int h = lastLevel.getHGrid(clusterChild.hQuad); int v = lastLevel.getVGrid(clusterChild.vQuad); //List<GridCluster> parentCandidates = lastLevel.getGridClustersPerQuad(h, v); GridCluster clusterParent = lastLevel.getClusterWithPoint(childPoint); //GridCluster clusterParent = lastLevel.getClusterWithPointInQuad(childPoint); if (clusterParent != null) { clusterChild.setParent(clusterParent); clusterParent.addChild(clusterChild); } } }
public void managePoints(GridCluster cluster) { int i = 0; int h, v; int auxLevel; bool found; List <MapPoint> points = cluster.getPoints(); //Debug.Log("Managin cluster with " + points.Count); int numPoints = points.Count; for (i = 0; i < numPoints; i++) { //h = getHGrid(points[i].getMarker().position.y); //v = getVGrid(points[i].getMarker().position.x); //h = getHGrid(points[i].getY()); //v = getVGrid(points[i].getX()); auxLevel = 0; found = false; int numClusters = this.clusters.Count; while (!found && auxLevel < numClusters) { found = this.clusters[auxLevel].checkPoint(points[i].getX(), points[i].getY());// h, v);//,points[i].getCategory()); auxLevel++; } if (found) { this.clusters[auxLevel - 1].addPoint(points[i]); points[i].addCluster(this.clusters[auxLevel - 1]); } else { h = getHGrid(points[i].getX()); v = getVGrid(points[i].getY()); GridCluster newGridCluster = new GridCluster(h, v, points[i], this); newGridCluster.setLevel(this.level); points[i].addCluster(newGridCluster); newGridCluster.setParent(cluster); cluster.addChild(newGridCluster); this.clusters.Add(newGridCluster); //QuadCluster quadC = this.getQuadCluster(h, v); //quadC.addCluster(newGridCluster); //if (level==0 || level== 1) //{ // Debug.Log("Se crea quad en nivel " + level + " con h= " + h + " , v=" + v); // } } } }
public void managePointsNew(GridCluster cluster) { int i = 0; List <MapPoint> points = cluster.getPoints(); //Debug.Log("Managin cluster with " + points.Count); int numPoints = points.Count; List <GridCluster> newClusters = new List <GridCluster>(); float width = (cluster.maxX - cluster.minX) / 2.5f; float heigth = cluster.maxY - cluster.minY; Vector2 size = new Vector2(width, heigth); if (size.x != 0.0f) { Rect area1 = new Rect(new Vector2(cluster.minX, cluster.minY), size); //Rect area2 = new Rect(new Vector2(cluster.minX + (cluster.maxX - cluster.minX) / 3.0f, cluster.minY), size); Rect area3 = new Rect(new Vector2(cluster.maxX - (cluster.maxX - cluster.minX) / 3.0f, cluster.minY), size); Vector2 center1 = getRectCenter(area1); //Vector2 center2 = getRectCenter(area2); Vector2 center3 = getRectCenter(area3); GridCluster cluster1 = new GridCluster(0, 0); // this.getHGrid(center1.x), this.getVGrid(center1.y)); // GridCluster cluster2 = new GridCluster(0,0); //;this.getHGrid(center2.x), this.getVGrid(center2.y)); GridCluster cluster3 = new GridCluster(0, 0); // this.getHGrid(center3.x), this.getVGrid(center3.y)); for (i = 0; i < numPoints; i++) { MapPoint p = cluster.getPoints()[i]; if (isInRect(p.getX(), p.getY(), area1)) { p.addCluster(cluster1); cluster1.addPoint(p); } else { /* * if (isInRect(p.getX(), p.getY(), area2)) * { * p.addCluster(cluster2); * cluster2.addPoint(p); * } * else * {*/ p.addCluster(cluster3); cluster3.addPoint(p); //} } } int numclusters = 0; if (cluster1.getNumPoints() > 0) { cluster1.setParent(cluster); cluster1.setLevel(this.level); cluster.addChild(cluster1); this.clusters.Add(cluster1); numclusters++; } /* * if (cluster2.getNumPoints() > 0) * { * cluster2.setParent(cluster); * cluster.addChild(cluster2); * cluster2.setLevel(this.level); * this.clusters.Add(cluster2); * numclusters++; * }*/ if (cluster3.getNumPoints() > 0) { cluster3.setParent(cluster); cluster.addChild(cluster3); cluster3.setLevel(this.level); this.clusters.Add(cluster3); numclusters++; } //Debug.Log("Se crean "+ numclusters+ " clusters normales en nivel " + this.level); } else // grouppoint o clusters de 1 punto { //Debug.Log("Se crea un cluster de grouppoint/1 punto en nivel " + this.level); GridCluster cluster1 = new GridCluster(0, 0, cluster.getPoints()[0]); cluster1.setLevel(this.level); cluster1.setParent(cluster); cluster.addChild(cluster1); this.clusters.Add(cluster1); } }