public void CompleteImageData(eLeapImageType type, eLeapImageFormat format, UInt32 bpp, UInt32 width, UInt32 height, Int64 timestamp, Int64 frame_id, float x_offset, float y_offset, float x_scale, float y_scale, DistortionData distortionData, int distortion_size, UInt64 distortion_matrix_version) { lock (locker) { this.type = type; this.format = format; this.bpp = bpp; this.width = width; this.height = height; this.timestamp = timestamp; this.frame_id = frame_id; this.DistortionData = distortionData; this.DistortionSize = distortion_size; this.DistortionMatrixKey = distortion_matrix_version; isComplete = true; } }
private void handleImageCompletion(ref LEAP_IMAGE_COMPLETE_EVENT imageMsg) { LEAP_IMAGE_PROPERTIES props; StructMarshal <LEAP_IMAGE_PROPERTIES> .PtrToStruct(imageMsg.properties, out props); ImageFuture pendingImage = _pendingImageRequestList.FindAndRemove(imageMsg.token); if (pendingImage == null) { return; } //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; StructMarshal <LEAP_DISTORTION_MATRIX> .PtrToStruct(imageMsg.distortionMatrix, out matrix); Array.Copy(matrix.matrix_data, _currentDistortionData.Data, matrix.matrix_data.Length); if (LeapDistortionChange != null) { LeapDistortionChange.DispatchOnContext <DistortionEventArgs>(this, EventContext, 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; if (LeapImageReady != null) { LeapImageReady.DispatchOnContext <ImageEventArgs>(this, EventContext, new ImageEventArgs(completedImage)); } }
public ImageData(Image.CameraType camera, LEAP_IMAGE image, DistortionData distortionData) { this.camera = camera; this._properties = image.properties; this.DistortionMatrixKey = image.matrix_version; this.DistortionData = distortionData; this._object = MemoryManager.GetPinnedObject(image.data); this.byteOffset = image.offset; }
private void OnEnable() { if (m_distortionData == null) { m_distortionData = new DistortionData(gameObject); } DistortionManager.Instance.Register(m_distortionData); }
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)); } }
public void Register(DistortionData distortionData) { if (distortionData.renderer == null) { return; } if (m_distortionDatas.Contains(distortionData)) { return; } m_distortionDatas.Add(distortionData); }
private void handleImage(ref LEAP_IMAGE_EVENT imageMsg) { if (LeapImage != null) { //Update distortion data, if changed if ((_currentLeftDistortionData.Version != imageMsg.leftImage.matrix_version) || !_currentLeftDistortionData.IsValid) { _currentLeftDistortionData = createDistortionData(imageMsg.leftImage, Image.CameraType.LEFT); } if ((_currentRightDistortionData.Version != imageMsg.rightImage.matrix_version) || !_currentRightDistortionData.IsValid) { _currentRightDistortionData = createDistortionData(imageMsg.rightImage, Image.CameraType.RIGHT); } ImageData leftImage = new ImageData(Image.CameraType.LEFT, imageMsg.leftImage, _currentLeftDistortionData); ImageData rightImage = new ImageData(Image.CameraType.RIGHT, imageMsg.rightImage, _currentRightDistortionData); Image stereoImage = new Image(imageMsg.info.frame_id, imageMsg.info.timestamp, leftImage, rightImage); LeapImage.DispatchOnContext(this, EventContext, new ImageEventArgs(stereoImage)); } }
private DistortionData createDistortionData(LEAP_IMAGE image, Image.CameraType camera) { DistortionData distortionData = new DistortionData(); distortionData.Version = image.matrix_version; distortionData.Width = LeapC.DistortionSize; //fixed value for now distortionData.Height = LeapC.DistortionSize; //fixed value for now //Visit LeapC.h for more details. We need to marshal the float data manually //since the distortion struct cannot be represented safely in c# distortionData.Data = new float[(int)(distortionData.Width * distortionData.Height * 2)]; //2 float values per map point Marshal.Copy(image.distortionMatrix, distortionData.Data, 0, distortionData.Data.Length); if (LeapDistortionChange != null) { LeapDistortionChange.DispatchOnContext(this, EventContext, new DistortionEventArgs(distortionData, camera)); } return distortionData; }
private DistortionData createDistortionData(LEAP_IMAGE image, Image.CameraType camera) { DistortionData distortionData = new DistortionData(); distortionData.Version = image.matrix_version; distortionData.Width = LeapC.DistortionSize; //fixed value for now distortionData.Height = LeapC.DistortionSize; //fixed value for now distortionData.Data = new float[(int)(distortionData.Width * distortionData.Height * 2)]; //2 float values per map point LEAP_DISTORTION_MATRIX matrix; StructMarshal <LEAP_DISTORTION_MATRIX> .PtrToStruct(image.distortionMatrix, out matrix); Array.Copy(matrix.matrix_data, distortionData.Data, matrix.matrix_data.Length); if (LeapDistortionChange != null) { LeapDistortionChange.DispatchOnContext <DistortionEventArgs>(this, EventContext, new DistortionEventArgs(distortionData, camera)); } return(distortionData); }
public void Unregister(DistortionData distortionData) { m_distortionDatas.Remove(distortionData); }