AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SpatialUnderstandingDllObjectPlacement.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 using UnityEngine;
5 using System.Collections;
6 using System.Runtime.InteropServices;
7 using System;
8 using System.Collections.Generic;
9 
10 namespace HoloToolkit.Unity
11 {
17  {
26  [StructLayout(LayoutKind.Sequential, Pack = 1)]
28  {
33  public enum PlacementType
34  {
35  Place_OnFloor,
36  Place_OnWall,
37  Place_OnCeiling,
38  Place_OnShape,
39  Place_OnEdge,
40  Place_OnFloorAndCeiling,
41  Place_RandomInAir,
42  Place_InMidAir,
43  Place_UnderPlatformEdge,
44  };
45 
52  [FlagsAttribute]
53  public enum WallTypeFlags
54  {
55  None = 0,
56  Normal = (1 << 0),
57  External = (1 << 1),
58  Virtual = (1 << 2),
59  ExternalVirtual = (1 << 3),
60  };
61 
68  public static ObjectPlacementDefinition Create_OnFloor(Vector3 halfDims)
69  {
71  placement.Type = PlacementType.Place_OnFloor;
72  placement.HalfDims = halfDims;
73  return placement;
74  }
75 
88  Vector3 halfDims,
89  float heightMin,
90  float heightMax,
91  WallTypeFlags wallTypes = WallTypeFlags.External | WallTypeFlags.Normal,
92  float marginLeft = 0.0f,
93  float marginRight = 0.0f)
94  {
96  placement.Type = PlacementType.Place_OnWall;
97  placement.HalfDims = halfDims;
98  placement.PlacementParam_Float_0 = heightMin;
99  placement.PlacementParam_Float_1 = heightMax;
100  placement.PlacementParam_Float_2 = marginLeft;
101  placement.PlacementParam_Float_3 = marginRight;
102  placement.WallFlags = (int)wallTypes;
103  return placement;
104  }
105 
112  public static ObjectPlacementDefinition Create_OnCeiling(Vector3 halfDims)
113  {
115  placement.Type = PlacementType.Place_OnCeiling;
116  placement.HalfDims = halfDims;
117  return placement;
118  }
119 
128  public static ObjectPlacementDefinition Create_OnShape(Vector3 halfDims, string shapeName, int componentIndex)
129  {
131  placement.Type = PlacementType.Place_OnShape;
132  placement.HalfDims = halfDims;
133  placement.PlacementParam_Str_0 = SpatialUnderstanding.Instance.UnderstandingDLL.PinString(shapeName);
134  placement.PlacementParam_Int_0 = componentIndex;
135  return placement;
136  }
137 
145  public static ObjectPlacementDefinition Create_OnEdge(Vector3 halfDims, Vector3 halfDimsBottom)
146  {
148  placement.Type = PlacementType.Place_OnEdge;
149  placement.HalfDims = halfDims;
150  placement.PlacementParam_Float_0 = halfDimsBottom.x;
151  placement.PlacementParam_Float_1 = halfDimsBottom.y;
152  placement.PlacementParam_Float_2 = halfDimsBottom.z;
153  return placement;
154  }
155 
163  public static ObjectPlacementDefinition Create_OnFloorAndCeiling(Vector3 halfDims, Vector3 halfDimsBottom)
164  {
166  placement.Type = PlacementType.Place_OnFloorAndCeiling;
167  placement.HalfDims = halfDims;
168  placement.PlacementParam_Float_0 = halfDimsBottom.x;
169  placement.PlacementParam_Float_1 = halfDimsBottom.y;
170  placement.PlacementParam_Float_2 = halfDimsBottom.z;
171  return placement;
172  }
173 
181  public static ObjectPlacementDefinition Create_RandomInAir(Vector3 halfDims)
182  {
184  placement.Type = PlacementType.Place_RandomInAir;
185  placement.HalfDims = halfDims;
186  return placement;
187  }
188 
196  public static ObjectPlacementDefinition Create_InMidAir(Vector3 halfDims)
197  {
199  placement.Type = PlacementType.Place_InMidAir;
200  placement.HalfDims = halfDims;
201  return placement;
202  }
203 
210  public static ObjectPlacementDefinition Create_UnderPlatformEdge(Vector3 halfDims)
211  {
213  placement.Type = PlacementType.Place_UnderPlatformEdge;
214  placement.HalfDims = halfDims;
215  return placement;
216  }
217 
224  public IntPtr PlacementParam_Str_0;
225  public int WallFlags;
226  public Vector3 HalfDims;
227  };
228 
233  [StructLayout(LayoutKind.Sequential, Pack = 1)]
234  public struct ObjectPlacementRule
235  {
242  {
243  Rule_AwayFromPosition,
244  Rule_AwayFromWalls,
245  Rule_AwayFromOtherObjects,
246  };
247 
255  public static ObjectPlacementRule Create_AwayFromPosition(Vector3 position, float minDistance)
256  {
258  rule.Type = ObjectPlacementRuleType.Rule_AwayFromPosition;
259  rule.RuleParam_Vec3_0 = position;
260  rule.RuleParam_Float_0 = minDistance;
261  return rule;
262  }
263 
271  public static ObjectPlacementRule Create_AwayFromWalls(float minDistance, float minWallHeight = 0.0f)
272  {
274  rule.Type = ObjectPlacementRuleType.Rule_AwayFromWalls;
275  rule.RuleParam_Float_0 = minDistance;
276  rule.RuleParam_Float_1 = minWallHeight;
277  return rule;
278  }
279 
286  public static ObjectPlacementRule Create_AwayFromOtherObjects(float minDistance)
287  {
289  rule.Type = ObjectPlacementRuleType.Rule_AwayFromOtherObjects;
290  rule.RuleParam_Float_0 = minDistance;
291  return rule;
292  }
293 
295  public int RuleParam_Int_0;
296  public float RuleParam_Float_0;
297  public float RuleParam_Float_1;
298  public Vector3 RuleParam_Vec3_0;
299  };
300 
306  [StructLayout(LayoutKind.Sequential, Pack = 1)]
308  {
313  {
314  Constraint_NearPoint,
315  Constraint_NearWall,
316  Constraint_AwayFromWalls,
317  Constraint_NearCenter,
318  Constraint_AwayFromOtherObjects,
319  Constraint_AwayFromPoint
320  };
321 
331  public static ObjectPlacementConstraint Create_NearPoint(Vector3 position, float minDistance = 0.0f, float maxDistance = 0.0f)
332  {
334  constraint.Type = ObjectPlacementConstraintType.Constraint_NearPoint;
335  constraint.RuleParam_Vec3_0 = position;
336  constraint.RuleParam_Float_0 = minDistance;
337  constraint.RuleParam_Float_1 = maxDistance;
338  return constraint;
339  }
340 
351  public static ObjectPlacementConstraint Create_NearWall(float minDistance = 0.0f, float maxDistance = 0.0f, float minWallHeight = 0.0f, bool includeVirtualWalls = false)
352  {
354  constraint.Type = ObjectPlacementConstraintType.Constraint_NearWall;
355  constraint.RuleParam_Float_0 = minDistance;
356  constraint.RuleParam_Float_1 = maxDistance;
357  constraint.RuleParam_Float_2 = minWallHeight;
358  constraint.RuleParam_Int_0 = includeVirtualWalls ? 1 : 0;
359  return constraint;
360  }
361 
368  {
370  constraint.Type = ObjectPlacementConstraintType.Constraint_AwayFromWalls;
371  return constraint;
372  }
373 
381  public static ObjectPlacementConstraint Create_NearCenter(float minDistance = 0.0f, float maxDistance = 0.0f)
382  {
384  constraint.Type = ObjectPlacementConstraintType.Constraint_NearCenter;
385  constraint.RuleParam_Float_0 = minDistance;
386  constraint.RuleParam_Float_1 = maxDistance;
387  return constraint;
388  }
389 
396  {
398  constraint.Type = ObjectPlacementConstraintType.Constraint_AwayFromOtherObjects;
399  return constraint;
400  }
401 
408  public static ObjectPlacementConstraint Create_AwayFromPoint(Vector3 position)
409  {
411  constraint.Type = ObjectPlacementConstraintType.Constraint_AwayFromPoint;
412  constraint.RuleParam_Vec3_0 = position;
413  return constraint;
414  }
415 
417  public int RuleParam_Int_0;
418  public float RuleParam_Float_0;
419  public float RuleParam_Float_1;
420  public float RuleParam_Float_2;
421  public Vector3 RuleParam_Vec3_0;
422  };
423 
428  [StructLayout(LayoutKind.Sequential, Pack = 1)]
429  public class ObjectPlacementResult : ICloneable
430  {
431  public object Clone()
432  {
433  return this.MemberwiseClone();
434  }
435 
436  public Vector3 Position;
437  public Vector3 HalfDims;
438  public Vector3 Forward;
439  public Vector3 Right;
440  public Vector3 Up;
441  };
442 
443  // Functions
449  [DllImport("SpatialUnderstanding", CallingConvention = CallingConvention.Cdecl)]
450  public static extern int Solver_Init();
451 
473  [DllImport("SpatialUnderstanding", CallingConvention = CallingConvention.Cdecl)]
474  public static extern int Solver_PlaceObject(
475  [In, MarshalAs(UnmanagedType.LPStr)] string objectName,
476  [In] IntPtr placementDefinition,// ObjectPlacementDefinition
477  [In] int placementRuleCount,
478  [In] IntPtr placementRules, // ObjectPlacementRule
479  [In] int constraintCount,
480  [In] IntPtr placementConstraints,// ObjectPlacementConstraint
481  [Out] IntPtr placementResult); // ObjectPlacementResult
482 
491  [DllImport("SpatialUnderstanding", CallingConvention = CallingConvention.Cdecl)]
492  public static extern int Solver_RemoveObject(
493  [In, MarshalAs(UnmanagedType.LPStr)] string objectName);
494 
501  [DllImport("SpatialUnderstanding", CallingConvention = CallingConvention.Cdecl)]
502  public static extern void Solver_RemoveAllObjects();
503  }
504 }
static ObjectPlacementDefinition Create_UnderPlatformEdge(Vector3 halfDims)
Constructs an object placement query definition requiring the object to be place under a platform edg...
ObjectPlacementRuleType
Type of object placement rule. Each rule is defined by its type and a set of per-type parameters...
static ObjectPlacementDefinition Create_OnShape(Vector3 halfDims, string shapeName, int componentIndex)
Constructs an object placement query definition requiring the object to be placed on top of another o...
static ObjectPlacementConstraint Create_NearPoint(Vector3 position, float minDistance=0.0f, float maxDistance=0.0f)
Constructs an object placement constraint requesting that the placement volume be placed no closer th...
static ObjectPlacementRule Create_AwayFromOtherObjects(float minDistance)
Constructs an object placement rule requiring the placement volume to be placed a minimum distance aw...
static ObjectPlacementDefinition Create_RandomInAir(Vector3 halfDims)
Constructs an object placement query definition requiring the object to be placed floating in space...
static ObjectPlacementConstraint Create_AwayFromWalls()
Constructs an object placement constraint requesting that the placement volume be placed away from al...
static ObjectPlacementDefinition Create_OnEdge(Vector3 halfDims, Vector3 halfDimsBottom)
Constructs an object placement query definition requiring the object to be placed on the edge of a pl...
static ObjectPlacementConstraint Create_NearWall(float minDistance=0.0f, float maxDistance=0.0f, float minWallHeight=0.0f, bool includeVirtualWalls=false)
Constructs an object placement constraint requesting that the placement volume be placed no closer th...
static ObjectPlacementDefinition Create_OnFloor(Vector3 halfDims)
Constructs an object placement query definition requiring the object to be placed on the floor...
Object placement result. Defines an oriented bounding box result for the object placement query...
static ObjectPlacementRule Create_AwayFromWalls(float minDistance, float minWallHeight=0.0f)
Constructs an object placement rule requiring the placement volume to be placed a minimum distance aw...
static ObjectPlacementDefinition Create_OnCeiling(Vector3 halfDims)
Constructs an object placement query definition requiring the object to be place on the ceiling...
Encapsulates the object placement queries of the understanding DLL. These queries will not be valid u...
static T Instance
Returns the Singleton instance of the classes type. If no instance is found, then we search for an in...
Definition: Singleton.cs:26
Defines an object placement rule. Rules are one part of an object placement definition. Rules may not be violated by the returned query.
static ObjectPlacementRule Create_AwayFromPosition(Vector3 position, float minDistance)
Constructs an object placement rule requiring the placement volume to be placed a minimum distance aw...
static ObjectPlacementDefinition Create_InMidAir(Vector3 halfDims)
Constructs an object placement query definition requiring the object to be placed floating in space...
Defines an object placement constraint. Constraints are one part of an object placement definition...
WallTypeFlags
Type of wall. External walls bound the playspace. Virtual walls are created at the edge of the playsp...
Defines an object placement query. A query consists of a type a name, type, set of rules...
static ObjectPlacementConstraint Create_NearCenter(float minDistance=0.0f, float maxDistance=0.0f)
Constructs an object placement constraint requesting that the placement volume be placed near the cen...
static ObjectPlacementDefinition Create_OnFloorAndCeiling(Vector3 halfDims, Vector3 halfDimsBottom)
Constructs an object placement query definition requiring the object to be have space on the floor an...
The SpatialUnderstanding class controls the state and flow of the scanning process used in the unders...
static ObjectPlacementConstraint Create_AwayFromOtherObjects()
Constructs an object placement constraint requesting that the placement volume be placed away from ot...
static ObjectPlacementConstraint Create_AwayFromPoint(Vector3 position)
Constructs an object placement constraint requesting that the placement volume be placed away from th...
static ObjectPlacementDefinition Create_OnWall(Vector3 halfDims, float heightMin, float heightMax, WallTypeFlags wallTypes=WallTypeFlags.External|WallTypeFlags.Normal, float marginLeft=0.0f, float marginRight=0.0f)
Constructs an object placement query definition requiring the object to be placed on a wall...