예제 #1
0
        protected override void ProcessLeg(int leg, bool visualize, Viewport viewport, bool present, bool clear)
        {
            //Visualizing axes
            if (ViewMode == Views.Special && SpecialView == SpecialViews.CorePosition && leg == VisualizedLeg)
            {
                Visualize(SingleTargetTick ? SingleTargetA : SingleTargetB, SignedDepthVisualizationTechnique, MainViewport, false);
                SetModelProjection(-mainRotation + SplitPlaneAngle + MathHelper.PiOver2);
                VisualizeAxes(ColorModelTechnique);
                XDevice.Present();
            }

            //Polar reprojection
            XDevice.RasterizerState = new RasterizerState()
            {
                ScissorTestEnable = true, CullMode = CullMode.CullCounterClockwiseFace
            };
            XDevice.SetRenderTarget(SingleTargetTick ? SingleTargetB : SingleTargetA);
            XDevice.Clear(Color.Black);
            DepthSampler.SetValue(SingleTargetTick ? SingleTargetA : SingleTargetB);
            CorePos.SetValue(new Vector3(CoreY, 0, leg == 0 ? -CoreX : CoreX));
            SetExCoreReprojection(mainRotation);
            XEffect.CurrentTechnique = PolarOutputTechnique;
            for (int half = 0; half < 2; half++)
            {
                XDevice.ScissorRectangle = ExCoreTargetClippingRectangles[half];
                FiShift.SetValue(half == 0 ? 0f : 1f);
                XEffect.CurrentTechnique.Passes[0].Apply();
                MaxiPlane.Draw();
            }

            if (ViewMode == Views.Special && SpecialView == SpecialViews.CoreReprojection && visualize)
            {
                XDevice.SetRenderTarget(null);
                XDevice.Viewport = viewport;
                if (clear)
                {
                    XDevice.Clear(Color.White);
                }
                XEffect.CurrentTechnique = PolarDisplayTechnique;
                for (int half = 0; half < 2; half++)
                {
                    XDevice.ScissorRectangle = MainTargetClippingRectangles[half];
                    FiShift.SetValue(half == 0 ? 0f : 1f);
                    XEffect.CurrentTechnique.Passes[0].Apply();
                    MaxiPlane.Draw();
                }
                if (present)
                {
                    XDevice.Present();
                }
                XDevice.Viewport = MainViewport;
            }

            XDevice.RasterizerState = RasterizerState.CullCounterClockwise;

            //Polar sum
            XDevice.SetRenderTarget(ExCoreTick[leg] ? ExCoreTargetA[leg] : ExCoreTargetB[leg]);
            if (NextExCoreClear[leg])
            {
                XDevice.Clear(ClearOptions.Target, Color.Black, 1, 0);
                NextExCoreClear[leg] = false;
            }
            else
            {
                DepthSamplerA.SetValue(SingleTargetTick ? SingleTargetB : SingleTargetA);
                DepthSamplerB.SetValue(ExCoreTick[leg] ? ExCoreTargetB[leg] : ExCoreTargetA[leg]);
                XEffect.CurrentTechnique = PolarAddTechnique;
                XEffect.CurrentTechnique.Passes[0].Apply();
                MiniPlane.Draw();
            }

            //Averaged visualization
            if (ViewMode == Views.Special && SpecialView == SpecialViews.CorePolarDepth && visualize)
            {
                XDevice.SetRenderTarget(null);
                XDevice.Viewport = viewport;
                if (clear)
                {
                    XDevice.Clear(Color.White);
                }
                DepthSampler.SetValue(ExCoreTick[leg] ? ExCoreTargetA[leg] : ExCoreTargetB[leg]);
                XEffect.CurrentTechnique = PolarAvgDisplayTechnique;
                XEffect.CurrentTechnique.Passes[0].Apply();
                MiniPlane.Draw();
                if (present)
                {
                    XDevice.Present();
                }
                XDevice.Viewport = MainViewport;
            }

            VisualizeModel(leg);
            ExCoreTick[leg] = !ExCoreTick[leg];
        }
예제 #2
0
        protected void ProcessFrame()
        {
            if (XDevice == null || !Scanning)
            {
                return;
            }

            Processing++;
            try
            {
                if (DepthCacheUsed >= DepthAveragingCacheSize)
                {
                    if (FrameID % FusionSpacing == 0)
                    {
                        XDevice.SetRenderTarget(Vector2TargetA);
                        XDevice.Clear(Color.Black);
                        XDevice.SetRenderTarget(Vector2TargetB);
                        XDevice.Clear(Color.Black);

                        int mainIndex = (DepthIndex + DepthMainItem) % DepthAveragingCacheSize;
                        mainRotation = DepthCache[mainIndex].Rotation;
                        byte[] deltaData;
                        float  deltaRotation;
                        bool   tick = false;
                        for (int i = 0; i < DepthAveragingCacheSize; i++)
                        {
                            deltaData     = DepthCache[i].Data;
                            deltaRotation = DepthCache[i].Rotation - mainRotation;
                            if (deltaRotation > MathHelper.Pi)
                            {
                                deltaRotation -= MathHelper.TwoPi;
                            }
                            if (deltaRotation < -MathHelper.Pi)
                            {
                                deltaRotation += MathHelper.TwoPi;
                            }

                            for (int j = 0; j < 16; j++)
                            {
                                XDevice.Textures[j] = null;
                            }
                            TRawDepth.SetData <byte>(deltaData);

                            //Anti-distort
                            XDevice.SetRenderTarget(SingleTargetA);
                            XDevice.Clear(Color.Black);
                            XDevice.RasterizerState   = RasterizerState.CullNone;
                            XDevice.BlendState        = BlendState.Opaque;
                            XDevice.DepthStencilState = DepthStencilState.None;

                            DepthSampler.SetValue(TRawDepth);
                            DepthCorrectionSampler.SetValue(TDepthCorrection);
                            XEffect.CurrentTechnique = DepthAntiDistortTechnique; //<----
                            XEffect.CurrentTechnique.Passes[0].Apply();
                            MiniPlane.Draw();
                            if (ViewMode == Views.AntiDistort)
                            {
                                Visualize(SingleTargetA, DepthVisualizationTechnique, MainViewport);
                            }

                            //Reprojection + transform
                            SetReprojection(deltaRotation);
                            TriangleRemoveLimit.SetValue(Context.TriangleRemoveLimit);
                            XDevice.SetRenderTarget(SingleTargetB);
                            XDevice.Clear(Color.Black);
                            XDevice.BlendState        = BlendState.Opaque;
                            XDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
                            XDevice.DepthStencilState = DepthStencilState.Default;

                            DepthSampler.SetValue(SingleTargetA);
                            XEffect.CurrentTechnique = PerspectiveReprojectionTechnique; //<----
                            XEffect.CurrentTechnique.Passes[0].Apply();
                            MaxiPlane.Draw();

                            if (ViewMode == Views.Sum)
                            {
                                Visualize(SingleTargetB, DepthVisualizationTechnique, MainViewport);
                            }

                            //Sum
                            XDevice.SetRenderTarget(tick ? Vector2TargetA : Vector2TargetB);
                            XDevice.Clear(Color.Black);
                            XDevice.RasterizerState   = RasterizerState.CullNone;
                            XDevice.BlendState        = BlendState.Opaque;
                            XDevice.DepthStencilState = DepthStencilState.None;

                            DepthSamplerA.SetValue(SingleTargetB);
                            DepthSamplerB.SetValue(tick ? Vector2TargetB : Vector2TargetA);
                            XEffect.CurrentTechnique = SumTechnique; //<----
                            XEffect.CurrentTechnique.Passes[0].Apply();
                            MiniPlane.Draw();
                            tick = !tick;
                        }

                        //Fusion + transform
                        SetFusionReprojection(0f, mainRotation);
                        XDevice.SetRenderTarget(SingleTargetTick ? SingleTargetA : SingleTargetB);
                        DepthSampler.SetValue(tick ? Vector2TargetB : Vector2TargetA);
                        XEffect.CurrentTechnique = AvgTechnique; //<----
                        XEffect.CurrentTechnique.Passes[0].Apply();
                        MiniPlane.Draw();

                        if (ViewMode == Views.Avg)
                        {
                            Visualize(SingleTargetTick ? SingleTargetA : SingleTargetB, SignedDepthVisualizationTechnique, MainViewport);
                        }

                        //Gauss
                        for (int i = 0; i < 0; i++)
                        {
                            XDevice.SetRenderTarget(SingleTargetTick ? SingleTargetB : SingleTargetA);
                            DepthSampler.SetValue(SingleTargetTick ? SingleTargetA : SingleTargetB);
                            XEffect.CurrentTechnique = VGaussTechnique;
                            XEffect.CurrentTechnique.Passes[0].Apply();
                            MiniPlane.Draw();
                            SingleTargetTick = !SingleTargetTick;

                            XDevice.SetRenderTarget(SingleTargetTick ? SingleTargetB : SingleTargetA);
                            DepthSampler.SetValue(SingleTargetTick ? SingleTargetA : SingleTargetB);
                            XEffect.CurrentTechnique = HGaussTechnique;
                            XEffect.CurrentTechnique.Passes[0].Apply();
                            MiniPlane.Draw();
                            SingleTargetTick = !SingleTargetTick;
                        }

                        if (ViewMode == Views.Gauss)
                        {
                            Visualize(SingleTargetTick ? SingleTargetA : SingleTargetB, SignedDepthVisualizationTechnique, MainViewport);
                        }

                        for (int leg = 0; leg < 2; leg++)
                        {
                            SideSelector.SetValue(leg == 0 ? 1f : -1f);
                            ProcessLeg(leg, leg == VisualizedLeg || VisualizedLeg == 2, VisualizedLeg == 2 ? Viewports[leg] : MainViewport, leg == VisualizedLeg || (VisualizedLeg == 2 && leg == 1), VisualizedLeg != 2 || (VisualizedLeg == 2 && leg == 0));
                        }
                    }
                    FrameID++;
                }
                if (StopPending)
                {
                    StopARE.Set();
                    StopPending = false;
                }
            }
            catch
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
            Processing--;
        }