Skip to content

Commit

Permalink
fix bugs and add new pcd format support
Browse files Browse the repository at this point in the history
  • Loading branch information
moelang committed Jul 22, 2019
1 parent 014173a commit 95c1c9e
Show file tree
Hide file tree
Showing 49 changed files with 536 additions and 102 deletions.
2 changes: 1 addition & 1 deletion PcdTools/Editor/EditorMenuExterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using UnityEditor;
using UnityEngine;

namespace Packages.AutowareUnityTools.PcdTools.Editor
namespace Packages.MapToolbox.PcdTools.Editor
{
class EditorMenuExterns
{
Expand Down
2 changes: 1 addition & 1 deletion PcdTools/Editor/PcdImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using UnityEditorInternal;
using UnityEngine;

namespace Packages.AutowareUnityTools.PcdTools.Editor
namespace Packages.MapToolbox.PcdTools.Editor
{
[ScriptedImporter(1, "pcd")]
class PcdImporter : ScriptedImporter
Expand Down
2 changes: 1 addition & 1 deletion PcdTools/HeightMeshBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using UnityEngine;
using UnityEngine.Rendering;

namespace Packages.AutowareUnityTools.PcdTools
namespace Packages.MapToolbox.PcdTools
{
public static class HeightMeshBuild
{
Expand Down
17 changes: 15 additions & 2 deletions PcdTools/PcdReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
using Unity.Mathematics;
using UnityEngine;

namespace Packages.AutowareUnityTools.PcdTools
namespace Packages.MapToolbox.PcdTools
{
public class PcdReader : StreamReader
{
public string FilePath { get; private set; }
public NativeArray<float3byte4> PcdData_xyz_rgb { get; set; }
public NativeArray<float4> PcdData_xyz_intensity { get; set; }
public NativeArray<float3> PcdData_xyz { get; private set; }
public NativeArray<xyz_intensity_ring> PcdData_xyz_intensity_ring { get; set; }
public PcdReader(string filePath) : base(filePath)
{
FilePath = filePath;
Expand Down Expand Up @@ -87,14 +88,24 @@ public PcdReader(string filePath) : base(filePath)
}
}
break;
case "x y z _ intensity ring _":
PcdData_xyz_intensity_ring = new NativeArray<xyz_intensity_ring>(pointsCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
unsafe
{
fixed (byte* data = new BinaryReader(BaseStream).ReadBytes(pointsCount * sizeof(xyz_intensity_ring)))
{
UnsafeUtility.MemCpy(PcdData_xyz_intensity_ring.GetUnsafePtr(), data, pointsCount * sizeof(xyz_intensity_ring));
}
}
break;
default:
Debug.LogError($"Unknow field type {fields}");
break;
}
}
else
{
Debug.LogError("Binary format pcd surported only currently !");
Debug.LogError("Binary format pcd supported only currently !");
}
}
else
Expand All @@ -110,6 +121,8 @@ protected override void Dispose(bool disposing)
PcdData_xyz_rgb.Dispose();
if (PcdData_xyz_intensity.IsCreated)
PcdData_xyz_intensity.Dispose();
if (PcdData_xyz_intensity_ring.IsCreated)
PcdData_xyz_intensity_ring.Dispose();
base.Dispose(disposing);
}
}
Expand Down
2 changes: 1 addition & 1 deletion PcdTools/PcdWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using Unity.Collections.LowLevel.Unsafe;
using Unity.Mathematics;

namespace Packages.AutowareUnityTools.PcdTools
namespace Packages.MapToolbox.PcdTools
{
public class PcdWriter : StreamWriter
{
Expand Down
35 changes: 33 additions & 2 deletions PcdTools/PointsMeshBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
using UnityEngine;
using UnityEngine.Rendering;

namespace Packages.AutowareUnityTools.PcdTools
namespace Packages.MapToolbox.PcdTools
{
public static class PointsMeshBuild
{
const float max_intensity = 100;
public static Mesh PointsMesh(this PcdReader pcdReader)
{
if (pcdReader.PcdData_xyz.IsCreated)
Expand Down Expand Up @@ -80,6 +81,24 @@ public static Mesh PointsMesh(this PcdReader pcdReader)
}
}
}
else if (pcdReader.PcdData_xyz_intensity_ring.IsCreated)
{
using (var vertices = new NativeArray<Vector3>(pcdReader.PcdData_xyz_intensity_ring.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory))
{
using (var colors = new NativeArray<Color32>(pcdReader.PcdData_xyz_intensity_ring.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory))
{
new Ros2Unity_xyz_intensity_ring() { pcd = pcdReader.PcdData_xyz_intensity_ring, vertices = vertices, colors = colors }.Schedule(vertices.Length, 128).Complete();
Mesh mesh = new Mesh()
{
indexFormat = vertices.Length > 65535 ? IndexFormat.UInt32 : IndexFormat.UInt16,
vertices = vertices.ToArray(),
colors32 = colors.ToArray()
};
mesh.SetIndices(Enumerable.Range(0, mesh.vertexCount).ToArray(), MeshTopology.Points, 0);
return mesh;
}
}
}
else
{
return new Mesh();
Expand Down Expand Up @@ -113,7 +132,19 @@ struct Ros2Unity_xyz_intensity : IJobParallelFor
public void Execute(int index)
{
vertices[index] = new Vector3(-pcd[index].y, pcd[index].z, pcd[index].x);
colors[index] = Color32.Lerp(Color.red, Color.green, pcd[index].w / 100);
colors[index] = Color32.Lerp(Color.red, Color.green, pcd[index].w / max_intensity);
}
}
[BurstCompile]
struct Ros2Unity_xyz_intensity_ring : IJobParallelFor
{
[ReadOnly] internal NativeArray<xyz_intensity_ring> pcd;
[WriteOnly] internal NativeArray<Vector3> vertices;
[WriteOnly] internal NativeArray<Color32> colors;
public void Execute(int index)
{
vertices[index] = new Vector3(-pcd[index].point.y, pcd[index].point.z, pcd[index].point.x);
colors[index] = Color32.Lerp(Color.red, Color.green, pcd[index].intensity / max_intensity);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PcdTools/float3byte4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using Unity.Mathematics;

namespace Packages.AutowareUnityTools.PcdTools
namespace Packages.MapToolbox.PcdTools
{
public struct float3byte4
{
Expand Down
34 changes: 34 additions & 0 deletions PcdTools/xyz_intensity_ring.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#region License
/******************************************************************************
* Copyright 2019 The AutoCore Authors. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#endregion

using Unity.Mathematics;

namespace Packages.MapToolbox.PcdTools
{
/// <summary>
/// Pcd format https://github.com/autocore-ai/MapToolbox/issues/6
/// </summary>
public struct xyz_intensity_ring
{
public float3 point;
public byte _0;
public float intensity;
public ushort ring;
public byte _1;
}
}
11 changes: 11 additions & 0 deletions PcdTools/xyz_intensity_ring.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ This a unity plugin helps user create vector maps for [Autoware](https://github.

* pcd import
* binary pcd
* ✔️ x y z intensity
* ✔️ x y z
* ✔️ x y z color
* ✔️ x y z intensity
* ✔️ x y z intensity ring
* vector maps export
* Autoware
* ✔️ lane merge and branch
Expand Down Expand Up @@ -43,6 +45,7 @@ This a unity plugin helps user create vector maps for [Autoware](https://github.
"com.autocore.map-toolbox": "https://github.com/autocore-ai/MapToolbox.git",
"com.nition.unity-octree": "https://github.com/autocore-ai/UnityOctree.git#upm",
```
## user manual
## User manual
* please check video. docs will be provided soon.

[![Watch the video](https://img.youtube.com/vi/WTRHPs8pN04/0.jpg)](https://youtu.be/WTRHPs8pN04)
2 changes: 1 addition & 1 deletion VectorMapTools/AutoHeightBezier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using UnityEngine;

namespace Packages.AutowareUnityTools.VectorMapTools
namespace Packages.MapToolbox.VectorMapTools
{
public class AutoHeightBezier : Bezier
{
Expand Down
2 changes: 1 addition & 1 deletion VectorMapTools/AutoHeightLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using UnityEngine;

namespace Packages.AutowareUnityTools.VectorMapTools
namespace Packages.MapToolbox.VectorMapTools
{
public class AutoHeightLine : Line
{
Expand Down
4 changes: 2 additions & 2 deletions VectorMapTools/Bezier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using UnityEngine;

namespace Packages.AutowareUnityTools.VectorMapTools
namespace Packages.MapToolbox.VectorMapTools
{
public class Bezier : LRMapElement
{
Expand Down Expand Up @@ -50,7 +50,7 @@ public virtual Vector3 EndPosition
endTangent += endPositionMove;
}
}
internal override Vector3? Pivot
public override Vector3? Pivot
{
set
{
Expand Down
3 changes: 1 addition & 2 deletions VectorMapTools/Curb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
using System.Collections.Generic;
using UnityEngine;

namespace Packages.AutowareUnityTools.VectorMapTools
namespace Packages.MapToolbox.VectorMapTools
{
public class Curb : DoubleConnectBezier
{
public static List<Curb> List { get; set; } = new List<Curb>();
protected override void Awake()
{
base.Awake();
List.Add(this);
LineRenderer.sharedMaterial = new Material(Shader.Find("Unlit/Color"))
{
color = Color.red
Expand Down
2 changes: 1 addition & 1 deletion VectorMapTools/DoubleConnectBezier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using System.Linq;
using UnityEngine;

namespace Packages.AutowareUnityTools.VectorMapTools
namespace Packages.MapToolbox.VectorMapTools
{
public class DoubleConnectBezier : AutoHeightBezier
{
Expand Down
2 changes: 1 addition & 1 deletion VectorMapTools/Editor/BezierEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using UnityEditor;
using UnityEngine;

namespace Packages.AutowareUnityTools.VectorMapTools.Editor
namespace Packages.MapToolbox.VectorMapTools.Editor
{
[CustomEditor(typeof(Bezier))]
class BezierEditor : LRMapElementEditor
Expand Down
2 changes: 1 addition & 1 deletion VectorMapTools/Editor/CurbEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using UnityEditor;

namespace Packages.AutowareUnityTools.VectorMapTools.Editor
namespace Packages.MapToolbox.VectorMapTools.Editor
{
[CustomEditor(typeof(Curb))]
class CurbEditor : BezierEditor { }
Expand Down
6 changes: 3 additions & 3 deletions VectorMapTools/Editor/EditorMenuExterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*****************************************************************************/
#endregion

using Packages.AutowareUnityTools.VectorMapTools.Export;
using Packages.MapToolbox.VectorMapTools.Export;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace Packages.AutowareUnityTools.VectorMapTools.Editor
namespace Packages.MapToolbox.VectorMapTools.Editor
{
class EditorMenuExterns
{
Expand Down Expand Up @@ -76,7 +76,7 @@ private static void ExportVectorMap()
if (!string.IsNullOrEmpty(folder))
{
PlayerPrefs.SetString("ExportVectorMap", folder);
VectorMapExporter.ExportMaps(folder);
new VectorMapCollection().WriteFiles(folder);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion VectorMapTools/Editor/LRMapElementEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using UnityEditor;

namespace Packages.AutowareUnityTools.VectorMapTools.Editor
namespace Packages.MapToolbox.VectorMapTools.Editor
{
[CustomEditor(typeof(LRMapElement))]
class LRMapElementEditor : UnityEditor.Editor
Expand Down
2 changes: 1 addition & 1 deletion VectorMapTools/Editor/LaneEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using UnityEditor;

namespace Packages.AutowareUnityTools.VectorMapTools.Editor
namespace Packages.MapToolbox.VectorMapTools.Editor
{
[CustomEditor(typeof(Lane))]
class LaneEditor : BezierEditor { }
Expand Down
2 changes: 1 addition & 1 deletion VectorMapTools/Editor/LineEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using UnityEditor;
using UnityEngine;

namespace Packages.AutowareUnityTools.VectorMapTools.Editor
namespace Packages.MapToolbox.VectorMapTools.Editor
{
[CustomEditor(typeof(Line))]
class LineEditor : UnityEditor.Editor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Packages.AutowareUnityTools.VectorMapTools.Editor",
"references": [
"GUID:8eabb44705a93db47bc5b2b6feda08e3"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion VectorMapTools/Editor/RoadEdgeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using UnityEditor;

namespace Packages.AutowareUnityTools.VectorMapTools.Editor
namespace Packages.MapToolbox.VectorMapTools.Editor
{
[CustomEditor(typeof(RoadEdge))]
class RoadEdgeEditor : BezierEditor { }
Expand Down
2 changes: 1 addition & 1 deletion VectorMapTools/Editor/SignalLightEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using UnityEditor;

namespace Packages.AutowareUnityTools.VectorMapTools.Editor
namespace Packages.MapToolbox.VectorMapTools.Editor
{
[CustomEditor(typeof(SignalLight))]
class SignalLightEditor : UnityEditor.Editor
Expand Down
Loading

0 comments on commit 95c1c9e

Please sign in to comment.