示例#1
0
 unsafe public void Add(PhaseOutput phase, int length)
 {
     for (var i = 0; i < length; i++)
     {
         Phase[i] += phase.Phase[i];
         Phase[i] = Common.Mod(Phase[i], 2 * Math.PI);
     }
 }
示例#2
0
    unsafe public static PhaseOutput ComputePhase(string dll)
    {
        var file = Common.OSTest.IsWindows() ? String.Format("./libphase++{0}.dll", dll) : (Common.OSTest.IsRunningOnMac() ? String.Format("./libphase++{0}.dylib", dll) : String.Format("./libphase++{0}.so", dll));

        if (File.Exists(file))
        {
            IntPtr pLibrary = DLLLoader.LoadLibrary(file);
            IntPtr pCompute = DLLLoader.GetProcAddress(pLibrary, "Compute");
            IntPtr pPhase   = DLLLoader.GetProcAddress(pLibrary, "Phase");
            IntPtr pRelease = DLLLoader.GetProcAddress(pLibrary, "Release");

            var Compute = DLLLoader.LoadFunction <FCompute>(pCompute);
            var Phase   = DLLLoader.LoadFunction <FPhase>(pPhase);
            var Release = DLLLoader.LoadFunction <FRelease>(pRelease);

            double *SpotsX;
            double *SpotsY;

            GetPoints(Spots, Width, Height, out SpotsX, out SpotsY);

            void **Parameters = stackalloc void *[6];

            var width  = Width;
            var height = Height;
            var nfft   = Math.Max(NFFT, Math.Max(Width, Height));
            var N      = Spots.Count;

            Parameters[0] = &width;
            Parameters[1] = &height;
            Parameters[2] = &nfft;
            Parameters[3] = &N;
            Parameters[4] = SpotsX;
            Parameters[5] = SpotsY;

            Compute(6, Parameters);

            var output = Phase();

            var phase = new PhaseOutput(output, width * height);

            // Free resources
            Release();

            DLLLoader.FreeLibrary(pLibrary);

            return(phase);
        }

        var length = Width * Height > 0 ? Width * Height : 256 * 256;

        return(new PhaseOutput(length));
    }
示例#3
0
    unsafe public static PhaseOutput ComputePhase(string dll)
    {
        var file = Common.OSTest.IsWindows() ? String.Format("./libphase++{0}.dll", dll) : (Common.OSTest.IsRunningOnMac() ? String.Format("./libphase++{0}.dylib", dll) : String.Format("./libphase++{0}.so", dll));

        if (File.Exists(file))
        {
            IntPtr pLibrary = DLLLoader.LoadLibrary(file);
            IntPtr pCompute = DLLLoader.GetProcAddress(pLibrary, "Compute");
            IntPtr pPhase   = DLLLoader.GetProcAddress(pLibrary, "Phase");
            IntPtr pRelease = DLLLoader.GetProcAddress(pLibrary, "Release");

            var Compute = DLLLoader.LoadFunction <FCompute>(pCompute);
            var Phase   = DLLLoader.LoadFunction <FPhase>(pPhase);
            var Release = DLLLoader.LoadFunction <FRelease>(pRelease);

            void **Parameters = stackalloc void *[5];

            var width      = Width;
            var height     = Height;
            var z          = Z;
            var wavelength = Wavelength;
            var pitch      = Pitch;

            Parameters[0] = &width;
            Parameters[1] = &height;
            Parameters[2] = &z;
            Parameters[3] = &wavelength;
            Parameters[4] = &pitch;

            Compute(5, Parameters);

            var output = Phase();

            var phase = new PhaseOutput(output, width * height);

            // Free resources
            Release();

            DLLLoader.FreeLibrary(pLibrary);

            return(phase);
        }

        var length = Width * Height > 0 ? Width * Height : 256 * 256;

        return(new PhaseOutput(length));
    }
示例#4
0
    unsafe public static PhaseOutput ComputePhase(string dll)
    {
        var file = Common.OSTest.IsWindows() ? String.Format("./libphase++{0}.dll", dll) : (Common.OSTest.IsRunningOnMac() ? String.Format("./libphase++{0}.dylib", dll) : String.Format("./libphase++{0}.so", dll));

        if (File.Exists(file))
        {
            IntPtr pLibrary = DLLLoader.LoadLibrary(file);
            IntPtr pCompute = DLLLoader.GetProcAddress(pLibrary, "Compute");
            IntPtr pPhase   = DLLLoader.GetProcAddress(pLibrary, "Phase");
            IntPtr pRelease = DLLLoader.GetProcAddress(pLibrary, "Release");

            var Compute = DLLLoader.LoadFunction <FCompute>(pCompute);
            var Phase   = DLLLoader.LoadFunction <FPhase>(pPhase);
            var Release = DLLLoader.LoadFunction <FRelease>(pRelease);

            var target  = Common.PreparePixbuf(Target);
            var targetx = Target.Width;
            var targety = Target.Height;

            var iterations = Iterations;

            void **Parameters = stackalloc void *[4];

            Parameters[0] = target;
            Parameters[1] = &targetx;
            Parameters[2] = &targety;
            Parameters[3] = &iterations;

            Compute(4, Parameters);

            var output = Phase();

            var phase = new PhaseOutput(output, targetx * targety);

            // Free resources
            Release();

            DLLLoader.FreeLibrary(pLibrary);

            return(phase);
        }

        var length = Target != null ? Target.Width * Target.Height : 256 * 256;

        return(new PhaseOutput(length));
    }
示例#5
0
 /// <summary>
 /// This is where the phase output is processed by the Game.
 /// </summary>
 protected virtual void OnPhaseCompleted(Phase sender, PhaseOutput args)
 {
 }
示例#6
0
    unsafe protected void ComputePhase()
    {
        Tic();

        var start = Ticks();

        var srcx = InputPixbuf.Width;
        var srcy = InputPixbuf.Height;

        var size = srcx * srcy;

        var phase = new PhaseOutput(size);

        if (Spots.Count > 0)
        {
            SpotsDLL.SetParameters(srcx, srcy, Parameters.NFFT, Spots, true);

            var spots = SpotsDLL.ComputePhase("spots");

            phase.Add(spots, size);
        }

        if (GerchbergSaxtonPhase.Active)
        {
            GerchbergSaxtonDLL.SetIterations(Convert.ToInt32(Iterations.Value));
            GerchbergSaxtonDLL.SetTarget(InputPixbuf);

            var gs = GerchbergSaxtonDLL.ComputePhase("gs");

            phase.Add(gs, size);

            gs.Free();
        }

        if (LensPhase.Active)
        {
            LensPhaseDLL.SetParameters(srcx, srcy, Parameters.LensZ, Parameters.Pitch, Parameters.Wavelength);

            var lens = LensPhaseDLL.ComputePhase("lens");

            phase.Add(lens, size);

            lens.Free();
        }

        if (BlazedPhase.Active)
        {
            BlazedPhaseDLL.SetParameters(srcx, srcy, Parameters.BlazedX, Parameters.BlazedY);

            var blazed = BlazedPhaseDLL.ComputePhase("blazed");

            phase.Add(blazed, size);

            blazed.Free();
        }

        var pixbuf = Common.PreparePixbuf(phase.Phase, srcx, srcy);

        if (PhasePixbuf != null && pixbuf != null)
        {
            Common.Free(PhasePixbuf);

            PhasePixbuf = Common.InitializePixbuf(pixbuf.Width, pixbuf.Height);

            pixbuf.Composite(PhasePixbuf, 0, 0, pixbuf.Width, pixbuf.Height, 0, 0, 1, 1, InterpType.Nearest, 255);

            ResetPhaseScrollBars();

            RenderImage(PhaseImage, PhasePixbuf, Parameters.PhaseX, Parameters.PhaseY);
        }

        phase.Free();

        Common.Free(pixbuf);

        var elapsed = Ticks() - start;

        Elapsed.Text      = elapsed.ToString(ci);
        PhaseElapsed.Text = elapsed.ToString(ci);
    }