6 using System.Collections.Generic;
9 namespace HoloToolkit.Examples.SpatialUnderstandingFeatureOverview
17 const int QueryResultMaxCount = 512;
18 const int DisplayResultMaxCount = 32;
21 private List<AnimatedBox> lineBoxList =
new List<AnimatedBox>();
33 lineBoxList =
new List<AnimatedBox>();
62 new Vector3(alignment.Center.x, (alignment.CeilingYValue + alignment.FloorYValue) * 0.5f, alignment.Center.z),
63 Quaternion.LookRotation(alignment.BasisZ, alignment.BasisY),
65 new Vector3(alignment.HalfDims.x, (alignment.CeilingYValue - alignment.FloorYValue) * 0.5f, alignment.HalfDims.z))
81 float minHeightOfWallSpace = 0.5f;
82 float minWidthOfWallSpace = 0.75f;
83 float minHeightAboveFloor = 1.25f;
84 float minFacingClearance = 1.5f;
89 minHeightOfWallSpace, minWidthOfWallSpace, minHeightAboveFloor, minFacingClearance,
90 resultsTopology.Length, resultsTopologyPtr);
93 HandleResults_Topology(
"Find Position On Wall", locationCount,
new Vector3(minWidthOfWallSpace, minHeightOfWallSpace, 0.025f), Color.blue);
99 float minHeightOfWallSpace = 1.0f;
100 float minWidthOfWallSpace = 1.5f;
101 float minHeightAboveFloor = 1.5f;
102 float minFacingClearance = 0.5f;
113 minHeightOfWallSpace, minWidthOfWallSpace, minHeightAboveFloor, minFacingClearance,
114 resultsTopology.Length, resultsTopologyPtr);
117 HandleResults_Topology(
"Find Large Positions On Walls", locationCount,
new Vector3(minWidthOfWallSpace, minHeightOfWallSpace, 0.025f), Color.yellow);
145 resultsTopology[0].position,
146 Quaternion.LookRotation(resultsTopology[0].normal, Vector3.up),
148 new Vector3(resultsTopology[0].width, resultsTopology[0].length, 0.05f) * 0.5f)
156 float minWidthOfWallSpace = 1.0f;
157 float minHeightAboveFloor = 1.0f;
168 minWidthOfWallSpace, minHeightAboveFloor,
169 resultsTopology.Length, resultsTopologyPtr);
172 HandleResults_Topology(
"Find Positions On Floor", locationCount,
new Vector3(minWidthOfWallSpace, 0.025f, minHeightAboveFloor), Color.red);
180 resultsTopology.Length, resultsTopologyPtr);
183 HandleResults_Topology(
"Find Largest Positions On Floor", locationCount,
new Vector3(1.0f, 1.0f, 0.025f), Color.yellow);
189 float minHeight = 0.125f;
190 float maxHeight = 1.0f;
191 float minFacingClearance = 1.0f;
202 minHeight, maxHeight, minFacingClearance,
203 resultsTopology.Length, resultsTopologyPtr);
206 HandleResults_Topology(
"Find Placeable Positions", locationCount,
new Vector3(0.25f, 0.025f, 0.25f), Color.cyan);
212 float minHeight = 0.125f;
213 float maxHeight = 2.0f;
214 float minFacingClearance = 1.0f;
215 float minWidth = .5f;
226 minHeight, maxHeight, minFacingClearance, minWidth,
227 resultsTopology.Length, resultsTopologyPtr);
230 HandleResults_Topology(
"Find Large Sittable Positions", locationCount,
new Vector3(minWidth, 0.025f, minWidth), Color.cyan);
236 float minRadius = 0.1f;
247 shapeName, minRadius,
248 resultsShape.Length, resultsShapePtr);
251 HandleResults_Shape(
"Find Positions on Shape '" + shapeName +
"'", shapeCount, Color.cyan,
new Vector3(0.1f, 0.025f, 0.1f));
266 resultsShape.Length, resultsShapePtr);
269 HandleResults_Shape(
"Find Shape Min/Max '" + shapeName +
"'", shapeCount, Color.blue,
new Vector3(0.25f, 0.025f, 0.25f));
272 private void HandleResults_Topology(
string visDesc,
int locationCount, Vector3 boxFullDims, Color color)
284 int lineInc = Mathf.CeilToInt((
float)locationCount / (
float)DisplayResultMaxCount);
285 int boxesDisplayed = 0;
286 for (
int i = 0; i < locationCount; i += lineInc)
292 resultsTopology[i].position,
293 Quaternion.LookRotation(resultsTopology[i].normal, Vector3.up),
301 if (locationCount == boxesDisplayed)
303 AppState.
Instance.SpaceQueryDescription =
string.Format(
"{0} ({1})", visDesc, locationCount);
307 AppState.
Instance.SpaceQueryDescription =
string.Format(
"{0} (found={1}, displayed={2})", visDesc, locationCount, boxesDisplayed);
311 private void HandleResults_Shape(
string visDesc,
int shapeCount, Color color, Vector3 defaultHalfDims)
327 int lineInc = Mathf.CeilToInt((
float)shapeCount / (
float)DisplayResultMaxCount);
328 int boxesDisplayed = 0;
329 for (
int i = 0; i < shapeCount; i += lineInc)
335 resultsShape[i].position,
336 Quaternion.LookRotation(alignment.BasisZ, alignment.BasisY),
338 (resultsShape[i].halfDims.sqrMagnitude < 0.01f) ? defaultHalfDims : resultsShape[i].halfDims)
344 if (shapeCount == boxesDisplayed)
346 AppState.
Instance.SpaceQueryDescription =
string.Format(
"{0} ({1})", visDesc, shapeCount);
350 AppState.
Instance.SpaceQueryDescription =
string.Format(
"{0} (found={1}, displayed={2})", visDesc, shapeCount, boxesDisplayed);
354 private bool Draw_LineBoxList()
356 bool needsUpdate =
false;
357 for (
int i = 0; i < lineBoxList.Count; ++i)
359 needsUpdate |= Draw_AnimatedBox(lineBoxList[i]);
364 private void Update_Queries()
367 if (Input.GetKeyDown(KeyCode.Escape))
371 if (Input.GetKeyDown(KeyCode.F))
373 Query_PlayspaceAlignment();
377 if (Input.GetKeyDown(KeyCode.G))
379 Query_Topology_FindPositionOnWall();
381 if (Input.GetKeyDown(KeyCode.H))
383 Query_Topology_FindLargePositionsOnWalls();
385 if (Input.GetKeyDown(KeyCode.J))
387 Query_Topology_FindLargeWall();
389 if (Input.GetKeyDown(KeyCode.K))
391 Query_Topology_FindPositionsOnFloor();
393 if (Input.GetKeyDown(KeyCode.L))
395 Query_Topology_FindLargestPositionsOnFloor();
397 if (Input.GetKeyDown(KeyCode.Semicolon))
399 Query_Topology_FindPositionsPlaceable();
403 if (Input.GetKeyDown(KeyCode.Quote))
405 Query_Shape_FindShapeHalfDims(
"All Surfaces");
407 if (Input.GetKeyDown(KeyCode.Z))
409 Query_Shape_FindPositionsOnShape(
"Sittable");
411 if (Input.GetKeyDown(KeyCode.X))
413 Query_Shape_FindShapeHalfDims(
"Chair");
415 if (Input.GetKeyDown(KeyCode.C))
417 Query_Shape_FindShapeHalfDims(
"Large Surface");
419 if (Input.GetKeyDown(KeyCode.V))
421 Query_Shape_FindShapeHalfDims(
"Large Empty Surface");
423 if (Input.GetKeyDown(KeyCode.B))
425 Query_Shape_FindShapeHalfDims(
"Couch");
429 private void Update()
441 bool needsUpdate =
false;
442 needsUpdate |= Draw_LineBoxList();
445 LineDraw_End(needsUpdate);