Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            var timer = new Timer();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 10;
            timer.Start();
            
            panel1.MouseMove += panel1_MouseMove;
            panel1.MouseDown += panel1_MouseDown;
            panel1.MouseUp += panel1_MouseUp;

            /* Create a new DirectCanvasFactory.  This is the root class 
             * where almost all resources are created */
            m_directCanvasFactory = new DirectCanvasFactory();

            /* Create a new WindowsFromsPresenter, passing it our factory 
             * and our Winforms control that we want to render to */
            m_presenter = new WindowsFormsPresenter(m_directCanvasFactory, panel1);

            m_d3dScene = new D3DScene(m_presenter);
            m_currentScene = m_d3dScene;

            _touchHandler = Factory.CreateHandler<Windows7.Multitouch.TouchHandler>(panel1);

            _touchHandler.TouchDown += OnTouchDownHandler;
            _touchHandler.TouchMove += OnTouchMoveHandler;
            _touchHandler.TouchUp += OnTouchUpHandler;
        }
Exemplo n.º 2
0
        public ThresholdEffect(DirectCanvasFactory directCanvas)
            : base(directCanvas)
        {
            SetShaderSource(GetResourceString(SHADER_RESOURCE_NAME, Assembly.GetExecutingAssembly()), SHADER_ENTRY);

            RegisterProperty<Color4>(TINTCOLOR_REGISTER);
            RegisterProperty<float>(MINTHRESHOLD_VALUE);
            RegisterProperty<float>(MAXTHRESHOLD_VALUE);
            Filter = ShaderEffectFilter.Point;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of the resource factory
        /// </summary>
        /// <param name="canvas">The DirectCanvasFactory this factory belongs to</param>
        public ResourceFactory(DirectCanvasFactory canvas)
        {
            m_directCanvasFactory = canvas;
            m_textureResourceOwner = new RenderTargetTexture(m_directCanvasFactory.DeviceContext.Device, 
                                                             MINIMUM_RENDERTARGET_WIDTH, 
                                                             MINIMUM_RENDERTARGET_HEIGHT);

            m_renderTargetResourceOwner = new Direct2DRenderTarget(m_directCanvasFactory.DeviceContext, 
                                                                   m_textureResourceOwner.InternalDxgiSurface);
        }
Exemplo n.º 4
0
        public GPGPUEffect(DirectCanvasFactory directCanvas)
            : base(directCanvas)
        {
            SetShaderSource(GetResourceString(SHADER_RESOURCE_NAME, Assembly.GetExecutingAssembly()), SHADER_ENTRY);

            RegisterProperty<float>(SIGMA_REGISTER);
            RegisterProperty<float>(WIDTH_REGISTER);
            RegisterProperty<float>(HEIGHT_REGISTER);
            RegisterProperty<Color4>(TINTCOLOR_REGISTER);
            RegisterProperty<float>(THRESHOLD_VALUE);
        }
Exemplo n.º 5
0
 public ImageProcessor(Size ImageSize)
 {
     try
     {
         Factory = new DirectCanvasFactory();
         thresholdEffect = new ThresholdEffect(Factory);
         edgeEffect = new EdgeDetectEffect(Factory);
         unpackEffect = new UnpackDepthEffect(Factory);
         colorMapEffect = new ColorMapDepthEffect(Factory);
         InitLayers(ImageSize);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine("Exception initializing ImageProcessor: " + ex.ToString());
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new WPFPresenter instance.
 /// </summary>
 /// <param name="directCanvas">The DirectCanvas factor this presenter belongs to</param>
 /// <param name="width">The pixel width of the presenter</param>
 /// <param name="height">The pixel height of the presenter</param>
 /// <param name="image">The WPF Image to render to</param>
 public WPFPresenter(DirectCanvasFactory directCanvas, int width, int height, Image image)
     : this(directCanvas, width, height)
 {
     // Check and see if we are on the UI thread as we may want to support multi-threaded scenarios.
     if (!image.Dispatcher.CheckAccess())
     {
         image.Dispatcher.Invoke((Action)delegate
         {
             image.Source = m_d3dImage;
         });
     }
     else
     {
         image.Source = m_d3dImage;
     }
 }
Exemplo n.º 7
0
 public WPFPresenter(DirectCanvasFactory directCanvas, int width, int height)
     : base(directCanvas)
 {
     // Check and see if we are on the UI thread as we may want to support multi-threaded scenarios.
     InitD3DImage(width, height);
 }
Exemplo n.º 8
0
        public unsafe Image ToDirectCanvasImage(DirectCanvasFactory factory, out ushort minValue, out ushort maxValue)
        {
            Image sourceImage = factory.CreateImage(_width, _height);
            var imageData = sourceImage.Lock(DirectCanvas.Imaging.ImageLock.ReadWrite);
            int numPixels = _width * _height;

            //Image is BGRA format, 4 bytes per pixel
            byte* imagePtr = (byte*)imageData.Scan0.ToPointer();

            minValue = ushort.MaxValue;
            maxValue = ushort.MinValue;

            fixed (ushort* sourceDataPtr = this.DepthPixels)
            {
                ushort* sourcePtr = sourceDataPtr;
                ushort* targetPtr = (ushort*)imagePtr;
                //for (int i = 0; i < numPixels; i++)
                for (int x = 0; x < _width; x++)
                {
                    for (int y = 0; y < _height; y++)
                    {
                        //int i = x + y * _width;
                        //ushort value = sourceData[i];
                        ushort value = *sourcePtr;

                        if (value > maxValue)
                            maxValue = value;
                        if (value > 100 && value < minValue)
                            minValue = value;

                        //pack ushort into first two bytes of pixel
                        //((ushort*)imagePtr)[i * 2] = value;
                        *targetPtr = value;
                        //imagePtr[i * 4] = (byte)(value & 255); //low byte in B
                        //imagePtr[i * 4 + 1] = (byte)(value >> 8); //high byte in G

                        //store 255 in Alpha channel of pixel
                        //imagePtr[i * 4 + 3] = 255;
                        //if (_crop.Contains(x, y))
                        //{
                        //    *(imagePtr + 3) = 255;
                        //}
                        //else
                        //{
                        //    *(imagePtr + 3) = 128;
                        //}

                        sourcePtr++;
                        imagePtr += 4;
                        targetPtr += 1;
                    }
                }
            }

            sourceImage.Unlock(imageData);

            return sourceImage;
        }
Exemplo n.º 9
0
        public unsafe Image ToDirectCanvasImage(DirectCanvasFactory factory)
        {
            //ushort min, max;
            //return ToDirectCanvasImage(factory, out min, out max);
            Image sourceImage = factory.CreateImage(_width, _height);
            var imageData = sourceImage.Lock(DirectCanvas.Imaging.ImageLock.ReadWrite);
            int numPixels = _width * _height;

            //Image is BGRA format, 4 bytes per pixel
            //byte* imagePtr = (byte*)imageData.Scan0.ToPointer();

            int len = _width * _height * sizeof(ushort);

            //imagePtr[i * 4 + 0] = (byte)(value & 255);  //low byte of pixel 1 in B
            //imagePtr[i * 4 + 1] = (byte)(value >> 8);   //high byte of pixel 1 in G
            //imagePtr[i * 4 + 2] = (byte)(value2 & 255); //low byte of pixel 2 in R
            //imagePtr[i * 4 + 3] = (byte)(value2 >> 8);  //high byte of pixel 2 in A

            fixed (ushort* sourceDataPtr = this.DepthPixels)
            {
                NativeInterop.MoveMemory(imageData.Scan0, (IntPtr)sourceDataPtr, len);
            }
            sourceImage.Unlock(imageData);

            return sourceImage;
        }
Exemplo n.º 10
0
        private void InitDirectCanvas()
        {
            m_directCanvasFactory = new DirectCanvasFactory();

            /* Create a new WindowsFromsPresenter, passing it our factory 
             * and our Winforms control that we want to render to */
            m_presenter = new WPFPresenter(m_directCanvasFactory,
                                           (int)Width /* Pixel width of our presenter */,
                                           (int)Height /* Pixel height of our presenter */,
                                           wpfImage /* The WPF Image to render to */);
            m_presenter.CurrentScene = m_scene;
            m_presenter.StartRendering();

            m_shaderScene = new PixelShaderScene(m_presenter);
            m_geometryScene = new GeometryScene(m_presenter);
            m_compositorScene = new CompositorScene(m_presenter);
            m_superBlurScene = new SuperBlur(m_presenter);
            m_transitionScene = new TransitionEffectScene(m_presenter);

            m_scene = m_geometryScene;
        }
Exemplo n.º 11
0
 internal protected Presenter(DirectCanvasFactory directCanvas) : base(directCanvas)
 {
     m_fpsCounter.Start();
 }
Exemplo n.º 12
0
 /// <summary>
 /// Creates a new instance of the DrawingLayer.  This is the constructor that 
 /// presenter subclasses will use, making sure they override the D2DRenderTarget and RenderTargetTexture
 /// </summary>
 /// <param name="directCanvasFactory">The factory that the DrawingLayer belongs to</param>
 internal DrawingLayer(DirectCanvasFactory directCanvasFactory)
 {
     m_drawStateManagement = new DrawStateManagement();
     m_directCanvasFactory = directCanvasFactory;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a new instance of the DrawingLayer
        /// </summary>
        /// <param name="directCanvasFactory">The factory that the DrawingLayer belongs to</param>
        /// <param name="renderTargetTexture">The Direct3D texture to use</param>
        internal DrawingLayer(DirectCanvasFactory directCanvasFactory, RenderTargetTexture renderTargetTexture)
        {
            m_directCanvasFactory = directCanvasFactory;
            m_format = renderTargetTexture.Description.Format;

            m_drawStateManagement = new DrawStateManagement();

            /* Set our Direct3D texture */
            RenderTargetTexture = renderTargetTexture;

            /* Create the Direct2D render target, using our Direct3D texture we were passed */
            D2DRenderTarget = new Direct2DRenderTarget(m_directCanvasFactory.DeviceContext,
                                                       m_renderTargetTexture.InternalDxgiSurface, 
                                                       m_format);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a new instance of the DrawingLayer
        /// </summary>
        /// <param name="directCanvasFactory">The factory that the DrawingLayer belongs to</param>
        /// <param name="width">The pixel size in width to make the D3D texture</param>
        /// <param name="height">The pixel size in height to make the D3D texture</param>
        /// <param name="format">The color format to make the D3D texture</param>
        /// <param name="optionFlags">Option flags to use on the creation of the D3D texture</param>
        internal DrawingLayer(DirectCanvasFactory directCanvasFactory, 
                              int width, 
                              int height, 
                              Format format = Format.B8G8R8A8_UNorm, 
                              ResourceOptionFlags optionFlags = ResourceOptionFlags.None)
        {
            m_directCanvasFactory = directCanvasFactory;
            m_format = format;

            m_drawStateManagement = new DrawStateManagement();

            var device = m_directCanvasFactory.DeviceContext.Device;

            /* Create our Direct3D texture */
            RenderTargetTexture = new RenderTargetTexture(device, width, height, m_format, optionFlags);

            /* Create the Direct2D render target, using our Direct3D texture we just created */
            D2DRenderTarget = new Direct2DRenderTarget(m_directCanvasFactory.DeviceContext,
                                                       m_renderTargetTexture.InternalDxgiSurface, 
                                                       m_format);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Instantiates a new Windows Forms Presenter
        /// </summary>
        /// <param name="directCanvas">The DirectCanvasFactor this presenter belongs to</param>
        /// <param name="control"></param>
        public WindowsFormsPresenter(DirectCanvasFactory directCanvas, Control control) : base(directCanvas)
        {
            m_control = control;

            AttachToControl();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a new WPFPresenter instance.
        /// </summary>
        /// <param name="directCanvas">The DirectCanvas factor this presenter belongs to</param>
        /// <param name="width">The pixel width of the presenter</param>
        /// <param name="height">The pixel height of the presenter</param>
        /// <param name="image">The WPF Image to render to</param>
        public WPFBlitPresenter(DirectCanvasFactory directCanvas, int width, int height, Image image)
            : base(directCanvas)
        {
            m_width = width;
            m_height = height;
            m_image = image;

            /* Check and see if we are on the UI thread as we may want to support
             * multi-threaded scenarios */
            if (!image.Dispatcher.CheckAccess())
            {
                image.Dispatcher.Invoke((Action)delegate
                {
                    m_d3dImage = new D3DImage();
                    image.Source = m_d3dImage;
                });
            }
            else
            {
                m_d3dImage = new D3DImage();
                image.Source = m_d3dImage;
            }

            /* Initialize our special layers */
            CreateLayer(m_width, m_height);
        }