예제 #1
0
        private void SetGrid()
        {
            int numberRows    = Width / t_gridCellWidth;
            int numberColumns = Height / t_gridCellHeight;

            /*
             * // depending on image ratio, portion of image may not be modified because there is one row missing
             * if (numberRows * t_gridCellWidth < Width)
             * {
             *  numberRows++;
             * }
             *
             * // depending on image ratio, portion of image may not be modified because there is one column missing
             * if (numberColumns * t_gridCellHeight < Height)
             * {
             *  numberColumns++;
             * }*/

            t_cells = new PressureGridCell[numberRows, numberColumns];

            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();

            Engine.Threading.ParamList paramList = new Threading.ParamList();
            paramList.Add("numCol", typeof(int), numberColumns);

            loop.Loop(numberRows, Threaded_SetGrid, paramList);
            loop.Dispose();
        }
예제 #2
0
        private int Threaded_Loop_Cell_Part_2(int start, int end, Threading.ParamList paramList)
        {
            AutonomousParticle p = (AutonomousParticle)paramList.Get("particle").Value;

            Engine.Color.Cell[] cells = (Engine.Color.Cell[])paramList.Get("cells").Value;
            int counter = (int)paramList.Get("counter").Value;

            int offset = 0;

            if (!t_glassBlock)
            {
                offset = Engine.Surface.Ops.GetGridOffset(0, start, t_cellSize, t_cellSize);
            }

            for (int y = start; y < end; y++)
            {
                for (int x = 0; x < t_cellSize; x++)
                {
                    cells[offset] = Engine.Calc.Color.FastAlphaBlend(cells[offset], t_imageProcessed.GetPixel((int)(p.Position.X - (t_cellSize / 2) + x), (int)(p.Position.Y - (t_cellSize / 2) + y), Surface.PixelRetrievalOptions.ReturnNeutralGray));
                    t_imageProcessed.SetPixel(cells[offset], (int)(p.Position.X - (t_cellSize / 2) + x), (int)(p.Position.Y - (t_cellSize / 2) + y), Surface.PixelSetOptions.Ignore);
                    offset++;
                }
            }

            return(0);
        }
예제 #3
0
        private int Threaded_Loop(int start, int end, Threading.ParamList paramList)
        {
            int counter = (int)paramList.Get("counter").Value;

            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();

            for (int ii = start; ii < end; ii++)
            {
                // collect pixels in each grid cell
                Engine.Color.Cell[] cells = new Engine.Color.Cell[t_cellSize * t_cellSize];

                AutonomousParticle p = t_particles[ii];

                Engine.Threading.ParamList paramList2 = new Threading.ParamList();
                paramList2.Add("particle", typeof(AutonomousParticle), p);
                paramList2.Add("cells", typeof(Engine.Color.Cell[]), cells);
                paramList2.Add("counter", typeof(int), counter);

                loop.Loop(t_cellSize, Threaded_Loop_Cell_Part_1, paramList2);

                p.Move();

                loop.Loop(t_cellSize, Threaded_Loop_Cell_Part_2, paramList2);
            }

            loop.Dispose();

            return(0);
        }
예제 #4
0
        internal override void Draw(MousePoint p)
        {
            if (t_particles.Length == 0)
            {
                return;
            }

            if (!t_skipper.Skip())
            {
                return;
            }

            // atractor must follow the pen between each call to draw
            int[] delta          = MousePoint.Delta(t_previousPoint, p);
            Engine.Calc.Vector d = new Engine.Calc.Vector(delta[0], delta[1]);
            t_attractor.Move(d);

            if (t_imageSource.IsOutOfBounds(p.X, p.Y))
            {
                return;
            }

            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();

            Engine.Threading.ParamList paramList = new Threading.ParamList();
            paramList.Add("x", typeof(int), p.X);
            paramList.Add("y", typeof(int), p.Y);

            loop.Loop(t_particles.Length, Threaded_Draw, paramList);
            loop.Dispose();

            t_previousPoint = p;
        }
예제 #5
0
        private void CreateFlowField()
        {
            t_flowField = new Engine.Calc.Vector[t_imageSource.Width, t_imageSource.Height];


            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();

            Engine.Threading.ParamList paramList = new Threading.ParamList();

            loop.Loop(t_imageSource.Height, Threaded_CreateFlowField, paramList);
            loop.Dispose();
        }
예제 #6
0
        public Engine.Effects.Code.Particles.AutonomousParticle[] GetParticles()
        {
            Engine.Effects.Code.Particles.AutonomousParticle[] particles = new Effects.Code.Particles.AutonomousParticle[t_cells.GetLength(0) * t_cells.GetLength(1)];

            Engine.Threading.ParamList paramList = new Threading.ParamList();
            paramList.Add("particles", typeof(int), particles);

            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();
            loop.Loop(t_cells.GetLength(0), Threaded_GetParticles, paramList);
            loop.Dispose();

            return(particles);
        }
예제 #7
0
        private void Loop()
        {
            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();

            for (int i = 0; i < t_flowLength; i++)
            {
                Engine.Threading.ParamList paramList = new Threading.ParamList();
                paramList.Add("counter", typeof(int), i);
                loop.Loop(t_particles.Length, Threaded_Loop, paramList);
            }

            loop.Dispose();
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        private void ParticleFlow(int x, float divSpread)
        {
            double divSpread255 = divSpread / 255;
            double divSpread2f  = divSpread / 2f;

            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();

            Engine.Threading.ParamList paramList = new Threading.ParamList();
            paramList.Add(paramName_X, typeof(int), x);
            paramList.Add(paramName_divSpread255, typeof(double), divSpread255);
            paramList.Add(paramName_divSpread2f, typeof(double), divSpread2f);

            loop.Loop(t_imageSource.Height, Threaded_ParticleFlow, paramList);
            loop.Dispose();
        }
예제 #9
0
        internal override void Draw(MousePoint p)
        {
            t_buffer_1.SetFluidAmount(5d, p.X, p.Y, PixelSetOptions.Ignore);

            int offset = 0;

            for (int i = 0; i < t_steps; i++)
            {
                offset = 0;
                for (int y = 0; y < t_imageSource.Height; y++)
                {
                    Engine.Threading.ParamList paramList = new Threading.ParamList();
                    paramList.Add("y", typeof(int), y);
                    loop.Loop(t_imageSource.Width, Threaded_Draw, paramList);
                    //Threaded_Draw(0, t_imageSource.Width, paramList);
                }

                Engine.EngineCppLibrary.CalculateRippleEffect s_calculateRippleEffect = (Engine.EngineCppLibrary.CalculateRippleEffect)Marshal.GetDelegateForFunctionPointer(
                    Engine.EngineCppLibrary.Pointer_calculateRippleEffect,
                    typeof(Engine.EngineCppLibrary.CalculateRippleEffect));

                s_calculateRippleEffect(t_imageSource.Width * t_imageSource.Height, sum, b1_1, b1_2, b1_3, b1_4, b2_1, t_dampening);

                offset = 0;
                for (int y = 0; y < t_imageSource.Height; y++)
                {
                    for (int x = 0; x < t_imageSource.Width; x++)
                    {
                        t_buffer_2.SetFluidAmount(sum[offset], x, y, PixelSetOptions.Ignore);
                        offset++;
                    }
                }

                Engine.Effects.Particles.FluidField temp = t_buffer_1;
                t_buffer_1 = t_buffer_2;
                t_buffer_2 = temp;
            }

            ShadeImage();
        }
예제 #10
0
        private int Threaded_GetParticles(int start, int end, Threading.ParamList paramlist)
        {
            Engine.Effects.Code.Particles.AutonomousParticle[] particles = (Engine.Effects.Code.Particles.AutonomousParticle[])paramlist.Get("particles").Value;

            for (int x = start; x < end; x++)
            {
                for (int y = 0; y < t_cells.GetLength(1); y++)
                {
                    int offset = Engine.Surface.Ops.GetGridOffset(x, y, t_cells.GetLength(0), t_cells.GetLength(1));

                    particles[offset] = new Effects.Code.Particles.AutonomousParticle(new Engine.Calc.Vector((x * t_gridCellWidth) + (t_gridCellWidth / 2),
                                                                                                             (y * t_gridCellHeight) + (t_gridCellHeight / 2)));

                    Engine.Calc.Vector vel = t_cells[x, y].Pressure;
                    vel.Normalize();
                    vel.SetMagnitude(2);
                    particles[offset].Velocity = vel;

                    //t_cells[x, y].CalculateAveragePressure(t_flowField, x * t_gridCellWidth, y * t_gridCellHeight);
                }
            }

            return(0);
        }
예제 #11
0
        public static Engine.Surface.Canvas CreatePerlinNoisePlane(Engine.Surface.Canvas source, double frequency, int seed, int octaves)
        {
            Engine.Effects.Noise.IModule module = new Engine.Effects.Noise.Perlin();

            ((Perlin)module).Frequency    = frequency;
            ((Perlin)module).NoiseQuality = NoiseQuality.Standard;
            ((Perlin)module).Seed         = seed;
            ((Perlin)module).OctaveCount  = octaves;
            ((Perlin)module).Lacunarity   = 2.0;
            ((Perlin)module).Persistence  = 0.5;

            Engine.Surface.Canvas perlinSurface = new Canvas(source.Width, source.Height);

            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();

            Engine.Threading.ParamList paramList = new Threading.ParamList();
            paramList.Add(paramName_module, typeof(Engine.Effects.Noise.IModule), module);
            paramList.Add(paramName_canvas, typeof(Engine.Surface.Canvas), perlinSurface);

            loop.Loop(source.Height, Threaded_CreatePerlinNoisePlane, paramList);
            loop.Dispose();

            return(perlinSurface);
        }
예제 #12
0
        private void ThreadedProcess()
        {
            if (t_noiseType == NoiseTypes.Undefined)
            {
                t_noiseType = NoiseTypes.FastNoise;
            }

            Engine.Effects.Noise.IModule module;

            // switch block : source and info at : https://libnoisedotnet.codeplex.com/downloads/get/720936
            // and http://libnoise.sourceforge.net/tutorials/tutorial8.html

            switch (t_noiseType)
            {
            case NoiseTypes.Billow:
                module = new Engine.Effects.Noise.Billow();

                ((Billow)module).Frequency    = t_frequency;
                ((Billow)module).NoiseQuality = NoiseQuality.Standard;
                ((Billow)module).Seed         = t_seed;
                ((Billow)module).OctaveCount  = t_octaves;
                ((Billow)module).Lacunarity   = t_lacunarity;
                ((Billow)module).Persistence  = t_persistence;
                break;

            case NoiseTypes.FastBillow:
                module = new Engine.Effects.Noise.FastBillow();

                ((FastBillow)module).Frequency    = t_frequency;
                ((FastBillow)module).NoiseQuality = NoiseQuality.Standard;
                ((FastBillow)module).Seed         = t_seed;
                ((FastBillow)module).OctaveCount  = t_octaves;
                ((FastBillow)module).Lacunarity   = t_lacunarity;
                ((FastBillow)module).Persistence  = t_persistence;
                break;

            case NoiseTypes.FastNoise:
                module = new Engine.Effects.Noise.FastNoise();

                ((FastNoise)module).Frequency    = t_frequency;
                ((FastNoise)module).NoiseQuality = NoiseQuality.Standard;
                ((FastNoise)module).Seed         = t_seed;
                ((FastNoise)module).OctaveCount  = t_octaves;
                ((FastNoise)module).Lacunarity   = t_lacunarity;
                ((FastNoise)module).Persistence  = t_persistence;
                break;

            default:
                module = new Engine.Effects.Noise.Perlin();

                ((Perlin)module).Frequency    = t_frequency;
                ((Perlin)module).NoiseQuality = NoiseQuality.Standard;
                ((Perlin)module).Seed         = t_seed;
                ((Perlin)module).OctaveCount  = t_octaves;
                ((Perlin)module).Lacunarity   = t_lacunarity;
                ((Perlin)module).Persistence  = t_persistence;
                break;
            }

            t_imageProcessed = new Engine.Surface.Canvas(t_imageSource.Width, t_imageSource.Height);

            t_workflow.AllowInvalidate = true;

            Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop();

            Engine.Threading.ParamList paramList = new Threading.ParamList();
            paramList.Add(paramName_module, typeof(Engine.Effects.Noise.IModule), module);

            loop.Loop(t_imageSource.Height, Threaded_Process, paramList);
            loop.Dispose();

            base.PostProcess();
        }