-
Notifications
You must be signed in to change notification settings - Fork 79
Sim level z-axis integration #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nadarenator
wants to merge
10
commits into
main
Choose a base branch
from
feat/z-axis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4db824d
partial changes
nadarenator 3bd4fc2
partial changes
nadarenator 73b9266
yet another partial change
nadarenator 1123be5
json reading revisions
nadarenator f63e799
updated types and export sizes
nadarenator 4029a93
rotation and other lvl_gen changes
nadarenator efc1869
Fix export sizes
aaravpandya 0bb2bab
compiler error fixes
nadarenator 98f82f1
Fix relative obs
aaravpandya a833ee2
make json z conditional
nadarenator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,15 +7,21 @@ | |
|
|
||
| namespace gpudrive | ||
| { | ||
| void from_json(const nlohmann::json &j, MapVector2 &p) | ||
| void from_json(const nlohmann::json &j, MapVector3 &p) | ||
| { | ||
| p.x = j.at("x").get<float>(); | ||
| p.y = j.at("y").get<float>(); | ||
| if (j.contains("z")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it sometimes not contain it? |
||
| p.z = j.at("z").get<float>(); | ||
| } | ||
| else { | ||
| p.z = 0.0; | ||
| } | ||
| } | ||
|
|
||
| void from_json(const nlohmann::json &j, MapObject &obj) | ||
| { | ||
| obj.mean = {0,0}; | ||
| obj.mean = {0,0,0}; | ||
| uint32_t i = 0; | ||
| for (const auto &pos : j.at("position")) | ||
| { | ||
|
|
@@ -24,6 +30,7 @@ namespace gpudrive | |
| from_json(pos, obj.position[i]); | ||
| obj.mean.x += (obj.position[i].x - obj.mean.x)/(i+1); | ||
| obj.mean.y += (obj.position[i].y - obj.mean.y)/(i+1); | ||
| obj.mean.z += (obj.position[i].z - obj.mean.z)/(i+1); | ||
| ++i; | ||
| } | ||
| else | ||
|
|
@@ -100,7 +107,7 @@ namespace gpudrive | |
|
|
||
| void from_json(const nlohmann::json &j, MapRoad &road, float polylineReductionThreshold = 0.0) | ||
| { | ||
| road.mean = {0,0}; | ||
| road.mean = {0,0,0}; | ||
| std::string type = j.at("type"); | ||
| if(type == "road_edge") | ||
| road.type = EntityType::RoadEdge; | ||
|
|
@@ -118,10 +125,10 @@ namespace gpudrive | |
| road.type = EntityType::None; | ||
|
|
||
|
|
||
| std::vector<MapVector2> geometry_points_; | ||
| std::vector<MapVector3> geometry_points_; | ||
| for(const auto &point: j.at("geometry")) | ||
| { | ||
| MapVector2 p; | ||
| MapVector3 p; | ||
| from_json(point, p); | ||
| geometry_points_.push_back(p); | ||
| } | ||
|
|
@@ -154,10 +161,24 @@ namespace gpudrive | |
| } | ||
| if (k_2 >= num_sampled_points) | ||
| break; | ||
| //Using 3D space area calculation | ||
| auto point1 = geometry_points_[k * sample_every_n_]; | ||
| auto point2 = geometry_points_[k_1 * sample_every_n_]; | ||
| auto point3 = geometry_points_[k_2 * sample_every_n_]; | ||
| float_t area = 0.5 * std::abs((point1.x - point3.x) * (point2.y - point1.y) - (point1.x - point2.x) * (point3.y - point1.y)); | ||
| // Vector 1: point1 -> point2 | ||
| float vx1 = point2.x - point1.x; | ||
| float vy1 = point2.y - point1.y; | ||
| float vz1 = point2.z - point1.z; | ||
| // Vector 2: point1 -> point3 | ||
| float vx2 = point3.x - point1.x; | ||
| float vy2 = point3.y - point1.y; | ||
| float vz2 = point3.z - point1.z; | ||
| // Cross product to get the normal vector | ||
| float nx = vy1 * vz2 - vz1 * vy2; | ||
| float ny = vz1 * vx2 - vx1 * vz2; | ||
| float nz = vx1 * vy2 - vy1 * vx2; | ||
| // Magnitude of the cross product | ||
| float_t area = 0.5 * std::sqrt(nx * nx + ny * ny + nz * nz); | ||
| if (area < polylineReductionThreshold) | ||
| { // If the area is less than the threshold, then we skip the middle point | ||
| skip[k_1] = true; // Mark the middle point as skipped | ||
|
|
@@ -175,7 +196,7 @@ namespace gpudrive | |
| k = 0; | ||
| skip[0] = false; | ||
| skip[num_sampled_points - 1] = false; | ||
| std::vector<MapVector2> new_geometry_points; // This list stores the points that are not skipped | ||
| std::vector<MapVector3> new_geometry_points; // This list stores the points that are not skipped | ||
| while (k < num_sampled_points) | ||
| { | ||
| if (!skip[k]) | ||
|
|
@@ -229,14 +250,16 @@ namespace gpudrive | |
| { | ||
| road.mean.x += (road.geometry[i].x - road.mean.x)/(i+1); | ||
| road.mean.y += (road.geometry[i].y - road.mean.y)/(i+1); | ||
| road.mean.z += (road.geometry[i].z - road.mean.z)/(i+1); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| std::pair<float, float> calc_mean(const nlohmann::json &j) | ||
| std::tuple<float, float, float> calc_mean(const nlohmann::json &j) | ||
| { | ||
| std::pair<float, float> mean = {0, 0}; | ||
| std::tuple<float, float, float> mean = {0, 0, 0}; | ||
| int64_t numEntities = 0; | ||
|
|
||
| for (const auto &obj : j["objects"]) | ||
| { | ||
| int i = 0; | ||
|
|
@@ -247,32 +270,39 @@ namespace gpudrive | |
| numEntities++; | ||
| float newX = pos["x"]; | ||
| float newY = pos["y"]; | ||
| float newZ = pos["z"]; | ||
|
|
||
| // Update mean incrementally | ||
| mean.first += (newX - mean.first) / numEntities; | ||
| mean.second += (newY - mean.second) / numEntities; | ||
| std::get<0>(mean) += (newX - std::get<0>(mean)) / numEntities; | ||
| std::get<1>(mean) += (newY - std::get<1>(mean)) / numEntities; | ||
| std::get<2>(mean) += (newZ - std::get<2>(mean)) / numEntities; | ||
| } | ||
| } | ||
|
|
||
| for (const auto &obj : j["roads"]) | ||
| { | ||
| for (const auto &point : obj["geometry"]) | ||
| { | ||
| numEntities++; | ||
| float newX = point["x"]; | ||
| float newY = point["y"]; | ||
|
|
||
| // Update mean incrementally | ||
| mean.first += (newX - mean.first) / numEntities; | ||
| mean.second += (newY - mean.second) / numEntities; | ||
| float newZ = point["z"]; | ||
|
|
||
| std::get<0>(mean) += (newX - std::get<0>(mean)) / numEntities; | ||
| std::get<1>(mean) += (newY - std::get<1>(mean)) / numEntities; | ||
| std::get<2>(mean) += (newZ - std::get<2>(mean)) / numEntities; | ||
| } | ||
| } | ||
|
|
||
| return mean; | ||
| } | ||
|
|
||
|
|
||
| void from_json(const nlohmann::json &j, Map &map, float polylineReductionThreshold) | ||
| { | ||
| auto mean = calc_mean(j); | ||
| map.mean = {mean.first, mean.second}; | ||
| map.mean = {std::get<0>(mean), std::get<1>(mean), std::get<2>(mean)}; // Updated to handle all 3 components | ||
|
|
||
| map.numObjects = std::min(j.at("objects").size(), static_cast<size_t>(MAX_OBJECTS)); | ||
| size_t idx = 0; | ||
| for (const auto &obj : j.at("objects")) | ||
|
|
@@ -281,7 +311,7 @@ namespace gpudrive | |
| break; | ||
| obj.get_to(map.objects[idx++]); | ||
| } | ||
|
|
||
| map.numRoads = std::min(j.at("roads").size(), static_cast<size_t>(MAX_ROADS)); | ||
| size_t countRoadPoints = 0; | ||
| idx = 0; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably do not want this change to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think this branch contains a lot of changes we do not want to include. I am starting a different branch with only the minimal required changes to access the z logs