Esempio n. 1
0
        public void Analyze()
        {
            int numCols = Capture.Rect.Width / GlyphColumnWidth;
            int numRows = Capture.Rect.Height / GlyphRowHeight;

            if (numCols <= 0 || numRows <= 0)
            {
                throw new AnalysisException(Invariant($"The glyphs palette is smaller than expected. Dimensions are: {Capture.Rect.Size}."));
            }

            for (int row = 0; row < numRows; row++)
            {
                for (int col = 0; col < numCols; col++)
                {
                    var location = new Point(col * GlyphColumnWidth, row * GlyphRowHeight).Add(GlyphOffset);
                    var type     = m_glyphAnalyzer.Analyze(location);

                    // The last glyph may be centred on the last row
                    if (type == null && row == numRows - 1 && col == 0)
                    {
                        col++;
                        location.X += GlyphColumnWidth / 2;
                        type        = m_glyphAnalyzer.Analyze(location);
                    }

                    if (type == null)
                    {
                        throw new AnalysisException(Invariant($"Can't identify the glyph at {location}."));
                    }

                    m_palette.AddTool(type.Value, new Tool <GlyphType>(type.Value, location));
                }
            }
        }
Esempio n. 2
0
        public void Analyze()
        {
            var prevLocation = new Point(0, 0);

            while (m_palette.Tools.Count() < MaxMolecules)
            {
                // Look for a pixel which is not part of the background of the palette, and not part of a molecule we've
                // already analyzed.
                var searchRect = new Rectangle(0, prevLocation.Y, Capture.Bitmap.Width, Capture.Bitmap.Height - prevLocation.Y);
                var location   = BitmapUtils.FindFirstPoint(Capture.Bitmap, searchRect, col => col.GetBrightness() > BrightnessThreshold);
                if (location == null)
                {
                    break;
                }

                sm_log.Info(Invariant($"Found molecule at {location}"));

                // The sidebar does not scroll very accurately - sometimes the molecules move by 0 pixels and sometimes by 1 or 2.
                // Because of this we set the location to the pixel below, under the assumption that a molecule won't
                // have an isolated pixel at the top.
                var realLoc = location.Value;
                realLoc.Y++;

                var molecule = AnalyzeMolecule(realLoc);
                molecule.ID = m_palette.Tools.Count();
                m_palette.AddTool(molecule.ID, new Tool <Molecule>(molecule, realLoc));

                prevLocation = realLoc;
            }
        }
Esempio n. 3
0
 private void AddMechanism(MechanismType type, Point location)
 {
     m_palette.AddTool(type, new Tool <MechanismType>(type, location));
 }