Example #1
0
        public void AddParkingObject(ParkingObject newObject)
        {
            // add our new object
            associatedParkings.Add(newObject);

            cumulativeBox.top    += newObject.Box.top;
            cumulativeBox.left   += newObject.Box.left;
            cumulativeBox.width  += newObject.Box.width;
            cumulativeBox.height += newObject.Box.height;

            RecalculateAverageBox();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        static ParkingObject[] ParseXML(string filename)
        {
            // make our list to store parking objects in
            List <ParkingObject> parkings = new List <ParkingObject>();

            // open supplied xml document
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            // get every node of the proper type
            XmlNodeList parkingEventsNode = doc.GetElementsByTagName("ParkingEvent");

            // for each individual node...
            foreach (XmlNode node in parkingEventsNode)
            {
                // get each attribute
                XmlAttributeCollection attributes = node.Attributes;

                // and parse it
                string type   = attributes["type"].InnerText;
                int    top    = int.Parse(attributes["top"].InnerText);
                int    left   = int.Parse(attributes["left"].InnerText);
                int    width  = int.Parse(attributes["width"].InnerText);
                int    height = int.Parse(attributes["height"].InnerText);

                // build a bounding box
                BoundingBox bb = new BoundingBox(top, left, width, height);

                // build the parking object
                ParkingObject obj = new ParkingObject(type, bb);

                // add it to our list
                parkings.Add(obj);
            }

            // return our final array
            return(parkings.ToArray());
        }
        public void AddParkingEvent(ParkingObject parkingObject)
        {
            // check against our current list of parking spots
            foreach (ParkingSpot spot in associatedSpots)
            {
                // if this new event significantly overlaps with another parking spot,
                if (BoundingBox.DirectionlessOverlap(spot.Box, parkingObject.Box) > spotDetectionThreshold)
                {
                    // add this event to this parking spot
                    spot.AddParkingObject(parkingObject);

                    // and then stop
                    return;
                }
            }

            //if we didn't find a parking spot that overlaps enough, make a new spot.
            ParkingSpot newSpot = new ParkingSpot();

            newSpot.AddParkingObject(parkingObject);
            associatedSpots.Add(newSpot);
        }