コード例 #1
0
 private eLeapRS _lastResult; //Used to avoid repeating the same log message, ie. for events like time out
 private void reportAbnormalResults(string context, eLeapRS result)
 {
     if (result != eLeapRS.eLeapRS_Success &&
         result != _lastResult)
     {
         string msg = context + " " + result;
         this.LeapLogEvent.Dispatch <LogEventArgs>(this,
                                                   new LogEventArgs(MessageSeverity.MESSAGE_CRITICAL,
                                                                    LeapC.GetNow(),
                                                                    msg)
                                                   );
     }
     _lastResult = result;
 }
コード例 #2
0
ファイル: Connection.cs プロジェクト: tuita520/handUI
        private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg)
        {
            IntPtr deviceHandle = deviceMsg.device.handle;

            if (deviceHandle == IntPtr.Zero)
            {
                return;
            }

            LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO();
            eLeapRS          result;

            IntPtr device;

            result = LeapC.OpenDevice(deviceMsg.device, out device);
            if (result != eLeapRS.eLeapRS_Success)
            {
                return;
            }

            deviceInfo.serial = IntPtr.Zero;
            deviceInfo.size   = (uint)Marshal.SizeOf(deviceInfo);
            result            = LeapC.GetDeviceInfo(device, ref deviceInfo); //Query the serial length
            if (result != eLeapRS.eLeapRS_Success)
            {
                return;
            }

            deviceInfo.serial = Marshal.AllocCoTaskMem((int)deviceInfo.serial_length);
            result            = LeapC.GetDeviceInfo(device, ref deviceInfo); //Query the serial

            if (result == eLeapRS.eLeapRS_Success)
            {
                Device apiDevice = new Device(deviceHandle,
                                              deviceInfo.h_fov,              //radians
                                              deviceInfo.v_fov,              //radians
                                              deviceInfo.range / 1000.0f,    //to mm
                                              deviceInfo.baseline / 1000.0f, //to mm
                                              (Device.DeviceType)deviceInfo.type,
                                              (deviceInfo.status == eLeapDeviceStatus.eLeapDeviceStatus_Streaming),
                                              Marshal.PtrToStringAnsi(deviceInfo.serial));
                Marshal.FreeCoTaskMem(deviceInfo.serial);
                _devices.AddOrUpdate(apiDevice);

                if (LeapDevice != null)
                {
                    LeapDevice.DispatchOnContext(this, EventContext, new DeviceEventArgs(apiDevice));
                }
            }
        }
コード例 #3
0
ファイル: Connection.cs プロジェクト: midgithub/MegaBookDome
        private void handleImageCompletion(ref LEAP_IMAGE_COMPLETE_EVENT imageMsg)
        {
            LEAP_IMAGE_PROPERTIES props        = LeapC.PtrToStruct <LEAP_IMAGE_PROPERTIES>(imageMsg.properties);
            ImageReference        pendingImage = null;

            lock (lockPendingImageList)
            {
                _pendingImageRequests.TryGetValue(imageMsg.token.requestID, out pendingImage);
            }
            if (pendingImage != null)
            {
                //Update distortion data, if changed
                if ((_currentDistortionData.Version != imageMsg.matrix_version) || !_currentDistortionData.IsValid)
                {
                    _currentDistortionData         = new DistortionData();
                    _currentDistortionData.Version = imageMsg.matrix_version;
                    _currentDistortionData.Width   = LeapC.DistortionSize; //fixed value for now
                    _currentDistortionData.Height  = LeapC.DistortionSize; //fixed value for now
                    if (_currentDistortionData.Data == null || _currentDistortionData.Data.Length != (2 * _currentDistortionData.Width * _currentDistortionData.Height * 2))
                    {
                        _currentDistortionData.Data = new float[(int)(2 * _currentDistortionData.Width * _currentDistortionData.Height * 2)]; //2 float values per map point
                    }
                    LEAP_DISTORTION_MATRIX matrix = LeapC.PtrToStruct <LEAP_DISTORTION_MATRIX>(imageMsg.distortionMatrix);
                    Array.Copy(matrix.matrix_data, _currentDistortionData.Data, matrix.matrix_data.Length);
                    this.LeapDistortionChange.Dispatch <DistortionEventArgs>(this, new DistortionEventArgs(_currentDistortionData));
                }

                pendingImage.imageData.CompleteImageData(props.type,
                                                         props.format,
                                                         props.bpp,
                                                         props.width,
                                                         props.height,
                                                         imageMsg.info.timestamp,
                                                         imageMsg.info.frame_id,
                                                         props.x_offset,
                                                         props.y_offset,
                                                         props.x_scale,
                                                         props.y_scale,
                                                         _currentDistortionData,
                                                         LeapC.DistortionSize,
                                                         imageMsg.matrix_version);

                Image completedImage = pendingImage.imageObject;
                lock (lockPendingImageList)
                {
                    _pendingImageRequests.Remove(imageMsg.token.requestID);
                }
                this.LeapImageReady.Dispatch <ImageEventArgs>(this, new ImageEventArgs(completedImage));
            }
        }
コード例 #4
0
        public uint GetConfigValue(string config_key)
        {
            lock (_connLocker) {
                uint requestId = 0;
                if (_leapConnection == IntPtr.Zero)
                {
                    return(requestId);
                }

                eLeapRS result = LeapC.RequestConfigValue(_leapConnection, config_key, out requestId);
                reportAbnormalResults("LeapC RequestConfigValue call was ", result);
                _configRequests [requestId] = config_key;
                return(requestId);
            }
        }
コード例 #5
0
        public int purgeAll(IntPtr connection)
        {
            int purgeCount = 0;

            lock (_locker)
            {
                purgeCount = _pending.Count;
                for (int i = 0; i < _pending.Count; i++)
                {
                    LeapC.CancelImageFrameRequest(connection, _pending[i].Token);
                }
                _pending.Clear();
            }
            return(purgeCount);
        }
コード例 #6
0
        public void ClearPolicy(Controller.PolicyFlag policy)
        {
            lock (_connLocker) {
                if (_leapConnection == IntPtr.Zero)
                {
                    return;
                }

                UInt64 clearFlags = (ulong)flagForPolicy(policy);
                _requestedPolicies = _requestedPolicies & ~clearFlags;
                eLeapRS result = eLeapRS.eLeapRS_UnknownError;
                result = LeapC.SetPolicyFlags(_leapConnection, 0, clearFlags);
                reportAbnormalResults("LeapC SetPolicyFlags call was ", result);
            }
        }
コード例 #7
0
        public Hand makeHand(ref LEAP_HAND hand, Frame owningFrame)
        {
            LEAP_BONE arm    = LeapC.PtrToStruct <LEAP_BONE>(hand.arm);
            Arm       newArm = makeArm(ref arm);
            LEAP_PALM palm   = LeapC.PtrToStruct <LEAP_PALM>(hand.palm);

            Hand newHand = new Hand(
                (int)owningFrame.Id,
                (int)hand.id,
                hand.confidence,
                hand.grab_strength,
                hand.grab_angle,
                hand.pinch_strength,
                hand.pinch_distance,
                palm.width,
                hand.type == eLeapHandType.eLeapHandType_Left,
                hand.visible_time,
                newArm,
                new List <Finger>(5),
                new Vector(palm.position.x, palm.position.y, palm.position.z),
                new Vector(palm.stabilized_position.x, palm.stabilized_position.y, palm.stabilized_position.z),
                new Vector(palm.velocity.x, palm.velocity.y, palm.velocity.z),
                new Vector(palm.normal.x, palm.normal.y, palm.normal.z),
                new Vector(palm.direction.x, palm.direction.y, palm.direction.z),
                newArm.NextJoint //wrist position
                );
            LEAP_DIGIT thumbDigit = LeapC.PtrToStruct <LEAP_DIGIT>(hand.thumb);

            newHand.Fingers.Insert(0, makeFinger(owningFrame, ref hand, ref thumbDigit, Finger.FingerType.TYPE_THUMB));

            LEAP_DIGIT indexDigit = LeapC.PtrToStruct <LEAP_DIGIT>(hand.index);

            newHand.Fingers.Insert(1, makeFinger(owningFrame, ref hand, ref indexDigit, Finger.FingerType.TYPE_INDEX));

            LEAP_DIGIT middleDigit = LeapC.PtrToStruct <LEAP_DIGIT>(hand.middle);

            newHand.Fingers.Insert(2, makeFinger(owningFrame, ref hand, ref middleDigit, Finger.FingerType.TYPE_MIDDLE));

            LEAP_DIGIT ringDigit = LeapC.PtrToStruct <LEAP_DIGIT>(hand.ring);

            newHand.Fingers.Insert(3, makeFinger(owningFrame, ref hand, ref ringDigit, Finger.FingerType.TYPE_RING));

            LEAP_DIGIT pinkyDigit = LeapC.PtrToStruct <LEAP_DIGIT>(hand.pinky);

            newHand.Fingers.Insert(4, makeFinger(owningFrame, ref hand, ref pinkyDigit, Finger.FingerType.TYPE_PINKY));

            return(newHand);
        }
コード例 #8
0
        public void GetInterpolatedFrameFromTime(Frame toFill, long time, long sourceTime)
        {
            ulong   interpolatedFrameSize = this.GetInterpolatedFrameSize(time);
            IntPtr  pEvent = Marshal.AllocHGlobal((int)interpolatedFrameSize);
            eLeapRS result = LeapC.InterpolateFrameFromTime(this._leapConnection, time, sourceTime, pEvent, interpolatedFrameSize);

            this.reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
            if (result == eLeapRS.eLeapRS_Success)
            {
                LEAP_TRACKING_EVENT leap_tracking_event;
                StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(pEvent, out leap_tracking_event);

                toFill.CopyFrom(ref leap_tracking_event);
            }
            Marshal.FreeHGlobal(pEvent);
        }
コード例 #9
0
ファイル: Connection.cs プロジェクト: LABSIM/APOLLON
        public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime)
        {
            UInt64  size           = GetInterpolatedFrameSize(time);
            IntPtr  trackingBuffer = Marshal.AllocHGlobal((Int32)size);
            eLeapRS result         = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);

            reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
            if (result == eLeapRS.eLeapRS_Success)
            {
                LEAP_TRACKING_EVENT tracking_evt;
                StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(trackingBuffer, out tracking_evt);

                toFill.CopyFrom(ref tracking_evt);
            }
            Marshal.FreeHGlobal(trackingBuffer);
        }
コード例 #10
0
ファイル: Connection.cs プロジェクト: hirenkumawat/DriveSuite
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
            }

            Stop();
            LeapC.DestroyConnection(_leapConnection);

            _disposed = true;
        }
コード例 #11
0
        public void Start()
        {
            if (_isRunning)
            {
                return;
            }

            eLeapRS result;

            if (_leapConnection == IntPtr.Zero)
            {
                result = LeapC.CreateConnection(out _leapConnection);
                if (result != eLeapRS.eLeapRS_Success || _leapConnection == IntPtr.Zero)
                {
                    reportAbnormalResults("LeapC CreateConnection call was ", result);
                    return;
                }
            }
            result = LeapC.OpenConnection(_leapConnection);
            if (result != eLeapRS.eLeapRS_Success)
            {
                reportAbnormalResults("LeapC OpenConnection call was ", result);
                return;
            }
            // The Allocator must persist the lifetime of the connection
            if (_pLeapAllocator.allocate == null)
            {
                _pLeapAllocator.allocate = _memoryManager.Pin;
            }
            if (_pLeapAllocator.deallocate == null)
            {
                _pLeapAllocator.deallocate = _memoryManager.Unpin;
            }
            LeapC.SetAllocator(_leapConnection, ref _pLeapAllocator);

            _isRunning = true;
            //AppDomain.CurrentDomain.DomainUnload += (arg1, arg2) => Dispose(true);

#if UNITY_EDITOR
            _polster              = new Thread(new ThreadStart(this.processMessages));
            _polster.Name         = "LeapC Worker";
            _polster.IsBackground = true;
            _polster.Start();
#else
            _polster = Task.Run((Action)this.processMessages);
#endif
        }
コード例 #12
0
        public void Stop()
        {
            if (!_isRunning)
            {
                return;
            }

            _isRunning = false;

#if UNITY_EDITOR
            _polster.Join();
#else
            _polster.Wait();
#endif

            LeapC.CloseConnection(_leapConnection);
        }
コード例 #13
0
ファイル: Connection.cs プロジェクト: midgithub/MegaBookDome
 public void Start()
 {
     if (!_isRunning)
     {
         if (_leapConnection == IntPtr.Zero)
         {
             eLeapRS result = LeapC.CreateConnection(out _leapConnection);
             reportAbnormalResults("LeapC CreateConnection call was ", result);
             result = LeapC.OpenConnection(_leapConnection);
             reportAbnormalResults("LeapC OpenConnection call was ", result);
         }
         _isRunning            = true;
         _polster              = new Thread(new ThreadStart(this.processMessages));
         _polster.IsBackground = true;
         _polster.Start();
     }
 }
コード例 #14
0
        public void GetInterpolatedLeftRightTransform(long time, long sourceTime, long leftId, long rightId, out LeapTransform leftTransform, out LeapTransform rightTransform)
        {
            leftTransform  = LeapTransform.Identity;
            rightTransform = LeapTransform.Identity;
            ulong   interpolatedFrameSize = this.GetInterpolatedFrameSize(time);
            IntPtr  pEvent = Marshal.AllocHGlobal((int)interpolatedFrameSize);
            eLeapRS result = LeapC.InterpolateFrameFromTime(this._leapConnection, time, sourceTime, pEvent, interpolatedFrameSize);

            this.reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
            if (result == eLeapRS.eLeapRS_Success)
            {
                LEAP_TRACKING_EVENT leap_tracking_event;
                StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(pEvent, out leap_tracking_event);

                int  num3   = leap_tracking_event.pHands.ToInt32();
                int  num4   = num3 + _handIdOffset;
                int  num5   = num3 + _handPositionOffset;
                int  num6   = num3 + _handOrientationOffset;
                int  size   = StructMarshal <LEAP_HAND> .Size;
                uint nHands = leap_tracking_event.nHands;
                while (nHands-- != 0)
                {
                    LEAP_VECTOR     leap_vector;
                    LEAP_QUATERNION leap_quaternion;
                    int             num2 = Marshal.ReadInt32(new IntPtr(num4));
                    StructMarshal <LEAP_VECTOR> .PtrToStruct(new IntPtr(num5), out leap_vector);

                    StructMarshal <LEAP_QUATERNION> .PtrToStruct(new IntPtr(num6), out leap_quaternion);

                    LeapTransform transform = new LeapTransform(leap_vector.ToLeapVector(), leap_quaternion.ToLeapQuaternion());
                    if (num2 == leftId)
                    {
                        leftTransform = transform;
                    }
                    else if (num2 == rightId)
                    {
                        rightTransform = transform;
                    }
                    num4 += size;
                    num5 += size;
                    num6 += size;
                }
            }
            Marshal.FreeHGlobal(pEvent);
        }
コード例 #15
0
        private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg)
        {
            IntPtr deviceHandle = deviceMsg.device.handle;

            if (deviceHandle == IntPtr.Zero)
            {
                return;
            }

            LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO();
            eLeapRS          result;

            IntPtr device;

            result = LeapC.OpenDevice(deviceMsg.device, out device);
            uint defaultLength = 14;

            deviceInfo.serial_length = defaultLength;
            deviceInfo.serial        = Marshal.AllocCoTaskMem((int)defaultLength);
            deviceInfo.size          = (uint)Marshal.SizeOf(deviceInfo);
            result = LeapC.GetDeviceInfo(device, out deviceInfo);

            if (result == eLeapRS.eLeapRS_InsufficientBuffer)
            {
                Marshal.FreeCoTaskMem(deviceInfo.serial);
                deviceInfo.serial = Marshal.AllocCoTaskMem((int)deviceInfo.serial_length);
                deviceInfo.size   = (uint)Marshal.SizeOf(deviceInfo);
                result            = LeapC.GetDeviceInfo(deviceHandle, out deviceInfo);
            }

            if (result == eLeapRS.eLeapRS_Success)
            {
                Device apiDevice = new Device(deviceHandle,
                                              deviceInfo.h_fov,           //radians
                                              deviceInfo.v_fov,           //radians
                                              deviceInfo.range / 1000,    //to mm
                                              deviceInfo.baseline / 1000, //to mm
                                              (deviceInfo.caps == (UInt32)eLeapDeviceCaps.eLeapDeviceCaps_Embedded),
                                              (deviceInfo.status == (UInt32)eLeapDeviceStatus.eLeapDeviceStatus_Streaming),
                                              Marshal.PtrToStringAnsi(deviceInfo.serial));
                Marshal.FreeCoTaskMem(deviceInfo.serial);
                _devices.AddOrUpdate(apiDevice);
                this.LeapDevice.Dispatch(this, new DeviceEventArgs(apiDevice));
            }
        }
コード例 #16
0
        public Frame GetInterpolatedFrame(Int64 time)
        {
            UInt64  size           = GetInterpolatedFrameSize(time);
            IntPtr  trackingBuffer = Marshal.AllocHGlobal((Int32)size);
            eLeapRS result         = LeapC.InterpolateFrame(_leapConnection, time, trackingBuffer, size);

            reportAbnormalResults("LeapC get interpolated frame call was ", result);
            Frame frame = null;

            if (result == eLeapRS.eLeapRS_Success)
            {
                LEAP_TRACKING_EVENT tracking_evt = StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(trackingBuffer);

                frame = frameFactory.makeFrame(ref tracking_evt);
            }
            Marshal.FreeHGlobal(trackingBuffer);
            return(frame);
        }
コード例 #17
0
    public void Stop() {
      if (!_isRunning)
        return;

      _isRunning = false;

      //Very important to close the connection before we try to join the
      //worker thread!  The call to PollConnection can sometimes block,
      //despite the timeout, causing an attempt to join the thread waiting
      //forever and preventing the connection from stopping.
      //
      //It seems that closing the connection causes PollConnection to 
      //unblock in these cases, so just make sure to close the connection
      //before trying to join the worker thread.
      LeapC.CloseConnection(_leapConnection);

      _polster.Join();
    }
コード例 #18
0
        public void SetPolicy(Controller.PolicyFlag policy)
        {
            lock (_connLocker) {
                if (_leapConnection == IntPtr.Zero)
                {
                    return;
                }

                UInt64 setFlags = (ulong)flagForPolicy(policy);
                _requestedPolicies = _requestedPolicies | setFlags;
                setFlags           = _requestedPolicies;
                UInt64 clearFlags = ~_requestedPolicies; //inverse of desired policies

                eLeapRS result = eLeapRS.eLeapRS_UnknownError;
                result = LeapC.SetPolicyFlags(_leapConnection, setFlags, clearFlags);
                reportAbnormalResults("LeapC SetPolicyFlags call was ", result);
            }
        }
コード例 #19
0
    public void GetInterpolatedLeftRightTransform(Int64 time,
                                                  Int64 sourceTime,
                                                  Int64 leftId,
                                                  Int64 rightId,
                                              out LeapTransform leftTransform,
                                              out LeapTransform rightTransform) {
      leftTransform = LeapTransform.Identity;
      rightTransform = LeapTransform.Identity;

      UInt64 size = GetInterpolatedFrameSize(time);
      IntPtr trackingBuffer = Marshal.AllocHGlobal((Int32)size);
      eLeapRS result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
      reportAbnormalResults("LeapC get interpolated frame from time call was ", result);

      if (result == eLeapRS.eLeapRS_Success) {
        LEAP_TRACKING_EVENT tracking_evt;
        StructMarshal<LEAP_TRACKING_EVENT>.PtrToStruct(trackingBuffer, out tracking_evt);

        int id;
        LEAP_VECTOR position;
        LEAP_QUATERNION orientation;

        long handPtr = tracking_evt.pHands.ToInt64();
        long idPtr = handPtr + _handIdOffset;
        long posPtr = handPtr + _handPositionOffset;
        long rotPtr = handPtr + _handOrientationOffset;
        int stride = StructMarshal<LEAP_HAND>.Size;

        for (uint i = tracking_evt.nHands; i-- != 0; idPtr += stride, posPtr += stride, rotPtr += stride) {
          id = Marshal.ReadInt32(new IntPtr(idPtr));
          StructMarshal<LEAP_VECTOR>.PtrToStruct(new IntPtr(posPtr), out position);
          StructMarshal<LEAP_QUATERNION>.PtrToStruct(new IntPtr(rotPtr), out orientation);

          LeapTransform transform = new LeapTransform(position.ToLeapVector(), orientation.ToLeapQuaternion());
          if (id == leftId) {
            leftTransform = transform;
          } else if (id == rightId) {
            rightTransform = transform;
          }
        }
      }

      Marshal.FreeHGlobal(trackingBuffer);
    }
コード例 #20
0
 public uint SetConfigValue<T>(string config_key, T value) where T : IConvertible {
   uint requestId = 0;
   eLeapRS result;
   Type dataType = value.GetType();
   if (dataType == typeof(bool)) {
     result = LeapC.SaveConfigValue(_leapConnection, config_key, Convert.ToBoolean(value), out requestId);
   } else if (dataType == typeof(Int32)) {
     result = LeapC.SaveConfigValue(_leapConnection, config_key, Convert.ToInt32(value), out requestId);
   } else if (dataType == typeof(float)) {
     result = LeapC.SaveConfigValue(_leapConnection, config_key, Convert.ToSingle(value), out requestId);
   } else if (dataType == typeof(string)) {
     result = LeapC.SaveConfigValue(_leapConnection, config_key, Convert.ToString(value), out requestId);
   } else {
     throw new ArgumentException("Only boolean, Int32, float, and string types are supported.");
   }
   reportAbnormalResults("LeapC SaveConfigValue call was ", result);
   _configRequests[requestId] = config_key;
   return requestId;
 }
コード例 #21
0
        public int purgeOld(IntPtr connection)
        {
            Int64 now        = LeapC.GetNow();
            int   purgeCount = 0;

            lock (_locker){
                for (int i = _pending.Count - 1; i >= 0; i--)
                {
                    ImageFuture ir = _pending[i];
                    if ((now - ir.Timestamp) > pendingTimeLimit)
                    {
                        _pending.RemoveAt(i);
                        LeapC.CancelImageFrameRequest(connection, ir.Token);
                        purgeCount++;
                    }
                }
            }
            return(purgeCount);
        }
コード例 #22
0
    public void GetPointMapping(ref PointMapping pm) {
      UInt64 size = 0;
      IntPtr buffer = IntPtr.Zero;
      while (true) {
        eLeapRS result = LeapC.GetPointMapping(_leapConnection, buffer, ref size);
        if (result == eLeapRS.eLeapRS_InsufficientBuffer) {
          if (buffer != IntPtr.Zero)
            Marshal.FreeHGlobal(buffer);
          buffer = Marshal.AllocHGlobal((Int32)size);
          continue;
        }
        reportAbnormalResults("LeapC get point mapping call was ", result);
        if (result != eLeapRS.eLeapRS_Success) {
          pm.points = null;
          pm.ids = null;
          return;
        }
        break;
      }
      LEAP_POINT_MAPPING pmi;
      StructMarshal<LEAP_POINT_MAPPING>.PtrToStruct(buffer, out pmi);
      Int32 nPoints = (Int32)pmi.nPoints;

      pm.frameId = pmi.frame_id;
      pm.timestamp = pmi.timestamp;
      pm.points = new Vector[nPoints];
      pm.ids = new UInt32[nPoints];

      float[] points = new float[3 * nPoints];
      Int32[] ids = new Int32[nPoints];
      Marshal.Copy(pmi.points, points, 0, 3 * nPoints);
      Marshal.Copy(pmi.ids, ids, 0, nPoints);

      int j = 0;
      for (int i = 0; i < nPoints; i++) {
        pm.points[i].x = points[j++];
        pm.points[i].y = points[j++];
        pm.points[i].z = points[j++];
        pm.ids[i] = unchecked((UInt32)ids[i]);
      }
      Marshal.FreeHGlobal(buffer);
    }
コード例 #23
0
        public void Cleanup()
        {
            lock (_connLocker) {
                if (_leapConnection == IntPtr.Zero)
                {
                    return;
                }

                Logger.Log("Connection Stopping");
                _pendingImageRequestList.purgeAll(_leapConnection);
                LeapC.DestroyConnection(_leapConnection);
                _leapConnection = IntPtr.Zero;
                Logger.Log("Connection Stopped");

                // cleanup
                _configRequests.Clear();
                _requestedPolicies = 0;
                _activePolicies    = 0;
            }
        }
コード例 #24
0
        public Frame makeFrame(ref LEAP_TRACKING_EVENT trackingMsg)
        {
            Frame newFrame = new Leap.Frame((long)trackingMsg.info.frame_id,
                                            (long)trackingMsg.info.timestamp,
                                            trackingMsg.framerate,
                                            new InteractionBox(trackingMsg.interaction_box_center.ToLeapVector(),
                                                               trackingMsg.interaction_box_size.ToLeapVector()),
                                            new List <Hand>((int)trackingMsg.nHands)
                                            );

            int pHandArrayOffset = 0;

            for (int h = 0; h < trackingMsg.nHands; h++)
            {
                LEAP_HAND hand = LeapC.PtrToStruct <LEAP_HAND>(new IntPtr(trackingMsg.pHands.ToInt64() + pHandArrayOffset));
                pHandArrayOffset += handStructSize;
                newFrame.Hands.Add(makeHand(ref hand, newFrame));
            }
            return(newFrame);
        }
コード例 #25
0
ファイル: Connection.cs プロジェクト: LABSIM/APOLLON
        public void TelemetryProfiling(ref LEAP_TELEMETRY_DATA telemetryData)
        {
            eLeapRS result = LeapC.LeapTelemetryProfiling(_leapConnection, ref telemetryData);

            reportAbnormalResults("LeapC TelemetryProfiling call was ", result);
        }
コード例 #26
0
        private Image RequestImages(ImageData imageData)
        {
            lock (_connLocker) {
                if (_leapConnection == IntPtr.Zero)
                {
                    return(Image.Invalid);
                }

                LEAP_IMAGE_FRAME_DESCRIPTION imageSpecifier = new LEAP_IMAGE_FRAME_DESCRIPTION();
                imageSpecifier.frame_id   = imageData.frame_id;
                imageSpecifier.type       = imageData.type;
                imageSpecifier.pBuffer    = imageData.getPinnedHandle();
                imageSpecifier.buffer_len = (ulong)imageData.pixelBuffer.LongLength;
                LEAP_IMAGE_FRAME_REQUEST_TOKEN token;
                eLeapRS result = eLeapRS.eLeapRS_UnknownError;

                result = LeapC.RequestImages(_leapConnection, ref imageSpecifier, out token);

                if (result == eLeapRS.eLeapRS_Success)
                {
                    imageData.isComplete = false;
                    imageData.index      = token.requestID;
                    Image futureImage = new Image(imageData);
                    _pendingImageRequestList.Add(new ImageFuture(futureImage, imageData, LeapC.GetNow(), token));
                    return(futureImage);
                }
                else
                {
                    imageData.unPinHandle();
                    reportAbnormalResults("LeapC Image Request call was ", result);
                    return(Image.Invalid);
                }
            }
        }
コード例 #27
0
ファイル: Connection.cs プロジェクト: LABSIM/APOLLON
        //Run in Polster thread, fills in object queues
        private void processMessages()
        {
            //Only profiling block currently is the Handle Event block
            const string HANDLE_EVENT_PROFILER_BLOCK = "Handle Event";
            bool         hasBegunProfilingForThread  = false;

            try
            {
                eLeapRS result;
                _leapInit.DispatchOnContext(this, EventContext, new LeapEventArgs(LeapEvent.EVENT_INIT));
                while (_isRunning)
                {
                    if (LeapBeginProfilingForThread != null && !hasBegunProfilingForThread)
                    {
                        LeapBeginProfilingForThread(new BeginProfilingForThreadArgs("Worker Thread",
                                                                                    HANDLE_EVENT_PROFILER_BLOCK));
                        hasBegunProfilingForThread = true;
                    }

                    LEAP_CONNECTION_MESSAGE _msg = new LEAP_CONNECTION_MESSAGE();
                    uint timeout = 150;
                    result = LeapC.PollConnection(_leapConnection, timeout, ref _msg);

                    if (result != eLeapRS.eLeapRS_Success)
                    {
                        reportAbnormalResults("LeapC PollConnection call was ", result);
                        continue;
                    }

                    if (LeapBeginProfilingBlock != null && hasBegunProfilingForThread)
                    {
                        LeapBeginProfilingBlock(new BeginProfilingBlockArgs(HANDLE_EVENT_PROFILER_BLOCK));
                    }

                    switch (_msg.type)
                    {
                    case eLeapEventType.eLeapEventType_None:
                        break;

                    case eLeapEventType.eLeapEventType_Connection:
                        LEAP_CONNECTION_EVENT connection_evt;
                        StructMarshal <LEAP_CONNECTION_EVENT> .PtrToStruct(_msg.eventStructPtr, out connection_evt);

                        handleConnection(ref connection_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConnectionLost:
                        LEAP_CONNECTION_LOST_EVENT connection_lost_evt;
                        StructMarshal <LEAP_CONNECTION_LOST_EVENT> .PtrToStruct(_msg.eventStructPtr, out connection_lost_evt);

                        handleConnectionLost(ref connection_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Device:
                        LEAP_DEVICE_EVENT device_evt;
                        StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr, out device_evt);

                        handleDevice(ref device_evt);
                        break;

                    // Note that unplugging a device generates an eLeapEventType_DeviceLost event
                    // message, not a failure message. DeviceLost is further down.
                    case eLeapEventType.eLeapEventType_DeviceFailure:
                        LEAP_DEVICE_FAILURE_EVENT device_failure_evt;
                        StructMarshal <LEAP_DEVICE_FAILURE_EVENT> .PtrToStruct(_msg.eventStructPtr, out device_failure_evt);

                        handleFailedDevice(ref device_failure_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Policy:
                        LEAP_POLICY_EVENT policy_evt;
                        StructMarshal <LEAP_POLICY_EVENT> .PtrToStruct(_msg.eventStructPtr, out policy_evt);

                        handlePolicyChange(ref policy_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Tracking:
                        LEAP_TRACKING_EVENT tracking_evt;
                        StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(_msg.eventStructPtr, out tracking_evt);

                        handleTrackingMessage(ref tracking_evt);
                        break;

                    case eLeapEventType.eLeapEventType_LogEvent:
                        LEAP_LOG_EVENT log_evt;
                        StructMarshal <LEAP_LOG_EVENT> .PtrToStruct(_msg.eventStructPtr, out log_evt);

                        reportLogMessage(ref log_evt);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceLost:
                        LEAP_DEVICE_EVENT device_lost_evt;
                        StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr, out device_lost_evt);

                        handleLostDevice(ref device_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigChange:
                        LEAP_CONFIG_CHANGE_EVENT config_change_evt;
                        StructMarshal <LEAP_CONFIG_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr, out config_change_evt);

                        handleConfigChange(ref config_change_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigResponse:
                        handleConfigResponse(ref _msg);
                        break;

                    case eLeapEventType.eLeapEventType_DroppedFrame:
                        LEAP_DROPPED_FRAME_EVENT dropped_frame_evt;
                        StructMarshal <LEAP_DROPPED_FRAME_EVENT> .PtrToStruct(_msg.eventStructPtr, out dropped_frame_evt);

                        handleDroppedFrame(ref dropped_frame_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Image:
                        LEAP_IMAGE_EVENT image_evt;
                        StructMarshal <LEAP_IMAGE_EVENT> .PtrToStruct(_msg.eventStructPtr, out image_evt);

                        handleImage(ref image_evt);
                        break;

                    case eLeapEventType.eLeapEventType_PointMappingChange:
                        LEAP_POINT_MAPPING_CHANGE_EVENT point_mapping_change_evt;
                        StructMarshal <LEAP_POINT_MAPPING_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr, out point_mapping_change_evt);

                        handlePointMappingChange(ref point_mapping_change_evt);
                        break;

                    case eLeapEventType.eLeapEventType_HeadPose:
                        LEAP_HEAD_POSE_EVENT head_pose_event;
                        StructMarshal <LEAP_HEAD_POSE_EVENT> .PtrToStruct(_msg.eventStructPtr, out head_pose_event);

                        handleHeadPoseChange(ref head_pose_event);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceStatusChange:
                        LEAP_DEVICE_STATUS_CHANGE_EVENT status_evt;
                        StructMarshal <LEAP_DEVICE_STATUS_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr, out status_evt);

                        handleDeviceStatusEvent(ref status_evt);
                        break;
                    } //switch on _msg.type

                    if (LeapEndProfilingBlock != null && hasBegunProfilingForThread)
                    {
                        LeapEndProfilingBlock(new EndProfilingBlockArgs(HANDLE_EVENT_PROFILER_BLOCK));
                    }
                } //while running
            }
            catch (Exception e)
            {
                Logger.Log("Exception: " + e);
                _isRunning = false;
            }
            finally
            {
                if (LeapEndProfilingForThread != null && hasBegunProfilingForThread)
                {
                    LeapEndProfilingForThread(new EndProfilingForThreadArgs());
                }
            }
        }
コード例 #28
0
        //Run in Polster thread, fills in object queues
        private void processMessages()
        {
            try
            {
                eLeapRS result;
                _leapInit.Dispatch <LeapEventArgs>(this, new LeapEventArgs(LeapEvent.EVENT_INIT));
                while (true)
                {
                    LEAP_CONNECTION_MESSAGE _msg = new LEAP_CONNECTION_MESSAGE();
                    lock (_connLocker) {
                        if (_leapConnection == IntPtr.Zero)
                        {
                            break;
                        }
                        uint timeout = 1000;
                        result = LeapC.PollConnection(_leapConnection, timeout, ref _msg);
                    }

                    if (result != eLeapRS.eLeapRS_Success)
                    {
                        reportAbnormalResults("LeapC PollConnection call was ", result);
                        continue;
                    }

                    switch (_msg.type)
                    {
                    case eLeapEventType.eLeapEventType_Connection:
                        LEAP_CONNECTION_EVENT connection_evt = StructMarshal <LEAP_CONNECTION_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConnection(ref connection_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConnectionLost:
                        LEAP_CONNECTION_LOST_EVENT connection_lost_evt = StructMarshal <LEAP_CONNECTION_LOST_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConnectionLost(ref connection_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Device:
                        LEAP_DEVICE_EVENT device_evt = StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleDevice(ref device_evt);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceLost:
                        LEAP_DEVICE_EVENT device_lost_evt = StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleLostDevice(ref device_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceFailure:
                        LEAP_DEVICE_FAILURE_EVENT device_failure_evt = StructMarshal <LEAP_DEVICE_FAILURE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleFailedDevice(ref device_failure_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Tracking:
                        LEAP_TRACKING_EVENT tracking_evt = StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleTrackingMessage(ref tracking_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ImageComplete:
                        completeCount++;
                        LEAP_IMAGE_COMPLETE_EVENT image_complete_evt = StructMarshal <LEAP_IMAGE_COMPLETE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleImageCompletion(ref image_complete_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ImageRequestError:
                        failedCount++;
                        LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT failed_image_evt = StructMarshal <LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleFailedImageRequest(ref failed_image_evt);
                        break;

                    case eLeapEventType.eLeapEventType_LogEvent:
                        LEAP_LOG_EVENT log_evt = StructMarshal <LEAP_LOG_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        reportLogMessage(ref log_evt);
                        break;

                    case eLeapEventType.eLeapEventType_PolicyChange:
                        LEAP_POLICY_EVENT policy_evt = StructMarshal <LEAP_POLICY_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handlePolicyChange(ref policy_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigChange:
                        LEAP_CONFIG_CHANGE_EVENT config_change_evt = StructMarshal <LEAP_CONFIG_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConfigChange(ref config_change_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigResponse:
                        handleConfigResponse(ref _msg);
                        break;

                    default:
                        //discard unknown message types
                        Logger.Log("Unhandled message type " + Enum.GetName(typeof(eLeapEventType), _msg.type));
                        break;
                    } //switch on _msg.type
                }     //while running
            }
            catch (Exception e)
            {
                Logger.Log("Exception: " + e);
                this.Cleanup();
            }
        }
コード例 #29
0
ファイル: Connection.cs プロジェクト: LABSIM/APOLLON
        public void GetInterpolatedHeadPose(ref LEAP_HEAD_POSE_EVENT toFill, Int64 time)
        {
            eLeapRS result = LeapC.InterpolateHeadPose(_leapConnection, time, ref toFill);

            reportAbnormalResults("LeapC get interpolated head pose call was ", result);
        }
コード例 #30
0
ファイル: Connection.cs プロジェクト: midgithub/MegaBookDome
 /**
  * Returns a timestamp value as close as possible to the current time.
  * Values are in microseconds, as with all the other timestamp values.
  *
  * @since 2.2.7
  *
  */
 public long Now()
 {
     return(LeapC.GetNow());
 }