Beispiel #1
0
        private static ushort[] FlipAndConvert2d(Array input)
        {
            using (MyStopWatch.Measure("FlipAndConvert2d")) {
                Int32[,] arr = (Int32[, ])input;
                int width  = arr.GetLength(0);
                int height = arr.GetLength(1);

                int      length    = width * height;
                ushort[] flatArray = new ushort[length];
                ushort   value;

                unsafe
                {
                    fixed(Int32 *ptr = arr)
                    {
                        int idx = 0, row = 0;

                        for (int i = 0; i < length; i++)
                        {
                            value = (ushort)ptr[i];

                            idx = ((i % height) * width) + row;
                            if ((i % (height)) == (height - 1))
                            {
                                row++;
                            }

                            ushort b = value;
                            flatArray[idx] = b;
                        }
                    }
                }
                return(flatArray);
            }
        }
 public void StartTimers()
 {
     if (IsRunning)
     {
         MyStopWatch.Start();
     }
 }
        public void Update()
        {
            var newPosition = Camera.main.transform.position;

            if (!_once)
            {
                var msw = new MyStopWatch();
                msw.StartSegment("Starting segment.");
                _once = true;
                _vegetationRuntimeManagementProxy.Start(newPosition);
                _vegetationRuntimeManagementProxy.StartThreading();
                //_globalInstancingContainer.StartThread();
                _debugGrassGroupsGrowerUnderTest.FinalizeStart();
                Debug.Log("L8: segment " + msw.CollectResults());
            }
            else
            {
                //_globalInstancingContainer.DrawFrame();
                _vegetationRuntimeManagementProxy.AddUpdate(newPosition);
                const int maxMsPerFrame = 4000;

                //_globalInstancingContainer.FinishUpdateBatch();
            }
            _debugGrassGroupsGrowerUnderTest.Update();
        }
Beispiel #4
0
    private void checkAlienation()
    {
        if (MainMain.isAlienationPhase())
        {
            // we are alienated right now
            if (alienationStopWatch != null && alienationStopWatch.isRunning())
            {
                long myAlienationDuration = (int)((Convert.ToSingle(MainMain.secondsOfChildAlienation) * 1000.0f) + (1500.0f * randomFloat(0.0f, 1.0f)));
                if (alienationStopWatch.execeedesMilliseconds(myAlienationDuration))
                {
                    // we gonna end this
                    playSoundOfADyingChild();
                    destroyGameObjectsParent(body);
                    alienationStopWatch.stop();

                    isAlienated = true;
                    MainMain.noOfChildrenInAlienation--;
                }
                else
                {
                    // we stay in that phase
                    setGameObjectVisible((randomChanceOccurs(0.5f) ? true : false));
                }
            }
            // start my alienation
            else if (MainMain.noOfChildrenInAlienation < 2 && isAlienated == false)
            {
                MainMain.noOfChildrenInAlienation++;
                alienationStopWatch = new MyStopWatch();
                setGameObjectVisible(false);
            }
        }
    }
        public void IsFull(MyStopWatch timer, Context context, IRaspberryPiStates emptyState,
                           IRaspberryPiStates fullState, IRaspberryPiStates notDoneState)
        {
            //Console.WriteLine("Fullstate");
            if (LaserTop.Detected() == false)
            {
                //bt.SendData("Fullstate");
                context.setState(fullState);
                return;
            }

            if (LaserTop.Detected() && Magnet.Detected() == true)
            {
                timer.StartTimer();
                //Bluetooth
                //bt.Init();
                //bt.SendData("NotDoneState");
                writer.JsonWriterFunc("NotDonestate", "0", "");
                context.setState(notDoneState);
            }
            else
            {
                throw new ArgumentException("Error In FullState");
            }
        }
Beispiel #6
0
 private async void ResizeTimer_Tick(object sender, EventArgs e)
 {
     using (MyStopWatch.Measure()) {
         (sender as DispatcherTimer).Stop();
         await LoadImage();
     }
 }
Beispiel #7
0
        public bool SelectProfile(ProfileMeta info)
        {
            lock (lockobj) {
                using (MyStopWatch.Measure()) {
                    try {
                        var p = Profile.Load(info.Location);

                        UnregisterChangedEventHandlers();
                        if (ActiveProfile != null)
                        {
                            ActiveProfile.Dispose();
                            Profiles.Where(x => x.Id == ActiveProfile.Id).First().IsActive = false;
                        }

                        ActiveProfile = p;
                        info.IsActive = true;

                        System.Threading.Thread.CurrentThread.CurrentUICulture = ActiveProfile.ApplicationSettings.Language;
                        System.Threading.Thread.CurrentThread.CurrentCulture   = ActiveProfile.ApplicationSettings.Language;
                        Locale.Loc.Instance.ReloadLocale(ActiveProfile.ApplicationSettings.Culture);

                        LocaleChanged?.Invoke(this, null);
                        ProfileChanged?.Invoke(this, null);
                        LocationChanged?.Invoke(this, null);
                        RegisterChangedEventHandlers();
                    } catch (Exception ex) {
                        Logger.Debug(ex.Message + Environment.NewLine + ex.StackTrace);
                        return(false);
                    }
                    return(true);
                }
            }
        }
        public void Start()
        {
            var sw = new MyStopWatch();

            sw.StartSegment("TamIdGeneration");
            TaskUtils.SetGlobalMultithreading(false);
            var tonesCount  = 3;
            var levelsCount = 3;
            var layersCount = 1;

            var tamTones = TAMTone.CreateList(tonesCount, new Dictionary <int, TAMStrokeOrientation>()
            {
                { 0, TAMStrokeOrientation.Horizontal },
                { 3, TAMStrokeOrientation.Vertical },
                { 5, TAMStrokeOrientation.Both }
            });
            var tamMipmapLevels = TAMMipmapLevel.CreateList(levelsCount);

            var configuration = TamIdPackGenerationConfiguration
                                .GetDefaultTamIdConfiguration(tamTones, tamMipmapLevels, 1f, layersCount, StrokeImagePath, BlankImagePath, false);

            configuration.SmallestLevelSoleImageResolution = new IntVector2(256, 256);
            var packGenerator = new TamIdPackGenerator();
            var pack          = packGenerator.GenerateTamPack(configuration, false, FindObjectOfType <ComputeShaderContainerGameObject>());

            TamIdGeneratorGO.DrawDebugPlates(pack);
            var fileManager = new TamIdPackFileManager();

            Debug.Log("Sw: " + sw.CollectResults());

            var tamIdPath = TemporaryImagesPath + TamName + @"\";

            Directory.CreateDirectory(tamIdPath);
            fileManager.Save(tamIdPath, tamTones, tamMipmapLevels, layersCount, pack);
        }
Beispiel #9
0
        private static byte[] UncompressData(byte[] raw, XISFCompressionInfo compressionInfo)
        {
            byte[] outArray = null;

            if (compressionInfo.CompressionType != XISFCompressionTypeEnum.NONE)
            {
                outArray = new byte[compressionInfo.UncompressedSize];

                using (MyStopWatch.Measure($"XISF Decompression = {compressionInfo.CompressionType}")) {
                    switch (compressionInfo.CompressionType)
                    {
                    case XISFCompressionTypeEnum.LZ4:
                    case XISFCompressionTypeEnum.LZ4HC:
                        int size = LZ4Codec.Decode(raw, 0, raw.Length, outArray, 0, compressionInfo.UncompressedSize);

                        if (size != compressionInfo.UncompressedSize)
                        {
                            Logger.Error($"XISF: Indicated uncompressed size does not equal actual size: Indicated: {compressionInfo.UncompressedSize}, Actual: {size}");
                        }

                        break;

                    case XISFCompressionTypeEnum.ZLIB:
                        outArray = ZlibStream.UncompressBuffer(raw);
                        break;
                    }
                }
            }

            return(outArray);
        }
Beispiel #10
0
        public void IsFull(MyStopWatch timer, Context context, IRaspberryPiStates emptyState,
                           IRaspberryPiStates fullState, IRaspberryPiStates notDoneState)
        {
            //Console.WriteLine("NotDoneState");
            if (LaserBot.Detected() == false)
            {
                //bt.SendData("NotDoneState");
                context.setState(notDoneState);
            }

            if (Magnet.Detected() == false && LaserBot.Detected() == true)
            {
                //bt.Init();
                string result = null;
                result = timer.StopTimer();
                Console.WriteLine(result);
                //bt.SendData(result);
                //bt.SendData("EmptyState");
                writer.JsonWriterFunc("Emptystate", result, "");
                context.setState(emptyState);
            }

            if (timer.GetTime() > MAX_TIME)
            {
                throw new InvalidOperationException("TimeOut");
            }
        }
Beispiel #11
0
        public void Start()
        {
            var startTime = _DAL.StartTiming(JobTimingId);

            this.StartTime = startTime;
            this.IsRunning = true;
            MyStopWatch.Start();
        }
Beispiel #12
0
 public void Update()
 {
     _updaterUntilException.Execute(() => { _ultraUpdatableContainer.Update(new EncapsulatedCameraForUpdate(ActiveCamera)); });
     if (msw != null)
     {
         Debug.Log("T65: game initialization took: " + msw.CollectResults());
         msw = null;
     }
 }
        static void Main(string[] args)
        {
            Init();
            MyStopWatch        timer        = new MyStopWatch();
            Context            context      = new Context();
            IRaspberryPiStates emptyState   = new EmptyState();
            IRaspberryPiStates fullState    = new FullState();
            IRaspberryPiStates notDoneState = new NotDoneState();
            //Bluetooth bt = new Bluetooth();
            //bt.Init();
            JsonWriter writer = new JsonWriter();

            context.setState(emptyState);
            writer.JsonWriterFunc("Emptystate", "0", "Start");
            //bt.SendData("EmptyState");
            while (ReferenceEquals(context.getState(), emptyState) ||
                   ReferenceEquals(context.getState(), fullState) ||
                   ReferenceEquals(context.getState(), notDoneState))
            {
                try
                {
                    context.IsFull(timer, context, emptyState, fullState, notDoneState);
                }
                catch (ArgumentException)
                {
                    //bt.SendData("ErrorFullStateGoEmptyState");
                    writer.JsonWriterFunc("Emptystate", "0", "Fullstate error");
                    context.setState(emptyState);
                }
                catch (InvalidOperationException)
                {
                    //bt.SendData("TimeoutGoEmptyState");
                    writer.JsonWriterFunc("Emptystate", "0", "Timeout");
                    context.setState(emptyState);
                }
                catch (Exception)
                {
                    //bt.SendData("ErrorGoEmptyState");
                    writer.JsonWriterFunc("Emptystate", "0", "ProgramCrash");
                    context.setState(emptyState);
                }
            }

            void Init()
            {
                MagnetSensor      Magnet   = new MagnetSensor();
                LaserSensorBottom LaserBot = new LaserSensorBottom();
                LaserSensorTop    LaserTop = new LaserSensorTop();

                Magnet.Initiate();
                LaserTop.Initiate();
                LaserBot.Initiate();
            }
        }
Beispiel #14
0
        public void Start()
        {
            var msw = new MyStopWatch();

            msw.StartSegment("Loading");
            var loader = new HabitatMapOsmLoader();
            var fields = loader.Load(@"C:\inz\osm\map.osm");

            msw.StartSegment("Translating");
            var translator = new HabitatFieldPositionTranslator(GeoCoordsToUnityTranslator.DefaultTranslator);

            fields = fields.Select(c => translator.Translate(c)).ToList();

            msw.StartSegment("MapCreating");
            var map = HabitatMap.Create(
                new MyRectangle(62 * 720, 67 * 720, 8 * 720, 8 * 720),
                new Vector2(90 * 8, 90 * 8),
                fields,
                HabitatType.NotSpecified,
                HabitatTypePriorityResolver.Default);


            GeoCoordsToUnityTranslator translator2 = GeoCoordsToUnityTranslator.DefaultTranslator;
            var         geoPos1  = new GeoCoordinate(49.600f, 19.543f);
            var         lifePos1 = translator2.TranslateToUnity(geoPos1);
            var         geoPos2  = new GeoCoordinate(49.610f, 19.552f);
            var         lifePos2 = translator2.TranslateToUnity(geoPos2);
            MyRectangle territoryUsedToCreateStainTexture =
                new MyRectangle(lifePos1.x, lifePos1.y, lifePos2.x - lifePos1.x, lifePos2.y - lifePos1.y);

            territoryUsedToCreateStainTexture = RectangleUtils.CalculateSubPosition(territoryUsedToCreateStainTexture,
                                                                                    new MyRectangle(0.65f, 0.65f, 0.1f, 0.1f));

            var treeX         = map.QueryMap(territoryUsedToCreateStainTexture);
            var parentObjectX = new GameObject($"MAGA");

            treeX.QueryAll()
            .ForEach(c => HabitatMapOsmLoaderDebugObject.CreateDebugHabitatField(c.Field, 0.01f, parentObjectX));

            msw.StartSegment("MapQuerying");
            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    var tree = map.QueryMap(
                        new MyRectangle(62 * 720 + x * 720, 67 * 720 + y * 720, 720, 720));
                    var parentObject = new GameObject($"x:{x} y:{y}");
                    tree.QueryAll()
                    .ForEach(c => HabitatMapOsmLoaderDebugObject.CreateDebugHabitatField(c.Field, 0.01f,
                                                                                         parentObject));
                }
            }
            Debug.Log("T64: " + msw.CollectResults());
        }
Beispiel #15
0
        public static BitmapSource Stretch(IImageStatistics statistics, Bitmap img, System.Windows.Media.PixelFormat pf, double factor, double blackClipping)
        {
            using (MyStopWatch.Measure()) {
                var filter = ImageUtility.GetColorRemappingFilter(statistics, factor, blackClipping, pf);
                filter.ApplyInPlace(img);

                var source = ImageUtility.ConvertBitmap(img, pf);
                source.Freeze();
                return(source);
            }
        }
Beispiel #16
0
 public void ReloadLocale(string culture)
 {
     using (MyStopWatch.Measure()) {
         try {
             _activeCulture = new CultureInfo(culture);
         } catch (Exception ex) {
             Logger.Error(ex);
         }
         RaiseAllPropertiesChanged();
     }
 }
Beispiel #17
0
 public static DebayeredImageData Debayer(BitmapSource source, System.Drawing.Imaging.PixelFormat pf, bool saveColorChannels = false, bool saveLumChannel = false, SensorType bayerPattern = SensorType.RGGB)
 {
     using (MyStopWatch.Measure()) {
         if (pf != System.Drawing.Imaging.PixelFormat.Format16bppGrayScale)
         {
             throw new NotSupportedException();
         }
         using (var bmp = BitmapFromSource(source, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale)) {
             return(Debayer(bmp, saveColorChannels, saveLumChannel, bayerPattern));
         }
     }
 }
        static void Main()
        {
            MyStopWatch stopwatch = new MyStopWatch();
            Handler1    handler1  = new Handler1();
            Handler2    handler2  = new Handler2();
            Handler3    handler3  = new Handler3();

            stopwatch.Event += handler1.OnTimer;
            stopwatch.Event += handler2.OnTimer;
            stopwatch.Event += handler3.OnTimer;
            stopwatch.Start(new TimeSpan(0, 0, 5));
        }
Beispiel #19
0
 private void Save()
 {
     lock (lockobj) {
         using (MyStopWatch.Measure()) {
             try {
                 ActiveProfile.Save();
             } catch (Exception ex) {
                 Logger.Error(ex);
             }
         }
     }
 }
Beispiel #20
0
        private static bool VerifyChecksum(byte[] raw, XISFChecksumTypeEnum cksumType, string providedCksum)
        {
            string      computedCksum;
            SHA3Managed sha3;

            using (MyStopWatch.Measure($"XISF Checksum = {cksumType}")) {
                switch (cksumType)
                {
                case XISFChecksumTypeEnum.SHA1:
                    SHA1 sha1 = new SHA1CryptoServiceProvider();
                    computedCksum = GetStringFromHash(sha1.ComputeHash(raw));
                    sha1.Dispose();
                    break;

                case XISFChecksumTypeEnum.SHA256:
                    SHA256 sha256 = new SHA256CryptoServiceProvider();
                    computedCksum = GetStringFromHash(sha256.ComputeHash(raw));
                    sha256.Dispose();
                    break;

                case XISFChecksumTypeEnum.SHA512:
                    SHA512 sha512 = new SHA512CryptoServiceProvider();
                    computedCksum = GetStringFromHash(sha512.ComputeHash(raw));
                    sha512.Dispose();
                    break;

                case XISFChecksumTypeEnum.SHA3_256:
                    sha3          = new SHA3Managed(256);
                    computedCksum = GetStringFromHash(sha3.ComputeHash(raw));
                    sha3.Dispose();
                    break;

                case XISFChecksumTypeEnum.SHA3_512:
                    sha3          = new SHA3Managed(512);
                    computedCksum = GetStringFromHash(sha3.ComputeHash(raw));
                    sha3.Dispose();
                    break;

                default:
                    return(false);
                }
            }
            if (computedCksum.Equals(providedCksum))
            {
                return(true);
            }
            else
            {
                Logger.Error($"XISF: Invalid data block checksum! Expected: {providedCksum} Got: {computedCksum}");
                return(false);
            }
        }
        public void TakeMeasurements(int frameNo, MeasurementScreenshotsSet screenshotsSet)
        {
            Debug.Log("R827 RESOLUTION: " + screenshotsSet.HatchMainTexture.Height + " " + screenshotsSet.HatchMainTexture.Width);
            var msw = new MyStopWatch();

            foreach (var gauge in _gauges)
            {
                msw.StartSegment(gauge.ToString());
                var result = gauge.TakeMeasurement(screenshotsSet);
                WriteResultsToFile(frameNo, result);
            }
            Debug.Log(msw.CollectResults());
        }
Beispiel #22
0
        public void Stop()
        {
            IsRunning = false;
            MyStopWatch.Stop();
            EndTime = DateTime.Now;

            var        ctx    = new TimeTrackerEntities();
            DJobTiming timing = ctx.DJobTimings.FirstOrDefault(x => x.JobTimingId == JobTimingId);

            timing.EndTime   = EndTime;
            timing.IsRunning = false;
            ctx.SaveChanges();
        }
        public float [] Generate(Mesh inputMesh, int radius = 5, bool useKring = true)
        {
            var unaliasedGenerator = new UnaliasedMeshGenerator();
            var unaliasedMesh      = unaliasedGenerator.GenerateUnaliasedMesh(inputMesh);

            var verticesFlatArray       = unaliasedMesh.Vertices.SelectMany(c => c.ToArray()).ToArray();
            var unaliasedVerticesCount  = unaliasedMesh.Vertices.Length;
            var unaliasedTrianglesCount = unaliasedMesh.Triangles.Length / 3;

            var outDirection1 = new float[3 * unaliasedVerticesCount];
            var outDirection2 = new float[3 * unaliasedVerticesCount];
            var outValues1    = new float[unaliasedVerticesCount];
            var outValues2    = new float[unaliasedVerticesCount];

            var sw = new MyStopWatch();

            sw.StartSegment("pc");
            PrincipalCurvatureDll.EnableLogging();
            int callStatus = PrincipalCurvatureDll.compute_principal_curvature(verticesFlatArray, unaliasedVerticesCount, unaliasedMesh.Triangles, unaliasedTrianglesCount, outDirection1, outDirection2,
                                                                               outValues1, outValues2, radius, useKring);

            sw.StartSegment("pc2");
            Preconditions.Assert(callStatus == 0, "Calling compute_principal_curvature failed, as returned status " + callStatus);
            //RemapCurvatureData(outDirection1, outDirection2, outValues1, outValues2);

            var inputVerticesCount = inputMesh.vertices.Length;
            var outArray           = new float[inputVerticesCount * 8];

            for (int i = 0; i < unaliasedVerticesCount; i++)
            {
                foreach (var inputVerticleIndex in unaliasedMesh.VerticlesToOriginalVerticles[unaliasedMesh.Vertices[i]])
                {
                    var outArrayIdx = inputVerticleIndex * 8;
                    var inArrayIdx  = i * 3;
                    outArray[outArrayIdx + 0] = outDirection1[inArrayIdx + 0];
                    outArray[outArrayIdx + 1] = outDirection1[inArrayIdx + 1];
                    outArray[outArrayIdx + 2] = outDirection1[inArrayIdx + 2];

                    outArray[outArrayIdx + 3] = outValues1[i];

                    outArray[outArrayIdx + 4] = outDirection2[inArrayIdx + 0];
                    outArray[outArrayIdx + 5] = outDirection2[inArrayIdx + 1];
                    outArray[outArrayIdx + 6] = outDirection2[inArrayIdx + 2];

                    outArray[outArrayIdx + 7] = outValues2[i];
                }
            }
            Debug.Log("A22: " + sw.CollectResults());
            return(outArray);
        }
Beispiel #24
0
        public void StopImpl()
        {
            if (!_isRunning)
            {
                return;
            }

            MyStopWatch w = new MyStopWatch();

            _isRunning = false;
            _channelManager.Stop();
            _discoverer.StopBroadcasting();
            _discoverer.StopListening();
            Env.Logger.Log($"Stop {nameof(SuperDriveCore)} in {w.Elipsed}ms. Discoverer.IsListening={_instance._discoverer.IsListening}", nameof(SuperDriveCore));
        }
Beispiel #25
0
        public BitmapSource GetAnnotatedImage()
        {
            using (MyStopWatch.Measure()) {
                using (var bmp = ImageUtility.Convert16BppTo8Bpp(_originalBitmapSource)) {
                    using (var newBitmap = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)) {
                        Graphics graphics = Graphics.FromImage(newBitmap);
                        graphics.DrawImage(bmp, 0, 0);

                        if (_starlist.Count > 0)
                        {
                            int   r, offset = 10;
                            float textposx, textposy;

                            var threshhold = 200;
                            if (_starlist.Count > threshhold)
                            {
                                _starlist.Sort((item1, item2) => item2.Average.CompareTo(item1.Average));
                                _starlist = _starlist.GetRange(0, threshhold);
                            }

                            foreach (Star star in _starlist)
                            {
                                _token.ThrowIfCancellationRequested();
                                r        = (int)Math.Ceiling(star.radius);
                                textposx = star.Position.X - offset;
                                textposy = star.Position.Y - offset;
                                graphics.DrawEllipse(ELLIPSEPEN, new RectangleF(star.Rectangle.X, star.Rectangle.Y, star.Rectangle.Width, star.Rectangle.Height));
                                graphics.DrawString(star.HFR.ToString("##.##"), FONT, TEXTBRUSH, new PointF(Convert.ToSingle(textposx - 1.5 * offset), Convert.ToSingle(textposy + 2.5 * offset)));
                            }
                        }

                        if (UseROI)
                        {
                            graphics.DrawRectangle(RECTPEN, (float)(1 - InnerCropRatio) * imageProperties.Width / 2, (float)(1 - InnerCropRatio) * imageProperties.Height / 2, (float)InnerCropRatio * imageProperties.Width, (float)InnerCropRatio * imageProperties.Height);
                            if (OuterCropRatio < 1)
                            {
                                graphics.DrawRectangle(RECTPEN, (float)(1 - OuterCropRatio) * imageProperties.Width / 2, (float)(1 - OuterCropRatio) * imageProperties.Height / 2, (float)OuterCropRatio * imageProperties.Width, (float)OuterCropRatio * imageProperties.Height);
                            }
                        }

                        var img = ImageUtility.ConvertBitmap(newBitmap, System.Windows.Media.PixelFormats.Bgr24);

                        img.Freeze();
                        return(img);
                    }
                }
            }
        }
Beispiel #26
0
        private void DoRTest()
        {
            MyStopWatch sw = new MyStopWatch();

            while (RTest_flag)
            {
                int pos1 = 6400 * 20 / 16;
                int time = int.Parse(Txt_RDelay.Text);
                switch (flag)
                {
                case 0:
                    headcard.PfMove(6, -(int)(pos1), int.Parse(Txt_RPf.Text), Chk_R1.Checked);
                    headcard.PfMove(7, -(int)(pos1), int.Parse(Txt_RPf.Text), Chk_R2.Checked);
                    if (Chk_R1.Checked || Chk_R2.Checked)
                    {
                        num1++;
                    }

                    sw.StartStopWatch(time);
                    flag = 1;
                    break;

                case 1:
                    if (sw.TimeUp())
                    {
                        SetRText("", num1);
                        headcard.PfMove(6, 0, int.Parse(Txt_RPf.Text), Chk_R1.Checked);
                        headcard.PfMove(7, 0, int.Parse(Txt_RPf.Text), Chk_R2.Checked);
                        if (Chk_R1.Checked || Chk_R2.Checked)
                        {
                            num1++;
                        }
                        sw.StartStopWatch(time);
                        flag = 3;
                    }
                    break;

                case 3:
                    if (sw.TimeUp())
                    {
                        SetRText("", num1);
                        Thread.Sleep(15);
                        flag = 0;
                    }
                    break;
                }
            }
        }
Beispiel #27
0
        public Task <IImageData> Convert(
            MemoryStream s,
            int bitDepth,
            string rawType,
            ImageMetaData metaData,
            CancellationToken token = default)
        {
            return(Task.Run(() => {
                using (MyStopWatch.Measure()) {
                    FIBITMAP img;
                    int left, top, imgWidth, imgHeight;
                    FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_RAW;
                    img = FreeImage.LoadFromStream(s, (FREE_IMAGE_LOAD_FLAGS)8, ref format);

                    FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, img, "Raw.Frame.Width", out MetadataTag widthTag);
                    FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, img, "Raw.Frame.Height", out MetadataTag heightTag);
                    FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, img, "Raw.Frame.Left", out MetadataTag leftTag);
                    FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, img, "Raw.Frame.Top", out MetadataTag topTag);
                    left = int.Parse(leftTag.ToString());
                    top = int.Parse(topTag.ToString());
                    imgWidth = int.Parse(widthTag.ToString());
                    imgHeight = int.Parse(heightTag.ToString());

                    using (var memStream = new MemoryStream()) {
                        FreeImage.SaveToStream(img, memStream, FREE_IMAGE_FORMAT.FIF_TIFF, FREE_IMAGE_SAVE_FLAGS.TIFF_NONE);
                        memStream.Position = 0;

                        var decoder = new TiffBitmapDecoder(memStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

                        CroppedBitmap cropped = new CroppedBitmap(decoder.Frames[0], new System.Windows.Int32Rect(left, top, imgWidth, imgHeight));

                        ushort[] outArray = new ushort[cropped.PixelWidth * cropped.PixelHeight];
                        cropped.CopyPixels(outArray, 2 * cropped.PixelWidth, 0);
                        FreeImage.UnloadEx(ref img);

                        var imageArray = new ImageArray(flatArray: outArray, rawData: s.ToArray(), rawType: rawType);
                        var data = new ImageData(
                            imageArray: imageArray,
                            width: cropped.PixelWidth,
                            height: cropped.PixelHeight,
                            bitDepth: bitDepth,
                            isBayered: true,
                            metaData: metaData);
                        return Task.FromResult <IImageData>(data);
                    }
                }
            }));
        }
Beispiel #28
0
        public async void CheckUrl(string url)
        {
            ProccessIsDone = false;
            MyStopWatch.Restart();
            WebRequest  webRequest = WebRequest.Create(url);
            WebResponse response   = await webRequest.GetResponseAsync();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                string numberOfCharacters = await reader.ReadToEndAsync();

                UrlSize = $"The Size Of Your Site Is: {numberOfCharacters.Length.ToString()} Bytes.";
            }
            ProccessIsDone = true;
            MyStopWatch.Stop();
        }
Beispiel #29
0
        public void Compute(ComputeShaderContainerGameObject computeShaderContainer)
        {
            TaskUtils.SetGlobalMultithreading(false);
            _gameInitializationFields.SetField(computeShaderContainer);

            var msw = new MyStopWatch();

            //var queries = RecordingTerrainShapeDb.LoadQueriesFromFile(@"C:\inz\allQueries.json");
            //Debug.Log("H8: " + StringUtils.ToString(queries.Select(c => c.QueryArea)));

            //msw.StartSegment("TerrainDbInitialization");
            //InitializeTerrainDb(true);

            //TestHeightNormalization();
            //return;

            msw.StartSegment("PathPrecomputation");
            var pathPrecomputation = new PathPrecomputation(_gameInitializationFields, _precomputationConfiguration,
                                                            _filePathsConfiguration);

            //pathPrecomputation.Compute();
            pathPrecomputation.Load();

            msw.StartSegment("HabitatMapDbPrecomputation");
            var habitatMapDbPrecomputation = new HabitatMapDbPrecomputation(_gameInitializationFields,
                                                                            _precomputationConfiguration, _filePathsConfiguration);

            habitatMapDbPrecomputation.Compute();
            habitatMapDbPrecomputation.Load();

            //msw.StartSegment("Ring1Precomputation");
            //var ring1Precomputation = new Ring1Precomputation(_gameInitializationFields, _precomputationConfiguration,
            //    _filePathsConfiguration);
            //ring1Precomputation.Compute();
            //ring1Precomputation.Load();

            //msw.StartSegment("VegetationDatabasePrecomputation");
            //var vegetationDatabasePrecomputation =
            //    new VegetationDatabasePrecomputation(_gameInitializationFields, _precomputationConfiguration, _filePathsConfiguration);
            //vegetationDatabasePrecomputation.Compute();

            //msw.StartSegment("Grass2billboardsPrecomputation");
            //var grass2BillboardsPrecomputation = new Grass2BillboardsPrecomputer(_gameInitializationFields, _filePathsConfiguration);
            ////grass2BillboardsPrecomputation.Compute();

            //Debug.Log("L8 Precomputation time: "+msw.CollectResults());
        }
 public void IsFull(MyStopWatch timer, Context context, IRaspberryPiStates emptyState,
                    IRaspberryPiStates fullState, IRaspberryPiStates notDoneState)
 {
     //Console.WriteLine("EmptyState");
     if (LaserTop.Detected() == true)
     {
         //bt.SendData("EmptyState");
         context.setState(emptyState);
     }
     else
     {
         //bt.Init();
         //bt.SendData("FullState");
         writer.JsonWriterFunc("Fullstate", "0", "");
         context.setState(fullState);
     }
 }