예제 #1
0
        private void CreateConvolutionBmp(int width, int height)
        {
            int[] pixels = new int[width * height];

            var dataSource = this.GetValueSync <IDataSource2D <Vector> >(DataSourceProperty);;

            GenerateWhiteNoizeImage(width, height, pixels);
            //GenerateWhiteCirclesImage(width, height, pixels);

            UpdateBitmap(pixels);

            int[] effectivePixels = CreateConvolutionArray(width, height, pixels);

            UpdateBitmap(effectivePixels);

            normalizeFilter.ApplyFilter(effectivePixels, width, height, dataSource.Data);

            magnitudeFilter.ApplyFilter(effectivePixels, width, height, dataSource.Data);

            UpdateBitmap(effectivePixels);
        }
		private void CreateConvolutionBmp(int width, int height, ParallelOptions parallelOptions)
		{
			var dataSource = this.GetValueSync<IDataSource2D<Vector>>(DataSourceProperty);
			if (dataSource == null)
				return;

			if (parallelOptions.CancellationToken.IsCancellationRequested)
				return;

			int[] pixels = null;
			if (unmodifiedWhiteNoize == null)
			{
				pixels = ImageHelper.CreateWhiteNoizeImage(width, height);
				unmodifiedWhiteNoize = new int[pixels.Length];
				pixels.CopyTo(unmodifiedWhiteNoize, 0);
			}
			else
			{
				pixels = new int[unmodifiedWhiteNoize.Length];
				unmodifiedWhiteNoize.CopyTo(pixels, 0);
			}

			if (parallelOptions.CancellationToken.IsCancellationRequested)
				return;

			UpdateBitmap(pixels);

			if (parallelOptions.CancellationToken.IsCancellationRequested)
				return;

			bool cancelled = false;
			int[] effectivePixels = CreateConvolutionArray(width, height, pixels, parallelOptions, out cancelled);

			if (cancelled)
				return;

			if (parallelOptions.CancellationToken.IsCancellationRequested)
				return;

			UpdateBitmap(effectivePixels);

			if (parallelOptions.CancellationToken.IsCancellationRequested)
				return;

			if (transparencyFilter == null)
				transparencyFilter = new TransparencyFilter(unmodifiedWhiteNoize);

			//effectivePixels = transparencyFilter.ApplyFilter(effectivePixels, width, height, dataSource.Data);

			effectivePixels = normalizeFilter.ApplyFilter(effectivePixels, width, height, dataSource.Data);

			if (parallelOptions.CancellationToken.IsCancellationRequested)
				return;

			effectivePixels = magnitudeFilter.ApplyFilter(effectivePixels, width, height, dataSource.Data);

			if (parallelOptions.CancellationToken.IsCancellationRequested)
				return;

			UpdateBitmap(effectivePixels);

			RaiseRenderingFinished();
		}