예제 #1
0
        /// <summary>
        /// Targets the visibility test.
        /// </summary>
        /// <param name="currentState">The current state of the agent.</param>
        /// <param name="visibilityCosineFactor">The visibility cosine factor.</param>
        /// <param name="cellularFloor">The cellular floor.</param>
        /// <returns>UV.</returns>
        public UV TargetVisibilityTest(StateBase currentState, double visibilityCosineFactor, CellularFloorBaseGeometry cellularFloor)
        {
            var vantageCell = cellularFloor.FindCell(currentState.Location);

            if (!this.AllVisibleCells.Contains(vantageCell.ID))
            {
                return(null);
            }
            UV target = null;

            foreach (var cellID in this.ReferencedVantageCells[vantageCell.ID])
            {
                UV targetCell = cellularFloor.FindCell(cellID);
                UV direction  = targetCell - currentState.Location;
                direction.Unitize();
                if (direction.DotProduct(currentState.Direction) >= visibilityCosineFactor)
                {
                    target = targetCell;
                    break;
                }
            }
            return(target);
        }
예제 #2
0
        /// <summary>
        /// Determines whether a visual the event is raised.
        /// </summary>
        /// <param name="currentState">The current state of the agent.</param>
        /// <param name="visibilityCosineFactor">The visibility cosine factor.</param>
        /// <param name="cellularFloor">The cellular floor.</param>
        /// <returns><c>true</c> if visual the event is raised, <c>false</c> otherwise.</returns>
        public bool VisualEventRaised(StateBase currentState, double visibilityCosineFactor, CellularFloorBaseGeometry cellularFloor)
        {
            var vantageCell = cellularFloor.FindCell(currentState.Location);

            if (!this.AllVisibleCells.Contains(vantageCell.ID))
            {
                return(false);
            }
            bool raised = false;

            foreach (var cellID in this.ReferencedVantageCells[vantageCell.ID])
            {
                UV targetCell = cellularFloor.FindCell(cellID);
                UV direction  = targetCell - currentState.Location;
                direction.Unitize();
                if (direction.DotProduct(currentState.Direction) >= visibilityCosineFactor)
                {
                    raised = true;
                    break;
                }
            }
            return(raised);
        }
        /// <summary>
        /// Gets the boundary polygons of a collection of cells.
        /// </summary>
        /// <param name="cellIDs">The visible cells.</param>
        /// <param name="cellularFloor">The cellular floor.</param>
        /// <returns>List&lt;BarrierPolygons&gt;.</returns>
        public static List <BarrierPolygon> GetBoundary(ICollection <int> cellIDs, CellularFloorBaseGeometry cellularFloor)
        {
            Dictionary <UVLine, int> guid = new Dictionary <UVLine, int>();

            foreach (var item in cellIDs)
            {
                var lines = cellularFloor.CellToLines(cellularFloor.FindCell(item));
                foreach (var line in lines)
                {
                    if (guid.ContainsKey(line))
                    {
                        guid[line]++;
                    }
                    else
                    {
                        guid.Add(line, 1);
                    }
                }
            }
            List <UVLine> boundaryLines = new List <UVLine>();

            foreach (KeyValuePair <UVLine, int> item in guid)
            {
                if (item.Value == 1)
                {
                    boundaryLines.Add(item.Key);
                }
            }
            guid.Clear();
            guid = null;
            var plines = PLine.ExtractPLines(boundaryLines);
            List <BarrierPolygon> boundary = new List <BarrierPolygon>();

            foreach (PLine item in plines)
            {
                var oneBoundary = item.Simplify(cellularFloor.CellSize / 10);
                if (oneBoundary != null)
                {
                    boundary.Add(new BarrierPolygon(oneBoundary.ToArray()));
                }
            }
            boundaryLines.Clear();
            boundaryLines = null;
            return(boundary);
        }
        /// <summary>
        /// Creats an instance of the CollisionAnalyzer.
        /// </summary>
        /// <param name="point">The agent or target location</param>
        /// <param name="cellularFloor">The CellularFloorBaseGeometry which includes the agent or target</param>
        /// <param name="barrierType">Barrier type</param>
        /// <returns>An instance of the CollisionAnalyzer which can be null</returns>
        public static CollisionAnalyzer GetCollidingEdge(UV point, CellularFloorBaseGeometry cellularFloor, BarrierType barrierType)
        {
            Cell cell = cellularFloor.FindCell(point);

            if (cell == null)
            {
                return(null);
            }
            switch (barrierType)
            {
            case BarrierType.Visual:
                if (cell.VisualOverlapState == OverlapState.Inside)
                {
                    return(null);
                }
                break;

            case BarrierType.Physical:
                if (cell.PhysicalOverlapState == OverlapState.Inside)
                {
                    return(null);
                }
                break;

            case BarrierType.Field:
                if (cell.FieldOverlapState == OverlapState.Outside)
                {
                    //cell.Visualize(MainDocument.TargetVisualizer, Cell.Size, Cell.Size, 0);
                    return(null);
                }
                break;

            case BarrierType.BarrierBuffer:
                return(null);
            }
            var colision = new CollisionAnalyzer(point, cell, cellularFloor, barrierType);

            if (colision.Barrrier == null)
            {
                return(null);
            }
            return(colision);
        }