Example #1
0
        private TD.Image DrawGrid()
        {
            // Skip drawing if viewport not sized yet
            if (_viewport.GetImageSize().IsEmpty())
            {
                return(null);
            }

            // Create image
            var image = new TD.Image(_viewport);

            // Update drawer items: pos, visibility,.. (according to collected update flags)
#if USE_PERF
            _perfUpdateItems.Start();
#endif
            _gridDrawer.UpdateItems();
            _gridDrawer.UpdateCursorItem();
#if USE_PERF
            _perfUpdateItems.Stop();
#endif

            // Draw items as image elements
#if USE_PERF
            _perfDrawItems.Start();
#endif
            _gridDrawer.DrawGrid(image);
#if USE_PERF
            _perfDrawItems.Stop();
#endif

            return(image);
        }
Example #2
0
        static void Test6_Plotter()
        {
            var harmonicity = HarmonicityUtils.CreateHarmonicity(null); // default

            var viewport = new Torec.Drawing.Viewport(1200, 600, 0, 1200, 1, -1);
            var image    = new Torec.Drawing.Image(viewport);

            var r0      = new Rational(1);
            var r1      = new Rational(2);
            var handler = new HandlerPipe <RationalInfo>(
                new RangeRationalHandler(r0, r1, false, true),
                new Samples.RationalPrinter(),
                new RationalPlotter(image, harmonicity)
                );

            Debug.WriteLine("Iterate {0} range {1}-{2}", harmonicity.GetType().Name, r0, r1);

            var limits = new RationalGenerator.Limits {
                dimensionCount = 7, rationalCount = 50, distance = -1
            };

            new RationalIterator(harmonicity, limits, null, handler).Iterate();

            image.Show(svg: true);
            //image.Show(svg: false);
        }
Example #3
0
        // Image
        private void menuImageOpenSvg_Click(object sender, RoutedEventArgs e)
        {
            // Export and open svg in default editor
            var image = new Torec.Drawing.Image(_viewport);

            _gridDrawer.DrawGrid(image);
            image.Show(true);
        }
Example #4
0
        private void RedrawMainImage() // UI thread
        {
            // Draw items to vector Image elements in UI thread
            TD.Image image = DrawGrid();
            if (image == null)
            {
                return;
            }

            // Signal render thread to do work
            lock (_renderLock) {
                _mainImage = image;
            }

            //Debug.WriteLine("Render DoWork sent");
            _eventRenderDoWork.Set(); // unblock RenderThread()

            // On render complete we continue in UI thread: UpdateMainBitmap()
        }
Example #5
0
        internal static void DrawGrid()
        {
            string harmonicityName = "Euler Barlow Tenney Narrow".Split()[0];

            Rational[] subgroup = Rational.ParseRationals("2.3.5");

            /*
             * var harmonicity = HarmonicityUtils.CreateHarmonicity(harmonicityName);
             * foreach (string s in "5/6 4/3".Split()) {
             *  Rational r = Rational.Parse(s);
             *  Debug.WriteLine("{0} d:{1} h:{2}",
             *      r, harmonicity.GetDistance(r), harmonicity.GetHarmonicity(r)
             *  );
             * }
             */

            var viewport = new Torec.Drawing.Viewport(1600, 1200, -1, 1, -3, 3);
            var image    = new Torec.Drawing.Image(viewport);

            var drawer = new Rationals.Drawing.GridDrawer();

            // configure drawer
            drawer.SetBounds(viewport.GetUserBounds());
            // below like UpdateDrawerFully()
            drawer.SetSubgroup(0, subgroup, null);
            drawer.SetGeneration(harmonicityName, 200);
            drawer.SetSlope(new Rational(3, 2), 2.0f);
            //
            drawer.SetEDGrids(Rationals.Drawing.GridDrawer.EDGrid.Parse("12edo"));
            drawer.SetPointRadius(1.0f);

            // generate grid items
            drawer.UpdateItems();

            // make image elements from grid items
            drawer.DrawGrid(image);

            // render/show svg
            image.Show(svg: true);
        }
Example #6
0
        private async void menuImageSaveAs_Click(object sender, RoutedEventArgs e)
        {
            // Save image as png/svg
            var dialog = new SaveFileDialog {
                Title = "Save Image As"
            };

            dialog.Filters.AddRange(new [] {
                new FileDialogFilter()
                {
                    Name = "Svg files", Extensions = { "svg" }
                },
                new FileDialogFilter()
                {
                    Name = "Png files", Extensions = { "png" }
                },
                new FileDialogFilter()
                {
                    Name = "All files", Extensions = { "*" }
                }
            });
            string filePath = await dialog.ShowAsync(this);

            if (filePath == null)
            {
                return;                   //!!! cancel?
            }
            var image = new Torec.Drawing.Image(_viewport);

            _gridDrawer.DrawGrid(image);
            if (System.IO.Path.GetExtension(filePath).ToLower() == ".svg")
            {
                image.WriteSvg(filePath);
            }
            else
            {
                image.WritePng(filePath, true);
            }
        }