Beispiel #1
0
    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 GridCluster(GridCluster a)
 {
     this.numFilteredPoints = 0;
     this.points.AddRange(a.getPoints());
     a.setParent(this);
     this.addChild(a);
     this.center = new MapPoint(a.getCenter().getX(), a.getCenter().getY());
 }
 public GridCluster(GridCluster a, GridCluster b)
 {
     this.numFilteredPoints = 0;
     this.points.AddRange(a.getPoints());
     this.points.AddRange(b.getPoints());
     a.setParent(this);
     b.setParent(this);
     this.addChild(a);
     this.addChild(b);
     this.setAverageCenter(a.getCenter(), b.getCenter());
 }
    protected MapPointMarker getClusterMarker(GridCluster gCluster, int id)
    {
        MapPointMarker mapPoint = new MapPointMarker(gCluster.getCenter().getX(), gCluster.getCenter().getY(), clusterPrefab, true);

        mapPoint.setGridCluster(gCluster);
        mapPoint.setLabel("Cluster " + id);

        //if(mapPoint.getMarker3D()!= null)
        //    mapPoint.getMarker3D().instance.name = id.ToString();


        mapPoint.setClusteredPoints(gCluster.getPoints());

        mapPoint.setCluster(true);
        if (mapPoint.getMarker3D() != null)
        {
            mapPoint.getMarker3D().altitude     = 30.0f;
            mapPoint.getMarker3D().altitudeType = OnlineMapsAltitudeType.absolute;
            mapPoint.getMarker3D().scale        = getScale(gCluster, this.points.Count);
        }

        mapPoint.setMap(this);



        addMarkerInstance(mapPoint);


        if (mapPoint.isGroupPoint())
        {
            var img = mapPoint.markerInstance.gameObject.GetComponentInChildren <Image>();
            if (img != null)
            {
                img.sprite = customGroupPointMarker;
                foreach (var imgchild in img.GetComponentsInChildren <Image>())
                {
                    if (imgchild != img)
                    {
                        imgchild.sprite = customGroupPointMarker;
                    }
                }
            }
        }

        gCluster.setCenter(mapPoint);

        //if (gCluster.isGroupPoints())
        //    Debug.Log("AQUI");

        /*
         *
         * if (gCluster.getCategory().Equals("silknow.org/#pthing"))
         * {
         *  SphereCollider sphereCollider = mapPoint.getMarker3D().instance.GetComponent<SphereCollider>();
         *  sphereCollider.radius = 1;
         *  //mapPoint.getMarker3D().scale = mapPoint.getMarker3D().scale * 100.0f;
         * }
         * else
         * {
         *  CapsuleCollider capsuleCollider = mapPoint.getMarker3D().instance.GetComponent<CapsuleCollider>();
         *  capsuleCollider.radius = 0.5f;
         *  capsuleCollider.height = 1.5f;
         *  capsuleCollider.direction = 1;
         *  mapPoint.getMarker3D().altitude = 70.0f;
         *  //mapPoint.getMarker3D().transform.position = mapPoint.getMarker3D().transform.position + new Vector3(0.0f, 60.0f, 0.0f);
         *  //mapPoint.getMarker3D().al
         *
         * }*/



        mapPoint.hide();

        return(mapPoint);
    }
Beispiel #5
0
    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);
        }
    }
    protected GridCluster getClosestTo(GridCluster from, List <GridCluster> clusterList, int since, float minimum, bool check)
    {
        GridCluster closest  = null;
        GridCluster closest1 = null;
        string      fromURI  = from.getPoints()[0].getURI();

        float minDistance  = 1000000.0f;
        float minDistance1 = 1000000.0f;
        //float minimum = 5.0f;

        int i = since;

        //i = 0;

        while (i < clusterList.Count)
        {
            if (!clusterList[i].processed && from != clusterList[i])  //&& clusterList[i].getNumPoints()>1)
            {
                float currentDistance = getDistance(from.getCenter(), clusterList[i].getCenter());

                if (currentDistance <= minimum)
                {
                    if (check)
                    {
                        //GridCluster closest2 = getClosestTo(clusterList[i], clusterList, since, minimum, false);

                        GridCluster closest2 = clusterList[i].closest;

                        if (closest2 != null)
                        {
                            if (closest2.getPoints()[0].getURI().Equals(fromURI))
                            {
                                if (currentDistance < minDistance && clusterList[i].getNumPoints() >= 1)
                                {
                                    minDistance = currentDistance;
                                    closest     = clusterList[i];
                                }

                                /*
                                 * if (currentDistance < minDistance1 && clusterList[i].getNumPoints() == 1)
                                 * {
                                 *  minDistance1 = currentDistance;
                                 *  closest1 = clusterList[i];
                                 * }*/
                            }
                        }
                    }
                    else
                    {
                        if (currentDistance < minDistance && clusterList[i].getNumPoints() >= 1)
                        {
                            minDistance = currentDistance;
                            closest     = clusterList[i];
                        }

                        /*
                         * if (currentDistance < minDistance1 && clusterList[i].getNumPoints() == 1)
                         * {
                         *  minDistance1 = currentDistance;
                         *  closest1 = clusterList[i];
                         * }*/
                    }
                }
            }

            i++;
        }

        //if (minDistance1 < minDistance / 1.25f)
        //  closest = closest1;

        return(closest);
    }