/// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="security">Used security level.</param>
 /// <param name="encrypt"></param>
 /// <param name="blockCipherKey"></param>
 /// <param name="aad"></param>
 /// <param name="iv"></param>
 /// <param name="tag"></param>
 public GXDLMSChipperingStream(Security security, bool encrypt, byte[] blockCipherKey, byte[] aad, byte[] iv, byte[] tag)
 {            
     this.Security = security;
     const int TagSize = 0x10;
     this.Tag = tag;
     if (this.Tag == null)//Tag size is 12 bytes.
     {
         this.Tag = new byte[12];
     }
     else if (this.Tag.Length != 12)
     {
         throw new ArgumentOutOfRangeException("Invalid tag.");
     }
     Encrypt = encrypt;
     WorkingKey = GenerateKey(true, blockCipherKey);
     int bufLength = Encrypt ? BlockSize : (BlockSize + TagSize);
     this.bufBlock = new byte[bufLength];
     Aad = aad;
     this.H = new byte[BlockSize];
     ProcessBlock(H, 0, H, 0);
     Init(H);
     this.J0 = new byte[16];
     Array.Copy(iv, 0, J0, 0, iv.Length);
     this.J0[15] = 0x01;
     this.S = GetGHash(Aad);
     this.counter = (byte[]) J0.Clone();
     this.BytesRemaining = 0;
     this.totalLength = 0;
 }
Ejemplo n.º 2
0
		public override void Initialize(RandomGenerator random) {
			InverseKey = mul(transpose4(GenerateUnimodularMatrix(random)), GenerateUnimodularMatrix(random));

			var cof = new uint[4, 4];
			for (int i = 0; i < 4; i++)
				for (int j = 0; j < 4; j++)
					cof[i, j] = cofactor4(InverseKey, i, j);
			Key = transpose4(cof);
		}
Ejemplo n.º 3
0
      /// <summary>
      /// Detect blobs from input image.
      /// </summary>
      /// <param name="img">The input image</param>
      /// <param name="blobs">The storage for the detected blobs</param>
      /// <returns>Number of pixels that has been labeled.</returns>
      public uint Detect(Image<Gray, Byte> img, CvBlobs blobs)
      {
         Size size = img.Size;

         if (_data == null || _data.GetLength(0) != size.Height || _data.GetLength(1) != size.Width)
         {
            DisposeObject();

            _data = new UInt32[size.Height, size.Width];
            _dataHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
            _ptr = CvInvoke.cvCreateImageHeader(size, (CvEnum.IplDepth)(_sizeOfUInt32 * 8), 1);
            CvInvoke.cvSetData(_ptr, _dataHandle.AddrOfPinnedObject(), _sizeOfUInt32 * size.Width);
         }

         return cvbCvLabel(img, _ptr, blobs);
      }
Ejemplo n.º 4
0
        private void FindBestFit(
            float x0, float y0,
			Filter filter, uint[,] matrix, int bpp,
            bool findBestMatrixSize, ref int matrixSize,
            bool fixedAperture, bool doCentroidFitForFixedAperture)
        {
            m_HasSaturatedPixels = false;
            m_PSFBackground = double.NaN;
            m_FoundBestPSFFit = null;
            m_PixelData = null;

            if (filter == Filter.LPD)
            {
                m_PixelData = ImageFilters.LowPassDifferenceFilter(matrix, bpp);
            }
            else if (filter == Filter.LP)
            {
                m_PixelData = ImageFilters.LowPassFilter(matrix, bpp, false);
            }
            else
                m_PixelData = matrix;

            int x0i = (int)Math.Round(x0);
            int y0i = (int)Math.Round(y0);

            bool isSolved = false;
            Trace.Assert(m_PixelData.GetLength(0) == m_PixelData.GetLength(1));
            int halfDataSize = (int)Math.Ceiling(m_PixelData.GetLength(0) / 2.0);

            if (findBestMatrixSize)
            {

                if (!fixedAperture)
                {
                    PSFFit fit = new PSFFit(x0i, y0i);

                    #region Copy only the matix around the PFS Fit Area
                    do
                    {
                        int halfSize = matrixSize / 2;
                        uint[,] fitAreaMatrix = new uint[matrixSize, matrixSize];
                        int xx = 0, yy = 0;
                        for (int y = halfDataSize - halfSize; y <= halfDataSize + halfSize; y++)
                        {
                            xx = 0;
                            for (int x = halfDataSize - halfSize; x <= halfDataSize + halfSize; x++)
                            {
                                fitAreaMatrix[xx, yy] = m_PixelData[x, y];
                                xx++;
                            }
                            yy++;
                        }
                        fit.Fit(fitAreaMatrix);

                        m_XCenter = fit.X0_Matrix + halfDataSize - halfSize;
                        m_YCenter = fit.Y0_Matrix + halfDataSize - halfSize;

                        if (!findBestMatrixSize)
                            break;

                        if (Math.Sqrt((m_XCenter - halfDataSize) * (m_XCenter - halfDataSize) + (m_YCenter - halfDataSize) * (m_YCenter - halfDataSize)) <
                            BestMatrixSizeDistanceDifferenceTolerance)
                            break;

                        matrixSize -= 2;
                    } while (matrixSize > 0);

                    #endregion

                    isSolved = fit.IsSolved;
                    if (isSolved)
                    {
                        m_FoundBestPSFFit = fit;
                    }
                }
                else
                {
                    // Fixed Aperture
                    if (doCentroidFitForFixedAperture)
                    {
                        //"Do a 5x5 centroid cenetring, then get the new byte[,] around this new center, and then pass for measuring with a fixed aperture value");
                    }

                    m_XCenter = halfDataSize - 1;
                    m_YCenter = halfDataSize - 1;
                }
            }
            else
            {
                m_XCenter = halfDataSize - 1;
                m_YCenter = halfDataSize - 1;
            }

            m_TotalReading = 0;
            m_TotalBackground = 0;
            m_PSFBackground = 0;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generate large sudoku from templates
        /// </summary>
        private void GenerateInternalLarge()
        {
            List<Sudoku> sudokus = Sudoku.InitFromFile("res/templates.sud");
            Sudoku sudoku = sudokus[new Random().Next(sudokus.Count())];

            this.sudokuValues = sudoku.sudokuValues;
        }
Ejemplo n.º 6
0
        public VqaReader(Stream stream)
        {
            this.stream = stream;

            // Decode FORM chunk
            if (stream.ReadASCII(4) != "FORM")
            {
                throw new InvalidDataException("Invalid vqa (invalid FORM section)");
            }
            /*var length = */ stream.ReadUInt32();

            if (stream.ReadASCII(8) != "WVQAVQHD")
            {
                throw new InvalidDataException("Invalid vqa (not WVQAVQHD)");
            }
            /*var length2 = */ stream.ReadUInt32();

            /*var version = */ stream.ReadUInt16();
            videoFlags = stream.ReadUInt16();
            frames     = stream.ReadUInt16();
            width      = stream.ReadUInt16();
            height     = stream.ReadUInt16();

            blockWidth       = stream.ReadUInt8();
            blockHeight      = stream.ReadUInt8();
            framerate        = stream.ReadUInt8();
            chunkBufferParts = stream.ReadUInt8();
            blocks           = new int2(width / blockWidth, height / blockHeight);

            numColors = stream.ReadUInt16();
            /*var maxBlocks = */ stream.ReadUInt16();
            /*var unknown1 = */ stream.ReadUInt16();
            /*var unknown2 = */ stream.ReadUInt32();

            // Audio
            sampleRate    = stream.ReadUInt16();
            audioChannels = stream.ReadByte();
            sampleBits    = stream.ReadByte();

            /*var unknown3 =*/ stream.ReadUInt32();
            /*var unknown4 =*/ stream.ReadUInt16();
            /*maxCbfzSize =*/ stream.ReadUInt32();            // Unreliable

            /*var unknown5 =*/ stream.ReadUInt32();

            var frameSize = Exts.NextPowerOf2(Math.Max(width, height));

            if (IsHqVqa)
            {
                cbfBuffer = new byte[maxCbfzSize];
                cbf       = new byte[maxCbfzSize * 3];
                origData  = new byte[maxCbfzSize];
            }
            else
            {
                cbfBuffer = new byte[width * height];
                cbf       = new byte[width * height];
                cbp       = new byte[width * height];
                origData  = new byte[2 * blocks.X * blocks.Y];
            }

            palette   = new uint[numColors];
            frameData = new uint[frameSize, frameSize];
            var type = stream.ReadASCII(4);

            while (type != "FINF")
            {
                // Sub type is a file tag
                if (type[3] == 'F')
                {
                    var jmp = int2.Swap(stream.ReadUInt32());
                    stream.Seek(jmp, SeekOrigin.Current);
                    type = stream.ReadASCII(4);
                }
                else
                {
                    throw new NotSupportedException("Vqa uses unknown Subtype: {0}".F(type));
                }
            }

            /*var length = */ stream.ReadUInt16();
            /*var unknown4 = */ stream.ReadUInt16();

            // Frame offsets
            offsets = new uint[frames];
            for (var i = 0; i < frames; i++)
            {
                offsets[i] = stream.ReadUInt32();
                if (offsets[i] > 0x40000000)
                {
                    offsets[i] -= 0x40000000;
                }
                offsets[i] <<= 1;
            }

            CollectAudioData();

            Reset();
        }
Ejemplo n.º 7
0
 public void ResizeGrid(int rows, int columns)
 {
     var newBackpack = new uint[rows, columns];
     Array.Copy(_backpack, newBackpack, _backpack.Length);
     _backpack = newBackpack;
 }
Ejemplo n.º 8
0
 public static List <PSFFit> GetStarsInArea(ref uint[,] data, int bpp, uint maxSignalValue, uint noiseValue, TangraConfig.PreProcessingFilter filter)
 {
     return(GetStarsInArea(ref data, bpp, maxSignalValue, noiseValue, filter, null, null));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Release all the unmanaged memory associated with this Blob detector
 /// </summary>
 protected override void DisposeObject()
 {
     if (_data != null)
      {
     _dataHandle.Free();
     CvInvoke.cvReleaseImageHeader(ref _ptr);
     _data = null;
      }
 }
        private void CalculateTwoObjectsPSFs()
        {
            if (m_AutoDoubleCenter != null)
            {
                m_Center = new ImagePixel(m_AutoDoubleCenter);
                m_X1Start = m_AutoDoubleX1Start;
                m_Y1Start = m_AutoDoubleY1Start;
                m_X2Start = m_AutoDoubleX2Start;
                m_Y2Start = m_AutoDoubleY2Start;
                m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center.X, m_Center.Y, 35);
                m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center.X, m_Center.Y, 35);
            }

            if (!m_UserPeakMode &&
                !FirstObjectPeakDefined() && !SecondObjectPeakDefined() &&
                !LocatePeaks())
            {
                m_UserPeakMode = true;

                MessageBox.Show(
                    this,
                    "Please click on the image to define the center of each of the two objects.",
                    "Tangra",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Question);

                picTarget1Pixels.Cursor = Cursors.Cross;

                UpdateViews();

                return;
            }

            if (!FirstObjectPeakDefined() || !SecondObjectPeakDefined())
            {
                MessageBox.Show(
                    this,
                    "Cannot locate two objects.",
                    "Tangra",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }

            var psfFit = new DoublePSFFit(m_Center.X, m_Center.Y);
            if (TangraConfig.Settings.Photometry.PsfFittingMethod == TangraConfig.PsfFittingMethod.LinearFitOfAveragedModel)
                psfFit.FittingMethod = PSFFittingMethod.LinearFitOfAveragedModel;
            psfFit.Fit(m_ProcessingPixels, m_X1Start, m_Y1Start, m_X2Start, m_Y2Start);

            if (psfFit.IsSolved)
            {
                m_DoubleGaussian = psfFit;
                m_FWHM = (float)psfFit.FWHM;
                m_X0 = psfFit.X0_Matrix;
                m_Y0 = psfFit.Y0_Matrix;

                m_FWHM1 = (float)psfFit.FWHM1;
                m_FWHM2 = (float)psfFit.FWHM2;
                m_X1 = psfFit.X1_Matrix;
                m_Y1 = psfFit.Y1_Matrix;
                m_X2 = psfFit.X2_Matrix;
                m_Y2 = psfFit.Y2_Matrix;
                m_X1Center = (float)psfFit.X1Center;
                m_Y1Center = (float)psfFit.Y1Center;
                m_X2Center = (float)psfFit.X2Center;
                m_Y2Center = (float)psfFit.Y2Center;

                if (m_Aperture1 == null)
                {
                    if (TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM)
                        m_Aperture1 = (float)(psfFit.FWHM1 * TangraConfig.Settings.Photometry.DefaultSignalAperture);
                    else
                        m_Aperture1 = (float)(TangraConfig.Settings.Photometry.DefaultSignalAperture);
                }
                else if (
                    TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM &&
                    m_Aperture1 < (float)(psfFit.FWHM1 * TangraConfig.Settings.Photometry.DefaultSignalAperture))
                {
                    // When the default aperture size is in FWHM we always use the largest aperture so far
                    m_Aperture1 = (float)(psfFit.FWHM1 * TangraConfig.Settings.Photometry.DefaultSignalAperture);
                }

                if (m_Aperture2 == null)
                {
                    if (TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM)
                        m_Aperture2 = (float)(psfFit.FWHM2 * TangraConfig.Settings.Photometry.DefaultSignalAperture);
                    else
                        m_Aperture2 = (float)(TangraConfig.Settings.Photometry.DefaultSignalAperture);
                }
                else if (
                    TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM &&
                    m_Aperture2 < (float)(psfFit.FWHM2 * TangraConfig.Settings.Photometry.DefaultSignalAperture))
                {
                    // When the default aperture size is in FWHM we always use the largest aperture so far
                    m_Aperture2 = (float) (psfFit.FWHM2*TangraConfig.Settings.Photometry.DefaultSignalAperture);
                }

                if (m_Aperture1 > m_Aperture2) m_Aperture2 = m_Aperture1;
                if (m_Aperture2 > m_Aperture1) m_Aperture1 = m_Aperture2;

                nudAperture1.SetNUDValue(m_Aperture1.Value);

                m_Aperture = null;
                m_Gaussian = null;
            }
        }
Ejemplo n.º 11
0
 //重新申请空间
 public void Reinit(uint r, uint c)
 {
     rows    = r;
     columns = c;
     value   = new uint[r, c];
 }
Ejemplo n.º 12
0
 public PrngGlibc3()
 {
     this._NextMatrix = GenerateNextMatrix();
     this._PreviousMatrix = GeneratePreviousMatrix();
 }
        private void CalculateSingleObjectPSF()
        {
            m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_OriginalCenter.X, m_OriginalCenter.Y, 35);
            m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_OriginalCenter.X, m_OriginalCenter.Y, 35);

            var psfFit = new PSFFit(m_OriginalCenter.X, m_OriginalCenter.Y);

            psfFit.Fit(m_ProcessingPixels);

            if (psfFit.IsSolved)
            {
                m_Gaussian = psfFit;
                m_FWHM = (float)m_Gaussian.FWHM;
                m_X0 = m_Gaussian.X0_Matrix;
                m_Y0 = m_Gaussian.Y0_Matrix;
                m_X0Center = (float)psfFit.XCenter;
                m_Y0Center = (float)psfFit.YCenter;

                if (m_Aperture == null)
                {
                    if (TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM)
                        m_Aperture = (float)(m_Gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture);
                    else
                        m_Aperture = (float)(TangraConfig.Settings.Photometry.DefaultSignalAperture);
                }
                else if (
                    TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM &&
                    m_Aperture < (float)(psfFit.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture))
                {
                    // When the default aperture size is in FWHM we always use the largest aperture so far
                    m_Aperture = (float)(psfFit.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture);
                }

                nudAperture1.SetNUDValue(m_Aperture.Value);

                m_Aperture1 = null;
                m_Aperture2 = null;
                m_DoubleGaussian = null;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// second cycle runs after "calculate_simple_amount_of_items()" and builds the first level pattern
        /// </summary>
        private void run_second_cycle()
        {
            log("Running second cycle..");
            sw.Start();

            List<uint> tempIndexes = new List<uint>();

            bool hi1 = false, hi2 = false;
            for(int i = 0; i < rep_items_2nd.Length; i++){ //run through all pairs
                for (int r = 0; r < dataset_count; r++) //all datasets rows
                {
                    hi1 = false; hi2 = false;

                    for (int c = 0; c < dataset_attribute_count; c++) //all dataset columns
                    {
                        if (rep_dataset[r, c] == rep_items_2nd[i][0])
                            hi1 = true;

                        if (rep_dataset[r, c] == rep_items_2nd[i][1])
                            hi2 = true;
                    }

                    if (hi1 && hi2) //if pair was present in this row increase its count
                    {
                        rep_items_2nd[i][2]++;

                        if (!tempIndexes.Contains((uint)r))
                            tempIndexes.Add((uint)r); //store the index of the row that contained a pair (faster check if index was added)
                    }
                }
            }

            //get rid of the datasets that do not contain any pairs
            uint[,] reDataset = new uint[tempIndexes.Count, dataset_attribute_count];
            for (int r = 0; r < tempIndexes.Count; r++)
                for (int c = 0; c < dataset_attribute_count; c++)
                    reDataset[r, c] = rep_dataset[r, c];

            //overwrite current dataset
            rep_dataset = reDataset;
            dataset_count = rep_dataset.Length / dataset_attribute_count;

            log(string.Format("Second cycle done, took {0} ms.", sw.ElapsedMilliseconds));
            sw.Reset();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// runs a cycle "N", make sure to run "build_pair_list_for_n_cycle" before -> counts the possible pairs in the dataset
        /// </summary>
        /// <param name="n">number of cycles</param>
        private void run_n_cycle(int n)
        {
            log(string.Format("Running next cycle {0}..", n));
            sw.Start();

            List<uint> tempIndexes = new List<uint>();
            int colCount = 1;

            for (int i = 0; i < rep_items_n_conf.Length; i++) //for every pair combination -> P
            {
                for (int r = 0; r < dataset_count; r++) //run through all datasets -> D
                {
                    colCount = 1;

                    for (int c = 0; c < dataset_attribute_count; c++) //and through all items -> I
                    {
                       uint itemD = rep_dataset[r, c];
                       uint itemC = rep_items_n_conf[i][colCount - 1];

                       if (itemD == itemC)
                           colCount++;
                    }

                    if (colCount == n)
                    {
                        rep_items_n_conf[i][n]++;

                        if (!tempIndexes.Contains((uint)r))
                            tempIndexes.Add((uint)r); //store the index of the row that contained a pair (faster check if index was added)
                    }
                }
            }

            //get rid of the datasets that do not contain any pairs
            uint[,] reDataset = new uint[tempIndexes.Count, dataset_attribute_count];
            for (int r = 0; r < tempIndexes.Count; r++)
                for (int c = 0; c < dataset_attribute_count; c++)
                    reDataset[r, c] = rep_dataset[r, c];

            //overwrite current dataset
            rep_dataset = reDataset;
            dataset_count = rep_dataset.Length / dataset_attribute_count;

            log(string.Format("Cycle run done, took {0} ms.",sw.ElapsedMilliseconds));
            sw.Reset();
        }
        /// <summary>
        /// Aoustic processed event handler for the donator.
        /// Store duration and/or f0 of donator locally.
        /// </summary>
        /// <param name="sender">Sender of the event handler.</param>
        /// <param name="e">Event argument object.</param>
        private void OnDonatorAcousticProcessed(object sender, TtsModuleEventArgs e)
        {
            if (e.ModuleType == TtsModuleType.TM_APT_DURATION &&
                _config.DonateDuration)
            {
                _donatorDuration = e.Utterance.Acoustic.Durations.ToArray();
            }

            if (e.ModuleType == TtsModuleType.TM_APT_F0 &&
                _config.DonateF0)
            {
                _donatorF0 = e.Utterance.Acoustic.F0s.ToArray();
            }

            if (e.ModuleType == TtsModuleType.TM_APT_LSF)
            {
                _receiver.SpeechSynthesizer.Speak(_curScriptSententence.Text);
            }
        }
Ejemplo n.º 17
0
 public void Init(bool forEncryption, byte[] key)
 {
     WorkingKey         = GenerateWorkingKey(key, forEncryption);
     this.forEncryption = forEncryption;
 }
        private void Initialise()
        {
            picTarget1Pixels.Image = new Bitmap(AREA_SIDE * MAGN_FACTOR, AREA_SIDE * MAGN_FACTOR, PixelFormat.Format24bppRgb);
            picTarget1PSF.Image = new Bitmap(picTarget1PSF.Width, picTarget1PSF.Height);

            m_AllTargetColors = new Color[]
            {
                TangraConfig.Settings.Color.Target1,
                TangraConfig.Settings.Color.Target2,
                TangraConfig.Settings.Color.Target3,
                TangraConfig.Settings.Color.Target4
            };

            m_Color = m_AllTargetColors[m_ObjectId];
            if (m_ObjectId < 3 && !m_IsEdit)
                m_Color2 = m_AllTargetColors[m_ObjectId + 1];

            bool doubleModeDisabled = false;

            if (m_IsEdit && m_ObjectId2 <=3)
            {
                m_Color2 = m_AllTargetColors[m_ObjectId2];
            }
            else if (m_ObjectId == 3 || m_ObjectId2 == 4)
            {
                doubleModeDisabled = true;
                rbTwoObjects.Enabled = false;
            }

            m_Pen = new Pen(m_Color);
            m_Brush = new SolidBrush(m_Color);
            m_Pen2 = new Pen(m_Color2);
            m_Brush2 = new SolidBrush(m_Color2);

            m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center.X, m_Center.Y, 35);
            m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center.X, m_Center.Y, 35);

            ImagePixel newCenter = null;
            bool autoDoubleObjectLocated = m_TryAutoDoubleFind && TryAutoLocateDoubleObject(out newCenter);
            if (autoDoubleObjectLocated)
            {
                int deltaX = (int)Math.Round(newCenter.XDouble - 18);
                int deltaY = (int)Math.Round(newCenter.YDouble - 18);
                m_X1Start -= deltaX;
                m_Y1Start -= deltaY;
                m_X2Start -= deltaX;
                m_Y2Start -= deltaY;
                m_Center = new ImagePixel(newCenter.Brightness, m_Center.XDouble + newCenter.XDouble - 18, m_Center.YDouble + newCenter.YDouble - 18);
                m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center.X, m_Center.Y, 35);
                m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center.X, m_Center.Y, 35);

                m_AutoDoubleCenter = new ImagePixel(m_Center);
                m_AutoDoubleX1Start = m_X1Start;
                m_AutoDoubleY1Start = m_Y1Start;
                m_AutoDoubleX2Start = m_X2Start;
                m_AutoDoubleY2Start = m_Y2Start;
            }

            bool occultedStartAlreadyPicked = m_State.MeasuringStars.Any(x => x.IsOcultedStar());

            if (m_IsEdit)
            {
                rbOcculted.Enabled = m_EditingOccultedStar || !occultedStartAlreadyPicked;
                rbReference.Checked = !m_EditingOccultedStar;
                rbOcculted.Checked = m_EditingOccultedStar;
            }
            else
            {
                if (occultedStartAlreadyPicked)
                {
                    rbOcculted.Enabled = false;
                    rbReference.Checked = true;
                }
                else
                {
                    rbOcculted.Enabled = true;
                    rbOcculted.Checked = true;
                }
            }

            if (doubleModeDisabled || !autoDoubleObjectLocated)
                rbOneObject.Checked = true;

            UpdateStateControls();

            DrawCollorPanel();
            DrawCollorPanel2();

            CalculatePSF();
        }
Ejemplo n.º 19
0
 /***************************/
 //以下是基本操作
 /***************************/
 //构造方法:申请空间
 public BinaryMatrix(uint r, uint c)
 {
     rows    = r;
     columns = c;
     value   = new uint[r, c];
 }
Ejemplo n.º 20
0
 public PrngDotNetBase()
 {
     this._NextMatrix = GenerateNextMatrix();
     this._PreviousMatrix = GeneratePreviousMatrix();
 }
Ejemplo n.º 21
0
        private static void CheckPixelsFromBrightToFaint(
            uint[,] data, int nWidth, int nHeight, int bpp, uint maxSignalValue, uint aboveNoiseLevelRequired, Rectangle excludeArea, ExaminePeakPixelCandidate callback)
        {
            bool excludeAreaDefined = Rectangle.Empty != excludeArea;

            int includsionCheckStep = 10;

            if (bpp == 12)
            {
                includsionCheckStep = 50;
            }
            else if (bpp == 14)
            {
                includsionCheckStep = 60;
            }
            else if (bpp == 16)
            {
                includsionCheckStep = 100;
            }

            int maxPixelValue = 255;

            if (bpp > 8)
            {
                maxPixelValue = (int)maxSignalValue;
            }

            int currInclusionLimit = maxPixelValue - includsionCheckStep + 1;

            while (currInclusionLimit > aboveNoiseLevelRequired)
            {
                for (int i = 1; i < nWidth - 1; i++)
                {
                    for (int j = 1; j < nHeight - 1; j++)
                    {
                        if (excludeAreaDefined && excludeArea.Contains(i, j))
                        {
                            continue;
                        }

                        uint testedPixel = data[i, j];

                        if (testedPixel > currInclusionLimit &&
                            testedPixel <= currInclusionLimit + includsionCheckStep &&
                            testedPixel >= data[i - 1, j] &&
                            testedPixel >= data[i - 1, j - 1] &&
                            testedPixel >= data[i, j - 1] &&
                            testedPixel >= data[i + 1, j - 1] &&
                            testedPixel >= data[i + 1, j] &&
                            testedPixel >= data[i + 1, j + 1] &&
                            testedPixel >= data[i, j + 1] &&
                            testedPixel >= data[i - 1, j + 1])
                        {
                            if (!callback(i, j, testedPixel))
                            {
                                return;
                            }
                        }
                    }
                }

                currInclusionLimit -= includsionCheckStep;
            }
        }
Ejemplo n.º 22
0
        public override string Encrypt(string text)
        {
            dublicateKey();
            int c = _Key.Length;
            text = elongationText(text);

            _P = (uint[])_bufferP.Clone();
            _S = (uint[,])_bufferS.Clone();

            int[] bufferKey32Bits = new int[32];

            //Инициализация массивов P и S при помощи секретного ключа K
            int counterKey32bit = 0;
            int counterP = 0;
            for (int i = 0; i < 18 * 32; i++)
            {
                if (i % 32 == 0 && i != 0)
                {
                    _P[counterP] = (uint)(Convert.ToInt32(bufferKey32Bits.ToStringArray(), 2) ^ (int)_bufferP[counterP]);
                    Array.Clear(bufferKey32Bits, 0, bufferKey32Bits.Length);
                    counterKey32bit = 0;
                    counterP++;
                }
                bufferKey32Bits[counterKey32bit] = _Key.ToBits()[i];
                counterKey32bit++;
            }

            StringBuilder result = new StringBuilder();

            int counterText64bit = 0;
            int[] bufferText64Bits = new int[64];
            rezult = text;
            for (int i = 0; i < text.ToBits().Length+1; i++)
            {
                if (i % 64 == 0 && i != 0)
                {
                    result.Append(blowfish64(bufferText64Bits, false).ToStringArray());
                    Array.Clear(bufferText64Bits, 0, bufferText64Bits.Length);
                    counterText64bit = 0;
                }
                if(i != text.ToBits().Length)
                    bufferText64Bits[counterText64bit] = text.ToBits()[i];
                counterText64bit++;
            }

            return text.ToBits().ToStringArray();
        }
 public IntegralImage(int outputImgWidth, int outputImgHeight)
 {
     Integral        = new uint[outputImgWidth, outputImgHeight];
     OutputImgWidth  = outputImgWidth;
     OutputImgHeight = outputImgHeight;
 }
Ejemplo n.º 24
0
        public override string Decrypt(string text)
        {
            _P = (uint[])_bufferP.Clone();
            _S = (uint[,])_bufferS.Clone();

            int[] bufferKey32Bits = new int[32];

            //Инициализация массивов P и S при помощи секретного ключа K
            int counterKey32bit = 0;
            int counterP = 17;
            for (int i = 18 * 32; i > -1; i--)
            {
                if (i % 32 == 0 && i != 18 * 32)
                {
                    _P[counterP] = (uint)(Convert.ToInt32(bufferKey32Bits.ToStringArray(), 2) ^ (int)_bufferP[counterP]);
                    Array.Clear(bufferKey32Bits, 0, bufferKey32Bits.Length);
                    counterKey32bit = 0;
                    counterP--;
                }
                if (i != 0)
                    bufferKey32Bits[counterKey32bit] = _Key.ToBits()[18 * 32 - i];
                counterKey32bit++;
            }

            StringBuilder result = new StringBuilder();

            int counterText64bit = 0;
            int[] bufferText64Bits = new int[64];
            for (int i = 0; i < text.Length + 1; i++)
            {
                if (i % 64 == 0 && i != 0)
                {
                    result.Append(blowfish64(bufferText64Bits, true).ToStringArray());
                    Array.Clear(bufferText64Bits, 0, bufferText64Bits.Length);
                    counterText64bit = 0;
                }
                if (i != text.Length)
                    bufferText64Bits[counterText64bit] = text[i]-48;
                counterText64bit++;
            }

            return rezult.ToString();
        }
Ejemplo n.º 25
0
        private void LoadCharSheet()
        {
            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            Stream file       = thisExe.GetManifestResourceStream("DirectXEmu.images.charSheet.png");
            Bitmap charBitmap = (Bitmap)Bitmap.FromStream(file);

            file.Close();
            charSheet = new uint[charBitmap.Height / 2, charBitmap.Width / 2];
            unsafe
            {
                BitmapData bmd    = charBitmap.LockBits(new Rectangle(0, 0, charBitmap.Width, charBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                uint *     pixels = (uint *)(bmd.Scan0);
                for (int x = 0; x < (charBitmap.Width >> 1); x++)
                {
                    for (int y = 0; y < (charBitmap.Height >> 1); y++)
                    {
                        uint color = pixels[((y << 1) * charBitmap.Width) + (x << 1)];
                        if ((color & 0xFF000000) != 0xFF000000)
                        {
                            color = 0xFF000000;
                        }
                        charSheet[y, x] = color;
                    }
                }
                charBitmap.UnlockBits(bmd);
            }
            charSize = 8;
            charSheetSprites[' '] = 0;
            charSheetSprites['0'] = 1;
            charSheetSprites['1'] = 2;
            charSheetSprites['2'] = 3;
            charSheetSprites['3'] = 4;
            charSheetSprites['4'] = 5;
            charSheetSprites['5'] = 6;
            charSheetSprites['6'] = 7;
            charSheetSprites['7'] = 8;
            charSheetSprites['8'] = 9;
            charSheetSprites['9'] = 10;
            charSheetSprites['a'] = 11;
            charSheetSprites['b'] = 12;
            charSheetSprites['c'] = 13;
            charSheetSprites['d'] = 14;
            charSheetSprites['e'] = 15;
            charSheetSprites['f'] = 16;
            charSheetSprites['g'] = 17;
            charSheetSprites['h'] = 18;
            charSheetSprites['i'] = 19;
            charSheetSprites['j'] = 20;
            charSheetSprites['k'] = 21;
            charSheetSprites['l'] = 22;
            charSheetSprites['m'] = 23;
            charSheetSprites['n'] = 24;
            charSheetSprites['o'] = 25;
            charSheetSprites['p'] = 26;
            charSheetSprites['q'] = 27;
            charSheetSprites['r'] = 28;
            charSheetSprites['s'] = 29;
            charSheetSprites['t'] = 30;
            charSheetSprites['u'] = 31;
            charSheetSprites['v'] = 32;
            charSheetSprites['w'] = 33;
            charSheetSprites['x'] = 34;
            charSheetSprites['y'] = 35;
            charSheetSprites['z'] = 36;
            charSheetSprites['='] = 37;
            charSheetSprites['.'] = 45;
            charSheetSprites[':'] = 46;
        }
Ejemplo n.º 26
0
 public TileLayer()
 {
     GIds = null;
     SolidLayer = false;
 }
Ejemplo n.º 27
0
 public void SetData(uint[,] colors)
 {
 }
Ejemplo n.º 28
0
        public CPUID(int thread)
        {
            this.thread = thread;

            uint maxCpuid    = 0;
            uint maxCpuidExt = 0;

            uint eax, ebx, ecx, edx;

            if (thread >= 64)
            {
                throw new ArgumentOutOfRangeException("thread");
            }
            ulong mask = 1UL << thread;

            if (Opcode.CpuidTx(CPUID_0, 0,
                               out eax, out ebx, out ecx, out edx, mask))
            {
                if (eax > 0)
                {
                    maxCpuid = eax;
                }
                else
                {
                    return;
                }

                StringBuilder vendorBuilder = new StringBuilder();
                AppendRegister(vendorBuilder, ebx);
                AppendRegister(vendorBuilder, edx);
                AppendRegister(vendorBuilder, ecx);
                string cpuVendor = vendorBuilder.ToString();
                switch (cpuVendor)
                {
                case "GenuineIntel":
                    vendor = Vendor.Intel;
                    break;

                case "AuthenticAMD":
                    vendor = Vendor.AMD;
                    break;

                default:
                    vendor = Vendor.Unknown;
                    break;
                }
                eax = ebx = ecx = edx = 0;
                if (Opcode.CpuidTx(CPUID_EXT, 0,
                                   out eax, out ebx, out ecx, out edx, mask))
                {
                    if (eax > CPUID_EXT)
                    {
                        maxCpuidExt = eax - CPUID_EXT;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    throw new ArgumentOutOfRangeException("thread");
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("thread");
            }

            maxCpuid    = Math.Min(maxCpuid, 1024);
            maxCpuidExt = Math.Min(maxCpuidExt, 1024);

            cpuidData = new uint[maxCpuid + 1, 4];
            for (uint i = 0; i < (maxCpuid + 1); i++)
            {
                Opcode.CpuidTx(CPUID_0 + i, 0,
                               out cpuidData[i, 0], out cpuidData[i, 1],
                               out cpuidData[i, 2], out cpuidData[i, 3], mask);
            }

            cpuidExtData = new uint[maxCpuidExt + 1, 4];
            for (uint i = 0; i < (maxCpuidExt + 1); i++)
            {
                Opcode.CpuidTx(CPUID_EXT + i, 0,
                               out cpuidExtData[i, 0], out cpuidExtData[i, 1],
                               out cpuidExtData[i, 2], out cpuidExtData[i, 3], mask);
            }

            StringBuilder nameBuilder = new StringBuilder();

            for (uint i = 2; i <= 4; i++)
            {
                if (Opcode.CpuidTx(CPUID_EXT + i, 0,
                                   out eax, out ebx, out ecx, out edx, mask))
                {
                    AppendRegister(nameBuilder, eax);
                    AppendRegister(nameBuilder, ebx);
                    AppendRegister(nameBuilder, ecx);
                    AppendRegister(nameBuilder, edx);
                }
            }
            nameBuilder.Replace('\0', ' ');
            cpuBrandString = nameBuilder.ToString().Trim();
            nameBuilder.Replace("(R)", " ");
            nameBuilder.Replace("(TM)", " ");
            nameBuilder.Replace("(tm)", "");
            nameBuilder.Replace("CPU", "");
            nameBuilder.Replace("Quad-Core Processor", "");
            nameBuilder.Replace("Six-Core Processor", "");
            nameBuilder.Replace("Eight-Core Processor", "");
            for (int i = 0; i < 10; i++)
            {
                nameBuilder.Replace("  ", " ");
            }
            name = nameBuilder.ToString();
            if (name.Contains("@"))
            {
                name = name.Remove(name.LastIndexOf('@'));
            }
            name = name.Trim();

            this.family = ((cpuidData[1, 0] & 0x0FF00000) >> 20) +
                          ((cpuidData[1, 0] & 0x0F00) >> 8);
            this.model = ((cpuidData[1, 0] & 0x0F0000) >> 12) +
                         ((cpuidData[1, 0] & 0xF0) >> 4);
            this.stepping = (cpuidData[1, 0] & 0x0F);

            this.apicId = (cpuidData[1, 1] >> 24) & 0xFF;

            switch (vendor)
            {
            case Vendor.Intel:
                uint maxCoreAndThreadIdPerPackage = (cpuidData[1, 1] >> 16) & 0xFF;
                uint maxCoreIdPerPackage;
                if (maxCpuid >= 4)
                {
                    maxCoreIdPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1;
                }
                else
                {
                    maxCoreIdPerPackage = 1;
                }
                threadMaskWith =
                    NextLog2(maxCoreAndThreadIdPerPackage / maxCoreIdPerPackage);
                coreMaskWith = NextLog2(maxCoreIdPerPackage);
                break;

            case Vendor.AMD:
                uint corePerPackage;
                if (maxCpuidExt >= 8)
                {
                    corePerPackage = (cpuidExtData[8, 2] & 0xFF) + 1;
                }
                else
                {
                    corePerPackage = 1;
                }
                threadMaskWith = 0;
                coreMaskWith   = NextLog2(corePerPackage);

                if (this.family == 0x17)
                {
                    // ApicIdCoreIdSize: APIC ID size.
                    // cores per DIE
                    // we need this for Ryzen 5 (4 cores, 8 threads) ans Ryzen 6 (6 cores, 12 threads)
                    // Ryzen 5: [core0][core1][dummy][dummy][core2][core3] (Core0 EBX = 00080800, Core2 EBX = 08080800)
                    uint max_cores_per_die = (cpuidExtData[8, 2] >> 12) & 0xF;
                    switch (max_cores_per_die)
                    {
                    case 0x04: // Ryzen
                        coreMaskWith = NextLog2(16);
                        break;

                    case 0x05:// Threadripper
                        coreMaskWith = NextLog2(32);
                        break;

                    case 0x06:// Epic
                        coreMaskWith = NextLog2(64);
                        break;
                    }
                }
                break;

            default:
                threadMaskWith = 0;
                coreMaskWith   = 0;
                break;
            }

            processorId = (apicId >> (int)(coreMaskWith + threadMaskWith));
            coreId      = ((apicId >> (int)(threadMaskWith))
                           - (processorId << (int)(coreMaskWith)));
            threadId = apicId
                       - (processorId << (int)(coreMaskWith + threadMaskWith))
                       - (coreId << (int)(threadMaskWith));
        }
Ejemplo n.º 29
0
		/**
		* initialise an AES cipher.
		*
		* @param forEncryption whether or not we are for encryption.
		* @param parameters the parameters required to set up the cipher.
		* @exception ArgumentException if the parameters argument is
		* inappropriate.
		*/
		public void Init(
			bool				forEncryption,
			ICipherParameters	parameters)
		{
			KeyParameter keyParameter = parameters as KeyParameter;

			if (keyParameter == null)
				throw new ArgumentException("invalid parameter passed to AES init - " + parameters.GetType().Name);

			WorkingKey = GenerateWorkingKey(keyParameter.GetKey(), forEncryption);

			this.forEncryption = forEncryption;
		}
Ejemplo n.º 30
0
        private bool GetFitInMatrix(ITrackedObjectPsfFit gaussian, ref int matirxSize, float preselectedAperture)
        {
            rbGuidingStar.Text = "Guiding Star";
            m_IsBrightEnoughForAutoGuidingStar = false;

            if (m_Aperture == null)
            {
                if (gaussian != null && !double.IsNaN(gaussian.FWHM) && TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM)
                    m_Aperture = (float)(gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture);
                else
                    m_Aperture = (float)(TangraConfig.Settings.Photometry.DefaultSignalAperture);
            }
            else if (
                gaussian != null && !double.IsNaN(gaussian.FWHM) && TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM &&
                m_Aperture < (float)(gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture))
            {
                m_Aperture = (float) (gaussian.FWHM*TangraConfig.Settings.Photometry.DefaultSignalAperture);
            }

            nudFitMatrixSize.ValueChanged -= nudFitMatrixSize_ValueChanged;
            try
            {
                uint[,] autoStarsPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center.X, m_Center.Y, 35);
                m_AutoStarsInLargerArea = StarFinder.GetStarsInArea(
                    ref autoStarsPixels,
                    m_AstroImage.Pixelmap.BitPixCamera,
                    m_AstroImage.Pixelmap.MaxSignalValue,
                    m_AstroImage.MedianNoise,
                    LightCurveReductionContext.Instance.DigitalFilter);

                m_ProcessingPixels = ImageFilters.CutArrayEdges(autoStarsPixels, 9);
                m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center.X, m_Center.Y, 17);

                m_AutoStarsInArea = new List<PSFFit>();
                foreach (PSFFit autoStar in m_AutoStarsInLargerArea)
                {
                    if (autoStar.XCenter > 9 && autoStar.XCenter < 9 + 17 &&
                        autoStar.YCenter > 9 && autoStar.YCenter < 9 + 17)
                    {
                        // Don't change original star so use a clone
                        PSFFit clone = autoStar.Clone();
                        clone.SetNewFieldCenterFrom35PixMatrix(8, 8);
                        m_AutoStarsInArea.Add(clone);
                    }
                }

                int oldMatirxSize = matirxSize;

                if (m_AutoStarsInArea.Count == 0)
                {
                    rbGuidingStar.Text = "Guiding Star";

                    // There are no stars that are bright enough. Simply let the user do what they want, but still try to default to a sensible aperture size
                    MeasurementsHelper measurement = ReduceLightCurveOperation.DoConfiguredMeasurement(m_ProcessingPixels, m_Aperture.Value, m_AstroImage.Pixelmap.BitPixCamera, m_AstroImage.Pixelmap.MaxSignalValue, 3.0, ref matirxSize);

                    if (measurement.FoundBestPSFFit != null &&
                        measurement.FoundBestPSFFit.IsSolved &&
                        measurement.FoundBestPSFFit.Certainty > 0.1)
                    {
                        m_X0 = measurement.XCenter;
                        m_Y0 = measurement.YCenter;
                        m_FWHM = (float) measurement.FoundBestPSFFit.FWHM;
                    }
                    else
                    {
                        m_X0 = 8;
                        m_Y0 = 8;
                        m_FWHM = 6;
                    }

                    m_Gaussian = null;
                    nudFitMatrixSize.SetNUDValue(11);
                }
                else if (m_AutoStarsInArea.Count == 1)
                {
                    // There is exactly one good star found. Go and do a fit in a wider area
                    double bestFindTolerance = 3.0;

                    for (int i = 0; i < 2; i++)
                    {
                        MeasurementsHelper measurement = ReduceLightCurveOperation.DoConfiguredMeasurement(m_ProcessingPixels, m_Aperture.Value, m_AstroImage.Pixelmap.BitPixCamera, m_AstroImage.Pixelmap.MaxSignalValue, bestFindTolerance, ref matirxSize);
                        if (measurement != null && matirxSize != -1)
                        {
                            if (matirxSize < 5)
                            {
                                // Do a centroid in the full area, and get another matix centered at the centroid
                                ImagePixel centroid = new ImagePixel(m_Center.X, m_Center.Y);

                                m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(centroid);
                                m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(centroid);

                                m_X0 = centroid.X;
                                m_Y0 = centroid.Y;
                                m_FWHM = 6;
                                m_Gaussian = null;

                                nudFitMatrixSize.SetNUDValue(11);
                            }
                            else
                            {
                                m_X0 = measurement.XCenter;
                                m_Y0 = measurement.YCenter;
                                if (measurement.FoundBestPSFFit != null)
                                {
                                    m_FWHM = (float)measurement.FoundBestPSFFit.FWHM;
                                    m_Gaussian = measurement.FoundBestPSFFit;
                                }
                                else
                                {
                                    m_FWHM = 6;
                                    m_Gaussian = null;
                                }
                                m_ProcessingPixels = measurement.PixelData;
                                nudFitMatrixSize.SetNUDValue(matirxSize);
                            }
                        }
                        else
                        {
                            matirxSize = oldMatirxSize;
                            return false;
                        }

                        if (m_Gaussian != null)
                        {
                            if (IsBrightEnoughtForGuidingStar())
                            {
                                rbGuidingStar.Text = "Guiding/Comparison Star";
                                m_IsBrightEnoughForAutoGuidingStar = true;
                            }

                            break;
                        }
                    }
                }
                else if (m_AutoStarsInArea.Count > 1)
                {
                    rbGuidingStar.Text = "Guiding Star";

                    // There are more stars found.
                    double xBest = m_Gaussian != null
                                      ? m_Gaussian.XCenter
                                      : m_IsEdit ? ObjectToAdd.ApertureMatrixX0
                                                 : 8.5;

                    double yBest = m_Gaussian != null
                                      ? m_Gaussian.YCenter
                                      : m_IsEdit ? ObjectToAdd.ApertureMatrixY0
                                                 : 8.5;

                    // by default use the one closest to the original location
                    PSFFit closestFit = m_AutoStarsInArea[0];
                    double closestDist = double.MaxValue;
                    foreach (PSFFit star in m_AutoStarsInArea)
                    {
                        double dist =
                            Math.Sqrt((star.XCenter - xBest) * (star.XCenter - xBest) +
                                      (star.YCenter - yBest) * (star.YCenter - yBest));
                        if (closestDist > dist)
                        {
                            closestDist = dist;
                            closestFit = star;
                        }
                    }

                    m_X0 = (float)closestFit.XCenter;
                    m_Y0 = (float)closestFit.YCenter;
                    m_FWHM = (float)closestFit.FWHM;
                    m_Gaussian = closestFit;

                    nudFitMatrixSize.SetNUDValue(m_IsEdit ? ObjectToAdd.PsfFitMatrixSize : closestFit.MatrixSize);
                }

                //if (m_Gaussian == null && gaussian.Certainty > 0.1 && ImagePixel.ComputeDistance(gaussian.X0_Matrix, 8, gaussian.Y0_Matrix, 8) < 3)
                //{
                //	// Id we failed to locate a bright enough autostar, but the default Gaussian is still certain enough and close enought to the center, we present it as a starting point
                //	m_X0 = (float)gaussian.X0_Matrix;
                //	m_Y0 = (float)gaussian.Y0_Matrix;
                //	m_FWHM = (float)gaussian.FWHM;
                //	m_Gaussian = gaussian;
                //}

                decimal appVal;
                if (float.IsNaN(preselectedAperture))
                {
                    if (float.IsNaN(m_Aperture.Value))
                    {
                        appVal = Convert.ToDecimal(TangraConfig.Settings.Photometry.DefaultSignalAperture);
                    }
                    else
                    {
                        appVal = Convert.ToDecimal(m_Aperture.Value);
                        if (nudAperture1.Maximum < appVal) nudAperture1.Maximum = appVal + 1;
                    }
                }
                else
                    appVal = (decimal)preselectedAperture;

                if ((float)appVal > m_Aperture) m_Aperture = (float)appVal;

                nudAperture1.SetNUDValue(Math.Round(appVal, 2));

                PlotSingleTargetPixels();

                PlotGaussian();

                return true;
            }
            finally
            {
                nudFitMatrixSize.ValueChanged += nudFitMatrixSize_ValueChanged;
            }
        }
Ejemplo n.º 31
0
 // From here down this code is ALMOST a simple copy of the code from BouncyCastle
 public void Init(bool encrypt)
 {
     initialized = true;
     forencrypt = encrypt;
     WorkingKey = GenerateWorkingKey();
 }
Ejemplo n.º 32
0
        /// <summary>
        /// Solve the sudoku. This methods will try to solve the sudoku using trivial
        /// values, and switch to hypothesis tests when no more solutions could be found.
        /// If still no solution are found, the sudoku is likely to be invalid.
        /// </summary>
        /// <returns>True if the sudoku can be (and is) solved, false otherwise</returns>
        public bool Solve()
        {
            uint[,] savedValues = (uint[,]) this.sudokuValues.Clone();

            this.InitSolver();

            // Try the speed method
            if (SolveSpeed()) {
                if (Validate() == null) {
                    UpdateSudoku();
                    return true;
                } else
                    goto revert;
            }

            // Try with hypothesis
            if (SolveInternal(0, 0)) {
                UpdateSudoku();
                return true;
            } else
                goto revert;

            revert:
                this.sudokuValues = savedValues; // revert
                return false;
        }
Ejemplo n.º 33
0
 public Blowfish()
 {
     PArray = new uint[18];
     SBoxes = new uint[4, 256];
 }
        /**
        * initialise an AES cipher.
        *
        * @param forEncryption whether or not we are for encryption.
        * @param parameters the parameters required to set up the cipher.
        * @exception ArgumentException if the parameters argument is
        * inappropriate.
        */
        public void Init(bool forEncryption, ICipherParameters parameters)
        {
            if (!(parameters is KeyParameter))
                throw new ArgumentException("invalid parameter passed to AES init - " + parameters.GetType().ToString());

            WorkingKey = GenerateWorkingKey(((KeyParameter)parameters).GetKey(), forEncryption);
            this.forEncryption = forEncryption;
        }
Ejemplo n.º 35
0
        internal frmAddOrEditSingleTarget(int objectId, TrackedObjectConfig selectedObject, LCStateMachine state, VideoController videoController)
        {
            InitializeComponent();

            m_VideoController = videoController;

            m_AutocenteredApertureAvailable = true;

            Text = "Edit Object";

            btnAdd.Text = "Save";
            btnDontAdd.Text = "Cancel";
            btnDelete.Visible = true;
            m_IsEdit = true;

            m_ObjectId = objectId;
            m_State = state;
            m_AstroImage = m_State.VideoOperation.m_StackedAstroImage;

            ObjectToAdd = selectedObject;

            if (selectedObject.TrackingType != TrackingType.ComparisonStar)
                nudFitMatrixSize.SetNUDValue(selectedObject.PsfFitMatrixSize);

            m_Center = new ImagePixel(
                selectedObject.OriginalFieldCenterX,
                selectedObject.OriginalFieldCenterY);

            if (ObjectToAdd.PositionTolerance > 0)
                nudPositionTolerance.SetNUDValue((decimal)ObjectToAdd.PositionTolerance);

            Initialize();

            if (!selectedObject.IsWeakSignalObject && !selectedObject.IsFixedAperture)
            {
                int matrixSize = selectedObject.PsfFitMatrixSize;
                GetFitInMatrix(selectedObject.Gaussian, ref matrixSize, selectedObject.ApertureInPixels);
                selectedObject.PsfFitMatrixSize = matrixSize;
            }
            else
            {
                m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center);
                m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center);

                m_FWHM = 6;
                m_Gaussian = null;
                m_X0 = selectedObject.ApertureMatrixX0;
                m_Y0 = selectedObject.ApertureMatrixY0;
                dx = selectedObject.ApertureDX;
                dy = selectedObject.ApertureDY;

                PlotSingleTargetPixels();

                nudAperture1.SetNUDValue((decimal) Math.Round(ObjectToAdd.ApertureInPixels, 2));
            }

            SetHeightAndType();

            if (selectedObject.TrackingType == TrackingType.GuidingStar)
                SelectedObjectType = TrackingType.GuidingStar;
            else if (selectedObject.TrackingType == TrackingType.OccultedStar)
                SelectedObjectType = TrackingType.OccultedStar;
        }
Ejemplo n.º 36
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="encrypt"></param>
 /// <param name="kek">Key Encrypting Key, also known as Master key.</param>
 public GXDLMSChipperingStream(bool encrypt, byte[] kek)
 {
     Encrypt = encrypt;
     WorkingKey = GenerateKey(encrypt, kek);
 }
Ejemplo n.º 37
0
 public void Dispose()
 {
     GC.SuppressFinalize(S);
     GC.SuppressFinalize(P);
     S = null;
     P = null;
     GC.SuppressFinalize(this);
 }
Ejemplo n.º 38
0
    public static int Main()
    {
        bool passed = true;
        //initialize class
        CL cl1 = new CL();
        //initialize struct
        VT vt1;

        vt1.i_vt_op1     = 3;
        vt1.ui_vt_op1    = 3;
        vt1.l_vt_op1     = 3;
        vt1.ul_vt_op1    = 3;
        vt1.f_vt_op1     = 3;
        vt1.d_vt_op1     = 3;
        vt1.m_vt_op1     = 3;
        vt1.i_vt_op2     = 7;
        vt1.ui_vt_op2    = 7;
        vt1.l_vt_op2     = 7;
        vt1.ul_vt_op2    = 7;
        vt1.f_vt_op2     = 7;
        vt1.d_vt_op2     = 7;
        vt1.m_vt_op2     = 7;
        vt1.nHldr_vt_op2 = new numHolder(7);

        int[] i_arr1d_op1 = { 0, 3 };
        int[,] i_arr2d_op1  = { { 0, 3 }, { 1, 1 } };
        int[,,] i_arr3d_op1 = { { { 0, 3 }, { 1, 1 } } };
        uint[] ui_arr1d_op1 = { 0, 3 };
        uint[,] ui_arr2d_op1  = { { 0, 3 }, { 1, 1 } };
        uint[,,] ui_arr3d_op1 = { { { 0, 3 }, { 1, 1 } } };
        long[] l_arr1d_op1 = { 0, 3 };
        long[,] l_arr2d_op1  = { { 0, 3 }, { 1, 1 } };
        long[,,] l_arr3d_op1 = { { { 0, 3 }, { 1, 1 } } };
        ulong[] ul_arr1d_op1 = { 0, 3 };
        ulong[,] ul_arr2d_op1  = { { 0, 3 }, { 1, 1 } };
        ulong[,,] ul_arr3d_op1 = { { { 0, 3 }, { 1, 1 } } };
        float[] f_arr1d_op1 = { 0, 3 };
        float[,] f_arr2d_op1  = { { 0, 3 }, { 1, 1 } };
        float[,,] f_arr3d_op1 = { { { 0, 3 }, { 1, 1 } } };
        double[] d_arr1d_op1 = { 0, 3 };
        double[,] d_arr2d_op1  = { { 0, 3 }, { 1, 1 } };
        double[,,] d_arr3d_op1 = { { { 0, 3 }, { 1, 1 } } };
        decimal[] m_arr1d_op1 = { 0, 3 };
        decimal[,] m_arr2d_op1  = { { 0, 3 }, { 1, 1 } };
        decimal[,,] m_arr3d_op1 = { { { 0, 3 }, { 1, 1 } } };

        int[] i_arr1d_op2 = { 7, 0, 1 };
        int[,] i_arr2d_op2  = { { 0, 7 }, { 1, 1 } };
        int[,,] i_arr3d_op2 = { { { 0, 7 }, { 1, 1 } } };
        uint[] ui_arr1d_op2 = { 7, 0, 1 };
        uint[,] ui_arr2d_op2  = { { 0, 7 }, { 1, 1 } };
        uint[,,] ui_arr3d_op2 = { { { 0, 7 }, { 1, 1 } } };
        long[] l_arr1d_op2 = { 7, 0, 1 };
        long[,] l_arr2d_op2  = { { 0, 7 }, { 1, 1 } };
        long[,,] l_arr3d_op2 = { { { 0, 7 }, { 1, 1 } } };
        ulong[] ul_arr1d_op2 = { 7, 0, 1 };
        ulong[,] ul_arr2d_op2  = { { 0, 7 }, { 1, 1 } };
        ulong[,,] ul_arr3d_op2 = { { { 0, 7 }, { 1, 1 } } };
        float[] f_arr1d_op2 = { 7, 0, 1 };
        float[,] f_arr2d_op2  = { { 0, 7 }, { 1, 1 } };
        float[,,] f_arr3d_op2 = { { { 0, 7 }, { 1, 1 } } };
        double[] d_arr1d_op2 = { 7, 0, 1 };
        double[,] d_arr2d_op2  = { { 0, 7 }, { 1, 1 } };
        double[,,] d_arr3d_op2 = { { { 0, 7 }, { 1, 1 } } };
        decimal[] m_arr1d_op2 = { 7, 0, 1 };
        decimal[,] m_arr2d_op2  = { { 0, 7 }, { 1, 1 } };
        decimal[,,] m_arr3d_op2 = { { { 0, 7 }, { 1, 1 } } };
        numHolder[] nHldr_arr1d_op2 = { new numHolder(7), new numHolder(0), new numHolder(1) };
        numHolder[,] nHldr_arr2d_op2  = { { new numHolder(0), new numHolder(7) }, { new numHolder(1), new numHolder(1) } };
        numHolder[,,] nHldr_arr3d_op2 = { { { new numHolder(0), new numHolder(7) }, { new numHolder(1), new numHolder(1) } } };

        int[,] index = { { 0, 0 }, { 1, 1 } };

        {
            int       i_l_op1     = 3;
            int       i_l_op2     = 7;
            uint      ui_l_op2    = 7;
            long      l_l_op2     = 7;
            ulong     ul_l_op2    = 7;
            float     f_l_op2     = 7;
            double    d_l_op2     = 7;
            decimal   m_l_op2     = 7;
            numHolder nHldr_l_op2 = new numHolder(7);
            if ((i_l_op1 * i_l_op2 != i_l_op1 * ui_l_op2) || (i_l_op1 * ui_l_op2 != i_l_op1 * l_l_op2) || (i_l_op1 * l_l_op2 != i_l_op1 * (int)ul_l_op2) || (i_l_op1 * (int)ul_l_op2 != i_l_op1 * f_l_op2) || (i_l_op1 * f_l_op2 != i_l_op1 * d_l_op2) || ((decimal)(i_l_op1 * d_l_op2) != i_l_op1 * m_l_op2) || (i_l_op1 * m_l_op2 != i_l_op1 * i_l_op2) || (i_l_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 1 failed");
                passed = false;
            }
            if ((i_l_op1 * s_i_s_op2 != i_l_op1 * s_ui_s_op2) || (i_l_op1 * s_ui_s_op2 != i_l_op1 * s_l_s_op2) || (i_l_op1 * s_l_s_op2 != i_l_op1 * (int)s_ul_s_op2) || (i_l_op1 * (int)s_ul_s_op2 != i_l_op1 * s_f_s_op2) || (i_l_op1 * s_f_s_op2 != i_l_op1 * s_d_s_op2) || ((decimal)(i_l_op1 * s_d_s_op2) != i_l_op1 * s_m_s_op2) || (i_l_op1 * s_m_s_op2 != i_l_op1 * s_i_s_op2) || (i_l_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 2 failed");
                passed = false;
            }
            if ((s_i_s_op1 * i_l_op2 != s_i_s_op1 * ui_l_op2) || (s_i_s_op1 * ui_l_op2 != s_i_s_op1 * l_l_op2) || (s_i_s_op1 * l_l_op2 != s_i_s_op1 * (int)ul_l_op2) || (s_i_s_op1 * (int)ul_l_op2 != s_i_s_op1 * f_l_op2) || (s_i_s_op1 * f_l_op2 != s_i_s_op1 * d_l_op2) || ((decimal)(s_i_s_op1 * d_l_op2) != s_i_s_op1 * m_l_op2) || (s_i_s_op1 * m_l_op2 != s_i_s_op1 * i_l_op2) || (s_i_s_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 3 failed");
                passed = false;
            }
            if ((s_i_s_op1 * s_i_s_op2 != s_i_s_op1 * s_ui_s_op2) || (s_i_s_op1 * s_ui_s_op2 != s_i_s_op1 * s_l_s_op2) || (s_i_s_op1 * s_l_s_op2 != s_i_s_op1 * (int)s_ul_s_op2) || (s_i_s_op1 * (int)s_ul_s_op2 != s_i_s_op1 * s_f_s_op2) || (s_i_s_op1 * s_f_s_op2 != s_i_s_op1 * s_d_s_op2) || ((decimal)(s_i_s_op1 * s_d_s_op2) != s_i_s_op1 * s_m_s_op2) || (s_i_s_op1 * s_m_s_op2 != s_i_s_op1 * s_i_s_op2) || (s_i_s_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 4 failed");
                passed = false;
            }
        }

        {
            uint      ui_l_op1    = 3;
            int       i_l_op2     = 7;
            uint      ui_l_op2    = 7;
            long      l_l_op2     = 7;
            ulong     ul_l_op2    = 7;
            float     f_l_op2     = 7;
            double    d_l_op2     = 7;
            decimal   m_l_op2     = 7;
            numHolder nHldr_l_op2 = new numHolder(7);
            if ((ui_l_op1 * i_l_op2 != ui_l_op1 * ui_l_op2) || (ui_l_op1 * ui_l_op2 != ui_l_op1 * l_l_op2) || ((ulong)(ui_l_op1 * l_l_op2) != ui_l_op1 * ul_l_op2) || (ui_l_op1 * ul_l_op2 != ui_l_op1 * f_l_op2) || (ui_l_op1 * f_l_op2 != ui_l_op1 * d_l_op2) || ((decimal)(ui_l_op1 * d_l_op2) != ui_l_op1 * m_l_op2) || (ui_l_op1 * m_l_op2 != ui_l_op1 * i_l_op2) || (ui_l_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 5 failed");
                passed = false;
            }
            if ((ui_l_op1 * s_i_s_op2 != ui_l_op1 * s_ui_s_op2) || (ui_l_op1 * s_ui_s_op2 != ui_l_op1 * s_l_s_op2) || ((ulong)(ui_l_op1 * s_l_s_op2) != ui_l_op1 * s_ul_s_op2) || (ui_l_op1 * s_ul_s_op2 != ui_l_op1 * s_f_s_op2) || (ui_l_op1 * s_f_s_op2 != ui_l_op1 * s_d_s_op2) || ((decimal)(ui_l_op1 * s_d_s_op2) != ui_l_op1 * s_m_s_op2) || (ui_l_op1 * s_m_s_op2 != ui_l_op1 * s_i_s_op2) || (ui_l_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 6 failed");
                passed = false;
            }
            if ((s_ui_s_op1 * i_l_op2 != s_ui_s_op1 * ui_l_op2) || (s_ui_s_op1 * ui_l_op2 != s_ui_s_op1 * l_l_op2) || ((ulong)(s_ui_s_op1 * l_l_op2) != s_ui_s_op1 * ul_l_op2) || (s_ui_s_op1 * ul_l_op2 != s_ui_s_op1 * f_l_op2) || (s_ui_s_op1 * f_l_op2 != s_ui_s_op1 * d_l_op2) || ((decimal)(s_ui_s_op1 * d_l_op2) != s_ui_s_op1 * m_l_op2) || (s_ui_s_op1 * m_l_op2 != s_ui_s_op1 * i_l_op2) || (s_ui_s_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 7 failed");
                passed = false;
            }
            if ((s_ui_s_op1 * s_i_s_op2 != s_ui_s_op1 * s_ui_s_op2) || (s_ui_s_op1 * s_ui_s_op2 != s_ui_s_op1 * s_l_s_op2) || ((ulong)(s_ui_s_op1 * s_l_s_op2) != s_ui_s_op1 * s_ul_s_op2) || (s_ui_s_op1 * s_ul_s_op2 != s_ui_s_op1 * s_f_s_op2) || (s_ui_s_op1 * s_f_s_op2 != s_ui_s_op1 * s_d_s_op2) || ((decimal)(s_ui_s_op1 * s_d_s_op2) != s_ui_s_op1 * s_m_s_op2) || (s_ui_s_op1 * s_m_s_op2 != s_ui_s_op1 * s_i_s_op2) || (s_ui_s_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 8 failed");
                passed = false;
            }
        }

        {
            long      l_l_op1     = 3;
            int       i_l_op2     = 7;
            uint      ui_l_op2    = 7;
            long      l_l_op2     = 7;
            ulong     ul_l_op2    = 7;
            float     f_l_op2     = 7;
            double    d_l_op2     = 7;
            decimal   m_l_op2     = 7;
            numHolder nHldr_l_op2 = new numHolder(7);
            if ((l_l_op1 * i_l_op2 != l_l_op1 * ui_l_op2) || (l_l_op1 * ui_l_op2 != l_l_op1 * l_l_op2) || (l_l_op1 * l_l_op2 != l_l_op1 * (long)ul_l_op2) || (l_l_op1 * (long)ul_l_op2 != l_l_op1 * f_l_op2) || (l_l_op1 * f_l_op2 != l_l_op1 * d_l_op2) || ((decimal)(l_l_op1 * d_l_op2) != l_l_op1 * m_l_op2) || (l_l_op1 * m_l_op2 != l_l_op1 * i_l_op2) || (l_l_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 9 failed");
                passed = false;
            }
            if ((l_l_op1 * s_i_s_op2 != l_l_op1 * s_ui_s_op2) || (l_l_op1 * s_ui_s_op2 != l_l_op1 * s_l_s_op2) || (l_l_op1 * s_l_s_op2 != l_l_op1 * (long)s_ul_s_op2) || (l_l_op1 * (long)s_ul_s_op2 != l_l_op1 * s_f_s_op2) || (l_l_op1 * s_f_s_op2 != l_l_op1 * s_d_s_op2) || ((decimal)(l_l_op1 * s_d_s_op2) != l_l_op1 * s_m_s_op2) || (l_l_op1 * s_m_s_op2 != l_l_op1 * s_i_s_op2) || (l_l_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 10 failed");
                passed = false;
            }
            if ((s_l_s_op1 * i_l_op2 != s_l_s_op1 * ui_l_op2) || (s_l_s_op1 * ui_l_op2 != s_l_s_op1 * l_l_op2) || (s_l_s_op1 * l_l_op2 != s_l_s_op1 * (long)ul_l_op2) || (s_l_s_op1 * (long)ul_l_op2 != s_l_s_op1 * f_l_op2) || (s_l_s_op1 * f_l_op2 != s_l_s_op1 * d_l_op2) || ((decimal)(s_l_s_op1 * d_l_op2) != s_l_s_op1 * m_l_op2) || (s_l_s_op1 * m_l_op2 != s_l_s_op1 * i_l_op2) || (s_l_s_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 11 failed");
                passed = false;
            }
            if ((s_l_s_op1 * s_i_s_op2 != s_l_s_op1 * s_ui_s_op2) || (s_l_s_op1 * s_ui_s_op2 != s_l_s_op1 * s_l_s_op2) || (s_l_s_op1 * s_l_s_op2 != s_l_s_op1 * (long)s_ul_s_op2) || (s_l_s_op1 * (long)s_ul_s_op2 != s_l_s_op1 * s_f_s_op2) || (s_l_s_op1 * s_f_s_op2 != s_l_s_op1 * s_d_s_op2) || ((decimal)(s_l_s_op1 * s_d_s_op2) != s_l_s_op1 * s_m_s_op2) || (s_l_s_op1 * s_m_s_op2 != s_l_s_op1 * s_i_s_op2) || (s_l_s_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 12 failed");
                passed = false;
            }
        }

        {
            ulong     ul_l_op1    = 3;
            int       i_l_op2     = 7;
            uint      ui_l_op2    = 7;
            long      l_l_op2     = 7;
            ulong     ul_l_op2    = 7;
            float     f_l_op2     = 7;
            double    d_l_op2     = 7;
            decimal   m_l_op2     = 7;
            numHolder nHldr_l_op2 = new numHolder(7);
            if ((ul_l_op1 * (ulong)i_l_op2 != ul_l_op1 * ui_l_op2) || (ul_l_op1 * ui_l_op2 != ul_l_op1 * (ulong)l_l_op2) || (ul_l_op1 * (ulong)l_l_op2 != ul_l_op1 * ul_l_op2) || (ul_l_op1 * ul_l_op2 != ul_l_op1 * f_l_op2) || (ul_l_op1 * f_l_op2 != ul_l_op1 * d_l_op2) || ((decimal)(ul_l_op1 * d_l_op2) != ul_l_op1 * m_l_op2) || (ul_l_op1 * m_l_op2 != ul_l_op1 * (ulong)i_l_op2) || (ul_l_op1 * (ulong)i_l_op2 != 21))
            {
                Console.WriteLine("testcase 13 failed");
                passed = false;
            }
            if ((ul_l_op1 * (ulong)s_i_s_op2 != ul_l_op1 * s_ui_s_op2) || (ul_l_op1 * s_ui_s_op2 != ul_l_op1 * (ulong)s_l_s_op2) || (ul_l_op1 * (ulong)s_l_s_op2 != ul_l_op1 * s_ul_s_op2) || (ul_l_op1 * s_ul_s_op2 != ul_l_op1 * s_f_s_op2) || (ul_l_op1 * s_f_s_op2 != ul_l_op1 * s_d_s_op2) || ((decimal)(ul_l_op1 * s_d_s_op2) != ul_l_op1 * s_m_s_op2) || (ul_l_op1 * s_m_s_op2 != ul_l_op1 * (ulong)s_i_s_op2) || (ul_l_op1 * (ulong)s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 14 failed");
                passed = false;
            }
            if ((s_ul_s_op1 * (ulong)i_l_op2 != s_ul_s_op1 * ui_l_op2) || (s_ul_s_op1 * ui_l_op2 != s_ul_s_op1 * (ulong)l_l_op2) || (s_ul_s_op1 * (ulong)l_l_op2 != s_ul_s_op1 * ul_l_op2) || (s_ul_s_op1 * ul_l_op2 != s_ul_s_op1 * f_l_op2) || (s_ul_s_op1 * f_l_op2 != s_ul_s_op1 * d_l_op2) || ((decimal)(s_ul_s_op1 * d_l_op2) != s_ul_s_op1 * m_l_op2) || (s_ul_s_op1 * m_l_op2 != s_ul_s_op1 * (ulong)i_l_op2) || (s_ul_s_op1 * (ulong)i_l_op2 != 21))
            {
                Console.WriteLine("testcase 15 failed");
                passed = false;
            }
            if ((s_ul_s_op1 * (ulong)s_i_s_op2 != s_ul_s_op1 * s_ui_s_op2) || (s_ul_s_op1 * s_ui_s_op2 != s_ul_s_op1 * (ulong)s_l_s_op2) || (s_ul_s_op1 * (ulong)s_l_s_op2 != s_ul_s_op1 * s_ul_s_op2) || (s_ul_s_op1 * s_ul_s_op2 != s_ul_s_op1 * s_f_s_op2) || (s_ul_s_op1 * s_f_s_op2 != s_ul_s_op1 * s_d_s_op2) || ((decimal)(s_ul_s_op1 * s_d_s_op2) != s_ul_s_op1 * s_m_s_op2) || (s_ul_s_op1 * s_m_s_op2 != s_ul_s_op1 * (ulong)s_i_s_op2) || (s_ul_s_op1 * (ulong)s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 16 failed");
                passed = false;
            }
        }

        {
            float     f_l_op1     = 3;
            int       i_l_op2     = 7;
            uint      ui_l_op2    = 7;
            long      l_l_op2     = 7;
            ulong     ul_l_op2    = 7;
            float     f_l_op2     = 7;
            double    d_l_op2     = 7;
            decimal   m_l_op2     = 7;
            numHolder nHldr_l_op2 = new numHolder(7);
            if ((f_l_op1 * i_l_op2 != f_l_op1 * ui_l_op2) || (f_l_op1 * ui_l_op2 != f_l_op1 * l_l_op2) || (f_l_op1 * l_l_op2 != f_l_op1 * ul_l_op2) || (f_l_op1 * ul_l_op2 != f_l_op1 * f_l_op2) || (f_l_op1 * f_l_op2 != f_l_op1 * d_l_op2) || (f_l_op1 * d_l_op2 != f_l_op1 * (float)m_l_op2) || (f_l_op1 * (float)m_l_op2 != f_l_op1 * i_l_op2) || (f_l_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 17 failed");
                passed = false;
            }
            if ((f_l_op1 * s_i_s_op2 != f_l_op1 * s_ui_s_op2) || (f_l_op1 * s_ui_s_op2 != f_l_op1 * s_l_s_op2) || (f_l_op1 * s_l_s_op2 != f_l_op1 * s_ul_s_op2) || (f_l_op1 * s_ul_s_op2 != f_l_op1 * s_f_s_op2) || (f_l_op1 * s_f_s_op2 != f_l_op1 * s_d_s_op2) || (f_l_op1 * s_d_s_op2 != f_l_op1 * (float)s_m_s_op2) || (f_l_op1 * (float)s_m_s_op2 != f_l_op1 * s_i_s_op2) || (f_l_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 18 failed");
                passed = false;
            }
            if ((s_f_s_op1 * i_l_op2 != s_f_s_op1 * ui_l_op2) || (s_f_s_op1 * ui_l_op2 != s_f_s_op1 * l_l_op2) || (s_f_s_op1 * l_l_op2 != s_f_s_op1 * ul_l_op2) || (s_f_s_op1 * ul_l_op2 != s_f_s_op1 * f_l_op2) || (s_f_s_op1 * f_l_op2 != s_f_s_op1 * d_l_op2) || (s_f_s_op1 * d_l_op2 != s_f_s_op1 * (float)m_l_op2) || (s_f_s_op1 * (float)m_l_op2 != s_f_s_op1 * i_l_op2) || (s_f_s_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 19 failed");
                passed = false;
            }
            if ((s_f_s_op1 * s_i_s_op2 != s_f_s_op1 * s_ui_s_op2) || (s_f_s_op1 * s_ui_s_op2 != s_f_s_op1 * s_l_s_op2) || (s_f_s_op1 * s_l_s_op2 != s_f_s_op1 * s_ul_s_op2) || (s_f_s_op1 * s_ul_s_op2 != s_f_s_op1 * s_f_s_op2) || (s_f_s_op1 * s_f_s_op2 != s_f_s_op1 * s_d_s_op2) || (s_f_s_op1 * s_d_s_op2 != s_f_s_op1 * (float)s_m_s_op2) || (s_f_s_op1 * (float)s_m_s_op2 != s_f_s_op1 * s_i_s_op2) || (s_f_s_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 20 failed");
                passed = false;
            }
        }

        {
            double    d_l_op1     = 3;
            int       i_l_op2     = 7;
            uint      ui_l_op2    = 7;
            long      l_l_op2     = 7;
            ulong     ul_l_op2    = 7;
            float     f_l_op2     = 7;
            double    d_l_op2     = 7;
            decimal   m_l_op2     = 7;
            numHolder nHldr_l_op2 = new numHolder(7);
            if ((d_l_op1 * i_l_op2 != d_l_op1 * ui_l_op2) || (d_l_op1 * ui_l_op2 != d_l_op1 * l_l_op2) || (d_l_op1 * l_l_op2 != d_l_op1 * ul_l_op2) || (d_l_op1 * ul_l_op2 != d_l_op1 * f_l_op2) || (d_l_op1 * f_l_op2 != d_l_op1 * d_l_op2) || (d_l_op1 * d_l_op2 != d_l_op1 * (double)m_l_op2) || (d_l_op1 * (double)m_l_op2 != d_l_op1 * i_l_op2) || (d_l_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 21 failed");
                passed = false;
            }
            if ((d_l_op1 * s_i_s_op2 != d_l_op1 * s_ui_s_op2) || (d_l_op1 * s_ui_s_op2 != d_l_op1 * s_l_s_op2) || (d_l_op1 * s_l_s_op2 != d_l_op1 * s_ul_s_op2) || (d_l_op1 * s_ul_s_op2 != d_l_op1 * s_f_s_op2) || (d_l_op1 * s_f_s_op2 != d_l_op1 * s_d_s_op2) || (d_l_op1 * s_d_s_op2 != d_l_op1 * (double)s_m_s_op2) || (d_l_op1 * (double)s_m_s_op2 != d_l_op1 * s_i_s_op2) || (d_l_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 22 failed");
                passed = false;
            }
            if ((s_d_s_op1 * i_l_op2 != s_d_s_op1 * ui_l_op2) || (s_d_s_op1 * ui_l_op2 != s_d_s_op1 * l_l_op2) || (s_d_s_op1 * l_l_op2 != s_d_s_op1 * ul_l_op2) || (s_d_s_op1 * ul_l_op2 != s_d_s_op1 * f_l_op2) || (s_d_s_op1 * f_l_op2 != s_d_s_op1 * d_l_op2) || (s_d_s_op1 * d_l_op2 != s_d_s_op1 * (double)m_l_op2) || (s_d_s_op1 * (double)m_l_op2 != s_d_s_op1 * i_l_op2) || (s_d_s_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 23 failed");
                passed = false;
            }
            if ((s_d_s_op1 * s_i_s_op2 != s_d_s_op1 * s_ui_s_op2) || (s_d_s_op1 * s_ui_s_op2 != s_d_s_op1 * s_l_s_op2) || (s_d_s_op1 * s_l_s_op2 != s_d_s_op1 * s_ul_s_op2) || (s_d_s_op1 * s_ul_s_op2 != s_d_s_op1 * s_f_s_op2) || (s_d_s_op1 * s_f_s_op2 != s_d_s_op1 * s_d_s_op2) || (s_d_s_op1 * s_d_s_op2 != s_d_s_op1 * (double)s_m_s_op2) || (s_d_s_op1 * (double)s_m_s_op2 != s_d_s_op1 * s_i_s_op2) || (s_d_s_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 24 failed");
                passed = false;
            }
        }

        {
            decimal   m_l_op1     = 3;
            int       i_l_op2     = 7;
            uint      ui_l_op2    = 7;
            long      l_l_op2     = 7;
            ulong     ul_l_op2    = 7;
            float     f_l_op2     = 7;
            double    d_l_op2     = 7;
            decimal   m_l_op2     = 7;
            numHolder nHldr_l_op2 = new numHolder(7);
            if ((m_l_op1 * i_l_op2 != m_l_op1 * ui_l_op2) || (m_l_op1 * ui_l_op2 != m_l_op1 * l_l_op2) || (m_l_op1 * l_l_op2 != m_l_op1 * ul_l_op2) || (m_l_op1 * ul_l_op2 != m_l_op1 * (decimal)f_l_op2) || (m_l_op1 * (decimal)f_l_op2 != m_l_op1 * (decimal)d_l_op2) || (m_l_op1 * (decimal)d_l_op2 != m_l_op1 * m_l_op2) || (m_l_op1 * m_l_op2 != m_l_op1 * i_l_op2) || (m_l_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 25 failed");
                passed = false;
            }
            if ((m_l_op1 * s_i_s_op2 != m_l_op1 * s_ui_s_op2) || (m_l_op1 * s_ui_s_op2 != m_l_op1 * s_l_s_op2) || (m_l_op1 * s_l_s_op2 != m_l_op1 * s_ul_s_op2) || (m_l_op1 * s_ul_s_op2 != m_l_op1 * (decimal)s_f_s_op2) || (m_l_op1 * (decimal)s_f_s_op2 != m_l_op1 * (decimal)s_d_s_op2) || (m_l_op1 * (decimal)s_d_s_op2 != m_l_op1 * s_m_s_op2) || (m_l_op1 * s_m_s_op2 != m_l_op1 * s_i_s_op2) || (m_l_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 26 failed");
                passed = false;
            }
            if ((s_m_s_op1 * i_l_op2 != s_m_s_op1 * ui_l_op2) || (s_m_s_op1 * ui_l_op2 != s_m_s_op1 * l_l_op2) || (s_m_s_op1 * l_l_op2 != s_m_s_op1 * ul_l_op2) || (s_m_s_op1 * ul_l_op2 != s_m_s_op1 * (decimal)f_l_op2) || (s_m_s_op1 * (decimal)f_l_op2 != s_m_s_op1 * (decimal)d_l_op2) || (s_m_s_op1 * (decimal)d_l_op2 != s_m_s_op1 * m_l_op2) || (s_m_s_op1 * m_l_op2 != s_m_s_op1 * i_l_op2) || (s_m_s_op1 * i_l_op2 != 21))
            {
                Console.WriteLine("testcase 27 failed");
                passed = false;
            }
            if ((s_m_s_op1 * s_i_s_op2 != s_m_s_op1 * s_ui_s_op2) || (s_m_s_op1 * s_ui_s_op2 != s_m_s_op1 * s_l_s_op2) || (s_m_s_op1 * s_l_s_op2 != s_m_s_op1 * s_ul_s_op2) || (s_m_s_op1 * s_ul_s_op2 != s_m_s_op1 * (decimal)s_f_s_op2) || (s_m_s_op1 * (decimal)s_f_s_op2 != s_m_s_op1 * (decimal)s_d_s_op2) || (s_m_s_op1 * (decimal)s_d_s_op2 != s_m_s_op1 * s_m_s_op2) || (s_m_s_op1 * s_m_s_op2 != s_m_s_op1 * s_i_s_op2) || (s_m_s_op1 * s_i_s_op2 != 21))
            {
                Console.WriteLine("testcase 28 failed");
                passed = false;
            }
        }

        if (!passed)
        {
            Console.WriteLine("FAILED");
            return(1);
        }
        else
        {
            Console.WriteLine("PASSED");
            return(100);
        }
    }
Ejemplo n.º 39
0
 //重置矩阵
 public void ClearMatrix()
 {
     rows    = 0;
     columns = 0;
     value   = null;
 }
Ejemplo n.º 40
0
        private void GenerateFrame(Pixelmap pixmap, List <IStar> stars, ModelConfig modelConfig)
        {
            var mea = new MeasurementsHelper(
                pixmap.BitPixCamera,
                TangraConfig.BackgroundMethod.BackgroundMedian,
                TangraConfig.Settings.Photometry.SubPixelSquareSize,
                TangraConfig.Settings.Photometry.Saturation.GetSaturationForBpp(pixmap.BitPixCamera, pixmap.MaxSignalValue));

            float apertureSize       = APERTURE;
            float annulusInnerRadius = (GAP + APERTURE) / APERTURE;
            int   annulusMinPixels   = (int)(Math.PI * (Math.Pow(ANNULUS + GAP + APERTURE, 2) - Math.Pow(GAP + APERTURE, 2)));

            mea.SetCoreProperties(annulusInnerRadius, annulusMinPixels, CorePhotometrySettings.Default.RejectionBackgroundPixelsStdDev, 2 /* TODO: This must be configurable */);

            var measurements = new Dictionary <IStar, double>();

            foreach (IStar star in stars)
            {
                double x, y;

                GetOnPlateCoordinates(star.RADeg, star.DEDeg, modelConfig, out x, out y);

                if (x < 0 || x > modelConfig.FrameWidth || y < 0 || y > modelConfig.FrameHeight)
                {
                    continue;
                }

                float starMag = GetStarMag(star, modelConfig.PhotometricFilter);
                float iMax    = ModelStarAmplitude(star, starMag, modelConfig, pixmap.BitPixCamera, pixmap.MaxSignalValue);

                if (!float.IsNaN(iMax))
                {
                    VideoModelUtils.GenerateStar(pixmap, (float)x, (float)y, (float)modelConfig.FWHM, iMax, 0 /*Use Gaussian */);

                    if (modelConfig.CheckMagnitudes)
                    {
                        var image = new AstroImage(pixmap);
                        uint[,] data             = image.GetMeasurableAreaPixels((int)x, (int)y, 17);
                        uint[,] backgroundPixels = image.GetMeasurableAreaPixels((int)x, (int)y, 35);

                        PSFFit fit = new PSFFit((int)x, (int)y);
                        fit.Fit(data);

                        var result = mea.MeasureObject(new ImagePixel(x, y), data, backgroundPixels, pixmap.BitPixCamera,
                                                       TangraConfig.PreProcessingFilter.NoFilter,
                                                       TangraConfig.PhotometryReductionMethod.AperturePhotometry, TangraConfig.PsfQuadrature.NumericalInAperture,
                                                       TangraConfig.PsfFittingMethod.DirectNonLinearFit,
                                                       apertureSize, modelConfig.FWHM, (float)modelConfig.FWHM,
                                                       new FakeIMeasuredObject(fit),
                                                       null, null,
                                                       false);

                        if (result == NotMeasuredReasons.TrackedSuccessfully && !mea.HasSaturatedPixels)
                        {
                            // Add value for fitting
                            measurements.Add(star, mea.TotalReading - mea.TotalBackground);
                        }
                    }
                }
            }

            if (modelConfig.CheckMagnitudes)
            {
                CalculateGagnitudeFit(measurements, modelConfig.BVSlope);
            }
        }
Ejemplo n.º 41
0
    // Calculate shortest path(s) using Dijkstra's algorithm.  Note that
    // the matrix contains edge distance between vertexes.  A zero value
    // indicates no path between the verticies.  Since zero could be a
    // concievable distance, we add 1 to all distances such that we can
    // use zero to indicate no path between the verticies.  This means
    // the actual length is the distance value minus 1.

    public static uint[,] ShortestPaths(uint[,] graph, uint start, uint end)
    {
        // Do some validation.

        if (graph.Rank != 2)
        {
            throw(new InvalidOperationException("graph matrix must be two " +
                                                "dimensional"));
        }
        if (graph.GetLength(0) != graph.GetLength(1))
        {
            throw(new InvalidOperationException("graph matrix must be square"));
        }

        // Create an array to hold the distance to each vertex while calculating
        // the shortest path.

        uint[] distance = new uint[graph.GetLength(0)];
        for (uint i = 0; i < (uint)distance.Length; ++i)
        {
            distance[i] = uint.MaxValue;
        }

        // Set the distance of our start vertex to zero.  This will cause it to
        // get sorted to the front of the queue and thus get processed first.

        distance[start] = 0;

        // This queue initially contains all the indexes.

        uint[] queue = new uint[distance.Length];
        for (uint i = 0; i < (uint)queue.Length; ++i)
        {
            queue[i] = i;
        }
        int head = 0;

        IComparer distanceCompare = new DistanceCompare(distance);

        // Go until queue is empty.

        while (head != queue.Length)
        {
            // Sort the queue of indexes by distance.

            Array.Sort(queue, head, queue.Length - head, distanceCompare);

            // Get the vertex with the shortest distance.

            uint vertex = queue[head];

            // Remove front of queue.

            head++;

            // Check each neighbor of vertex and see if we need to update
            // the distance to that neighbor.

            for (uint i = 0; i < (uint)graph.GetLength(0); ++i)
            {
                // Is this a neighbor?

                if (graph[vertex, i] > 1)
                {
                    // If we found a shorter distance then update the distance.

                    if (distance[i] > distance[vertex] + (graph[vertex, i] - 1))
                    {
                        distance[i] = distance[vertex] + (graph[vertex, i] - 1);
                    }
                }
            }
        }

        // If no path found then return null.

        if (distance[end] == uint.MaxValue)
        {
            return(null);
        }

        else
        {
            // Create a return graph with just lengths for the shortest
            // paths.  Initialize all edges to 0 (meaning no path).

            uint[,] paths = new uint[graph.GetLength(0), graph.GetLength(1)];
            for (uint i = 0; i < (uint)graph.GetLength(0); ++i)
            {
                for (uint j = 0; j < graph.GetLength(1); ++j)
                {
                    paths[i, j] = 0;
                }
            }

            // Flags to tell whether we already handled a vertex when
            // generating the paths (eg. backtracing).

            bool[] handledVertex = new bool[graph.GetLength(0)];
            for (uint i = 0; i < (uint)handledVertex.Length; ++i)
            {
                handledVertex[i] = false;
            }

            // Vertexes queue used when determining the paths.

            uint[] vertexes = new uint[graph.GetLength(0)];
            vertexes[0] = end;
            uint cur   = 0;
            uint avail = 1;

            // Go from end to start along the shortest paths found to
            // fill in the paths graph.

            while (cur != avail)
            {
                for (uint i = 0; i < (uint)graph.GetLength(0); ++i)
                {
                    // Rows in the graph indicate outgoing edges from the vertex.
                    // Columns in the graph indicate incoming edges to the vertex.

                    // I'm checking down column vertexes[cur] to see if there
                    // in an incoming edge from vertex i.

                    if (graph[i, vertexes[cur]] > 1)
                    {
                        // If the edge was part of a shortest path, eg. distance
                        // of current vertex is the sum of the distance of the
                        // incoming vertex plus the edge, then the incoming vertex
                        // was part of a shortest path.

                        if (distance[vertexes[cur]] ==
                            (distance[i] + (graph[i, vertexes[cur]] - 1)))
                        {
                            // This incoming vertex was part of a shortest path
                            // so copy over its edge from the original graph.

                            paths[i, vertexes[cur]] = graph[i, vertexes[cur]];

                            // If we didn't handle this incoming vertex already
                            // add it to the queue.

                            if (handledVertex[i] == false)
                            {
                                vertexes[avail++] = i;
                                handledVertex[i]  = true;
                            }
                        }
                    }
                }

                // Move to next vertex to process.

                cur++;
            }

            return(paths);
        }
    }
Ejemplo n.º 42
0
        private void InitStarAmplitudeModelling(ModelConfig modelConfig, float accuracy, int bitPix, uint maxSignalValue)
        {
            if (m_MagnitudeToPeakDict != null)
            {
                return;
            }

            m_MagnitudeToPeakDict  = new Dictionary <double, int>();
            m_MagnitudeToPeakMags  = new List <double>();
            m_MagnitudeToPeakPeaks = new List <int>();

            var mea = new MeasurementsHelper(
                bitPix,
                TangraConfig.BackgroundMethod.BackgroundMedian,
                TangraConfig.Settings.Photometry.SubPixelSquareSize,
                TangraConfig.Settings.Photometry.Saturation.GetSaturationForBpp(bitPix, maxSignalValue));

            float apertureSize       = APERTURE;
            float annulusInnerRadius = (GAP + APERTURE) / APERTURE;
            int   annulusMinPixels   = (int)(Math.PI * (Math.Pow(ANNULUS + GAP + APERTURE, 2) - Math.Pow(GAP + APERTURE, 2)));

            mea.SetCoreProperties(annulusInnerRadius, annulusMinPixels, CorePhotometrySettings.Default.RejectionBackgroundPixelsStdDev, 2 /* TODO: This must be configurable */);

            int    peak        = (int)(maxSignalValue - (modelConfig.NoiseMean + modelConfig.DarkFrameMean) * modelConfig.Integration);
            int    TOTAL_STEPS = 100;
            double step        = Math.Log10(peak) / TOTAL_STEPS;
            double zeroMag     = double.NaN;

            for (int ii = 0; ii < TOTAL_STEPS; ii++)
            {
                int      amplitude = (int)Math.Round(Math.Pow(10, Math.Log10(peak) - ii * step));
                Pixelmap pixmap    = new Pixelmap(64, 64, bitPix, new uint[64 * 64], null, null);
                VideoModelUtils.GenerateStar(pixmap, 32, 32, (float)modelConfig.FWHM, amplitude, 0 /* Gaussian */);
                PSFFit     fit = new PSFFit(32, 32);
                AstroImage img = new AstroImage(pixmap);
                uint[,] data             = img.GetMeasurableAreaPixels(32, 32, 17);
                uint[,] backgroundPixels = img.GetMeasurableAreaPixels(32, 32, 35);

                fit.Fit(data);

                var result = mea.MeasureObject(new ImagePixel(32, 32), data, backgroundPixels, pixmap.BitPixCamera,
                                               TangraConfig.PreProcessingFilter.NoFilter,
                                               TangraConfig.PhotometryReductionMethod.AperturePhotometry, TangraConfig.PsfQuadrature.NumericalInAperture,
                                               TangraConfig.PsfFittingMethod.DirectNonLinearFit,
                                               apertureSize, modelConfig.FWHM, (float)modelConfig.FWHM,
                                               new FakeIMeasuredObject(fit),
                                               null, null,
                                               false);

                if (result == NotMeasuredReasons.TrackedSuccessfully && !mea.HasSaturatedPixels)
                {
                    // Add value for fitting
                    double measurement = mea.TotalReading - mea.TotalBackground;
                    if (double.IsNaN(zeroMag))
                    {
                        zeroMag = modelConfig.BrighestUnsaturatedStarMag + 2.5 * Math.Log10(measurement);
                    }
                    double magnitude = -2.5 * Math.Log10(measurement) + zeroMag;

                    m_MagnitudeToPeakDict[magnitude] = amplitude;
                    m_MagnitudeToPeakMags.Add(magnitude);
                    m_MagnitudeToPeakPeaks.Add(amplitude);
                }
            }
        }
Ejemplo n.º 43
0
        public static List <PSFFit> GetStarsInArea(
            ref uint[,] data, int bpp, uint maxSignalValue, TangraConfig.PreProcessingFilter filter,
            List <PotentialStarStruct> allPotentialStars,
            List <PSFFit> allFoundStars,
            uint aboveNoiseLevelRequired, double minDistanceInPixels,
            bool useLPDFilter, Rectangle excludeArea, FilterPotentialStars filterCallback)
        {
            double minFWHM = TangraConfig.Settings.Special.StarFinderMinFWHM;
            double maxFWHM = TangraConfig.Settings.Special.StarFinderMaxFWHM;

            int STAR_MATRIX_FIT = TangraConfig.Settings.Special.StarFinderFitArea;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            uint[,] lpdData;
            List <PotentialStarStruct> potentialStars = GetPeakPixelsInArea(
                data, out lpdData, bpp, maxSignalValue, aboveNoiseLevelRequired, minDistanceInPixels, useLPDFilter, excludeArea);

            if (filterCallback != null)
            {
                filterCallback(potentialStars);
            }
            sw.Stop();
            Trace.WriteLine(string.Format("GetPeakPixelsInArea: {0} sec", sw.Elapsed.TotalSeconds.ToString("0.00")));

            if (potentialStars.Count > 3)
            {
                // Only include the 3 brightest stars. The other ones cannot be stars
                potentialStars.Sort((x, y) => y.Z.CompareTo(x.Z));
                potentialStars = potentialStars.Take(3).ToList();
            }

            // Debugging purposes
            if (allPotentialStars != null)
            {
                allPotentialStars.AddRange(potentialStars);
            }

            uint[,] lpData = data;

            List <PSFFit> foundStars = new List <PSFFit>();

            double MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER = TangraConfig.Settings.Special.StarFinderMinDistanceOfPeakPixelFromCenter;

            sw.Reset();
            sw.Start();

            foreach (PotentialStarStruct starToTest in potentialStars)
            {
                PSFFit fit       = new PSFFit(starToTest.X, starToTest.Y);
                int    fitMatrix = (int)Math.Min(data.GetLength(0), STAR_MATRIX_FIT + 2);

                // Get a matrix with 1 pixel larger each way and set the border pixels to zero
                fit.Fit(lpData, fitMatrix, starToTest.X, starToTest.Y, true);

                if (fit.IsSolved)
                {
                    double distanceFromCenter = ImagePixel.ComputeDistance(fit.X0_Matrix, fitMatrix / 2, fit.Y0_Matrix, fitMatrix / 2);

                    if (fit.Certainty > 0 &&
                        fit.FWHM >= minFWHM &&
                        fit.FWHM <= maxFWHM &&
                        distanceFromCenter < MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER &&
                        fit.IMax > aboveNoiseLevelRequired)
                    {
                        // This object passes all tests to be furhter considered as a star
                        foundStars.Add(fit);
                    }
                }


                if (allFoundStars != null)
                {
                    allFoundStars.Add(fit);
                }
            }

            foundStars.Sort((f1, f2) => f1.IMax.CompareTo(f2.IMax));

            PSFFit[] testStars = foundStars.ToArray();
            for (int i = 0; i < testStars.Length; i++)
            {
                PSFFit fainterStar = testStars[i];
                for (int j = i + 1; j < testStars.Length; j++)
                {
                    PSFFit brighterStar = testStars[j];

                    if (fainterStar.UniqueId == brighterStar.UniqueId)
                    {
                        continue;
                    }

                    // If a the max of a fainter star is inside the fit of a brighter star
                    // then see if it is simply not a point of the other star

                    double dist = Math.Sqrt((fainterStar.XCenter - brighterStar.XCenter) * (fainterStar.XCenter - brighterStar.XCenter) + (fainterStar.YCenter - brighterStar.YCenter) * (fainterStar.YCenter - brighterStar.YCenter));
                    if (dist <= minDistanceInPixels)
                    {
                        if (foundStars.Contains(fainterStar))
                        {
                            foundStars.Remove(fainterStar);
                        }
                    }
                }
            }
            sw.Stop();
            Trace.WriteLine(string.Format("Doing PSFFitting: {0} sec", sw.Elapsed.TotalSeconds.ToString("0.00")));

            switch (filter)
            {
            case TangraConfig.PreProcessingFilter.NoFilter:
                break;

            case TangraConfig.PreProcessingFilter.LowPassFilter:
                data = lpData;
                break;

            case TangraConfig.PreProcessingFilter.LowPassDifferenceFilter:
                data = lpdData;
                break;
            }

            return(foundStars);
        }
Ejemplo n.º 44
0
        public VqaReader(Stream stream)
        {
            this.stream = stream;

            // Decode FORM chunk
            if (stream.ReadASCII(4) != "FORM")
            {
                throw new InvalidDataException("Invalid vqa (invalid FORM section)");
            }
            /*var length = */ stream.ReadUInt32();

            if (stream.ReadASCII(8) != "WVQAVQHD")
            {
                throw new InvalidDataException("Invalid vqa (not WVQAVQHD)");
            }
            /* var length = */ stream.ReadUInt32();

            /*var version = */ stream.ReadUInt16();
            /*var flags = */ stream.ReadUInt16();
            Frames = stream.ReadUInt16();
            Width  = stream.ReadUInt16();
            Height = stream.ReadUInt16();

            blockWidth  = stream.ReadUInt8();
            blockHeight = stream.ReadUInt8();
            Framerate   = stream.ReadUInt8();
            cbParts     = stream.ReadUInt8();
            blocks      = new int2(Width / blockWidth, Height / blockHeight);

            numColors = stream.ReadUInt16();
            /*var maxBlocks = */ stream.ReadUInt16();
            /*var unknown1 = */ stream.ReadUInt16();
            /*var unknown2 = */ stream.ReadUInt32();

            // Audio
            /*var freq = */ stream.ReadUInt16();
            /*var channels = */ stream.ReadByte();
            /*var bits = */ stream.ReadByte();
            /*var unknown3 = */ stream.ReadBytes(14);

            var frameSize = Exts.NextPowerOf2(Math.Max(Width, Height));

            cbf       = new byte[Width * Height];
            cbp       = new byte[Width * Height];
            palette   = new uint[numColors];
            origData  = new byte[2 * blocks.X * blocks.Y];
            frameData = new uint[frameSize, frameSize];

            var type = stream.ReadASCII(4);

            if (type != "FINF")
            {
                stream.Seek(27, SeekOrigin.Current);
                type = stream.ReadASCII(4);
            }

            /*var length = */ stream.ReadUInt16();
            /*var unknown4 = */ stream.ReadUInt16();

            // Frame offsets
            offsets = new UInt32[Frames];
            for (int i = 0; i < Frames; i++)
            {
                offsets[i] = stream.ReadUInt32();
                if (offsets[i] > 0x40000000)
                {
                    offsets[i] -= 0x40000000;
                }
                offsets[i] <<= 1;
            }

            CollectAudioData();

            Reset();
        }
Ejemplo n.º 45
0
        internal static List <PotentialStarStruct> GetPeakPixelsInArea(
            uint[,] data, out uint[,] lpdData, int bpp, uint maxSignalValue, uint aboveNoiseLevelRequired,
            double minDistanceInPixels, bool useLPDFilter, Rectangle excludeArea)
        {
            if (useLPDFilter)
            {
                lpdData = ImageFilters.LowPassDifferenceFilter(data, bpp, false);
            }
            else
            {
                lpdData = data;
            }

            int nWidth  = lpdData.GetLength(0);
            int nHeight = lpdData.GetLength(1);

            List <PotentialStarStruct> potentialStars = new List <PotentialStarStruct>();

            ExaminePeakPixelCandidate examinePixelCallback =
                delegate(int x, int y, uint z)
            {
                bool tooClose = false;

                // Local maximum, test for a star
                foreach (PotentialStarStruct prevStar in potentialStars)
                {
                    double dist =
                        Math.Sqrt((prevStar.X - x) * (prevStar.X - x) +
                                  (prevStar.Y - y) * (prevStar.Y - y));
                    if (dist <= minDistanceInPixels)
                    {
                        tooClose = true;
                        if (prevStar.Z < z)
                        {
                            prevStar.Z = z;
                            prevStar.X = x;
                            prevStar.Y = y;
                        }

                        break;
                    }
                }

                if (!tooClose)
                {
                    potentialStars.Add(new PotentialStarStruct()
                    {
                        X = x, Y = y, Z = z
                    });
                }

                // An early return if too many peak pixels have been found
                return(potentialStars.Count <=
                       TangraConfig.Settings.Special.
                       StarFinderMaxNumberOfPotentialStars);
            };

            if (useLPDFilter)
            {
                CheckAllPixels(lpdData, nWidth, nHeight, aboveNoiseLevelRequired, excludeArea, examinePixelCallback);
            }
            else
            {
                CheckPixelsFromBrightToFaint(lpdData, nWidth, nHeight, bpp, maxSignalValue, aboveNoiseLevelRequired, excludeArea, examinePixelCallback);
            }

            return(potentialStars);
        }
Ejemplo n.º 46
0
 public void Dispose()
 {
     _background = null;
 }
Ejemplo n.º 47
0
 public static SuperArray Create(uint[,] data) => Data.CreateArray(data);
Ejemplo n.º 48
0
        public static void DrawLineMirrored(Tilemap tilemap, Vector2 locPosA, Vector2 locPosB, uint[,] tileData)
        {
            int w  = tileData.GetLength(0);
            int h  = tileData.GetLength(1);
            int x0 = TilemapUtils.GetGridX(tilemap, locPosA);
            int y0 = TilemapUtils.GetGridY(tilemap, locPosA);
            int x1 = TilemapUtils.GetGridX(tilemap, locPosB);
            int y1 = TilemapUtils.GetGridY(tilemap, locPosB);

            TilemapDrawingUtils.Line(x0, y0, x1, y1,
                                     (x, y) =>
            {
                tilemap.SetTileData(x, y, tileData[(x % w + w) % w, (y % h + h) % h]);
                tilemap.SetTileData(x0 - x, y0 - y, tileData[((x0 - x) % w + w) % w, ((y0 - y) % h + h) % h]);
                return(true);
            }
                                     );
        }
Ejemplo n.º 49
0
        private void PadMessage()
        {
            /* Create array of bytes with a length that is a multiple of 4
             * to house the original message + the extra byte.
             */
            int requiredLength = (int)(Math.Ceiling((l + 1) / 4.0) * 4.0);

            byte[] BYTE_array = new byte[requiredLength];
            Array.Copy(_messagebytes, BYTE_array, l);
            BYTE_array[l] = 0x80;

            /* Process the byte array into an array of 32 bit words (uints)
             * This sections requires attention
             */
            uint[] UINT_array = new uint[(int)(requiredLength / 4)];
            byte[] temp       = new byte[4];
            int    count      = 0;

            for (int i = 0; i < BYTE_array.Length; i++)
            {
                temp[count] = BYTE_array[i];
                if (count == 3)
                {
                    if (BitConverter.IsLittleEndian)
                    {
                        Array.Reverse(temp);
                    }
                    UINT_array[i / 4] = BitConverter.ToUInt32(temp, 0);
                    count             = -1;
                }
                count++;
            }

            /* Now need to convert the byte array into a 64xn
             * 2d array of uints forming the padded message
             */
            numblocks = ((int)(Math.Truncate((UINT_array.Length + 2) / 16.0)) + 1);

            M = new uint[16, numblocks];
            for (int j = 0; j < (numblocks); j++)
            {
                for (int i = 0; i < 16; i++)
                {
                    if ((16 * j) + i < UINT_array.Length)
                    {
                        M[i, j] = UINT_array[(16 * j) + i];
                    }
                    else if (i < 14)
                    {
                        M[i, j] = 0;
                    }
                    else
                    {
                    }        //do nothing - placeholder for the length information
                }
                Console.WriteLine();
            }

            // The last 64 bytes (2 uints) represent the lenth of the message.
            ulong numbits = (ulong)(l * 8);               // Get number of bits from bytes

            M[14, numblocks - 1] = (uint)(numbits >> 32); // Get the high 32 bits
            M[15, numblocks - 1] = (uint)numbits;         // Get the low 32 bits

            // The message is now padded
        }
Ejemplo n.º 50
0
        public static void DrawRect(Tilemap tilemap, Vector2 locPosA, Vector2 locPosB, uint[,] tileData, bool isFilled, bool is9Sliced = false)
        {
            int w  = tileData.GetLength(0);
            int h  = tileData.GetLength(1);
            int x0 = TilemapUtils.GetGridX(tilemap, locPosA);
            int y0 = TilemapUtils.GetGridY(tilemap, locPosA);
            int x1 = TilemapUtils.GetGridX(tilemap, locPosB);
            int y1 = TilemapUtils.GetGridY(tilemap, locPosB);

            if (x0 > x1)
            {
                Swap <int>(ref x0, ref x1);
            }
            if (y0 > y1)
            {
                Swap <int>(ref y0, ref y1);
            }
            TilemapDrawingUtils.Rect(x0, y0, x1, y1, isFilled,
                                     (x, y) =>
            {
                if (is9Sliced)
                {
                    if (x == x0 && y == y0)
                    {
                        tilemap.SetTileData(x, y, tileData[0, 0]);
                    }
                    else if (x == x0 && y == y1)
                    {
                        tilemap.SetTileData(x, y, tileData[0, h - 1]);
                    }
                    else if (x == x1 && y == y0)
                    {
                        tilemap.SetTileData(x, y, tileData[w - 1, 0]);
                    }
                    else if (x == x1 && y == y1)
                    {
                        tilemap.SetTileData(x, y, tileData[w - 1, h - 1]);
                    }
                    else
                    {
                        int cw = w - 2;
                        int ch = h - 2;
                        int cx = cw >= 1 ? 1 + (x % cw + cw) % cw : (x % w + w) % w;
                        int cy = ch >= 1 ? 1 + (y % ch + ch) % ch : (y % h + h) % h;
                        if (x == x0)
                        {
                            tilemap.SetTileData(x, y, tileData[0, cy]);
                        }
                        else if (x == x1)
                        {
                            tilemap.SetTileData(x, y, tileData[w - 1, cy]);
                        }
                        else if (y == y0)
                        {
                            tilemap.SetTileData(x, y, tileData[cx, 0]);
                        }
                        else if (y == y1)
                        {
                            tilemap.SetTileData(x, y, tileData[cx, h - 1]);
                        }
                        else
                        {
                            tilemap.SetTileData(x, y, tileData[cx, cy]);
                        }
                    }
                }
                else
                {
                    tilemap.SetTileData(x, y, tileData[(x % w + w) % w, (y % h + h) % h]);
                }
                return(true);
            }
                                     );
        }
Ejemplo n.º 51
0
 public Blowfish(uint[] P, uint[,] S)
 {
     this.P = P;
     this.S = S;
 }
Ejemplo n.º 52
0
        //https://social.msdn.microsoft.com/Forums/en-US/9d926a16-0051-4ca3-b77c-8095fb489ae2/flood-fill-c?forum=csharplanguage
        public static void FloodFill(Tilemap tilemap, int gridX, int gridY, uint[,] tileData)
        {
            float timeStamp;

            timeStamp = Time.realtimeSinceStartup;
            //float callTimeStamp = timeStamp;

            int patternW             = tileData.GetLength(0);
            int patternH             = tileData.GetLength(1);
            LinkedList <Point> check = new LinkedList <Point>();
            uint floodFrom           = tilemap.GetTileData(gridX, gridY);

            tilemap.SetTileData(gridX, gridY, tileData[(gridX % patternW + patternW) % patternW, (gridY % patternH + patternH) % patternH]);
            bool isBrush = Tileset.GetBrushIdFromTileData(floodFrom) != 0;

            //Debug.Log(" Flood Fill Starts +++++++++++++++ ");
            if (
                (patternW > 0 && patternH > 0) &&
                isBrush?
                Tileset.GetBrushIdFromTileData(floodFrom) != Tileset.GetBrushIdFromTileData(tileData[0, 0])
                :
                floodFrom != tileData[0, 0]
                )
            {
                check.AddLast(new Point(gridX, gridY));
                while (check.Count > 0)
                {
                    Point cur = check.First.Value;
                    check.RemoveFirst();

                    foreach (Point off in new Point[] {
                        new Point(0, -1), new Point(0, 1),
                        new Point(-1, 0), new Point(1, 0)
                    })
                    {
                        Point next         = new Point(cur.X + off.X, cur.Y + off.Y);
                        uint  nextTileData = tilemap.GetTileData(next.X, next.Y);
                        if (
                            next.X >= tilemap.MinGridX && next.X <= tilemap.MaxGridX &&
                            next.Y >= tilemap.MinGridY && next.Y <= tilemap.MaxGridY
                            )
                        {
                            if (
                                isBrush?
                                Tileset.GetBrushIdFromTileData(floodFrom) == Tileset.GetBrushIdFromTileData(nextTileData)
                                :
                                floodFrom == nextTileData
                                )
                            {
                                check.AddLast(next);
                                tilemap.SetTileData(next.X, next.Y, tileData[(next.X % patternW + patternW) % patternW, (next.Y % patternH + patternH) % patternH]);
                            }
                        }
                    }

                    float timePast = Time.realtimeSinceStartup - timeStamp;
                    if (timePast > k_timeToAbortFloodFill)
                    {
#if UNITY_EDITOR
                        int result = UnityEditor.EditorUtility.DisplayDialogComplex("FloodFill is taking too much time", "Do you want to continue for another " + k_timeToAbortFloodFill + " seconds?", "Wait", "Cancel", "Wait and Don't ask again");
                        if (result == 0)
                        {
                            timeStamp = Time.realtimeSinceStartup;
                        }
                        else if (result == 1)
                        {
                            break;
                        }
                        else if (result == 2)
                        {
                            timeStamp = float.MaxValue;
                        }
#else
                        check.Clear();
#endif
                    }
                }
            }

            //Debug.Log("FloodFill Time " + (int)((Time.realtimeSinceStartup - callTimeStamp) * 1000) + "ms");
        }
Ejemplo n.º 53
0
        public CPUID(int thread)
        {
            this.thread = thread;

            uint maxCpuid    = 0;
            uint maxCpuidExt = 0;

            uint eax, ebx, ecx, edx;

            if (thread >= 32)
            {
                throw new ArgumentOutOfRangeException("thread");
            }
            UIntPtr mask = (UIntPtr)(1L << thread);

            if (WinRing0.CpuidTx(CPUID_0, 0,
                                 out eax, out ebx, out ecx, out edx, mask))
            {
                if (eax > 0)
                {
                    maxCpuid = eax;
                }
                else
                {
                    return;
                }

                StringBuilder vendorBuilder = new StringBuilder();
                AppendRegister(vendorBuilder, ebx);
                AppendRegister(vendorBuilder, edx);
                AppendRegister(vendorBuilder, ecx);
                string cpuVendor = vendorBuilder.ToString();
                switch (cpuVendor)
                {
                case "GenuineIntel":
                    vendor = Vendor.Intel;
                    break;

                case "AuthenticAMD":
                    vendor = Vendor.AMD;
                    break;

                default:
                    vendor = Vendor.Unknown;
                    break;
                }
                eax = ebx = ecx = edx = 0;
                if (WinRing0.CpuidTx(CPUID_EXT, 0,
                                     out eax, out ebx, out ecx, out edx, mask))
                {
                    if (eax > CPUID_EXT)
                    {
                        maxCpuidExt = eax - CPUID_EXT;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    throw new ArgumentOutOfRangeException("thread");
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("thread");
            }

            maxCpuid    = Math.Min(maxCpuid, 1024);
            maxCpuidExt = Math.Min(maxCpuidExt, 1024);

            cpuidData = new uint[maxCpuid + 1, 4];
            for (uint i = 0; i < (maxCpuid + 1); i++)
            {
                WinRing0.CpuidTx(CPUID_0 + i, 0,
                                 out cpuidData[i, 0], out cpuidData[i, 1],
                                 out cpuidData[i, 2], out cpuidData[i, 3], mask);
            }

            cpuidExtData = new uint[maxCpuidExt + 1, 4];
            for (uint i = 0; i < (maxCpuidExt + 1); i++)
            {
                WinRing0.CpuidTx(CPUID_EXT + i, 0,
                                 out cpuidExtData[i, 0], out cpuidExtData[i, 1],
                                 out cpuidExtData[i, 2], out cpuidExtData[i, 3], mask);
            }

            StringBuilder nameBuilder = new StringBuilder();

            for (uint i = 2; i <= 4; i++)
            {
                if (WinRing0.CpuidTx(CPUID_EXT + i, 0,
                                     out eax, out ebx, out ecx, out edx, mask))
                {
                    AppendRegister(nameBuilder, eax);
                    AppendRegister(nameBuilder, ebx);
                    AppendRegister(nameBuilder, ecx);
                    AppendRegister(nameBuilder, edx);
                }
            }
            nameBuilder.Replace('\0', ' ');
            cpuBrandString = nameBuilder.ToString().Trim();
            nameBuilder.Replace("(R)", " ");
            nameBuilder.Replace("(TM)", " ");
            nameBuilder.Replace("(tm)", " ");
            nameBuilder.Replace("CPU", "");
            for (int i = 0; i < 10; i++)
            {
                nameBuilder.Replace("  ", " ");
            }
            name = nameBuilder.ToString();
            if (name.Contains("@"))
            {
                name = name.Remove(name.LastIndexOf('@'));
            }
            name = name.Trim();

            this.family = ((cpuidData[1, 0] & 0x0FF00000) >> 20) +
                          ((cpuidData[1, 0] & 0x0F00) >> 8);
            this.model = ((cpuidData[1, 0] & 0x0F0000) >> 12) +
                         ((cpuidData[1, 0] & 0xF0) >> 4);
            this.stepping = (cpuidData[1, 0] & 0x0F);

            this.apicId = (cpuidData[1, 1] >> 24) & 0xFF;

            switch (vendor)
            {
            case Vendor.Intel:
                uint maxCoreAndThreadIdPerPackage = (cpuidData[1, 1] >> 16) & 0xFF;
                uint maxCoreIdPerPackage;
                if (maxCpuid >= 4)
                {
                    maxCoreIdPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1;
                }
                else
                {
                    maxCoreIdPerPackage = 1;
                }
                threadMaskWith =
                    NextLog2(maxCoreAndThreadIdPerPackage / maxCoreIdPerPackage);
                coreMaskWith = NextLog2(maxCoreIdPerPackage);
                break;

            case Vendor.AMD:
                uint corePerPackage;
                if (maxCpuidExt >= 8)
                {
                    corePerPackage = (cpuidExtData[8, 2] & 0xFF) + 1;
                }
                else
                {
                    corePerPackage = 1;
                }
                threadMaskWith = 0;
                coreMaskWith   = NextLog2(corePerPackage);
                break;

            default:
                threadMaskWith = 0;
                coreMaskWith   = 0;
                break;
            }

            processorId = (apicId >> (int)(coreMaskWith + threadMaskWith));
            coreId      = ((apicId >> (int)(threadMaskWith))
                           - (processorId << (int)(coreMaskWith)));
            threadId = apicId
                       - (processorId << (int)(coreMaskWith + threadMaskWith))
                       - (coreId << (int)(threadMaskWith));
        }
Ejemplo n.º 54
0
        public static void DrawEllipse(Tilemap tilemap, Vector2 locPosA, Vector2 locPosB, uint[,] tileData, bool isFilled)
        {
            int w  = tileData.GetLength(0);
            int h  = tileData.GetLength(1);
            int x0 = TilemapUtils.GetGridX(tilemap, locPosA);
            int y0 = TilemapUtils.GetGridY(tilemap, locPosA);
            int x1 = TilemapUtils.GetGridX(tilemap, locPosB);
            int y1 = TilemapUtils.GetGridY(tilemap, locPosB);
            int xf = 0;
            int yf = 0;

            //fix for cases where x1 x2 y1 or y2 are negative or x1 > x2 or y1 > y2
            // NOTE: I tested this only for case x1 == y1 == 0
            if (x0 > x1)
            {
                Swap <int>(ref x0, ref x1);
            }
            if (y0 > y1)
            {
                Swap <int>(ref y0, ref y1);
            }
            if (x0 < 0)
            {
                xf = x0; x0 = 0; x1 -= xf;
            }
            if (y0 < 0)
            {
                yf = y0; y0 = 0; y1 -= yf;
            }
            //
            TilemapDrawingUtils.Ellipse(x0, y0, x1, y1, isFilled,
                                        (x, y) =>
            {
                tilemap.SetTileData(x + xf, y + yf, tileData[((x + xf) % w + w) % w, ((y + yf) % h + h) % h]);
                return(true);
            }
                                        );
        }
Ejemplo n.º 55
0
        /// <summary>
        /// Constructs and initializes a blowfish instance with the supplied key.
        /// </summary>
        /// <param name="key">The key to cipher with.</param>
        public Blowfish(byte[] key)
        {
            short			i;
            short			j;
            short			k;
            uint			data;
            uint			datal;
            uint			datar;

            P = _P.Clone() as uint[];
            S = _S.Clone() as uint[,];

            j = 0;
            for (i = 0; i < N + 2; ++i)
            {
                data = 0x00000000;
                for (k = 0; k < 4; ++k)
                {
                    data = (data << 8) | key[j];
                    j++;
                    if (j >= key.Length)
                    {
                        j = 0;
                    }
                }
                P[i] = P[i] ^ data;
            }

            datal = 0x00000000;
            datar = 0x00000000;

            for (i = 0; i < N + 2; i += 2)
            {
                Encipher(ref datal, ref datar);
                P[i] = datal;
                P[i + 1] = datar;
            }

            for (i = 0; i < 4; ++i)
            {
                for (j = 0; j < 256; j += 2)
                {
                    Encipher(ref datal, ref datar);

                    S[i,j] = datal;
                    S[i,j + 1] = datar;
                }
            }
        }
 // Создадим временный массив вносимых банкнот
 public void InitBanknoteArrayTmp()
 {
     banknoteArrayTmp = new uint[, ] {
         { 5, 0 }, { 10, 0 }, { 20, 0 }, { 50, 0 }, { 100, 0 }, { 200, 0 }, { 500, 0 }, { 1000, 0 }
     };
 }
Ejemplo n.º 57
0
        public void ResolvePeakPixels(
			Rectangle osdRectangleToExclude, Rectangle rectToInclude, bool limitByInclusion,
			int edgeDistance, int minDistanceBetweenPixels)
        {
            int width = m_Image.Width;
                int height = m_Image.Height;

                uint[,] data = BitmapFilter.LowPassFilter(m_Image.Pixelmap.GetPixelsCopy(), m_Image.Pixelmap.BitPixCamera, false);

                List<uint> allPixels = new List<uint>();
                for (int y = edgeDistance; y < height - edgeDistance; ++y)
                {
                    for (int x = edgeDistance; x < width - edgeDistance; ++x)
                    {
                        if (limitByInclusion && !rectToInclude.Contains(x, y)) continue;
                        if (!limitByInclusion && osdRectangleToExclude.Contains(x, y)) continue;

                        allPixels.Add(data[x, y]);
                    }
                }
                double mode = BitmapFilter.GetMode(allPixels, 6);

                if (minDistanceBetweenPixels % 2 == 0) minDistanceBetweenPixels++;
                int halfDistance = (minDistanceBetweenPixels / 2) + 1;

                // TODO: Use 2x2 or 3x3 binning to reduce the number of peak pixels found

                for (int y = edgeDistance; y < height - edgeDistance; y += minDistanceBetweenPixels)
                {
                    for (int x = edgeDistance; x < width - edgeDistance; x+= minDistanceBetweenPixels)
                    {
                        int maxX = int.MinValue;
                        int maxY = int.MinValue;
                        uint maxVal = 0;

                        for (int i = 0; i < minDistanceBetweenPixels; i++)
                        {
                            for (int j = 0; j < minDistanceBetweenPixels; j++)
                            {
                                int xx = x + i;
                                int yy = y + j;

                                if (limitByInclusion && !rectToInclude.Contains(xx, yy)) continue;
                                if (!limitByInclusion && osdRectangleToExclude.Contains(xx, yy)) continue;

                                if (data[xx, yy] < mode) continue;

                                if (data[xx, yy] > maxVal)
                                {
                                    maxVal = data[xx, yy];
                                    maxX = xx;
                                    maxY = yy;
                                }
                            }
                        }

                        if (maxX != int.MinValue)
                        {
                            uint pix = data[maxX, maxY];
                            if (pix >= data[maxX - 1, maxY - 1] &&
                                pix >= data[maxX - 1, maxY] &&
                                pix >= data[maxX - 1, maxY + 1] &&
                                pix >= data[maxX, maxY - 1] &&
                                pix >= data[maxX, maxY + 1] &&
                                pix >= data[maxX + 1, maxY - 1] &&
                                pix >= data[maxX + 1, maxY] &&
                                pix >= data[maxX + 1, maxY + 1])
                            {
                                // peak Pixel found
                                m_PeakPixels.Add(new KeyValuePair<int, int>(maxX, maxY), pix);
                            }
                        }
                    }
                }

                m_PixelData = data;
        }
Ejemplo n.º 58
0
        // Constructor
        public RenderWindow(uint argRows, uint argColumns)
        {
            // Variable values:
            #region

            rowCount    = argRows + 1;
            columnCount = argColumns + 1;

            #endregion

            // Declare arrays:
            #region

            gridString      = new string[rowCount, columnCount, 4];
            gridStringCount = new uint[rowCount, columnCount];
            gridStringColor = new ConsoleColor[rowCount, columnCount, 4];

            gridType = new RenderGridTypes[rowCount, columnCount];
            gridCol  = new ConsoleColor[rowCount, columnCount];

            gamePoints    = new MassiveNumber();
            displayPoints = new MassiveNumber();

            agentPointsRate = new MassiveNumber[rowCount];

            agentIsLocked = new bool[rowCount];

            agentLabel = new string[rowCount];
            upgraLabel = new string[rowCount, 3];

            columnWidth = new int[columnCount];

            for (uint i = 0; i < columnCount; i++)
            {
                columnWidth[i] = 25;
            }

            for (uint i = 0; i < rowCount; i++)
            {
                agentCount[i] = new MassiveNumber();
                agentPrice[i] = new MassiveNumber();
                upgraCount[i] = new MassiveNumber();
                upgraPrice[i] = new MassiveNumber();

                agentPointsRate[i] = new MassiveNumber();
                agentIsLocked[i]   = true;
            }

            #endregion

            // Hardcoded values:
            #region

            optimalIsAgent = true;

            currentMenuInd = 1;     // 1 -> Agents
                                    // 2 -> Upgrades
            menuPages = 2;

            columnWidth[0] = 8;     // Empty
            columnWidth[1] = 30;    // Legend
            columnWidth[2] = 7;     // Agent Keys
            columnWidth[3] = 25;    // Agent Count
            columnWidth[4] = 17;    // Agent Price
                                    // Agent Label

            agentLabel[0] = "Stone Harvester";
            agentLabel[1] = "Coal Miner";
            agentLabel[2] = "Iron Miner";
            agentLabel[3] = "Drill Operator";
            agentLabel[4] = "Steel Drill Operator";
            agentLabel[5] = "Diamond Drill Operator";
            agentLabel[6] = "Blast Miner";
            agentLabel[7] = "Demolitionist";
            agentLabel[8] = "Demolition Expert";
            agentLabel[9] = "Crypto Miner";

            upgraLabel[0, 0] = "Better Grip Gloves";
            upgraLabel[0, 1] = "Morale Boost";
            upgraLabel[0, 2] = "Automated Stone Grabbing System";
            upgraLabel[1, 0] = "Sharper pickaxes";
            upgraLabel[1, 1] = "Morale Boost";
            upgraLabel[1, 2] = "Coffee";
            upgraLabel[2, 0] = "Sturdier Pickaxes";
            upgraLabel[2, 1] = "Morale Boost";
            upgraLabel[2, 2] = "Energy Drinks";

            upgraLabel[3, 0] = "Wireless Drills";
            upgraLabel[3, 1] = "Extended Battery Life";
            upgraLabel[3, 2] = "Dual-Bit Drills";
            upgraLabel[4, 0] = "Reinforced Drills";
            upgraLabel[4, 1] = "Battery Cell Array";
            upgraLabel[4, 2] = "Quad-Bit Drills";
            upgraLabel[5, 0] = "Lighter Drills";
            upgraLabel[5, 1] = "Portable Reactors";
            upgraLabel[5, 2] = "Omni-Bit Drills";

            upgraLabel[6, 0] = "Increased Potency";
            upgraLabel[6, 1] = "Faster Fuse Time";
            upgraLabel[6, 2] = "Cluster Explosive";
            upgraLabel[7, 0] = "Recursive Explosive Mining";
            upgraLabel[7, 1] = "Compact Explosive Mining";
            upgraLabel[7, 2] = "Hypersonic Explosive Mining";
            upgraLabel[8, 0] = "Thermobaric Explosive License";
            upgraLabel[8, 1] = "Anti-Matter Explosive License";
            upgraLabel[8, 2] = "Red Matter Explosive License";

            upgraLabel[9, 0] = "Faster Processors";
            upgraLabel[9, 1] = "Liquid Cooling";
            upgraLabel[9, 2] = "Overclocking";

            for (int i = 0; i < gridStringColor.GetLength(0); i++)
            {
                for (int j = 0; j < gridStringColor.GetLength(1); j++)
                {
                    for (int k = 0; k < gridStringColor.GetLength(2); k++)
                    {
                        gridStringColor[i, j, k] = ConsoleColor.White;
                    }
                }
            }

            for (uint i = 0; i < rowCount; i++)
            {
                for (uint j = 0; j < columnCount; j++)
                {
                    // Default to blank grid.
                    gridStringCount[i, j] = 0;
                    gridType[i, j]        = RenderGridTypes.GridEmpty;
                    gridString[i, j, 0]   = "";

                    // Write info
                    #region

                    if (j == 0 && i == 0)
                    {
                        gridType[i, j]           = RenderGridTypes.GridString;
                        gridStringColor[i, j, 1] = ConsoleColor.Gray;
                        gridStringCount[i, j]    = 1;

                        gridString[i, j, 0] = "Exit: ";
                        gridString[i, j, 1] = "X";
                    }

                    #endregion

                    // Write legend column.
                    #region

                    if (j == 1)
                    {
                        // Center these rows relative to the agents' rows.
                        if (i == rowCount / 2 - 1)
                        {
                            gridType[i, j]      = RenderGridTypes.GridPoints;
                            gridString[i, j, 0] = "Profits: ";
                        }
                        else if (i == rowCount / 2)
                        {
                            gridType[i, j]           = RenderGridTypes.GridString;
                            gridStringColor[i, j, 1] = ConsoleColor.Cyan;
                            gridStringCount[i, j]    = 2;

                            gridString[i, j, 0] = "Press ";
                            gridString[i, j, 1] = "Spacebar";
                            gridString[i, j, 2] = " to dig";
                        }
                        else if (i == rowCount / 2 + 1)
                        {
                            gridType[i, j]        = RenderGridTypes.GridChangeMenu;
                            gridStringCount[i, j] = 3;

                            gridString[i, j, 0] = "Press ";
                            gridString[i, j, 1] = "<-";
                            gridString[i, j, 2] = " or ";
                            gridString[i, j, 3] = "->";
                        }
                    }

                    #endregion

                    // Write key press column
                    #region

                    if (j == 2)
                    {
                        gridType[i, j]           = RenderGridTypes.GridString;
                        gridStringColor[i, j, 0] = ConsoleColor.Gray;
                        gridStringColor[i, j, 2] = ConsoleColor.Gray;
                        gridStringCount[i, j]    = 2;

                        gridString[i, j, 0] = "[";
                        gridString[i, j, 1] = "" + ((int)(i + 11) % 10);
                        gridString[i, j, 2] = "]";
                    }

                    #endregion

                    // Write agents price column.
                    #region

                    if (j == 3)
                    {
                        gridString[i, j, 0] = "Price: ";
                        gridType[i, j]      = RenderGridTypes.GridAgentPrice;
                    }

                    #endregion

                    // Write agents count column.
                    #region

                    if (j == 4)
                    {
                        if (i == 0)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 1)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 2)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 3)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 4)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 5)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 6)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 7)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 8)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 9)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                    }

                    #endregion

                    // Write agents label column.
                    #region

                    if (j == 5)
                    {
                        gridString[i, j, 0] = (agentLabel[i]);

                        if (i == 0)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 1)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 2)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 3)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 4)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 5)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 6)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 7)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 8)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 9)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                    }

                    #endregion
                }
            }

            #endregion
        }
Ejemplo n.º 59
0
 public void Init(bool forEncryption, byte[] key) {
     WorkingKey = GenerateWorkingKey(key, forEncryption);
     this.forEncryption = forEncryption;
 }
Ejemplo n.º 60
0
        /**
        * initialise an AES cipher.
        *
        * @param forEncryption whether or not we are for encryption.
        * @param parameters the parameters required to set up the cipher.
        * @exception ArgumentException if the parameters argument is
        * inappropriate.
        */
        public void Init(
            bool forEncryption,
            byte[] Key)
        {
            //if (!(parameters is KeyParameter))
            //    throw new ArgumentException("invalid parameter passed to AES init - " + parameters.GetType().ToString());

            WorkingKey = GenerateWorkingKey(Key, forEncryption);
            this.forEncryption = forEncryption;
        }