// Use this for initialization void Awake() { // gather dependencies MeshMan = MeshManager.Instance; VoxGridMan = new VoxelGridManager <byte>(myMinSize: DefaultVoxGridRes, myDefaultSize: DefaultVoxelSize); VertVis = new Visualizer("VertexMarkers", "Marker", "Line", DefaultMaterial); VertexInter = new Intersector(); Observer = GetComponent <SpatialMappingObserver>(); // finish setup SensorField.Transform = Camera.main.transform; SensorField.FOV = new Intersector.ViewVector((int)SensorFOV.x, (int)SensorFOV.y); MeshDensity = MeshMan.Density; SensorData = new byte[(int)SensorPixelCount.x, (int)SensorPixelCount.y]; for (int i = 0; i < SensorPixelCount.x; i++) { for (int j = 0; j < SensorPixelCount.y; j++) { SensorData[i, j] = (byte)(255f * (float)(i + j) / (SensorPixelCount.x + SensorPixelCount.y)); } } // finish dependendencies setup: some variables must be created in Start() MeshMan.BoundsVis = new Visualizer("MeshBounds", "Marker", "Line", DefaultMaterial); VerticesRendered = DefaultRenderVerts; }
// Use this for initialization void Start() { MeshMan = MeshManager.Instance; VoxGridMan = VoxelGridManager.Instance; MeshDensity = HoloToolkit.Unity.SpatialMapping. SpatialMappingManager.Instance.SurfaceObserver.TrianglesPerCubicMeter; }
// Use this for initialization void Start() { TextObj = TextContainer.GetComponent <TextMesh>(); Driver = EFPContainer.GetComponent <ExternalFeedDriver>(); MeshManagerObj = EFPContainer.GetComponent <MeshManager>(); GridManager = EFPContainer.GetComponent <VoxelGridManager>(); }
/// <summary> /// Called once at startup. /// </summary> void Start() { meshManager = MeshManager.Instance; voxManager = VoxelGridManager.Instance; voxManager.updateStruct = updateVoxelStructure; }
// Use this for initialization void Awake() { // gather dependencies MeshMan = MeshManager.Instance; VoxGridMan = new VoxelGridManager <byte>(myMinSize: DefaultVoxGridRes, myDefaultSize: DefaultVoxelSize); VertVis = new Visualizer("VertexMarkers", "Marker", "Line", DefaultMaterial); VertexInter = new Intersector(); Observer = GetComponent <SpatialMappingObserver>(); SensorDataUpdater = DataUpdateContainer.GetComponent <Receiving.ImageReceiver>(); // finish setup SensorField.Transform = Camera.main.transform; SensorField.FOV = new Intersector.ViewVector((int)(SensorFOV.x * SensorFOVReduction.x), (int)(SensorFOV.y * SensorFOVReduction.y)); MeshDensity = MeshMan.Density; SensorData = new byte[SensorDataHeight * SensorDataWidth]; // sync state to default values VerticesRendered = DefaultRenderVerts; ProximityConfig = DefaultToProximity; }
/// <summary> /// Sets vertex colors in all meshes ID'd as visible by meshGuide with values in voxGrid. /// </summary> public static void ColorMesh(ReadOnlyCollection <SpatialMappingSource.SurfaceObject> allMeshes, List <SurfacePoints> extraData, List <bool> meshGuide, VoxelGridManager <byte> voxGrid, Color32 color1, Color32 color2, Color32 noDataColor, byte value1, byte value2) { for (int i = 0; i < allMeshes.Count; i++) { if (meshGuide[i]) { List <Color32> coloring = new List <Color32>(); for (int j = 0; j < extraData[i].Wvertices.Count; j++) { if (voxGrid.Contains(extraData[i].Wvertices[j]) && voxGrid.NonNullCell(extraData[i].Wvertices[j])) { coloring.Add(ScaleColor(voxGrid.Get(extraData[i].Wvertices[j]), value1, value2, color1, color2)); } else { coloring.Add(noDataColor); } } allMeshes[i].Filter.sharedMesh.SetColors(coloring); } } }
/// <summary> /// Updates contents of DiagnosticsMessage. /// </summary> private void UpdateDiagnostics() { Seconds = StopWatch.ElapsedTicks / Stopwatch.Frequency; DiagnosticsMessage.Remove(0, DiagnosticsMessage.Length); // display title DiagnosticsMessage.Append("<size=144><b>Diagnostics</b></size>\n" + "- Determines visibility of mesh sections\n" + "- Calculates intersection with simulated sensor at main camera\n" + "- Updates non-occluded vertices in voxel grid\n" + "- Renders all vertices in visibile meshes via voxel grid data\n"); // display EFPDriver metadata DiagnosticsMessage.AppendFormat("<b>Driver</b>\n" + "Speed (ms / Hz): {0} / {1}\n" + "Total Memory Use: {2}\n" + "Elasped Time (s): {3}\n" + "Sensor Position: {4}, Euler Angles: {5}\n", Math.Round(Driver.DriverSpeed * 1000.0, 0), Math.Round(1.0 / Driver.DriverSpeed, 1), MemToStr(GC.GetTotalMemory(false)), Seconds, pointToStr(Driver.SensorField.Transform.position), pointToStr(Driver.SensorField.Transform.eulerAngles)); // display SpatialMappingObserver controls DiagnosticsMessage.AppendFormat("<b>Spatial Mapping Manager</b>\n" + "Mesh Density (triangles/m^3): {0}\n" + "Mesh Refresh Time (s): {1}\n" + "Cached Meshes: {2}\n", Math.Round(Driver.MeshDensity, 0), Math.Round(Observer.TimeBetweenUpdates, 1), Observer.SurfaceObjects.Count); // display MeshManager metadata DiagnosticsMessage.AppendFormat("<b>Mesh Manager</b>\n" + "Speed (ms): {0}\n" + "Visible Meshes: {1}\n" + "Triangles (in visible meshes / total): {2} / {3}\n" + "Vertices (in visible meshes / total): {4} / {5}\n", Math.Round(Driver.MeshManSpeed * 1000.0, 0), Driver.MeshMan.MeshesInView, Driver.MeshMan.TrianglesInView, Driver.MeshMan.TotalTriangleCount, Driver.MeshMan.VerticesInView, Driver.MeshMan.TotalVertexCount); // display Intersector metadata DiagnosticsMessage.AppendFormat("<b>Intersector</b>\n" + "Speed (ms): {0}\n" + "Occlusion Grid Resolution: {1}cm @ {2}m\n" + "Vertices in FOV (total / non-occluded): {3} / {4}\n", Math.Round(Driver.IntersectSpeed * 1000.0, 0), Math.Round(Driver.OcclusionObjSize * 100, 1), Driver.OcclusionObjDistance, Driver.VertexInter.VerticesInView, Driver.VertexInter.NonOccludedVertices); // display VoxelGridManager metadata VoxelGridManager <byte> .Metadata voxInfo = Driver.VoxGridMan.About(); DiagnosticsMessage.AppendFormat("<b>Voxel Grid Manager</b>\n" + "Speed (ms): {0}\n" + "Minimum Voxel Size (cm) {1}\n" + "Grid Components: {2}\n" + "Grid Voxels (non-null): {3} ({4})\n" + "Grid Volume (non-null) (m^2): {5} ({6})\n" + "Grid Memory Use: {7}\n", Math.Round(Driver.VoxGridManSpeed * 1000.0, 0), Math.Round(Driver.VoxelGridRes * 100.0, 0), voxInfo.components, voxInfo.voxels, voxInfo.nonNullVoxels, Math.Round(voxInfo.volume, 1), Math.Round(voxInfo.nonNullVolume, 1), MemToStr(voxInfo.memSize)); // display VertexVisualizer metadata DiagnosticsMessage.AppendFormat("<b>Vertex Visualizer</b>\n" + "Speed (ms): {0}\n", Math.Round(Driver.VertVisSpeed * 1000.0, 0)); }
/// <summary> /// Updates contents of DiagnosticsMessage. /// </summary> private void UpdateDiagnostics() { Seconds = StopWatch.ElapsedTicks / Stopwatch.Frequency; DiagnosticsMessage.Remove(0, DiagnosticsMessage.Length); // display title DiagnosticsMessage.Append("<size=144><b>External Feed Pathway Diagnostics</b></size>\n" + "- Accesses entire cached spatial data\n" + "- Calculates intersection with simulated sensor at main camera\n" + "- Updates non-occluded vertices in voxel grid\n"); // display EFPDriver metadata DiagnosticsMessage.AppendFormat("<b>Driver</b>\n" + "Speed (ms / Hz): {0} / {1}\n" + "Total Memory Use: {2}\n" + "Elasped Time (s): {3}\n" + "Sensor Position: {4}, Euler Angles: {5}\n", Math.Round(Driver.DriverSpeed * 1000.0, 0), Math.Round(1.0 / Driver.DriverSpeed, 1), MemToStr(GC.GetTotalMemory(false)), Seconds, pointToStr(Driver.SensorField.Transform.position), pointToStr(Driver.SensorField.Transform.eulerAngles)); // display MeshManager metadata DiagnosticsMessage.AppendFormat("<b>Mesh Manager</b>\n" + "Speed (ms): {0}\n" + "Mesh Density (triangles/m^3): {1}\n" + "Mesh Visiblity FOV Factor: {2}\n" + "Visible Meshes (total cached): {3} ({4})\n" + "Triangles (visible meshes / total): {5} / {6}\n" + "Vertices (visible meshes / total): {7} / {8}\n", Math.Round(Driver.MeshManSpeed * 1000.0, 0), Driver.MeshDensity, Driver.MeshMan.FOVFactor, Driver.MeshMan.MeshesInView, Driver.MeshMan.TotalMeshCount, Driver.MeshMan.TrianglesInView, Driver.MeshMan.TotalTriangleCount, Driver.MeshMan.VerticesInView, Driver.MeshMan.TotalVertexCount); // display Intersector metadata DiagnosticsMessage.AppendFormat("<b>Mesh Intersector</b>\n" + "Speed (ms): {0}\n" + "Occlusion Grid Resolution: {1}cm @ {2}m\n" + "Total Vertices (in FOV): {3} ({4})\n" + "Non-Occluded Vertices {5}\n", Math.Round(Driver.IntersectSpeed * 1000.0, 0), Driver.OcclusionObjSize * 100, Driver.OcclusionObjDistance, Driver.VertexInter.CheckedVertices, Driver.VertexInter.VerticesInView, Driver.VertexInter.NonOccludedVertices); // display VoxelGridManager metadata VoxelGridManager <byte> .Metadata voxInfo = Driver.VoxGridMan.About(); DiagnosticsMessage.AppendFormat("<b>Voxel Grid Manager</b>\n" + "Speed (ms): {0}\n" + "Minimum Voxel Size (cm) {1}\n" + "Grid Components: {2}\n" + "Grid Voxels (non-null): {3} ({4})\n" + "Grid Volume (non-null) (m^2): {5} ({6})\n" + "Grid Memory Use: {7}\n", Math.Round(Driver.VoxGridManSpeed * 1000.0, 0), Math.Round(Driver.VoxGridMan.minSize * 100.0, 0), voxInfo.components, voxInfo.voxels, voxInfo.nonNullVoxels, Math.Round(voxInfo.volume, 1), Math.Round(voxInfo.nonNullVolume, 1), MemToStr(voxInfo.memSize)); // display VertexVisualizer metadata DiagnosticsMessage.AppendFormat("<b>Vertex Visualizer</b>\n" + "Speed (ms): {0}\n" + "Rendered Mesh Vertices (total markers): {1} ({2})\n" + "Rendered Mesh-Bounds Vertices (total markers): {3} ({4})\n" + "Rendered Mesh-Bounds Lines (total lines): {5} ({6})\n", Math.Round(Driver.VertVisSpeed * 1000.0, 0), Driver.VertVis.MarkersInUse, Driver.VertVis.TotalMarkers, Driver.MeshMan.BoundsVis.MarkersInUse, Driver.MeshMan.BoundsVis.TotalMarkers, Driver.MeshMan.BoundsVis.LinesInUse, Driver.MeshMan.BoundsVis.TotalLines); }
// Test VoxelGridManager // Tests... // Instance (T1) // About (T1) // Set (structUpdate: true) (T2) // Set (structUpdate: false) (T3) static void TestVoxelGridManager() { Console.WriteLine("\nTesting VoxelGridManager...\n"); // Test 1: Constructor, About Console.WriteLine("Test 1: Creating VoxelGridManager..."); VoxelGridManager manager = VoxelGridManager.Instance; Console.WriteLine(about(manager.about())); Console.WriteLine("Re-accessing VoxleGridManager Instance..."); Console.WriteLine(about(manager.about())); Console.WriteLine(); // Test 2: Set (structUpdate: true) Vector3 boundsMin = new Vector3(0, 0, 0); Vector3 boundsMax = new Vector3(5, 5, 5); int iterations = 1000; Console.WriteLine("Test 2: set... conducting {0} iterations of random points " + "between {1} and {2}... " + "structUpdate: {3}", iterations, pointToStr(boundsMin), pointToStr(boundsMax), VoxelGridManager.Instance.updateStruct); System.Random rand = new System.Random(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < iterations; i++) { Vector3 point = randomPoint(boundsMin, boundsMax, rand); byte value = (byte)rand.Next(0, 255); List <Vector3> points = new List <Vector3>(); List <byte> values = new List <byte>(); points.Add(point); values.Add(value); VoxelGridManager.Instance.set(points, values); } stopWatch.Stop(); long millisecs = stopWatch.ElapsedMilliseconds; float perOp = 1000f * millisecs / (2.0f * iterations); Console.WriteLine("Avg time per op (us): {0}", perOp); Console.WriteLine("Elasped time (ms): {0}", millisecs); Console.WriteLine(about(manager.about()) + "\n"); // Test 3: Set (structUpdate: false) VoxelGridManager.Instance.updateStruct = false; boundsMin = new Vector3(0, 0, 0); boundsMax = new Vector3(5, 5, 5); iterations = 1000; Console.WriteLine("Test 2: set... conducting {0} iterations of random points " + "between {1} and {2}... " + "structUpdate: {3}", iterations, pointToStr(boundsMin), pointToStr(boundsMax), VoxelGridManager.Instance.updateStruct); stopWatch.Start(); for (int i = 0; i < iterations; i++) { Vector3 point = randomPoint(boundsMin, boundsMax, rand); byte value = (byte)rand.Next(0, 255); List <Vector3> points = new List <Vector3>(); List <byte> values = new List <byte>(); points.Add(point); values.Add(value); VoxelGridManager.Instance.set(points, values); } stopWatch.Stop(); millisecs = stopWatch.ElapsedMilliseconds; perOp = 1000f * millisecs / (2.0f * iterations); Console.WriteLine("Avg time per op (us): {0}", perOp); Console.WriteLine("Elasped time (ms): {0}", millisecs); Console.WriteLine(about(manager.about()) + "\n"); }
/// <summary> /// Sets vertex colors in all meshes ID'd as visible by meshGuide with values in voxGrid. /// </summary> public static void ColorMesh(ReadOnlyCollection <SpatialMappingSource.SurfaceObject> allMeshes, List <SurfacePoints> extraData, List <bool> meshGuide, VoxelGridManager <byte> voxGrid, Color32 color1, Color32 color2, byte value1, byte value2) { for (int i = 0; i < allMeshes.Count; i++) { if (meshGuide[i]) { List <Color32> coloring = new List <Color32>(); for (int j = 0; j < extraData[i].Wvertices.Count; j++) { float scaledVal = (float)(voxGrid.Get(extraData[i].Wvertices[j]) - value1) / (float)(value2 - value1); coloring.Add(LerpViaHSV(color1, color2, scaledVal)); } allMeshes[i].Filter.sharedMesh.SetColors(coloring); } } }