예제 #1
0
        private void InitializeRender(viz.Context context, EventTypePluginData data)
        {
            Debug.Assert(data != null);

            lock (this.lockObj)
            {
                Debug.Assert(data.rampTexture3d == null);
                Debug.Assert(data.rampTexture2d == null);

                if (context != null)
                {
                    BodyIndexPlugin.CreateTextures(data, context);

                    // 2D ramp texture is different from 3D ramp texture for visualization with skeleton
                    uint[] rampData = new uint[BodyIndexPlugin.cRampTextureLength];
                    rampData[0] = 0xFFFF0000;
                    rampData[1] = 0xFF00FF00;
                    rampData[2] = 0xFF40FFFF;
                    rampData[3] = 0xFFFFFF40;
                    rampData[4] = 0xFFFF40FF;
                    rampData[5] = 0xFF8080FF;
                    for (int i = 6; i < rampData.Length; ++i)
                    {
                        rampData[i] = 0xFFFFFFFF;
                    }

                    data.rampTexture3d = new viz.Texture(context, (uint)rampData.Length, 1, viz.TextureFormat.B8G8R8A8_UNORM, false);

                    unsafe
                    {
                        fixed(uint *pRampData = rampData)
                        {
                            data.rampTexture3d.UpdateData((byte *)pRampData, (uint)rampData.Length * sizeof(uint));
                        }
                    }

                    rampData[0] = 0xC0FF0000;
                    rampData[1] = 0xC000FF00;
                    rampData[2] = 0xC040FFFF;
                    rampData[3] = 0xC0FFFF40;
                    rampData[4] = 0xC0FF40FF;
                    rampData[5] = 0xC08080FF;
                    for (int i = 6; i < rampData.Length; i++)
                    {
                        rampData[i] = 0xFF000000;
                    }

                    data.rampTexture2d = new viz.Texture(context, (uint)rampData.Length, 1, viz.TextureFormat.B8G8R8A8_UNORM, false);

                    unsafe
                    {
                        fixed(uint *pRampData = rampData)
                        {
                            data.rampTexture2d.UpdateData((byte *)pRampData, (uint)rampData.Length * sizeof(uint));
                        }
                    }
                }
            }
        }
예제 #2
0
        private void HandleEvent(KStudioEvent eventObj, EventTypePluginData data, EventType eventType)
        {
            if ((eventObj != null) && (data != null))
            {
                if ((eventObj.EventStreamDataTypeId == KStudioEventStreamDataTypeIds.BodyIndex) ||
                    (eventObj.EventStreamDataTypeId == HackKStudioEventStreamDataTypeIds.BodyIndexMonitor))
                {
                    bool doDataEvent    = false;
                    bool doVisibleEvent = false;

                    lock (this.lockObj)
                    {
                        bool isSelectedData = (this.selectedData == data);

                        HGlobalBuffer newSharedFrame = eventObj.GetRetainableEventDataBuffer();
                        doVisibleEvent            = isSelectedData && (newSharedFrame == null) != (data.sharedBodyIndexFrame == null);
                        data.sharedBodyIndexFrame = newSharedFrame;

                        uint newWidth  = nui.Constants.STREAM_BODY_INDEX_WIDTH;
                        uint newHeight = nui.Constants.STREAM_BODY_INDEX_HEIGHT;

                        if ((data.rawBodyIndexTexture == null) || (newWidth != data.imageWidth) || (newHeight != data.imageHeight))
                        {
                            data.imageWidth  = newWidth;
                            data.imageHeight = newHeight;

                            viz.Context context = null;
                            if (this.pluginService != null)
                            {
                                context = this.pluginService.GetContext(eventType);
                            }

                            if (context != null)
                            {
                                BodyIndexPlugin.CreateTextures(data, context);
                            }
                        }

                        if (BodyIndexPlugin.UpdateSelectedPixelValue(data))
                        {
                            doDataEvent = isSelectedData;
                        }
                    }

                    if (doVisibleEvent)
                    {
                        this.RaisePropertyChanged("HasSelected2DPixelData");
                    }

                    if (doDataEvent)
                    {
                        this.RaisePropertyChanged("Selected2DPixelBodyIndex");
                    }
                }
            }
        }