/// <summary> /// Converts an xy rndf to a Rndf Network /// </summary> /// <param name="rndf"></param> /// <param name="projection"></param> /// <returns></returns> public static RndfNetwork ConvertXyRndfToRndfNetwork(IRndf rndf, PlanarProjection projection) { // create rndf network generator RndfNetworkGenerator networkGenerator = new RndfNetworkGenerator(); // create the rndf network RndfNetwork rndfNetwork = networkGenerator.CreateRndfNetwork(rndf, projection); // return the rndf return rndfNetwork; }
/// <summary> /// Parses an rndf /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static IRndf GenerateGpsRndf(string fileName) { // Convert file to a FileStream FileStream fs = new FileStream(fileName, FileMode.Open); // Create new Parser RndfParser parser = new RndfParser(); // Create a new Gps Rndf IRndf gpsRndf = parser.createRndf(fs); // dispose the fs fs.Dispose(); // return the rndf return(gpsRndf); }
/// <summary> /// determine and set the Ways of a segment usign the lane data already in xy /// </summary> /// <param name="segment"></param> /// <param name="Lanes"></param> public static IRndf DetermineWays(IRndf originalRndf) { // loop through segments foreach (SimpleSegment originalSegment in originalRndf.Segments) { // initialize ways originalSegment.Way1Lanes = new List<SimpleLane>(); originalSegment.Way2Lanes = new List<SimpleLane>(); // calculate directon of first lane SimpleLane initialLane = originalSegment.Lanes[0]; // get first and last waypoitns of lane Coordinates initialBeginning = initialLane.Waypoints[0].Position; Coordinates initialEnding = initialLane.Waypoints[initialLane.Waypoints.Count - 1].Position; // get change in position Coordinates initialDelta = initialEnding - initialBeginning; double initialAngle = initialDelta.ToDegrees(); // loop through lanes foreach (SimpleLane tempLane in originalSegment.Lanes) { // get first and last waypoitns of lane Coordinates laneBeginning = tempLane.Waypoints[0].Position; Coordinates laneEnding = tempLane.Waypoints[tempLane.Waypoints.Count - 1].Position; // get change in position Coordinates laneDelta = laneEnding - laneBeginning; double laneAngle = laneDelta.ToDegrees(); // calculate direction of each lane and add to Way1 if close to same dir as first if (initialAngle >= 40.0 && initialAngle <= 320.0) { if (Math.Abs(initialAngle - laneAngle) < 40.0) originalSegment.Way1Lanes.Add(tempLane); else originalSegment.Way2Lanes.Add(tempLane); } else if (initialAngle < 40.0) { if (laneAngle < 320.0) { if (Math.Abs(initialAngle - laneAngle) < 40.0) originalSegment.Way1Lanes.Add(tempLane); else originalSegment.Way2Lanes.Add(tempLane); } else { double reflectCurrent = 360 - laneAngle; if (initialAngle + reflectCurrent < 40.0) originalSegment.Way1Lanes.Add(tempLane); else originalSegment.Way2Lanes.Add(tempLane); } } else { if (laneAngle > 320.0) { if (Math.Abs(initialAngle - laneAngle) < 40.0) originalSegment.Way1Lanes.Add(tempLane); else originalSegment.Way2Lanes.Add(tempLane); } else { double reflectInitial = 360 - initialAngle; if (reflectInitial + laneAngle < 40.0) originalSegment.Way1Lanes.Add(tempLane); else originalSegment.Way2Lanes.Add(tempLane); } } } } // return the rndf return originalRndf; }
/// <summary> /// Averages all coordinates in the gps rndf and creates a planar projection /// </summary> /// <param name="rndf"></param> /// <returns></returns> public static PlanarProjection GetProjection(IRndf rndf) { // First group all the Coordinates List<Coordinates> coordinates = new List<Coordinates>(); // Get coordinates from segments List<SimpleSegment> segments = (List<SimpleSegment>)rndf.Segments; foreach (SimpleSegment segment in segments) { // Get coordinates from lanes List<SimpleLane> lanes = (List<SimpleLane>)segment.Lanes; foreach (SimpleLane lane in lanes) { // Get coordinates from waypoints List<SimpleWaypoint> waypoints = (List<SimpleWaypoint>)lane.Waypoints; foreach (SimpleWaypoint waypoint in waypoints) { // Add position to the coordinate list coordinates.Add(waypoint.Position); } } } // Get coordinates from zones List<SimpleZone> zones = (List<SimpleZone>)rndf.Zones; foreach (SimpleZone zone in zones) { // Get coordinates from perimeter ZonePerimeter perimeter = zone.Perimeter; List<PerimeterPoint> perimeterPoints = (List<PerimeterPoint>)perimeter.PerimeterPoints; foreach (PerimeterPoint perimeterPoint in perimeterPoints) { // Add perimeterPont position to coordinate list coordinates.Add(perimeterPoint.position); } // Get coordiantes from parking spots List<ParkingSpot> parkingSpots = (List<ParkingSpot>)zone.ParkingSpots; foreach (ParkingSpot parkingSpot in parkingSpots) { // Add waypoints in parking spot to coordinate list coordinates.Add(parkingSpot.Waypoint1.Position); coordinates.Add(parkingSpot.Waypoint2.Position); } } // Get origin for planar projection List<GpsCoordinate> gpsCoordinates = new List<GpsCoordinate>(); foreach (Coordinates coordinate in coordinates) { gpsCoordinates.Add(new GpsCoordinate(coordinate.X, coordinate.Y)); } // get planar projection origin GpsCoordinate projectionOrigin = GpsTools.CalculateOrigin(gpsCoordinates); // Create new projection PlanarProjection projection = GpsTools.PlanarProjection(projectionOrigin, true); // return created projection return projection; }
/// <summary> /// Opens an rndf file and transforms the points to xy around a central projection /// </summary> /// <param name="fileName"></param> /// <param name="rndf"></param> /// <param name="projection"></param> public static void GenerateXyRndfAndProjection(string fileName, out IRndf rndf, out PlanarProjection projection) { // generate the gps rndf IRndf gpsRndf = GenerateGpsRndf(fileName); // get the planar projection projection = GetProjection(gpsRndf); // create an xy rndf IRndf xyRndf = gpsRndf; #region Apply transform to all point // Get coordinates from segments foreach (SimpleSegment segment in xyRndf.Segments) { // Get coordinates from lanes List<SimpleLane> lanes = (List<SimpleLane>)segment.Lanes; foreach (SimpleLane lane in lanes) { // Get coordinates from waypoints List<SimpleWaypoint> waypoints = (List<SimpleWaypoint>)lane.Waypoints; foreach (SimpleWaypoint waypoint in waypoints) { // Transform the gps coordinate into an xy xoordinate GpsCoordinate position = new GpsCoordinate(waypoint.Position.X, waypoint.Position.Y); Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(position))); // Add position to the coordinate list waypoint.Position = tmpXY; } } } foreach (SimpleZone zone in xyRndf.Zones) { // Get coordinates from perimeter ZonePerimeter perimeter = zone.Perimeter; List<PerimeterPoint> perimeterPoints = (List<PerimeterPoint>)perimeter.PerimeterPoints; foreach (PerimeterPoint perimeterPoint in perimeterPoints) { // Transform the gps coordinate into an xy xoordinate GpsCoordinate position = new GpsCoordinate(perimeterPoint.position.X, perimeterPoint.position.Y); Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(perimeterPoint.position))); // Add position to the coordinate list perimeterPoint.position = tmpXY; } // Get coordiantes from parking spots List<ParkingSpot> parkingSpots = (List<ParkingSpot>)zone.ParkingSpots; foreach (ParkingSpot parkingSpot in parkingSpots) { // Transform the gps coordinate into an xy xoordinate GpsCoordinate position = new GpsCoordinate(parkingSpot.Waypoint1.Position.X, parkingSpot.Waypoint1.Position.Y); Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(parkingSpot.Waypoint1.Position))); // wp1 position set parkingSpot.Waypoint1.Position = tmpXY; // Transform the gps coordinate into an xy xoordinate position = new GpsCoordinate(parkingSpot.Waypoint2.Position.X, parkingSpot.Waypoint2.Position.Y); Coordinates tmpXY2 = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(parkingSpot.Waypoint2.Position))); // wp1 position set parkingSpot.Waypoint2.Position = tmpXY2; } } # endregion // set the return xy rndf rndf = xyRndf; }
/// <summary> /// Creates an rndf network from an xy rndf /// </summary> /// <returns></returns> public RndfNetwork CreateRndfNetwork(IRndf xyRndf, PlanarProjection projection) { return null; }
/// <summary> /// Constructor /// </summary> /// <param name="xyRndf"></param> public RoadNetworkGeneration(IRndf xyRndf) { this.xyRndf = xyRndf; }
/// <summary> /// Constructor /// </summary> /// <param name="xyRndf"></param> public RoadNetworkGeneration(IRndf xyRndf) { this.xyRndf = xyRndf; }
/// <summary> /// Opens an rndf file and transforms the points to xy around a central projection /// </summary> /// <param name="fileName"></param> /// <param name="rndf"></param> /// <param name="projection"></param> public static void GenerateXyRndfAndProjection(string fileName, out IRndf rndf, out PlanarProjection projection) { // generate the gps rndf IRndf gpsRndf = GenerateGpsRndf(fileName); // get the planar projection projection = GetProjection(gpsRndf); // create an xy rndf IRndf xyRndf = gpsRndf; #region Apply transform to all point // Get coordinates from segments foreach (SimpleSegment segment in xyRndf.Segments) { // Get coordinates from lanes List <SimpleLane> lanes = (List <SimpleLane>)segment.Lanes; foreach (SimpleLane lane in lanes) { // Get coordinates from waypoints List <SimpleWaypoint> waypoints = (List <SimpleWaypoint>)lane.Waypoints; foreach (SimpleWaypoint waypoint in waypoints) { // Transform the gps coordinate into an xy xoordinate GpsCoordinate position = new GpsCoordinate(waypoint.Position.X, waypoint.Position.Y); Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(position))); // Add position to the coordinate list waypoint.Position = tmpXY; } } } foreach (SimpleZone zone in xyRndf.Zones) { // Get coordinates from perimeter ZonePerimeter perimeter = zone.Perimeter; List <PerimeterPoint> perimeterPoints = (List <PerimeterPoint>)perimeter.PerimeterPoints; foreach (PerimeterPoint perimeterPoint in perimeterPoints) { // Transform the gps coordinate into an xy xoordinate GpsCoordinate position = new GpsCoordinate(perimeterPoint.position.X, perimeterPoint.position.Y); Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(perimeterPoint.position))); // Add position to the coordinate list perimeterPoint.position = tmpXY; } // Get coordiantes from parking spots List <ParkingSpot> parkingSpots = (List <ParkingSpot>)zone.ParkingSpots; foreach (ParkingSpot parkingSpot in parkingSpots) { // Transform the gps coordinate into an xy xoordinate GpsCoordinate position = new GpsCoordinate(parkingSpot.Waypoint1.Position.X, parkingSpot.Waypoint1.Position.Y); Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(parkingSpot.Waypoint1.Position))); // wp1 position set parkingSpot.Waypoint1.Position = tmpXY; // Transform the gps coordinate into an xy xoordinate position = new GpsCoordinate(parkingSpot.Waypoint2.Position.X, parkingSpot.Waypoint2.Position.Y); Coordinates tmpXY2 = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(parkingSpot.Waypoint2.Position))); // wp1 position set parkingSpot.Waypoint2.Position = tmpXY2; } } # endregion
/// <summary> /// Constructor /// </summary> /// <param name="xyRndf"></param> public InterconnectGeneration(IRndf xyRndf) { this.xyRndf = xyRndf; }
// Creates Rndf from an input FileStream public IRndf createRndf(FileStream fileStream) { numWps = 0; // File in Read Only mode, convert to stream StreamReader r = new StreamReader(fileStream, Encoding.UTF8); // Create new queue for input buffer Queue q = new Queue(); string word = ""; // Create the Rndf (with only segments for now, no zones) IRndf rndf = new IRndf(); rndf.Segments = new List<SimpleSegment>(); rndf.Zones = new List<SimpleZone>(); // Loop until reach end of file marker while ((word.Length < 8) || (word.Substring(0, 8) != "end_file")) { // get the next word word = parseWord(r, q); if (word == "RNDF_name") { word = parseWord(r, q); rndf.Name = word; } else if (word == "num_segments") { word = parseWord(r, q); rndf.NumSegs = int.Parse(word); } else if (word == "num_zones") { word = parseWord(r, q); rndf.NumZones = int.Parse(word); } else if (word == "format_version") { word = parseWord(r, q); rndf.FormatVersion = word; } else if (word == "creation_date") { word = parseWord(r, q); rndf.CreationDate = word; } else if (word == "segment") { // create new segment SimpleSegment seg = new SimpleSegment(); seg.Lanes = new List<SimpleLane>(); word = parseWord(r, q); seg.Id = word; // run until reach end of segment marker while (word != "end_segment") { // get next word word = parseWord(r, q); if (word == "segment_name") { word = parseWord(r, q); seg.Name = word; } else if (word == "num_lanes") { word = parseWord(r, q); seg.NumLanes = int.Parse(word); } else if (word == "end_segment") { // do nothing if at the end } else if (word == "lane") { // Create new lane SimpleLane ln = new SimpleLane(); ln.Checkpoints = new List<SimpleCheckpoint>(); ln.Waypoints = new List<SimpleWaypoint>(); ln.Stops = new List<string>(); ln.ExitEntries = new List<SimpleExitEntry>(); word = parseWord(r, q); ln.Id = word; // run until reach end of lane while (word != "end_lane") { // get next word word = parseWord(r, q); if (word == "num_waypoints") { word = parseWord(r, q); ln.NumWaypoints = int.Parse(word); } else if (word == "checkpoint") { // create checkpoint SimpleCheckpoint cp = new SimpleCheckpoint(); // get waypoint id string wp = parseWord(r, q); cp.WaypointId = wp; // get checkpoint id string id = parseWord(r, q); cp.CheckpointId = id; // add to collection of checkpoints within lane ln.Checkpoints.Add(cp); } else if (word == "lane_width") { word = parseWord(r, q); ln.LaneWidth = double.Parse(word); } else if (word == "stop") { word = parseWord(r, q); ln.Stops.Add(word); } else if (word == "left_boundary") { word = parseWord(r, q); ln.LeftBound = word; } else if (word == "right_boundary") { word = parseWord(r, q); ln.RightBound = word; } else if (word == "exit") { // create exit-entry pair SimpleExitEntry exitEntry = new SimpleExitEntry(); // get the exit id string exit = parseWord(r, q); exitEntry.ExitId = exit; // get the entry id string entry = parseWord(r, q); exitEntry.EntryId = entry; // add to collection of exit-entry pairs within lane ln.ExitEntries.Add(exitEntry); } else if (word == "end_lane") { // do nothing } // Otherwise we probably have a waypoint else { // check to make sure a wp by matching lane id to lane identifier of waypoint int laneIdLength = ln.Id.Length; // if waypoint matches then create the waypoint if (word.Length >= laneIdLength + 2 && (word.Substring(0, laneIdLength)).CompareTo(ln.Id) == 0) { // create a new waypoint SimpleWaypoint wp = new SimpleWaypoint(); wp.Position = new UrbanChallenge.Common.Coordinates(); // set its id wp.ID = word; // get latitude or X string lat = parseWord(r, q); wp.Position.X = double.Parse(lat); // get longitude or y string lon = parseWord(r, q); wp.Position.Y = double.Parse(lon); // add to lane's collection of waypoints ln.Waypoints.Add(wp); numWps += 1; } else { Console.WriteLine("Unknown identifier: " + word); } } } seg.Lanes.Add(ln); } else { Console.WriteLine("Unknown identifier: " + word); } } rndf.Segments.Add(seg); } else if (word == "zone") { // create new zone SimpleZone zone = new SimpleZone(); zone.ParkingSpots = new List<ParkingSpot>(); // get ID word = parseWord(r, q); zone.ZoneID = word; // run until reach end of segment marker while (word != "end_zone") { // get next word word = parseWord(r, q); if (word == "num_spots") { // get next word word = parseWord(r, q); // set num of parking spots zone.NumParkingSpots = int.Parse(word); } else if (word == "zone_name") { // get next word word = parseWord(r, q); // set zone name zone.Name = word; } else if (word == "perimeter") { // create perimeter zone.Perimeter = new ZonePerimeter(); zone.Perimeter.ExitEntries = new List<SimpleExitEntry>(); zone.Perimeter.PerimeterPoints = new List<PerimeterPoint>(); // set perimeter id zone.Perimeter.PerimeterID = parseWord(r, q); while (word != "end_perimeter") { // get next word word = parseWord(r, q); if (word == "num_perimeterpoints") { // set num of perimeter points zone.Perimeter.NumPerimeterPoints = int.Parse(parseWord(r, q)); } else if (word == "exit") { // create new exit,entry SimpleExitEntry ee = new SimpleExitEntry(); // set exit ee.ExitId = parseWord(r, q); // set entry ee.EntryId = parseWord(r, q); // add to perimeter exit entries zone.Perimeter.ExitEntries.Add(ee); } else if (word == "end_perimeter") { // Do Nothing } else { // create new perimeter point PerimeterPoint p = new PerimeterPoint(); // set id p.ID = word; // create new coordinate p.position = new UrbanChallenge.Common.Coordinates(); // setX p.position.X = Double.Parse(parseWord(r, q)); // setY p.position.Y = Double.Parse(parseWord(r, q)); // add to perimeter points zone.Perimeter.PerimeterPoints.Add(p); } } } else if (word == "spot") { // create a new spot ParkingSpot ps = new ParkingSpot(); // set spot id ps.SpotID = parseWord(r, q); while (word != "end_spot") { // get next word word = parseWord(r, q); if (word == "spot_width") { // set spot width ps.SpotWidth = parseWord(r, q); } else if (word == "checkpoint") { // get waypoint id that corresponds with checkpoint ps.CheckpointWaypointID = parseWord(r, q); // get checkpoint id ps.CheckpointID = parseWord(r, q); } else if (word == "end_spot") { // add spot to zone zone.ParkingSpots.Add(ps); } else { // SimpleWaypoint 1 #region // create new waypoint for waypoint1 ps.Waypoint1 = new SimpleWaypoint(); ps.Waypoint1.Position = new UrbanChallenge.Common.Coordinates(); // set id ps.Waypoint1.ID = word; // check if id is checkpointWaypointID if (ps.Waypoint1.ID == ps.CheckpointWaypointID) { ps.Waypoint1.IsCheckpoint = true; ps.Waypoint1.CheckpointID = ps.CheckpointID; } // setX ps.Waypoint1.Position.X = Double.Parse(parseWord(r, q)); // setY ps.Waypoint1.Position.Y = Double.Parse(parseWord(r, q)); #endregion // SimpleWaypoint 2 #region // create new waypoint for waypoint2 ps.Waypoint2 = new SimpleWaypoint(); ps.Waypoint2.Position = new UrbanChallenge.Common.Coordinates(); // set id ps.Waypoint2.ID = parseWord(r, q); // check if id is checkpointWaypointID if (ps.Waypoint2.ID == ps.CheckpointWaypointID) { ps.Waypoint2.IsCheckpoint = true; ps.Waypoint2.CheckpointID = ps.CheckpointID; } // setX ps.Waypoint2.Position.X = Double.Parse(parseWord(r, q)); // setY ps.Waypoint2.Position.Y = Double.Parse(parseWord(r, q)); #endregion } } } else if (word == "end_zone") { // Do Nothing } else { Console.WriteLine("Unrecognized: " + word); } } // Add zones to zone rndf.Zones.Add(zone); } else { if (word == "end_file") Console.WriteLine("Rndf Parse :: Successful"); else Console.WriteLine("Unknown identifier: " + word); } } return rndf; }
/// <summary> /// Creates an rndf network from an xy rndf /// </summary> /// <returns></returns> public RndfNetwork CreateRndfNetwork(IRndf xyRndf, PlanarProjection projection) { return(null); }
// Creates Rndf from an input FileStream public IRndf createRndf(FileStream fileStream) { numWps = 0; // File in Read Only mode, convert to stream StreamReader r = new StreamReader(fileStream, Encoding.UTF8); // Create new queue for input buffer Queue q = new Queue(); string word = ""; // Create the Rndf (with only segments for now, no zones) IRndf rndf = new IRndf(); rndf.Segments = new List <SimpleSegment>(); rndf.Zones = new List <SimpleZone>(); // Loop until reach end of file marker while ((word.Length < 8) || (word.Substring(0, 8) != "end_file")) { // get the next word word = parseWord(r, q); if (word == "RNDF_name") { word = parseWord(r, q); rndf.Name = word; } else if (word == "num_segments") { word = parseWord(r, q); rndf.NumSegs = int.Parse(word); } else if (word == "num_zones") { word = parseWord(r, q); rndf.NumZones = int.Parse(word); } else if (word == "format_version") { word = parseWord(r, q); rndf.FormatVersion = word; } else if (word == "creation_date") { word = parseWord(r, q); rndf.CreationDate = word; } else if (word == "segment") { // create new segment SimpleSegment seg = new SimpleSegment(); seg.Lanes = new List <SimpleLane>(); word = parseWord(r, q); seg.Id = word; // run until reach end of segment marker while (word != "end_segment") { // get next word word = parseWord(r, q); if (word == "segment_name") { word = parseWord(r, q); seg.Name = word; } else if (word == "num_lanes") { word = parseWord(r, q); seg.NumLanes = int.Parse(word); } else if (word == "end_segment") { // do nothing if at the end } else if (word == "lane") { // Create new lane SimpleLane ln = new SimpleLane(); ln.Checkpoints = new List <SimpleCheckpoint>(); ln.Waypoints = new List <SimpleWaypoint>(); ln.Stops = new List <string>(); ln.ExitEntries = new List <SimpleExitEntry>(); word = parseWord(r, q); ln.Id = word; // run until reach end of lane while (word != "end_lane") { // get next word word = parseWord(r, q); if (word == "num_waypoints") { word = parseWord(r, q); ln.NumWaypoints = int.Parse(word); } else if (word == "checkpoint") { // create checkpoint SimpleCheckpoint cp = new SimpleCheckpoint(); // get waypoint id string wp = parseWord(r, q); cp.WaypointId = wp; // get checkpoint id string id = parseWord(r, q); cp.CheckpointId = id; // add to collection of checkpoints within lane ln.Checkpoints.Add(cp); } else if (word == "lane_width") { word = parseWord(r, q); ln.LaneWidth = double.Parse(word); } else if (word == "stop") { word = parseWord(r, q); ln.Stops.Add(word); } else if (word == "left_boundary") { word = parseWord(r, q); ln.LeftBound = word; } else if (word == "right_boundary") { word = parseWord(r, q); ln.RightBound = word; } else if (word == "exit") { // create exit-entry pair SimpleExitEntry exitEntry = new SimpleExitEntry(); // get the exit id string exit = parseWord(r, q); exitEntry.ExitId = exit; // get the entry id string entry = parseWord(r, q); exitEntry.EntryId = entry; // add to collection of exit-entry pairs within lane ln.ExitEntries.Add(exitEntry); } else if (word == "end_lane") { // do nothing } // Otherwise we probably have a waypoint else { // check to make sure a wp by matching lane id to lane identifier of waypoint int laneIdLength = ln.Id.Length; // if waypoint matches then create the waypoint if (word.Length >= laneIdLength + 2 && (word.Substring(0, laneIdLength)).CompareTo(ln.Id) == 0) { // create a new waypoint SimpleWaypoint wp = new SimpleWaypoint(); wp.Position = new UrbanChallenge.Common.Coordinates(); // set its id wp.ID = word; // get latitude or X string lat = parseWord(r, q); wp.Position.X = double.Parse(lat); // get longitude or y string lon = parseWord(r, q); wp.Position.Y = double.Parse(lon); // add to lane's collection of waypoints ln.Waypoints.Add(wp); numWps += 1; } else { Console.WriteLine("Unknown identifier: " + word); } } } seg.Lanes.Add(ln); } else { Console.WriteLine("Unknown identifier: " + word); } } rndf.Segments.Add(seg); } else if (word == "zone") { // create new zone SimpleZone zone = new SimpleZone(); zone.ParkingSpots = new List <ParkingSpot>(); // get ID word = parseWord(r, q); zone.ZoneID = word; // run until reach end of segment marker while (word != "end_zone") { // get next word word = parseWord(r, q); if (word == "num_spots") { // get next word word = parseWord(r, q); // set num of parking spots zone.NumParkingSpots = int.Parse(word); } else if (word == "zone_name") { // get next word word = parseWord(r, q); // set zone name zone.Name = word; } else if (word == "perimeter") { // create perimeter zone.Perimeter = new ZonePerimeter(); zone.Perimeter.ExitEntries = new List <SimpleExitEntry>(); zone.Perimeter.PerimeterPoints = new List <PerimeterPoint>(); // set perimeter id zone.Perimeter.PerimeterID = parseWord(r, q); while (word != "end_perimeter") { // get next word word = parseWord(r, q); if (word == "num_perimeterpoints") { // set num of perimeter points zone.Perimeter.NumPerimeterPoints = int.Parse(parseWord(r, q)); } else if (word == "exit") { // create new exit,entry SimpleExitEntry ee = new SimpleExitEntry(); // set exit ee.ExitId = parseWord(r, q); // set entry ee.EntryId = parseWord(r, q); // add to perimeter exit entries zone.Perimeter.ExitEntries.Add(ee); } else if (word == "end_perimeter") { // Do Nothing } else { // create new perimeter point PerimeterPoint p = new PerimeterPoint(); // set id p.ID = word; // create new coordinate p.position = new UrbanChallenge.Common.Coordinates(); // setX p.position.X = Double.Parse(parseWord(r, q)); // setY p.position.Y = Double.Parse(parseWord(r, q)); // add to perimeter points zone.Perimeter.PerimeterPoints.Add(p); } } } else if (word == "spot") { // create a new spot ParkingSpot ps = new ParkingSpot(); // set spot id ps.SpotID = parseWord(r, q); while (word != "end_spot") { // get next word word = parseWord(r, q); if (word == "spot_width") { // set spot width ps.SpotWidth = parseWord(r, q); } else if (word == "checkpoint") { // get waypoint id that corresponds with checkpoint ps.CheckpointWaypointID = parseWord(r, q); // get checkpoint id ps.CheckpointID = parseWord(r, q); } else if (word == "end_spot") { // add spot to zone zone.ParkingSpots.Add(ps); } else { // SimpleWaypoint 1 #region // create new waypoint for waypoint1 ps.Waypoint1 = new SimpleWaypoint(); ps.Waypoint1.Position = new UrbanChallenge.Common.Coordinates(); // set id ps.Waypoint1.ID = word; // check if id is checkpointWaypointID if (ps.Waypoint1.ID == ps.CheckpointWaypointID) { ps.Waypoint1.IsCheckpoint = true; ps.Waypoint1.CheckpointID = ps.CheckpointID; } // setX ps.Waypoint1.Position.X = Double.Parse(parseWord(r, q)); // setY ps.Waypoint1.Position.Y = Double.Parse(parseWord(r, q)); #endregion // SimpleWaypoint 2 #region // create new waypoint for waypoint2 ps.Waypoint2 = new SimpleWaypoint(); ps.Waypoint2.Position = new UrbanChallenge.Common.Coordinates(); // set id ps.Waypoint2.ID = parseWord(r, q); // check if id is checkpointWaypointID if (ps.Waypoint2.ID == ps.CheckpointWaypointID) { ps.Waypoint2.IsCheckpoint = true; ps.Waypoint2.CheckpointID = ps.CheckpointID; } // setX ps.Waypoint2.Position.X = Double.Parse(parseWord(r, q)); // setY ps.Waypoint2.Position.Y = Double.Parse(parseWord(r, q)); #endregion } } } else if (word == "end_zone") { // Do Nothing } else { Console.WriteLine("Unrecognized: " + word); } } // Add zones to zone rndf.Zones.Add(zone); } else { if (word == "end_file") { Console.WriteLine("Rndf Parse :: Successful"); } else { Console.WriteLine("Unknown identifier: " + word); } } } return(rndf); }
/// <summary> /// Constructor /// </summary> /// <param name="xyRndf"></param> public InterconnectGeneration(IRndf xyRndf) { this.xyRndf = xyRndf; }