Verified Commit 6f8c4425 authored by Sebastian Höffner's avatar Sebastian Höffner
Browse files

Using HashSet instead of List for occupying objects to avoid duplicates.

parent 9a4ed4d7
......@@ -8,7 +8,7 @@ namespace dlu
[CustomEditor(typeof(OccupancyGrid))]
public class OccupancyGridEditor : Editor
{
private List<string>[,,] occupancy;
private HashSet<string>[,,] occupancy;
// This seems not to work? Maybe needs to serialize on MonoBehaviour?
[SerializeField]
......
......@@ -22,13 +22,13 @@ public class OccupancyGrid : MonoBehaviour
resolution = new Vector3(0.05f, 0.05f, 0.05f);
}
private List<string>[,,] occupancy;
private HashSet<string>[,,] occupancy;
public List<string>[,,] GenerateOccupancyGrid() {
public HashSet<string>[,,] GenerateOccupancyGrid() {
return GenerateOccupancyGrid(new HashSet<string>());
}
public List<string>[,,] GenerateOccupancyGrid(HashSet<string> excluded)
public HashSet<string>[,,] GenerateOccupancyGrid(HashSet<string> excluded)
{
// If all you have is a hammer...
Vector3 boundsMin = new Vector3(-1.55f, -0.05f, -1.55f); // NOTE HERE WE SET boundsMin !
......@@ -48,7 +48,7 @@ public class OccupancyGrid : MonoBehaviour
.ToList();
ignored.ForEach(go => go.SetActive(false));
occupancy = new List<string>[gridSize.x, gridSize.y, gridSize.z];
occupancy = new HashSet<string>[gridSize.x, gridSize.y, gridSize.z];
for (long ix = 0; ix < occupancy.GetLongLength(0); ++ix)
{
......@@ -59,7 +59,7 @@ public class OccupancyGrid : MonoBehaviour
Vector3 gridCell = idx2coord(ix, iy, iz, resolution);
Collider[] hitColliders = Physics.OverlapBox(gridCell, halfResolution, Quaternion.identity, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore);
occupancy[ix, iy, iz] = new List<string>(hitColliders.Length);
occupancy[ix, iy, iz] = new HashSet<string>();
foreach (Collider c in hitColliders)
{
InstanceIdentifier ii = c.gameObject.GetComponent<InstanceIdentifier>();
......
......@@ -94,7 +94,7 @@ public class SceneController : MonoBehaviour
}
}
occupancyGrid.resolution = Vector3.one * resolution;
List<string>[,,] occupancy = occupancyGrid.GenerateOccupancyGrid(excluded);
HashSet<string>[,,] occupancy = occupancyGrid.GenerateOccupancyGrid(excluded);
JSONObject jsonObject = new JSONObject();
jsonObject["max_index_x"] = occupancy.GetLongLength(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment