AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
VolumeBuffer.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 namespace HoloToolkit.Unity
5 {
10  public class VolumeBuffer<T>
11  {
12  public T[] DataArray;
13  public readonly Int3 Size;
14 
15  public bool IsEdge(Int3 pos)
16  {
17  return (((pos.x == 0) || ((pos.x + 1) == Size.x)) ||
18  ((pos.y == 0) || ((pos.y + 1) == Size.y)) ||
19  ((pos.z == 0) || ((pos.z + 1) == Size.z)));
20  }
21 
22  public bool IsValid(Int3 pos)
23  {
24  return (((pos.x >= 0) && (pos.x < Size.x)) &&
25  ((pos.y >= 0) && (pos.y < Size.y)) &&
26  ((pos.z >= 0) && (pos.z < Size.z)));
27  }
28 
29  public VolumeBuffer(Int3 size)
30  {
31  this.Size = size;
32  this.DataArray = new T[this.Size.sqrMagnitude];
33  }
34 
35  public VolumeBuffer(Int3 size, T[] ar)
36  {
37  this.Size = size;
38  this.DataArray = ar;
39  }
40 
41  public T this[Int3 pos]
42  {
43  get { return this.GetVoxel(pos); }
44  set { this.SetVoxel(pos, value); }
45  }
46 
47  public T GetVoxel(Int3 pos)
48  {
49  return this.DataArray[MathExtensions.CubicToLinearIndex(pos, this.Size)];
50  }
51 
52  public void SetVoxel(Int3 pos, T val)
53  {
54  this.DataArray[MathExtensions.CubicToLinearIndex(pos, this.Size)] = val;
55  }
56 
57  public void ClearEdges(T clearVal)
58  {
59  //TODO: there's no need to test - could just explicitly walk the edges
60  for (var i = 0; i < this.Size.sqrMagnitude; ++i)
61  {
62  var ndx = MathExtensions.LinearToCubicIndex(i, this.Size);
63  if (this.IsEdge(ndx))
64  {
65  this[ndx] = clearVal;
66  }
67  }
68  }
69  }
70 }
void SetVoxel(Int3 pos, T val)
Definition: VolumeBuffer.cs:52
VolumeBuffer(Int3 size, T[] ar)
Definition: VolumeBuffer.cs:35
Extension methods and helper functions for various math data
static int CubicToLinearIndex(Int3 ndx, Int3 size)
3D integer class - operates similarly to Unity&#39;s Vector3D
Definition: Int3.cs:16
static Int3 LinearToCubicIndex(int linearIndex, Int3 size)
Represents a 3D array of data
Definition: VolumeBuffer.cs:10