/// <summary>
        /// creates an Activity Destination from its string representation
        /// </summary>
        /// <param name="lines">The lines.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="cellularFloor">The cellular floor.</param>
        /// <param name="tolerance">The tolerance.</param>
        /// <returns>ActivityDestination.</returns>
        /// <exception cref="System.ArgumentException">
        /// Activity does not include a name!
        /// or
        /// Failed to parse activity's engagement duration: " + lines[startIndex + 3]
        /// or
        /// Activity does not include cell origins!
        /// or
        /// Failed to set activity engagement duration!
        /// </exception>
        public static ActivityDestination FromString(List <string> lines, int startIndex, Length_Unit_Types unitType, CellularFloor cellularFloor, double tolerance = 0.0000001d)
        {
            string name = lines[startIndex];

            if (string.IsNullOrEmpty(lines[startIndex]) || string.IsNullOrWhiteSpace(lines[startIndex]))
            {
                throw new ArgumentException("Activity does not include a name!");
            }
            StateBase      state   = StateBase.FromStringRepresentation(lines[startIndex + 1]);
            BarrierPolygon barrier = BarrierPolygon.FromStringRepresentation(lines[startIndex + 2]);

            //unit converion
            UnitConversion.Transform(state.Location, unitType, cellularFloor.UnitType);
            UnitConversion.Transform(state.Velocity, unitType, cellularFloor.UnitType);
            UnitConversion.Transform(barrier.BoundaryPoints, unitType, cellularFloor.UnitType);

            var    strings = lines[startIndex + 3].Split(',');
            double min = 0, max = 0;

            if (!double.TryParse(strings[0], out min) || !double.TryParse(strings[1], out max))
            {
                throw new ArgumentException("Failed to parse activity's engagement duration: " + lines[startIndex + 3]);
            }
            HashSet <Cell> origins = new HashSet <Cell>();
            var            indices = cellularFloor.GetIndicesInsideBarrier(barrier, tolerance);

            if (indices.Count > 0)
            {
                foreach (var index in indices)
                {
                    Cell cell = cellularFloor.FindCell(index);
                    if (cell != null && cell.FieldOverlapState == OverlapState.Inside)
                    {
                        origins.Add(cell);
                    }
                }
            }
            if (origins.Count == 0)
            {
                throw new ArgumentException("Activity does not include cell origins!");
            }
            ActivityDestination dest = new ActivityDestination(name, origins, state, barrier);

            if (!dest.TrySetEngagementTime(min, max))
            {
                throw new ArgumentException("Failed to set activity engagement duration!");
            }
            return(dest);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the boundary polygon of the visibility area.
        /// </summary>
        /// <param name="cellularFloor">The cellularFloor.</param>
        /// <returns>List&lt;BarrierPolygons&gt;.</returns>
        public List <BarrierPolygon> GetBoundary(CellularFloor cellularFloor)
        {
            Dictionary <UVLine, int> guid = new Dictionary <UVLine, int>();

            foreach (var item in this.VisibleCells)
            {
                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);
        }
Exemplo n.º 3
0
        private double OverlappingArea(CellularFloor cellularFloor, Index cellIndex, Index inputIndex)
        {
            if (inputIndex.I < 0 || inputIndex.I >= this.number_X || inputIndex.J < 0 || inputIndex.J >= this.number_Y)
            {
                return(0);
            }
            if (this.DataPoints[inputIndex.I, inputIndex.J] == null)
            {
                return(0);
            }
            if (cellularFloor.FindCell(cellIndex).VisualOverlapState != OverlapState.Outside)
            {
                return(0);
            }
            double   u1         = cellularFloor.Cells[cellIndex.I, cellIndex.J].U;
            double   u2         = u1 + this._host.cellularFloor.CellSize;
            Interval interval_U = new Interval(u1, u2);
            double   x1         = this.DataPoints[inputIndex.I, inputIndex.J].U;
            double   x2         = x1 + this.dist_x;
            Interval interval_X = new Interval(x1, x2);
            var      interval_A = interval_U.Overlap(interval_X);

            if (interval_A == null)
            {
                return(0);
            }
            double   v1         = cellularFloor.Cells[cellIndex.I, cellIndex.J].V;
            double   v2         = v1 + this._host.cellularFloor.CellSize;
            Interval interval_V = new Interval(v1, v2);
            double   y1         = this.DataPoints[inputIndex.I, inputIndex.J].V;
            double   y2         = y1 + this.dist_y;
            Interval interval_Y = new Interval(y1, y2);
            var      interval_B = interval_V.Overlap(interval_Y);

            if (interval_B == null)
            {
                return(0);
            }
            return(interval_A.Length * interval_B.Length);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VisibilityEvaluationEvent"/> class.
        /// </summary>
        /// <param name="visualTargets">The visual targets.</param>
        /// <param name="cellularFloor">The cellular floor.</param>
        /// <param name="tolerance">The tolerance by default set to the main document's absolute tolerance value.</param>
        /// <exception cref="System.ArgumentException">Cannot generate 'Occupancy Visual Event' with no visibility target cells!</exception>
        public VisibilityTarget(ICollection <SpatialAnalysis.Geometry.BarrierPolygon> visualTargets, CellularFloor cellularFloor, double tolerance = OSMDocument.AbsoluteTolerance)
        {
            this.VisualTargets = visualTargets.ToArray();
            HashSet <Index> allIndices = new HashSet <Index>();

            foreach (SpatialAnalysis.Geometry.BarrierPolygon item in this.VisualTargets)
            {
                allIndices.UnionWith(cellularFloor.GetIndicesInsideBarrier(item, tolerance));
            }
            var visibleCells = new HashSet <int>();

            foreach (Index item in allIndices)
            {
                if (cellularFloor.ContainsCell(item) &&
                    cellularFloor.Cells[item.I, item.J].VisualOverlapState == OverlapState.Outside)
                {
                    visibleCells.Add(cellularFloor.Cells[item.I, item.J].ID);
                }
            }
            allIndices.Clear();
            allIndices = null;
            if (visibleCells.Count == 0)
            {
                throw new ArgumentException("Cannot generate 'Occupancy Visual Event' with no visibility target cells!");
            }
            var            cellsOnEdge = CellUtility.GetEdgeOfField(cellularFloor, visibleCells);
            List <Isovist> isovists    = new List <Isovist>(cellsOnEdge.Count);
            double         depth       = cellularFloor.Origin.DistanceTo(cellularFloor.TopRight) + 1;

            foreach (int item in cellsOnEdge)
            {
                isovists.Add(new Isovist(cellularFloor.FindCell(item)));
            }
            Parallel.ForEach(isovists, (a) =>
            {
                a.Compute(depth, BarrierType.Visual, cellularFloor, 0.0000001);
            });
            HashSet <int> visibleArea = new HashSet <int>();

            foreach (Isovist item in isovists)
            {
                visibleArea.UnionWith(item.VisibleCells);
            }
            this.AllVisibleCells        = visibleArea;
            this.ReferencedVantageCells = new Dictionary <int, List <int> >();
            var vantageCells = new List <int>(isovists.Count);

            foreach (var item in this.AllVisibleCells)
            {
                this.ReferencedVantageCells.Add(item, new List <int>());
            }
            foreach (var isovist in isovists)
            {
                vantageCells.Add(isovist.VantageCell.ID);
                foreach (var cellID in isovist.VisibleCells)
                {
                    this.ReferencedVantageCells[cellID].Add(isovist.VantageCell.ID);
                }
            }
            this.VantageCells = vantageCells;
        }