Skip to content

Commit a9fe8a4

Browse files
committed
fixed road generator still experimental and has some problems
1 parent 53f701b commit a9fe8a4

File tree

9 files changed

+407
-7
lines changed

9 files changed

+407
-7
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:653946e825b91a985f815be9f31315f6471dc969ad7efd0ab4c38d405305fbbb
3-
size 934132
2+
oid sha256:f6564d0fd4ee099775d358dfae540c51be8f70d56059fe90b53875a45b9413c4
3+
size 850854
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:4932f5c7f2912c6fd86176acbd9db105f17be2d9146f9834e6c97d83eb487e69
3+
size 845941
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:7595094a83db92b43951ec42d868540bd3a2f8e479ef2540a0261600d3506bb0
3-
size 404916
2+
oid sha256:6d0dd0cba7e0b48cf9348dbf42af3557004161c9c699c04956ae2d5ffd39aa07
3+
size 416747
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:6fae7c33d2f8fcaef442319babfed2bc7b02ab0b1b599b8059f3dc1a8c2a10e1
3+
size 2826

Content/Blueprints/TrackGenerator/Blueprints/BP_TrackGenerator_2_Test.uasset

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "GeoJsonStruct.h"
2+
3+
FGeoJsonStruct FGeoJsonStruct::BuildGeoJsonStruct(
4+
FString GeometryType,
5+
FString Type
6+
// TArray<FVector> GeometryCoordinates
7+
)
8+
{
9+
FGeoJsonStruct FGeoJsonStruct;
10+
FGeoJsonStruct.GeometryType = GeometryType;
11+
FGeoJsonStruct.Type = Type;
12+
// FGeoJsonStruct.GeometryCoordinates = GeometryCoordinates;
13+
return FGeoJsonStruct;
14+
}
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
4+
#include "GeoJsonStructGeneratorComponent.h"
5+
6+
#include "JsonUtilities.h"
7+
8+
#include "Developer/DesktopPlatform/Public/IDesktopPlatform.h"
9+
#include "Developer/DesktopPlatform/Public/DesktopPlatformModule.h"
10+
#include <vector>
11+
#include <string>
12+
#include <nlohmann/json.hpp>
13+
#include <fstream>
14+
15+
using namespace std;
16+
using json = nlohmann::json;
17+
18+
// // Sets default values for this component's properties
19+
UGeoJsonStructGeneratorComponent::UGeoJsonStructGeneratorComponent()
20+
{
21+
}
22+
23+
24+
// void tokenize(string &str, char delim, vector<string> &out)
25+
// {
26+
// size_t start;
27+
// size_t end = 0;
28+
//
29+
// while ((start = str.find_first_not_of(delim, end)) != string::npos)
30+
// {
31+
// end = str.find(delim, start);
32+
// out.push_back(str.substr(start, end - start));
33+
// }
34+
// }
35+
36+
void UGeoJsonStructGeneratorComponent::OpenMyFileDialog(const FString& DialogTitle, const FString& DefaultPath,
37+
const FString& FileTypes, TArray<FString>& OutFileNames)
38+
{
39+
if (GEngine)
40+
41+
{
42+
//void* ParentWindowHandle = GEngine->GameViewport->GetWindow()->GetNativeWindow()->GetOSWindowHandle();
43+
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
44+
if (DesktopPlatform)
45+
{
46+
//Opening the file picker!
47+
uint32 SelectionFlag = 0;
48+
//A value of 0 represents single file selection while a value of 1 represents multiple file selection
49+
DesktopPlatform->OpenFileDialog(NULL, DialogTitle, DefaultPath, FString(""), FileTypes, SelectionFlag,
50+
OutFileNames);
51+
}
52+
}
53+
}
54+
55+
56+
FString UGeoJsonStructGeneratorComponent::ParseJsonToString(FString FilePath, FString FileName)
57+
{
58+
59+
FilePath += + "\\" + FileName;
60+
FString JsonString; //Json converted to FString
61+
FFileHelper::LoadFileToString(JsonString, *FilePath);
62+
return JsonString;
63+
//std::string MyStdString(TCHAR_TO_UTF8(*JsonString));
64+
}
65+
//
66+
// void UGeoJsonStructGeneratorComponent::ConvertLongLatToXY(FJsonValueArray arry)
67+
// {
68+
// auto test = arry;
69+
//
70+
// return test;
71+
// }
72+
73+
74+
// void from_json(const nlohmann::json& object, Inner& i)
75+
// {
76+
// // j.at("Name").get_to(i.Name);
77+
// // j.at("Value").get_to(i.Value);
78+
//
79+
// if (object.contains("type"))
80+
// {
81+
// object.at("type").get_to(i.Value);
82+
// }
83+
// object.at("geometry")["type"].get_to(i.Value);
84+
// }
85+
86+
87+
void UGeoJsonStructGeneratorComponent::ParseJson(const FString& File, TArray<FGeoJsonStruct>& GeoJsonStructs)
88+
{
89+
// json j;
90+
// ifstream ifs(*File);
91+
// if (!ifs.is_open())
92+
// {
93+
// //return false;;
94+
// }
95+
// ifs >> j;
96+
// ifs.close();
97+
98+
99+
// // iterate the array
100+
// for (json::iterator it = j.begin(); it != j.end(); ++it) {
101+
// std::cout << *it << '\n';
102+
// }
103+
//
104+
// // range-based for
105+
// for (auto& element : j) {
106+
// std::cout << element << '\n';
107+
// }
108+
109+
110+
// for (auto& elm : j.items())
111+
// {
112+
// nlohmann::json object = elm.value();
113+
//
114+
// string type;
115+
// int32 id;
116+
// string sourceLayer;
117+
// string source;
118+
//
119+
// string Geotype = object.at("geometry")["type"];
120+
//
121+
// nlohmann::json GeoArrycoordinates = object.at("geometry")["coordinates"];
122+
//
123+
// if (object.contains("type"))
124+
// {
125+
// type = object.at("type");
126+
// }
127+
// nlohmann::json Objproperties = object.at("properties");
128+
//
129+
// if (object.contains("id"))
130+
// {
131+
// id = object.at("id");
132+
// }
133+
//
134+
// nlohmann::json Objlayer = object.at("layer");
135+
//
136+
// if (object.contains("sourceLayer"))
137+
// {
138+
// sourceLayer = object.at("sourceLayer");
139+
// }
140+
//
141+
// if (object.contains("source"))
142+
// {
143+
// source = object.at("source");
144+
// }
145+
//
146+
// nlohmann::json Objstate = object.at("state");
147+
//
148+
//
149+
// if (Geotype == "LineString")
150+
// {
151+
// // JsonCoordinatesArray = Coordinates[1]->AsArray();
152+
// }
153+
//
154+
//
155+
//
156+
//
157+
//
158+
//
159+
//
160+
//
161+
// // FString Geotype(SGeotype. c_str());
162+
// // FString type(Stype.c_str());
163+
// //
164+
// // FGeoJsonStruct GeoJsonStruct = FGeoJsonStruct::BuildGeoJsonStruct(
165+
// // Geotype, type
166+
// // );
167+
// //
168+
// // GeoJsonStructs.Push(GeoJsonStruct);
169+
// // from_json();
170+
// // FString Geotype(SGeotype.c_str());
171+
// // FString type(Stype.c_str());
172+
// //
173+
// //
174+
// // FGeoJsonStruct GeoJsonStruct = FGeoJsonStruct::BuildGeoJsonStruct(
175+
// // Geotype, type
176+
// // );
177+
// //
178+
// // GeoJsonStructs.Push(GeoJsonStruct);
179+
// //std::cout << id << std::endl;
180+
// // GLog->Log("multiline done");
181+
// }
182+
}
183+
184+
185+
//
186+
// void UGeoJsonStructGeneratorComponent::GenerateStructsFromJson(const FString& File,
187+
// TArray<FGeoJsonStruct>& GeoJsonStructs)
188+
// {
189+
// FString JsonString; //Json converted to FString
190+
// FFileHelper::LoadFileToString(JsonString, *File);;
191+
//
192+
// // char* path = TCHAR_TO_ANSI(*File);
193+
// //
194+
// // string s=path;
195+
// // char d='-';
196+
// // vector<string> a;
197+
// // tokenize(s,d,a);
198+
// // string & zoom = a.at(1);
199+
// // string & resolution = a.at(4);
200+
// // GLog->Log(zoom.c_str());
201+
// // GLog->Log(resolution.c_str());
202+
//
203+
//
204+
// TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(*JsonString);
205+
// TArray<TSharedPtr<FJsonValue>> RawJsonValueArray;
206+
// bool success = FJsonSerializer::Deserialize(JsonReader, RawJsonValueArray);
207+
//
208+
//
209+
// if (success)
210+
// {
211+
// for (int32 Index = 0; Index < RawJsonValueArray.Num(); Index++)
212+
// {
213+
// TSharedPtr<FJsonObject>* JsonObject = new TSharedPtr<FJsonObject>(RawJsonValueArray[Index]->AsObject());
214+
// FJsonObject* GeoJsonObject = JsonObject->Get();
215+
// FString GeometryType;
216+
// FString Type;
217+
// TArray<TSharedPtr<FJsonValue>> JsonCoordinatesArray;
218+
// // FVector GeometryLongLat;
219+
//
220+
// // TSharedPtr<FJsonValue> GeoJsonValue = RawJsonValueArray[Index];
221+
// // TSharedPtr<FJsonObject> GeoJsonObject = GeoJsonValue->AsObject();
222+
//
223+
// if (GeoJsonObject->HasField("geometry"))
224+
// {
225+
// TSharedPtr<FJsonObject> geometry = GeoJsonObject->GetObjectField("geometry");
226+
//
227+
// if (GeoJsonObject->HasField("type"))
228+
// {
229+
// Type = GeoJsonObject->GetStringField("type");
230+
// }
231+
// if (geometry->HasField("type"))
232+
// {
233+
// GeometryType = geometry->GetStringField("type");
234+
// }
235+
//
236+
//
237+
// TArray<TSharedPtr<FJsonValue>> Coordinates = geometry->GetArrayField("coordinates");
238+
// if (GeometryType == "MultiLineString")
239+
// {
240+
// JsonCoordinatesArray = Coordinates[0]->AsArray();
241+
// }
242+
// if (GeometryType == "LineString")
243+
// {
244+
// JsonCoordinatesArray = Coordinates;
245+
// }
246+
//
247+
// if (GeometryType == "LineString")
248+
// {
249+
// JsonCoordinatesArray = Coordinates[1]->AsArray();
250+
// }
251+
// double Long;
252+
// double Lat;
253+
// TArray<FVector> GeometryCoordinates;
254+
//
255+
// for (int32 i = 0; i < JsonCoordinatesArray.Num(); i++)
256+
// {
257+
// TArray<TSharedPtr<FJsonValue>> JsonLongLat = JsonCoordinatesArray[i]->AsArray();
258+
// Long = JsonLongLat[0]->AsNumber();
259+
// Lat = JsonLongLat[1]->AsNumber();
260+
//
261+
// FVector LonLatCoordinates;
262+
//
263+
// LonLatCoordinates.X = Long;
264+
// LonLatCoordinates.Y = Lat;
265+
//
266+
// GeometryCoordinates.Push(LonLatCoordinates);
267+
//
268+
// FGeoJsonStruct GeoJsonStruct = FGeoJsonStruct::BuildGeoJsonStruct(
269+
// GeometryType, Type, GeometryCoordinates
270+
// );
271+
//
272+
// GeoJsonStructs.Push(GeoJsonStruct);
273+
//
274+
//
275+
// //
276+
// // if (GeoJsonObject->HasField("properties"))
277+
// // {
278+
// // TSharedPtr<FJsonObject> properties = GeoJsonObject->GetObjectField("properties");;
279+
// // }
280+
// // if (GeoJsonObject->HasField("layer"))
281+
// // {
282+
// // TSharedPtr<FJsonObject> layer = GeoJsonObject->GetObjectField("layer");
283+
// // }
284+
// // if (GeoJsonObject->HasField("source"))
285+
// // {
286+
// // FString source = GeoJsonObject->GetStringField("source");
287+
// // }
288+
// // if (GeoJsonObject->HasField("id"))
289+
// // {
290+
// // FString source = GeoJsonObject->GetStringField("id");
291+
// // }
292+
// // if (GeoJsonObject->HasField("state"))
293+
// // {
294+
// // TSharedPtr<FJsonObject> state = GeoJsonObject->GetObjectField("state");
295+
// // }
296+
// }
297+
// }
298+
// }
299+
// }
300+
// }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include "GeoJsonStruct.generated.h"
4+
5+
USTRUCT(BlueprintType)
6+
struct FGeoJsonStruct
7+
{
8+
GENERATED_USTRUCT_BODY()
9+
10+
public:
11+
UPROPERTY(EditAnyWhere, BluePrintReadWrite, Category = "GeoJson")
12+
FString GeometryType;
13+
14+
UPROPERTY(EditAnyWhere, BluePrintReadWrite, Category = "GeoJson")
15+
FString Type;
16+
17+
// UPROPERTY(EditAnyWhere, BluePrintReadWrite, Category = "GeoJson")
18+
// TArray<FVector> GeometryCoordinates;
19+
20+
public:
21+
static FGeoJsonStruct BuildGeoJsonStruct(
22+
FString GeometryType,
23+
FString Type
24+
// TArray<FVector> GeometryCoordinates
25+
);
26+
};
27+
28+
//
29+
// UPROPERTY()
30+
// FJsonObject properties;
31+
//
32+
// UPROPERTY()
33+
// FJsonObject layer;
34+
//
35+
// UPROPERTY()
36+
// FString source;
37+
//
38+
// UPROPERTY()
39+
// FJsonObject state;

0 commit comments

Comments
 (0)