public void InitializeRender(EventType eventType, viz.Context context) { switch (eventType) { case EventType.Monitor: Debug.Assert(this.monitorData != null); if ((this.monitorData.imageWidth != 0) && (this.monitorData.imageHeight != 0) && (this.monitorData.sharedDepthFrame != null)) { DepthPlugin.CreateTextures(this.monitorData, context); if (this.monitorData.depthMap != null) { unsafe { this.monitorData.depthMap.UpdateData((ushort *)this.monitorData.sharedDepthFrame.Buffer, this.monitorData.sharedDepthFrame.Size); } } } break; case EventType.Inspection: Debug.Assert(this.inspectionData != null); if ((this.inspectionData.imageWidth != 0) && (this.inspectionData.imageHeight != 0) && (this.inspectionData.sharedDepthFrame != null)) { DepthPlugin.CreateTextures(this.inspectionData, context); if (this.inspectionData.depthMap != null) { unsafe { this.inspectionData.depthMap.UpdateData((ushort *)this.inspectionData.sharedDepthFrame.Buffer, this.inspectionData.sharedDepthFrame.Size); } } } break; } }
protected virtual void Dispose(bool disposing) { if (disposing) { lock (this.lockObj) { DepthPlugin.DisposeData(this.monitorData, true); DepthPlugin.DisposeData(this.inspectionData, true); } } }
private void UpdatePropertyView(double x, double y, uint width, uint height, EventTypePluginData data) { Debug.Assert(data != null); bool doEvent = false; lock (this.lockObj) { if (this.selectedData != data) { doEvent = true; this.selectedData = data; } data.selected2DPixelX = 0; data.selected2DPixelY = 0; data.selected2DPixelDepth = 0; if (width == data.imageWidth) { data.selected2DPixelX = (uint)x; } else { data.selected2DPixelX = (uint)((x / width) * data.imageWidth); } if (height == data.imageHeight) { data.selected2DPixelY = (uint)y; } else { data.selected2DPixelY = (uint)((y / height) * data.imageHeight); } DepthPlugin.UpdateSelectedPixelValue(data); } this.RaisePropertyChanged("Selected2DPixelX"); this.RaisePropertyChanged("Selected2DPixelY"); this.RaisePropertyChanged("Selected2DPixelDepth"); if (doEvent) { this.RaisePropertyChanged("HasSelected2DPixelData"); } }
public void UninitializeRender(EventType eventType) { lock (this.lockObj) { switch (eventType) { case EventType.Monitor: Debug.Assert(this.monitorData != null); DepthPlugin.DisposeData(this.monitorData, false); break; case EventType.Inspection: Debug.Assert(this.inspectionData != null); DepthPlugin.DisposeData(this.inspectionData, false); break; } } }
public void Render3D(EventType eventType, IPluginViewSettings pluginViewSettings, viz.Context context, viz.Texture texture) { lock (this.lockObj) { EventTypePluginData data = null; nui.Registration registration = null; switch (eventType) { case EventType.Monitor: data = this.monitorData; break; case EventType.Inspection: data = this.inspectionData; break; } if (data != null) { if (this.pluginService != null) { registration = this.pluginService.GetRegistration(eventType); if (data.lastRegistration != registration) { data.lastRegistration = this.pluginService.GetRegistration(eventType); if ((data.lastRegistration != null) && (data.depthMap != null)) { uint xyTableSize; IntPtr xyTable = data.lastRegistration.GetXYTable(out xyTableSize); data.depthMap.UpdateXYTable(xyTable, xyTableSize); } } } DepthPlugin.Render3D(pluginViewSettings, texture, data, registration); } } }
private viz.Texture GetTexture(IPluginViewSettings pluginViewSettings, EventTypePluginData data) { Debug.Assert(data != null); viz.Texture value = null; lock (this.lockObj) { if (data.sharedDepthFrame != null) { DepthPlugin2DViewSettings depth2DSettingsViewSettings = pluginViewSettings as DepthPlugin2DViewSettings; if (depth2DSettingsViewSettings != null) { DepthPlugin.UpdateData(depth2DSettingsViewSettings, data); value = data.depthTexture; } } } return(value); }
// object owning data should be locked private static void Render3D(IPluginViewSettings pluginViewSettings, viz.Texture texture, EventTypePluginData data, nui.Registration registration) { Debug.Assert(data != null); DepthPlugin3DViewSettings depthPlugin3DViewSettings = pluginViewSettings as DepthPlugin3DViewSettings; if ((registration != null) && (depthPlugin3DViewSettings != null)) { DepthPlugin.UpdateData(depthPlugin3DViewSettings, texture, data); bool doColor = false; bool doBodyIndex = false; if (texture != null) { uint textureWidth = texture.GetWidth(); uint textureHeight = texture.GetHeight(); doColor = (textureWidth == nui.Constants.STREAM_COLOR_WIDTH) && (textureHeight == nui.Constants.STREAM_COLOR_HEIGHT); doBodyIndex = (texture.GetTextureFormat() == viz.TextureFormat.B8G8R8A8_UNORM) && (textureWidth == nui.Constants.STREAM_DEPTH_WIDTH) && (textureHeight == nui.Constants.STREAM_DEPTH_HEIGHT); } if ((depthPlugin3DViewSettings.IsSupplyingSurface && doBodyIndex) || (!depthPlugin3DViewSettings.IsSupplyingSurface && depthPlugin3DViewSettings.ViewType == DepthPlugin3DViewSettings.Depth3DViewType.SurfaceNormal)) { if (data.depthMap != null) { // special case for body index viz.Effect effect = new viz.Effect() { Direction = new viz.Vector(0.5f, 0.3f, 1.5f, 0), Ambient = new viz.Vector(0.0f, 0.0f, 0.0f, 1.0f), Diffuse = new viz.Vector(0.5f, 0.5f, 0.5f, 1.0f), Specular = new viz.Vector(1.0f, 1.0f, 1.0f, 1.0f), Power = 25.0f, EnableLighting = true, EnableTexture = false, }; if ((depthPlugin3DViewSettings.IsSupplyingSurface && doBodyIndex)) { if (data.depthMap != null) { data.depthMap.SetMode(viz.DepthVertexMode.SurfaceWithNormal, viz.DepthRampMode.None); effect.EnableTexture = true; } } if (!depthPlugin3DViewSettings.IsSupplyingSurface) { texture = null; } data.depthMap.Render(effect, texture); } } else { if (depthPlugin3DViewSettings.IsSupplyingSurface && doColor) { // special case for color if ((registration != null) && (data.depthMap != null) && (data.uvTable != null) && (data.sharedDepthFrame != null)) { data.depthMap.SetMode(viz.DepthVertexMode.SurfaceWithUV, viz.DepthRampMode.None); IntPtr ptr = data.sharedDepthFrame.Buffer; if (ptr != IntPtr.Zero) { registration.Process(ptr, data.uvTable.Buffer); } data.depthMap.UpdateUVTable(data.uvTable.Buffer, data.uvTable.Size); } } if (data.depthMap != null) { viz.Effect effect = new viz.Effect() { EnableTexture = texture != null, }; data.depthMap.Render(effect, texture); } } } }
private void HandleEvent(EventType eventType, KStudioEvent eventObj, EventTypePluginData data) { Debug.Assert(data != null); if (eventObj != null) { bool doDataEvent = false; bool doVisibleEvent = false; if ((eventObj.EventStreamDataTypeId == KStudioEventStreamDataTypeIds.Depth) || (eventObj.EventStreamDataTypeId == HackKStudioEventStreamDataTypeIds.DepthMonitor)) { lock (this.lockObj) { bool isSelectedData = (this.selectedData == data); HGlobalBuffer newSharedFrame = eventObj.GetRetainableEventDataBuffer(); doVisibleEvent = isSelectedData && (newSharedFrame == null) != (data.sharedDepthFrame == null); data.sharedDepthFrame = newSharedFrame; uint newWidth = nui.Constants.STREAM_DEPTH_WIDTH; uint newHeight = nui.Constants.STREAM_DEPTH_HEIGHT; if ((data.depthMap == null) || (newWidth != data.imageWidth) || (newHeight != data.imageHeight)) { viz.Context context = null; if (this.pluginService != null) { context = this.pluginService.GetContext(eventType); } data.imageWidth = newWidth; data.imageHeight = newHeight; DepthPlugin.CreateTextures(data, context); } if (data.sharedDepthFrame != null) { unsafe { data.depthMap.UpdateData((ushort *)data.sharedDepthFrame.Buffer, data.sharedDepthFrame.Size); } } if (DepthPlugin.UpdateSelectedPixelValue(data)) { doDataEvent = isSelectedData; } } if (doVisibleEvent) { this.RaisePropertyChanged("HasSelected2DPixelData"); } if (doDataEvent) { this.RaisePropertyChanged("Selected2DPixelDepth"); } } } }