예제 #1
0
        /// <summary>
        /// Determines what a person sees given person's position and direction of a view
        /// </summary>
        /// <param name="position">coordinates of a viewer</param>
        /// <param name="bearing">direction at which viewer looks (bearing) in radians</param>
        /// <returns>list of objects' descriptions</returns>
        public IEnumerable <string> At(GeoPoint position, double bearing)
        {
            if (position == null)
            {
                throw new ArgumentNullException("position");
            }

            var boundingBox         = GeoCalc.GetBoundingBox(position, Adjustment.BoundingBoxHeight, Adjustment.BoundingBoxWidth);
            var mapData             = ApiClient.GetDataInBoundingBox(ApiUrl, boundingBox);
            var objectsOfImportance = OsmApiDataProcessor.GetObjectsOfImportance(mapData);

            return(FilterObjectsByPositionAndBearing(objectsOfImportance, position, bearing));
        }
예제 #2
0
        /// <summary>
        /// Filters out only objects in a person's direction of a view
        /// </summary>
        private IEnumerable <string> FilterObjectsByPositionAndBearing(OsmObjectsOfImportance objects, GeoPoint position, double bearing)
        {
            Debug.Assert(objects != null, "objects == null");
            Debug.Assert(position != null, "position == null");

            var testingPoints = GetPointsAlongBearing(position, bearing);

            // filter objects
            var filterSingleNodesTask   = Task.Factory.StartNew(() => FilterSingleNodes(objects.SingleNodes, testingPoints));
            var filterBuildingsWaysTask = Task.Factory.StartNew(() =>
            {
                // filter buildings' ways by testing if some point along a person's direction of view is inside the way
                foreach (var point in testingPoints)
                {
                    foreach (var way in objects.BuildingsWays)
                    {
                        if (GeoCalc.IsPointInsidePolygon(point, way.Nodes))
                        {
                            return new { TestingPoint = point, Way = way }
                        }
                        ;
                    }
                }
                return(null);
            });

            Task.WaitAll(filterSingleNodesTask, filterBuildingsWaysTask);

            // print out objects' descriptions
            var building = filterBuildingsWaysTask.Result;

            if (building != null)
            {
                yield return(BuildingWayDescription(building.Way));
            }
            foreach (var node in filterSingleNodesTask.Result)
            {
                if (building == null ||
                    GeoCalc.GetDistance(node, building.TestingPoint) < Adjustment.MaxDeviationFromBearingBuildingIntersection)
                {
                    yield return(SingleNodeDescription(node));
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Filters single nodes by testing whether they are close to the points along a person's direction of view
        /// </summary>
        private ICollection <OsmNode> FilterSingleNodes(ICollection <OsmNode> singleNodes, IEnumerable <GeoPoint> testingPoints)
        {
            Debug.Assert(singleNodes != null, "singleNodes == null");
            Debug.Assert(testingPoints != null, "testingPoints == null");

            var result = new List <OsmNode>();

            foreach (var point in testingPoints)
            {
                foreach (var node in singleNodes)
                {
                    if (!result.Contains(node) && GeoCalc.GetDistance(point, node) < Adjustment.MaxDeviationFromBearing)
                    {
                        result.Add(node);
                    }
                }
            }
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Returns a collection of physical locations along a person's direction of a view ordered by distance (ascending)
        /// </summary>
        private IEnumerable <GeoPoint> GetPointsAlongBearing(GeoPoint position, double bearing)
        {
            Debug.Assert(position != null, "position == null");

            var pointsCount =
                (int)
                Math.Sqrt(Adjustment.BoundingBoxHeight * Adjustment.BoundingBoxHeight +
                          Adjustment.BoundingBoxWidth * Adjustment.BoundingBoxWidth) / 2 * Adjustment.TestByBearingStepLength;

            var points = new GeoPoint[pointsCount];

            for (var i = 0; i < pointsCount; i++)
            {
                var destination = GeoCalc.GetDestination(position, bearing, Adjustment.TestByBearingStepLength * i + 1);
                points[i] = new GeoPoint(destination.Latitude, destination.Longitude);
            }

            return(points);
        }