Пример #1
0
        /// <summary>
        /// Возвращает вертикальные последовательности пикселей для
        /// геометрической фигуры.
        /// </summary>
        /// <param name="sourceGeometry"></param>
        /// <param name="fill">Заливка</param>
        /// <param name="minX"></param>
        /// <param name="minY"></param>
        /// <param name="maxX"></param>
        /// <param name="maxY"></param>
        /// <returns>Список вертикальных последовательностей символов</returns>
        public IList <PixelSpan> GetVerticalSpans(IScannable sourceGeometry, int minX, int minY, int maxX, int maxY, FillBase fill)
        {
            List <PixelSpan> spans = new List <PixelSpan>();

            BoundingRectangle br = sourceGeometry.BoundingBox;

            float startY = Math.Max((float)br.MinY, minY);
            float endY   = Math.Min((float)br.MaxY + 1, maxY);
            float startX = (int)Math.Max((float)br.MinX - 1, minX);
            float endX   = Math.Min((float)br.MaxX + 1, maxX);

            sourceGeometry.InitScaning((int)startX, (int)endX, minY, maxY, Orientation.Vertical);

            List <float[]> pixelScanIntersections = new List <float[]>();

            for (float scanX = startX; scanX < endX; scanX++)
            {
                pixelScanIntersections.Clear();
                for (byte i = 0; i < _subPixelLevel; i++)
                {
                    float[] intersections;
                    sourceGeometry.ComputeVerticalIntersections(scanX + _scanStep * i, out intersections);
                    pixelScanIntersections.Add(intersections);
                }
                addSpans(Orientation.Vertical, spans, pixelScanIntersections, (int)scanX, fill);
            }

            return(spans);
        }
Пример #2
0
 public void Scan(IScannable basket)
 {
     for (var item = basket.TakeItem(); item != null; item = basket.TakeItem())
     {
         ScanItem(item);
     }
 }
Пример #3
0
        private void beginRenderObjectPool(object startData)
        {
            ThreadStartData tsd = (ThreadStartData)startData;
            int             f   = 0;

            foreach (IScannable obj in _objectPool)
            {
                BoundingRectangle br = obj.BoundingBox;
                if (obj.BoundingBox.Intersects(new BoundingRectangle(tsd.MinX, tsd.MinY, tsd.MaxX, tsd.MaxY)))
                {
                    IScannable newObj = (IScannable)obj.Clone();

                    IList <PixelSpan> spans = null;
                    if (br.Width >= br.Height)
                    {
                        spans = _spanGenerator.GetHorizontalSpans(newObj, tsd.MinX, tsd.MinY, tsd.MaxX, tsd.MaxY, _fillPool[f]);
                    }
                    else
                    {
                        spans = _spanGenerator.GetVerticalSpans(newObj, tsd.MinX, tsd.MinY, tsd.MaxX, tsd.MaxY, _fillPool[f]);
                    }
                    foreach (PixelSpan ps in spans)
                    {
                        _rasterData.BlendSpan(ps);
                    }
                }
                f++;
            }
        }
Пример #4
0
        /// <summary>
        /// Called to try and scan for clues in the areea.
        /// </summary>
        private void TryScanForClues()
        {
            if (!this.references.canPlayerScan.Value)
            {
                return;
            }

            PlayerScanResult scanResult = new PlayerScanResult();

            scanResult.scanResult = PlayerScanResultType.RESULT_FAILED;

            RaycastHit raycast;

            if (Physics.Raycast(
                    this.transform.position, this.transform.forward, out raycast))
            {
                IScannable scannable = raycast.rigidbody.GetComponent <IScannable>();
                if (scannable != null)
                {
                    if (raycast.distance > this.maxDistance)
                    {
                        scanResult.scanResult = PlayerScanResultType.RESULT_LINE_UP;
                    }
                    else
                    {
                        scannable.OnScanned(this, raycast, ref scanResult);
                    }
                }
            }

            this.references.canPlayerScan.Value = false;
            this.events.scanResultEvent?.CallEvent(scanResult);
        }
Пример #5
0
        private void renderMultipleThreads(IScannable obj, FillBase fill)
        {
            _objectPool.Add(obj);
            _fillPool.Add(fill);

            if (!_unlimitedPool && _objectPool.Count == _poolSize)
            {
                Flush();
            }
        }
Пример #6
0
        /// <inheritdoc/>
        public ConcurrentDictionary <string, ConcurrentQueue <string> > Scan(Scanner scanner, Stream stream, string file)
        {
            // Files can be protected in multiple ways
            var protections = new ConcurrentDictionary <string, ConcurrentQueue <string> >();

            // Load the current file content
            byte[] fileContent = null;
            try
            {
                using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
                {
                    fileContent = br.ReadBytes((int)stream.Length);
                }
            }
            catch
            {
                Utilities.AppendToDictionary(protections, file, "[File too large to be scanned]");
                return(protections);
            }

            // If we can, seek to the beginning of the stream
            if (stream.CanSeek)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            // Iterate through all content checks
            Parallel.ForEach(contentCheckClasses, contentCheckClass =>
            {
                string protection = contentCheckClass.CheckContents(file, fileContent, scanner.IncludePosition);

                // If we have a valid content check based on settings
                if (!contentCheckClass.GetType().Namespace.ToLowerInvariant().Contains("packertype") || scanner.ScanPackers)
                {
                    if (!string.IsNullOrWhiteSpace(protection))
                    {
                        Utilities.AppendToDictionary(protections, file, protection);
                    }
                }

                // If we have an IScannable implementation
                if (contentCheckClass is IScannable)
                {
                    IScannable scannable = contentCheckClass as IScannable;
                    if (file != null && !string.IsNullOrEmpty(protection))
                    {
                        var subProtections = scannable.Scan(scanner, null, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }
                }
            });

            return(protections);
        }
Пример #7
0
        /// <summary>
        /// Выводит объект.
        /// </summary>
        /// <param name="obj">Объект</param>
        /// <param name="fill">Заливка</param>
        public void Render(IScannable obj, FillBase fill)
        {
            switch (_parallelizationLevel)
            {
            case ParallelizationLevel.Single:
                renderSingleThread(obj, fill);
                break;

            case ParallelizationLevel.Duo:
            case ParallelizationLevel.Quad:
                renderMultipleThreads(obj, fill);
                break;
            }
        }
Пример #8
0
        private void renderSingleThread(IScannable obj, FillBase fill)
        {
            IList <PixelSpan> spans = null;

            if (obj.BoundingBox.Width >= obj.BoundingBox.Height)
            {
                spans = _spanGenerator.GetHorizontalSpans(obj, 0, 0, _rasterData.Width, _rasterData.Height, fill);
            }
            else
            {
                spans = _spanGenerator.GetVerticalSpans(obj, 0, 0, _rasterData.Width, _rasterData.Height, fill);
            }

            foreach (PixelSpan ps in spans)
            {
                _rasterData.BlendSpan(ps);
            }
        }
 public MobilogicsDeligateConnect(IScannable controller)
 {
     Controller = controller;
 }
Пример #10
0
        /// <summary>
        /// Возвращает вертикальные последовательности пикселей для
        /// геометрической фигуры.
        /// </summary>
        /// <param name="sourceGeometry"></param>
        /// <param name="fill">Заливка</param>
        /// <param name="minX"></param>
        /// <param name="minY"></param>
        /// <param name="maxX"></param>
        /// <param name="maxY"></param>
        /// <returns>Список вертикальных последовательностей символов</returns>
        public IList<PixelSpan> GetVerticalSpans(IScannable sourceGeometry, int minX, int minY, int maxX, int maxY, FillBase fill)
        {
            List<PixelSpan> spans = new List<PixelSpan>();

            BoundingRectangle br = sourceGeometry.BoundingBox;

            float startY = Math.Max((float)br.MinY, minY);
            float endY = Math.Min((float)br.MaxY + 1, maxY);
            float startX = (int)Math.Max((float)br.MinX - 1, minX);
            float endX = Math.Min((float)br.MaxX + 1, maxX);

            sourceGeometry.InitScaning((int)startX, (int)endX, minY, maxY, Orientation.Vertical);

            List<float[]> pixelScanIntersections = new List<float[]>();
            for (float scanX = startX; scanX < endX; scanX++)
            {
                pixelScanIntersections.Clear();
                for (byte i = 0; i < _subPixelLevel; i++)
                {
                    float[] intersections;
                    sourceGeometry.ComputeVerticalIntersections(scanX + _scanStep * i, out intersections);
                    pixelScanIntersections.Add(intersections);
                }
                addSpans(Orientation.Vertical, spans, pixelScanIntersections, (int)scanX, fill);
            }

            return spans;
        }
Пример #11
0
 /// <summary>
 /// Выводит объект.
 /// </summary>
 /// <param name="obj">Объект</param>
 /// <param name="fill">Заливка</param>
 public void Render(IScannable obj, FillBase fill)
 {
     switch(_parallelizationLevel)
     {
         case ParallelizationLevel.Single:
             renderSingleThread(obj, fill);
             break;
         case ParallelizationLevel.Duo:
         case ParallelizationLevel.Quad:
             renderMultipleThreads(obj, fill);
             break;
     }
 }
Пример #12
0
        private void renderMultipleThreads(IScannable obj, FillBase fill)
        {
            _objectPool.Add(obj);
            _fillPool.Add(fill);

            if (!_unlimitedPool && _objectPool.Count == _poolSize)
                Flush();
        }
Пример #13
0
        private void renderSingleThread(IScannable obj, FillBase fill)
        {
            IList<PixelSpan> spans = null;
            if (obj.BoundingBox.Width >= obj.BoundingBox.Height)
                spans = _spanGenerator.GetHorizontalSpans(obj, 0, 0, _rasterData.Width, _rasterData.Height, fill);
            else
                spans = _spanGenerator.GetVerticalSpans(obj, 0, 0, _rasterData.Width, _rasterData.Height, fill);

            foreach (PixelSpan ps in spans)
                _rasterData.BlendSpan(ps);
        }