SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
SlamFlexWrapper.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using System.Runtime.InteropServices;
4 using System;
8 public class SlamFlexWrapper {
12  public enum DetectionState
13  {
14  Started,
15  InProgres,
16  Stopped,
17  Finished
18  };
23  public delegate void SendStringDelegate(string s);
33  public delegate void SendPoseDelegate(float r1, float r2, float r3, double t1, double t2, double t3);
38  public delegate void SendLogDelegate(string text);
44  public delegate void SendArrayPointsDelegate(IntPtr pointer, int size);
45 
46  /* Interface to native implementation */
47  #if UNITY_IOS
48 
49  [DllImport ("__Internal")]
50  private static extern void _StartSlam ();
51 
52  [DllImport ("__Internal")]
53  private static extern IntPtr _SetNewFrame (IntPtr pointer, int width, int height);
54 
55  [DllImport ("__Internal")]
56  private static extern void _StopSlam ();
57 
58  [DllImport ("__Internal")]
59  private static extern void _StartPlaneDetection ();
60 
61 #elif UNITY_ANDROID
62 
63  [DllImport ("slamflex")]
64  private static extern void _StartSlam (SendStringDelegate ssd, SendPoseDelegate spd, SendLogDelegate sLogd, SendArrayPointsDelegate arrayPoints);
65 
66  [DllImport ("slamflex")]
67  private static extern IntPtr _SetNewFrame (IntPtr pointer, int width, int height);
68 
69  [DllImport ("slamflex")]
70  private static extern void _StopSlam ();
71 
72  [DllImport ("slamflex")]
73  private static extern void _StartPlaneDetection ();
74 
75 #endif
76 
77  /* Public interface for use inside C# / JS code */
78 
86  public static void StartSlam(SendStringDelegate ssd, SendPoseDelegate spd, SendLogDelegate sLogd, SendArrayPointsDelegate arrayPoints)
87  {
88  // Call plugin only when running on real device
89  if (ViablePlatform())
90  {
91  _StartSlam(ssd, spd, sLogd, arrayPoints);
92  }
93 
94  }
95 
96 
100  public static void StopSlam()
101  {
102  // Call plugin only when running on real device
103  if (ViablePlatform())
104  {
105  _StopSlam();
106  }
107  }
115  public static DetectionState SetNewFrame(IntPtr pointer, int width, int height)
116  {
117 // Call plugin only when running on real device
118  if (ViablePlatform())
119  {
120  DetectionState det_state = DetectionState.Stopped;
121  string state = Marshal.PtrToStringAnsi(_SetNewFrame(pointer, width, height));
122  switch (state)
123  {
124  case "Started":
125  {
126  det_state = DetectionState.Started;
127  break;
128  }
129  case "InProgres":
130  {
131  det_state = DetectionState.InProgres;
132  break;
133  }
134  case "Stopped":
135  {
136  det_state = DetectionState.Stopped;
137  break;
138  }
139  case "Finished":
140  {
141  det_state = DetectionState.Finished;
142  break;
143  }
144  default:
145  {
146  det_state = DetectionState.Finished;
147  break;
148  }
149 
150  }
151 
152  //det_state = (DetectionState)Enum.Parse(typeof(DetectionState), state);
153 
154  return det_state;
155  }
156  // Return mockup values for code running inside Editor
157  else
158  {
159  return DetectionState.Finished;
160  }
161  }
162 
166  public static void StartPlaneDetection()
167  {
168  if (ViablePlatform())
169  {
171  }
172  }
173 
178  private static bool ViablePlatform()
179  {
180  return (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer);
181  }
182 
183 
184 }
delegate void SendLogDelegate(string text)
Definition of delegate used from plugin to send log to Unity3D
delegate void SendPoseDelegate(float r1, float r2, float r3, double t1, double t2, double t3)
Definition of delegate used from plugin to send pose to Unity3D
static bool ViablePlatform()
Check if is viable platform for running plugin
delegate void SendStringDelegate(string s)
Definition of delegate used from plugin to send string to Unity3D
DetectionState
Enum for state of SLAM detection process
void _StopSlam()
Stops slam plane detection.
Definition: SLAMflex.cpp:114
void _StartPlaneDetection()
Initiate plane detection.
Definition: SLAMflex.cpp:83
SlamFlexWrapper implements interface to native implementation and public interface for use inside C# ...
void _StartSlam(void *pointerString, void *pointerPose, void *pointerStringLog, void *pointerArrayOfPoints)
Exported functions from libSlamflex library.
Definition: SLAMflex.cpp:72
static void StartSlam(SendStringDelegate ssd, SendPoseDelegate spd, SendLogDelegate sLogd, SendArrayPointsDelegate arrayPoints)
Starts SLAM detection
delegate void SendArrayPointsDelegate(IntPtr pointer, int size)
Definition of delegate used from plugin to send array of points to Unity3D
const char * _SetNewFrame(void *pointer, int width, int height)
Function called each frame with pointer to image and width, height of image.
Definition: SLAMflex.cpp:91
static DetectionState SetNewFrame(IntPtr pointer, int width, int height)
Send image data to plugin for SLAM detection
static void StopSlam()
Stops SLAM detection
static void StartPlaneDetection()
Initiate SLAM detection