using System; using System.Drawing; namespace Treko { public class InfoSpace { double _x0; double _y0; double _width; double _height; double _holoWidth; double _holoHeight; int _widthPix; int _heightPix; double _maxRadius; double _step; double _stepPix; public double X0 { get { return _x0; } set { _x0 = value; } } public double Y0 { get { return _y0; } set { _y0 = value; } } public double Width { get { return _width; } set { _width = value; } } public double Height { get { return _height; } set { _height = value; } } public int WidthPix { get { return _widthPix; } set { _widthPix = value; } } public int HeightPix { get { return _heightPix; } set { _heightPix = value; } } public double MaxRadius { get { return _maxRadius; } set { _maxRadius = value; } } public double Step { get { return _step; } set { _step = value; } } public double StepPix { get { return _stepPix; } set { _stepPix = value; } } InfoSpace() { } private double aspectRatio(double widthPix, double heightPix) { return widthPix / heightPix; } // HoloWidt - width of hologram // WidthPix - source image width in pixels // HeightPix - source image height in pixels // MaxRad - maximum radius of circle public InfoSpace(double X0, double Y0, double HoloWidth, double HoloHeight, int WidthPix, int HeightPix, double MaxRad, double step) { _x0 = X0; _y0 = Y0; _widthPix = WidthPix; _heightPix = HeightPix; _holoWidth = HoloWidth; _holoHeight = HoloHeight; _width = HoloWidth - 2 * MaxRad; _height = _width / aspectRatio(Convert.ToDouble(WidthPix), Convert.ToDouble(HeightPix)); _maxRadius = MaxRad; _step = step; _stepPix = (double)WidthPix / NColorPixelsHor(); } int NColorPixelsHor() { int nColorPix; nColorPix = Convert.ToInt16(Math.Ceiling(_width / _step)); return nColorPix; } int NColorPixelsVert() { int nColorPix; nColorPix = Convert.ToInt16(Math.Ceiling(_height / _step)); return nColorPix; } // Calculates average color of several pixels of input image public Color DefColor(int[,] pixels, double ii, double jj) { int m, n, w, h; int i = Convert.ToInt32(ii); int j = Convert.ToInt32(jj); Color col, RetCol; RetCol = Color.FromArgb(0, 0, 0); w = Convert.ToInt32(Math.Ceiling(_stepPix)); h = w; if ((w + i) > _widthPix) w = _widthPix - Convert.ToInt16(i); if ((h + j) > _heightPix) h = _heightPix - Convert.ToInt16(j); for (n = j; n < j + h; n++) { for (m = i; m < i + w; m++) { col = Color.FromArgb((int)pixels[n, m]); if ((col.R + col.G + col.B) > 0) RetCol = col; if (col.R > 0) return RetCol; } } return RetCol; } public ColorPixel[,] GenVectorData(int[,] Pixels, Angles angles, double radiusMax) { //HologramWidth = 30; double x, y; int nColorPixelsHor = NColorPixelsHor(); int nColorPixelsVert = NColorPixelsVert(); //decimal decim = nColorPixelsHor / 200; int decimate = (int)Math.Round((decimal)nColorPixelsHor / 200, MidpointRounding.AwayFromZero); if (decimate == 0) decimate = 1; //!!!!Nick ColorPixel[,] colorPixels = new ColorPixel[nColorPixelsHor, nColorPixelsVert]; double stepDouble = StepPix; for (int j = 0; j < nColorPixelsVert; j += decimate) { for (int i = 0; i < nColorPixelsHor; i += decimate) { x = i * stepDouble; y = j * stepDouble; Color color = DefColor(Pixels, x, y); if (color.R == 0 && color.G == 0 && color.B == 0) { colorPixels[i, j] = null; continue; } //if (i == 5 && j == 5) // i = 5; x = i * _step; y = j * _step; ColorPixel colPix = angles.CreateColorPixel(color, x + _x0, y + _y0, radiusMax, _step); colorPixels[i, j] = colPix; } } return colorPixels; } } }