-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxodr2path(comitted).txt
307 lines (262 loc) · 18.1 KB
/
xodr2path(comitted).txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EasyRoads3Dv3;
//___________________________
using System.Xml;
using System.IO;
using System;
public class XODR2PATH : MonoBehaviour{
public ERRoadNetwork roadNetwork;
//__________________________________________
public ERRoad Road;
public ERRoad road2;
public ERRoad roadTemp;
//__________________________________________
public GameObject go;
public enum PathType : ushort{
None = 0,
Line = 1,
Arc = 2,
Spiral = 3
}
void Start()
{
roadNetwork = new ERRoadNetwork();
//_____________________________________________________________________________________________
ERRoadType roadType = new ERRoadType();
roadType.roadWidth = 4.0f;
roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material;
//____________________________________________________________________________________________
var LineRoads = new List<ERRoad>(); // The container individually keeps road components
var linePaths = new List<LinePath>(); // The container individually keeps road components with the line geometry
var ArcRoads = new List<ERRoad>(); // The container individually keeps road components
var arcPaths = new List<ARCPath>(); // The container individually keeps road components with the arc geometry
//var SpiralRoads = new List<ERRoad>(); // The container individually keeps road components
//var spiralPaths = new List<SpiralPath>(); // TO DO : !!!!! // The container individually keeps road components with the spiral geometry
var connectedRoads = new List<ERRoad>();
/*
LinePath l1 = new LinePath( 0, 0.0f, 0.0f, 400.0f, 0f);
roads.Add(new ERRoad());
roads[0] = roadNetwork.CreateRoad("line"+ l1.pathIndex.ToString(), roadType, l1.markers);
ARCPath a1 = new ARCPath( 1, l1.xEnd, l1.yEnd, 800.0f, 0f, -0.002f);
roads.Add(new ERRoad());
roads[1] = roadNetwork.CreateRoad("line"+ a1.pathIndex.ToString(), roadType, a1.markers);
*/
PathType pathType;
XmlNodeList geoList = parseFile();
double tmp;
//Debug.Log("_________--------_________------"+geoList.Count);
//Debug.Log("Sin 90 : 1 ?= "+ Math.Cos()); // operates with the values in terms of Radian
for(int i=0; i< geoList.Count; i++){
connectedRoads.Add(new ERRoad());
var gotFirst = false;
foreach(XmlNode child in geoList[i].ChildNodes)
{
if(child.Name == "line")
{
//_______________________________________________________________________________________________________________________________
XmlElement geoA = (System.Xml.XmlElement)geoList[i];
var x_Value = geoA.GetAttribute("x");
double.TryParse( x_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float xVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
var y_Value = geoA.GetAttribute("y");
double.TryParse( y_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float yVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
var heading = geoA.GetAttribute("hdg");
double.TryParse( heading, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float hdgVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
var length = geoA.GetAttribute("length");
double.TryParse( length, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float lenVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
//Debug.Log("Child Node Name ==> line" + i.ToString());
//Debug.Log("TYPEOF => " + x_Value.GetType());
//Debug.Log("Child Node Name ==> line" + i.ToString());
pathType = PathType.Line;
linePaths.Add(new LinePath( linePaths.Count , xVal, yVal, lenVal, hdgVal));
LineRoads.Add(new ERRoad());
LineRoads[linePaths.Count-1] = roadNetwork.CreateRoad("line"+ (linePaths.Count-1).ToString(), roadType, linePaths[linePaths.Count-1].markers);
/*
if(gotFirst == false){
connectedRoads[i] = LineRoads[linePaths.Count-1];
gotFirst = true;
}else{
connectedRoads[i] = roadNetwork.ConnectRoads(connectedRoads[i], LineRoads[linePaths.Count-1]);
}
*/
// LineRoads[0] = roadNetwork.ConnectRoads(LineRoads[0], LineRoads[linePaths.Count-1]);
}else if(child.Name == "arc1"){
XmlElement geoA = (System.Xml.XmlElement)geoList[i];
//_______________________________________________________________________________________________________________________________
var x_Value = geoA.GetAttribute("x");
double.TryParse( x_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float xVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
var y_Value = geoA.GetAttribute("y");
double.TryParse( y_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float yVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
var heading = geoA.GetAttribute("hdg");
double.TryParse( heading, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float hdgVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
var length = geoA.GetAttribute("length");
double.TryParse( length, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float lenVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
var child_curvature = child.Attributes["curvature"];
double.TryParse( child_curvature.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp);
float curveVal = Convert.ToSingle(tmp);
//_______________________________________________________________________________________________________________________________
//var child_curvature = child.GetAttribute("curvature");
//Debug.Log("Child Node Name ==> arc" + i.ToString());
pathType = PathType.Arc;
//if(lenVal < 0.00001f){
// linePaths.Add(new LinePath( linePaths.Count , xVal, yVal, lenVal, hdgVal));
// LineRoads.Add(new ERRoad());
// LineRoads[linePaths.Count-1] = roadNetwork.CreateRoad("small_arc/Line"+ (linePaths.Count-1).ToString(), roadType, linePaths[linePaths.Count-1].markers);
//}else{
arcPaths.Add(new ARCPath( arcPaths.Count , xVal , yVal , lenVal, hdgVal, curveVal));
ArcRoads.Add(new ERRoad());
ArcRoads[arcPaths.Count-1] = roadNetwork.CreateRoad("arc"+ (arcPaths.Count-1).ToString(), roadType, arcPaths[arcPaths.Count-1].markers);
//}
// ARCPath( 1, 0, 0, 800.0f, 0f, -0.002f);
}else if(child.Name == "spiral"){
Debug.Log("Child Node Name ==> spiral" + i.ToString());
pathType = PathType.Spiral;
}
}
}
}
public XmlNodeList parseFile()
{
//____________________________________________________________
XmlDocument doc = new XmlDocument();
doc.Load("Town01.xml");
//____________________________________________________________
XmlNodeList elemList = doc.GetElementsByTagName("road"); //Element("OpenDRIVE").Elements("road");
//Debug.Log("1-");
//Debug.Log("Number of planView => " + elemList.Count);
//____________________________________________________________
XmlNodeList geoList = doc.GetElementsByTagName("geometry"); //Element("OpenDRIVE").Elements("road");
//Debug.Log("2-");
//Debug.Log("Num of geometry tags" + geoList.Count);
//____________________________________________________________
return geoList;
}
void Update()
{
}
}
public abstract class paths{// : MonoBehaviour{
public float xStart;
public float yStart;
public int pathIndex;
public abstract void createPath();
}
//_____________________________________________________________________________________________________________________________________________________________________
//____________________________________________________________________________ LINE GEOMETRY __________________________________________________________________________
//_____________________________________________________________________________________________________________________________________________________________________
public class LinePath : paths{
public float xEnd;
public float yEnd;
public float angle;
public float length;
//______________________________________
public Vector3[] markers = new Vector3[2];
public LinePath(int road_index , float x_Start, float y_Start, float length, float hdg){
this.xStart = x_Start;
this.yStart = y_Start;
this.angle = hdg; //Convert.ToSingle(Math.PI) * (hdg) / 180.0f;
this.length = length;
this.pathIndex = road_index;
//________________________________________________________________________________________________// //
this.markers[0] = new Vector3(this.xStart, 0, this.yStart); //
this.xEnd = this.xStart + Convert.ToSingle(Math.Cos(this.angle)) * this.length; //
this.yEnd = this.yStart + Convert.ToSingle(Math.Sin(this.angle)) * this.length; //
this.markers[1] = new Vector3(this.xEnd, 0, this.yEnd); //
//________________________________________________________________________________________________//
//roads[road_index] = roadNetwork.CreateRoad("line"+ this.pathIndex.ToString(), roadType, this.markers); //
//________________________________________________________________________________________________//
Debug.Log( "LENGTH => " + this.length);
Debug.Log( "X_start , Y_start = " + this.xStart.ToString() + "," + this.yStart.ToString());
}
public override void createPath(){
}
}
//_____________________________________________________________________________________________________________________________________________________________________
//_____________________________________________________________________________________________________________________________________________________________________
//_____________________________________________________________________________________________________________________________________________________________________
//_____________________________________________________________________________________________________________________________________________________________________
//____________________________________________________________________________ ARC GEOMETRY ___________________________________________________________________________
//_____________________________________________________________________________________________________________________________________________________________________
public class ARCPath : paths{
public float xArc;
public float xTemp;
public float xFinal;
public float yArc;
public float yTemp;
public float yFinal;
public float angle;
public float length;
public float radius;
public float centralAngle;
public int arrSize;
public int sign;
public Vector3[] markers;
//______________________________________
//public Vector3[] markers;
public ARCPath(int road_index ,float x_Start, float y_Start, float length, float hdg, float curvature){
this.xStart = x_Start;
this.yStart = y_Start;
this.angle = (Convert.ToSingle(Math.PI) * (hdg)) / 180.0f;
this.length = length;
this.pathIndex = road_index;
this.radius = (Math.Abs(1 / curvature));
this.centralAngle = this.length / this.radius;
//______________________________________________________________________________//
//______________________________________________________________________________//
if(this.length < 1){ //
this.arrSize = 2; //
}else if(this.length >= 15 || this.length < 10){ //
this.arrSize = Mathf.FloorToInt(this.length / 0.5f)+1; //
}else if((this.length >= 1)){ //
this.arrSize = Mathf.FloorToInt(this.length / 2.0f)+1; //
}else{ //
this.arrSize = 2; //
} //
//______________________________________________________________________________//
//______________________________________________________________________________//
this.sign = Math.Sign(curvature); //
//_________________________________________________________________________________________________//
this.markers = new Vector3[this.arrSize]; //
this.markers[0] = new Vector3(this.xStart, 0, this.yStart); //
//_________________________________________________________________________________________________//
/*
this.xArc = this.xStart + Convert.ToSingle(Math.Cos(this.angle + (Math.PI / 2) * this.sign - Math.PI )) * this.radius; // TODO => sign of cuvature
this.yArc = this.yStart + Convert.ToSingle(Math.Sin(this.angle + (Math.PI / 2) * this.sign - Math.PI )) * this.radius; //
*/
this.xArc = this.xStart + Convert.ToSingle(Math.Cos(hdg + (Math.PI / 2) * this.sign - Math.PI )) * this.radius;
this.yArc = this.yStart + Convert.ToSingle(Math.Sin(hdg + (Math.PI / 2) * this.sign - Math.PI )) * this.radius;
this.xFinal = this.xArc + Convert.ToSingle(Math.Cos(this.centralAngle)) * this.radius; // TODO => sign of cuvature
this.yFinal = this.yArc + Convert.ToSingle(Math.Sin(this.centralAngle)) * this.radius; // TODO => sign of cuvature
this.markers[this.arrSize-1] = new Vector3(this.xFinal, 0f, this.yFinal);
for(int i =1; i<(this.arrSize-1); i++){
this.xTemp = this.xArc + Convert.ToSingle(Math.Cos( ((i) * (this.centralAngle / (this.arrSize+1))) )) * this.radius; // TODO => sign of cuvature
this.yTemp = this.yArc + Convert.ToSingle(Math.Sin( ((i) * (this.centralAngle / (this.arrSize+1))) )) * this.radius; // TODO => sign of cuvature
this.markers[i] = new Vector3(this.xTemp, 0, this.yTemp); //
}
Debug.Log( "LENGTH => " + this.length);
Debug.Log( "X_start , Y_start = " + this.xStart.ToString() + "," + this.yStart.ToString());
}
public override void createPath(){
}
}
//_____________________________________________________________________________________________________________________________________________________________________
//_____________________________________________________________________________________________________________________________________________________________________
//_____________________________________________________________________________________________________________________________________________________________________