Ejemplo n.º 1
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                var path = new VertexStorage();
                path.MoveTo(0, 0);
                path.LineTo(Math.Sqrt(2), 0);
                path.LineTo(0, Height);

                var mesh = VertexSourceToMesh.Revolve(path, 4);
                mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width / 2, Depth / 2, 1));
                Mesh = mesh;

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
Ejemplo n.º 2
0
        private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, double dotRadius, int numSnapPoints, int markToSnapTo)
        {
            var graphics2DOpenGL = new Graphics2DOpenGL();

            double snappingRadians = MathHelper.Tau / numSnapPoints;
            var    clippingFrustum = GLHelper.GetClippingFrustum(InteractionContext.World);

            for (int i = 0; i < numSnapPoints; i++)
            {
                double startAngle = i * snappingRadians + mouseAngle;

                VertexStorage snapShape = new VertexStorage();
                snapShape.MoveTo(-10, 0);
                snapShape.LineTo(5, 7);
                snapShape.LineTo(5, -7);
                snapShape.ClosePolygon();

                var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
                // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);

                var color = Color.Black;
                if (i == markToSnapTo)
                {
                    color = Color.Red;
                }

                graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
            }
        }
Ejemplo n.º 3
0
        public void JsonSerializeVertexStorage()
        {
            var test1Control = new VertexStorage();

            test1Control.MoveTo(10, 11);
            test1Control.LineTo(100, 11);
            test1Control.LineTo(100, 110);
            test1Control.ClosePolygon();
            string jsonData    = JsonConvert.SerializeObject(test1Control);
            var    test1Result = JsonConvert.DeserializeObject <VertexStorage>(jsonData);

            Assert.AreEqual(test1Control.Count, test1Result.Count);

            var control = test1Control.Vertices().GetEnumerator();
            var result  = test1Result.Vertices().GetEnumerator();

            for (int i = 0; i < test1Control.Count; i++)
            {
                control.MoveNext();
                result.MoveNext();
                var controlVertex = control.Current;
                var resultVertex  = result.Current;
                Assert.AreEqual(controlVertex.command, resultVertex.command);
                Assert.AreEqual(controlVertex.position, resultVertex.position);
            }
        }
Ejemplo n.º 4
0
        public static void DrawMeasureLine(Graphics2D graphics2D, Vector2 lineStart, Vector2 lineEnd, Color color, LineArrows arrows)
        {
            graphics2D.Line(lineStart, lineEnd, Color.Black);

            Vector2 direction = lineEnd - lineStart;

            if (direction.LengthSquared > 0 &&
                (arrows.HasFlag(LineArrows.Start) || arrows.HasFlag(LineArrows.End)))
            {
                VertexStorage arrow = new VertexStorage();
                arrow.MoveTo(-3, -5);
                arrow.LineTo(0, 0);
                arrow.LineTo(3, -5);
                if (arrows.HasFlag(LineArrows.End))
                {
                    double        rotation        = Math.Atan2(direction.Y, direction.X);
                    IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4));
                    IVertexSource inPosition      = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(lineEnd));
                    graphics2D.Render(inPosition, Color.Black);
                }
                if (arrows.HasFlag(LineArrows.Start))
                {
                    double        rotation        = Math.Atan2(direction.Y, direction.X) + MathHelper.Tau / 2;
                    IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4));
                    IVertexSource inPosition      = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(lineStart));
                    graphics2D.Render(inPosition, Color.Black);
                }
            }
        }
Ejemplo n.º 5
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref valuesChanged);
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
                RingSides     = agg_basics.Clamp(RingSides, 3, 360, ref valuesChanged);

                StartingAngle = agg_basics.Clamp(StartingAngle, 0, 360 - .01, ref valuesChanged);
                EndingAngle   = agg_basics.Clamp(EndingAngle, StartingAngle + .01, 360, ref valuesChanged);

                var ringSides      = RingSides;
                var startingAngle  = StartingAngle;
                var endingAngle    = EndingAngle;
                var ringPhaseAngle = RingPhaseAngle;
                if (!Advanced)
                {
                    ringSides      = Math.Max(3, (int)(Sides / 2));
                    startingAngle  = 0;
                    endingAngle    = 360;
                    ringPhaseAngle = 0;
                }

                var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);

                using (new CenterAndHeightMaintainer(this))
                {
                    var poleRadius     = (OuterDiameter / 2 - innerDiameter / 2) / 2;
                    var toroidRadius   = innerDiameter / 2 + poleRadius;
                    var path           = new VertexStorage();
                    var angleDelta     = MathHelper.Tau / ringSides;
                    var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle);
                    var ringAngle      = ringStartAngle;
                    var circleCenter   = new Vector2(toroidRadius, 0);
                    path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
                    for (int i = 0; i < ringSides - 1; i++)
                    {
                        ringAngle += angleDelta;
                        path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle)));
                    }

                    path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));

                    var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                    var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                    Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Ejemplo n.º 6
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref changed);
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref changed);
                RingSides     = agg_basics.Clamp(RingSides, 3, 360, ref changed);

                var ringSides      = RingSides;
                var startingAngle  = StartingAngle;
                var endingAngle    = EndingAngle;
                var ringPhaseAngle = RingPhaseAngle;
                if (!Advanced)
                {
                    ringSides      = Math.Max(3, (int)(Sides / 2));
                    startingAngle  = 0;
                    endingAngle    = 360;
                    ringPhaseAngle = 0;
                }

                var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);

                var aabb = this.GetAxisAlignedBoundingBox();

                var poleRadius     = (OuterDiameter / 2 - innerDiameter / 2) / 2;
                var toroidRadius   = innerDiameter / 2 + poleRadius;
                var path           = new VertexStorage();
                var angleDelta     = MathHelper.Tau / ringSides;
                var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle);
                var ringAngle      = ringStartAngle;
                var circleCenter   = new Vector2(toroidRadius, 0);
                path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
                for (int i = 0; i < ringSides - 1; i++)
                {
                    ringAngle += angleDelta;
                    path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle)));
                }

                path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));

                var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            if (changed)
            {
                base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties));
            }
        }
Ejemplo n.º 7
0
        public void CreateGrid(Affine transform)
        {
            Vector2 gridOffset = gridCenterMm - gridSizeMm / 2;

            if (gridSizeMm.X > 0 && gridSizeMm.Y > 0)
            {
                grid.remove_all();
                for (int y = 0; y <= gridSizeMm.Y; y += 10)
                {
                    Vector2 start = new Vector2(0, y) + gridOffset;
                    Vector2 end   = new Vector2(gridSizeMm.X, y) + gridOffset;
                    transform.transform(ref start);
                    transform.transform(ref end);
                    grid.MoveTo((int)(start.X + .5), (int)(start.Y + .5) + .5);
                    grid.LineTo((int)(int)(end.X + .5), (int)(end.Y + .5) + .5);
                }

                for (int x = 0; x <= gridSizeMm.X; x += 10)
                {
                    Vector2 start = new Vector2(x, 0) + gridOffset;
                    Vector2 end   = new Vector2(x, gridSizeMm.Y) + gridOffset;
                    transform.transform(ref start);
                    transform.transform(ref end);
                    grid.MoveTo((int)(start.X + .5) + .5, (int)(start.Y + .5));
                    grid.LineTo((int)(end.X + .5) + .5, (int)(end.Y + .5));
                }
            }
        }
Ejemplo n.º 8
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                Sides = agg_basics.Clamp(Sides, 3, 360, ref changed);
                var aabb = this.GetAxisAlignedBoundingBox();

                var path = new VertexStorage();
                path.MoveTo(0, 0);
                path.LineTo(Diameter / 2, 0);
                path.LineTo(0, Height);

                Mesh = VertexSourceToMesh.Revolve(path, Sides);
                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            if (changed)
            {
                base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties));
            }
        }
Ejemplo n.º 9
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            targetBounds = this.GetTargetBounds(productTour.ActiveItem.Widget);

            var dimRegion = new VertexStorage();

            dimRegion.MoveTo(LocalBounds.Left, LocalBounds.Bottom);
            dimRegion.LineTo(LocalBounds.Right, LocalBounds.Bottom);
            dimRegion.LineTo(LocalBounds.Right, LocalBounds.Top);
            dimRegion.LineTo(LocalBounds.Left, LocalBounds.Top);

            var targetRect = new VertexStorage();

            targetRect.MoveTo(targetBounds.Right, targetBounds.Bottom);
            targetRect.LineTo(targetBounds.Left, targetBounds.Bottom);
            targetRect.LineTo(targetBounds.Left, targetBounds.Top);
            targetRect.LineTo(targetBounds.Right, targetBounds.Top);

            var overlayMinusTargetRect = new CombinePaths(dimRegion, targetRect);

            graphics2D.Render(overlayMinusTargetRect, new Color(Color.Black, 180));

            base.OnDraw(graphics2D);

            graphics2D.Render(new Stroke(new RoundedRect(targetBounds, 0), 2), Color.White.WithAlpha(50));
            //graphics2D.Render(new Stroke(new RoundedRect(GetContentBounds(), 3), 4), theme.PrimaryAccentColor);
        }
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                var radius     = Diameter / 2;
                var angleDelta = MathHelper.Tau / 4 / LatitudeSides;
                var angle      = 0.0;
                var path       = new VertexStorage();
                path.MoveTo(0, 0);
                path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                for (int i = 0; i < LatitudeSides; i++)
                {
                    angle += angleDelta;
                    path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                }

                Mesh = VertexSourceToMesh.Revolve(path, LongitudeSides);
                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
Ejemplo n.º 11
0
        private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, int numSnapPoints, int markToSnapTo)
        {
            var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale);

            double snappingRadians = MathHelper.Tau / numSnapPoints;

            for (int i = 0; i < numSnapPoints; i++)
            {
                double startAngle = i * snappingRadians + mouseAngle;

                var snapShape = new VertexStorage();
                var scale     = GuiWidget.DeviceScale;
                snapShape.MoveTo(-10 * scale, 0);
                snapShape.LineTo(5 * scale, 7 * scale);
                snapShape.LineTo(5 * scale, -7 * scale);
                snapShape.ClosePolygon();

                var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
                // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);

                var color = theme.TextColor;
                if (i == markToSnapTo)
                {
                    color = theme.PrimaryAccentColor;
                }

                graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
            }
        }
Ejemplo n.º 12
0
        public void BuildHistogramFromImage(ImageBuffer image, ImageToPathObject3D_2.AnalysisTypes analysisType)
        {
            // build the histogram cache
            var height = (int)(100 * GuiWidget.DeviceScale);

            _histogramRawCache = new ImageBuffer(256, height);
            var counts = new int[_histogramRawCache.Width];
            IThresholdFunction function = new MapOnMaxIntensity(0, 1);
            var bottom = 0;

            if (analysisType == ImageToPathObject3D_2.AnalysisTypes.Colors)
            {
                function = new QuickHue();
                bottom   = (int)(10 * GuiWidget.DeviceScale);
            }

            byte[] buffer = image.GetBuffer();
            for (int y = 0; y < image.Height; y++)
            {
                int imageBufferOffset = image.GetBufferOffsetY(y);

                for (int x = 0; x < image.Width; x++)
                {
                    int imageBufferOffsetWithX = imageBufferOffset + x * 4;
                    var color = GetRGBA(buffer, imageBufferOffsetWithX);
                    counts[(int)(function.Transform(color) * (_histogramRawCache.Width - 1))]++;
                }
            }

            double max = counts.Select((value, index) => new { value, index })
                         .OrderByDescending(vi => vi.value)
                         .First().value;
            var graphics = _histogramRawCache.NewGraphics2D();
            var theme    = ApplicationController.Instance.Theme;

            graphics.Clear(theme.SlightShade);

            var graphShape  = new VertexStorage();
            var graphHeight = height - bottom;

            graphShape.MoveTo(0, bottom);
            for (int i = 0; i < 256; i++)
            {
                graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight);
                // graphShape.LineTo(i, bottom + Easing.Cubic.Out(counts[i] / max) * graphHeight);
                // graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight);
                // graphShape.LineTo(i, bottom + counts[i] / max * graphHeight);
            }
            graphShape.LineTo(256, bottom);
            graphShape.LineTo(0, bottom);
            graphics.Render(graphShape, 0, 0, theme.TextColor);

            for (int i = 0; i < 256; i++)
            {
                var hue = ColorF.FromHSL(i / 255.0, 1, .49).ToColor();
                graphics.Line(i, 0, i, bottom, hue);
            }
        }
Ejemplo n.º 13
0
        // TODO: EditorTools owns this, move to more general location
        private static Mesh CreateCylinder(double height = 20, double radius = 10, int rotationCount = 30)
        {
            var path = new VertexStorage();

            path.MoveTo(0, 0);
            path.LineTo(radius, 0);
            path.LineTo(radius, height);
            path.LineTo(0, height);

            return(VertexSourceToMesh.Revolve(path, rotationCount));
        }
Ejemplo n.º 14
0
        static DropArrow()
        {
            DownArrow = new VertexStorage();
            DownArrow.MoveTo(-ArrowHeight, 0);
            DownArrow.LineTo(ArrowHeight, 0);
            DownArrow.LineTo(0, -ArrowHeight);

            UpArrow = new VertexStorage();
            UpArrow.MoveTo(-ArrowHeight, -ArrowHeight);
            UpArrow.LineTo(ArrowHeight, -ArrowHeight);
            UpArrow.LineTo(0, 0);
        }
Ejemplo n.º 15
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            var roundSegments = RoundSegments.ClampIfNotCalculated(this, 2, 90, ref valuesChanged);

            Invalidate(InvalidateType.DisplayValues);

            using (RebuildLock())
            {
                var height = Height.Value(this);
                var width  = Width.Value(this);
                using (new CenterAndHeightMaintainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, 0);
                    path.LineTo(width, 0);

                    var range = 360 / 4.0;
                    switch (Round)
                    {
                    case RoundTypes.Up:
                        for (int i = 1; i < roundSegments - 1; i++)
                        {
                            var angle = range / (roundSegments - 1) * i;
                            var rad   = MathHelper.DegreesToRadians(angle);
                            path.LineTo(Math.Cos(rad) * width, Math.Sin(rad) * height);
                        }
                        break;

                    case RoundTypes.Down:
                        for (int i = 1; i < roundSegments - 1; i++)
                        {
                            var angle = range / (roundSegments - 1) * i;
                            var rad   = MathHelper.DegreesToRadians(angle);
                            path.LineTo(width - Math.Sin(rad) * width, height - Math.Cos(rad) * height);
                        }
                        break;
                    }

                    path.LineTo(0, height);

                    Mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this));
                    Mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));

            return(Task.CompletedTask);
        }
Ejemplo n.º 16
0
        public void ThreeItemPolygonCountTest()
        {
            var storage = new VertexStorage();

            // Square
            storage.MoveTo(0, 0);
            storage.LineTo(100, 0);
            storage.LineTo(100, 100);
            storage.LineTo(0, 100);
            storage.ClosePolygon();

            // Triangle
            storage.MoveTo(30, 30);
            storage.LineTo(40, 30);
            storage.LineTo(35, 40);
            storage.ClosePolygon();

            // Small Square
            storage.MoveTo(20, 20);
            storage.LineTo(25, 20);
            storage.LineTo(25, 25);
            storage.LineTo(20, 25);
            storage.ClosePolygon();

            var polygons = storage.CreatePolygons();

            //var image = new ImageBuffer(200, 200);
            //var graphics = image.NewGraphics2D();
            //graphics.Render(new Stroke(storage), Color.Blue);
            //ImageTgaIO.Save(image, @"c:\temp\some.tga");

            Assert.AreEqual(3, polygons.Count, "Three polygons should be create for a two squares and a triangle");
        }
Ejemplo n.º 17
0
        public void CubePolygonCountTest()
        {
            var square = new VertexStorage();

            square.MoveTo(0, 0);
            square.LineTo(100, 0);
            square.LineTo(100, 100);
            square.LineTo(0, 100);
            square.ClosePolygon();

            var polygons = square.CreatePolygons();

            Assert.AreEqual(1, polygons.Count, "One polygon should be created for a simple 4 point cube path");
        }
Ejemplo n.º 18
0
        private static void BuildDropArrow()
        {
            _downArrow = new VertexStorage();
            _downArrow.MoveTo(-ArrowHeight, 0);
            _downArrow.LineTo(ArrowHeight, 0);
            _downArrow.LineTo(0, -ArrowHeight);

            _upArrow = new VertexStorage();
            _upArrow.MoveTo(-ArrowHeight, -ArrowHeight);
            _upArrow.LineTo(ArrowHeight, -ArrowHeight);
            _upArrow.LineTo(0, 0);

            calculatedDeviceScale = GuiWidget.DeviceScale;
        }
Ejemplo n.º 19
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            GammaLookUpTable    gamma         = new GammaLookUpTable(gammaSlider.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender  = new BlenderGammaBGRA(gamma);
            ImageBuffer         rasterGamma   = new ImageBuffer();

            rasterGamma.Attach(widgetsSubImage, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(widgetsSubImage);
            ImageClippingProxy clippingProxyGamma  = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(new ColorF(1, 1, 1));

            ScanlineRasterizer  rasterizer = new ScanlineRasterizer();
            scanline_unpacked_8 sl         = new scanline_unpacked_8();

            int size_mul = (int)pixelSizeSlider.Value;

            renderer_enlarged ren_en = new renderer_enlarged(size_mul);

            rasterizer.reset();
            rasterizer.move_to_d(m_x[0] / size_mul, m_y[0] / size_mul);
            rasterizer.line_to_d(m_x[1] / size_mul, m_y[1] / size_mul);
            rasterizer.line_to_d(m_x[2] / size_mul, m_y[2] / size_mul);
            ren_en.RenderSolid(clippingProxyGamma, rasterizer, sl, Color.Black);

            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.RenderSolid(clippingProxyGamma, rasterizer, sl, Color.Black);

            rasterizer.gamma(new gamma_none());

            VertexStorage ps = new VertexStorage();
            Stroke        pg = new Stroke(ps);

            pg.Width = 2;

            ps.remove_all();
            ps.MoveTo(m_x[0], m_y[0]);
            ps.LineTo(m_x[1], m_y[1]);
            ps.LineTo(m_x[2], m_y[2]);
            ps.LineTo(m_x[0], m_y[0]);
            rasterizer.add_path(pg);
            scanlineRenderer.RenderSolid(clippingProxyNormal, rasterizer, sl, new Color(0, 150, 160, 200));

            base.OnDraw(graphics2D);
        }
Ejemplo n.º 20
0
        private static IVertexSource BuildShape(RectangleDouble rect, double topLeftRadius, double topRightRadius, double bottomRightRadius, double bottomLeftRadius)
        {
            // See https://photos.app.goo.gl/YdTiehf6ih7fSoDA9 for point diagram

            var centerY = rect.YCenter;

            double radius;
            var    tabShape2 = new VertexStorage();

            // A -> B
            radius = bottomLeftRadius;

            tabShape2.MoveTo(rect.Left + radius, rect.Bottom);
            if (radius > 0)
            {
                tabShape2.curve3(rect.Left, rect.Bottom, rect.Left, rect.Bottom + radius);
            }

            // C -> D
            radius = topLeftRadius;
            tabShape2.LineTo(rect.Left, rect.Top - radius);
            if (radius > 0)
            {
                tabShape2.curve3(rect.Left, rect.Top, rect.Left + radius, rect.Top);
            }

            // E -> F
            radius = topRightRadius;
            tabShape2.LineTo(rect.Right - radius, rect.Top);
            if (radius > 0)
            {
                tabShape2.curve3(rect.Right, rect.Top, rect.Right, rect.Top - radius);
            }

            // G -> H
            radius = bottomRightRadius;
            tabShape2.LineTo(rect.Right, rect.Bottom + radius);
            if (radius > 0)
            {
                tabShape2.curve3(rect.Right, rect.Bottom, rect.Right - radius, rect.Bottom);
            }

            // H -> A
            radius = bottomLeftRadius;
            tabShape2.LineTo(rect.Left - radius, rect.Bottom);

            return(new FlattenCurves(tabShape2));
        }
Ejemplo n.º 21
0
        public void TwoItemPolygonCountTest()
        {
            var square = new VertexStorage();

            square.MoveTo(0, 0);
            square.LineTo(100, 0);
            square.LineTo(100, 100);
            square.LineTo(0, 100);
            square.ClosePolygon();

            var result = square.CombineWith(new Ellipse(Vector2.Zero, 10));

            var polygons = result.CreatePolygons();

            Assert.AreEqual(2, polygons.Count, "Two polygons should be create for a combined square and ellipse");
        }
Ejemplo n.º 22
0
        public void MoveToCreatesAdditionalPolygonTest()
        {
            // Any MoveTo should always create a new Polygon
            var storage = new VertexStorage();

            storage.MoveTo(0, 0);
            storage.LineTo(100, 0);
            storage.LineTo(100, 100);
            storage.MoveTo(30, 30);
            storage.LineTo(0, 100);
            storage.ClosePolygon();

            var polygons = storage.CreatePolygons();

            Assert.AreEqual(2, polygons.Count, "Two polygons should be created for a path with a floating MoveTo command");
        }
Ejemplo n.º 23
0
            public override void OnDraw(Graphics2D graphics2D)
            {
                base.OnDraw(graphics2D);

                // draw the right arrow
                var x = this.LocalBounds.Right - this.LocalBounds.Height / 2;
                var y = this.Size.Y / 2 + 2;

                var arrow = new VertexStorage();

                arrow.MoveTo(x + 3, y);
                arrow.LineTo(x - 3, y + 5);
                arrow.LineTo(x - 3, y - 5);

                graphics2D.Render(arrow, theme.TextColor);
            }
        public static void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, Matrix4X4 matrix, Vector2 offset, double scale, Color silhouetteColor)
        {
            graphics2D.Rasterizer.gamma(new gamma_power(.3));
            VertexStorage polygonProjected = new VertexStorage();

            foreach (Face face in meshToDraw.Faces)
            {
                if (Vector3.TransformNormal(face.Normal, matrix).Z > 0)
                {
                    polygonProjected.remove_all();
                    bool first = true;
                    foreach (FaceEdge faceEdge in face.FaceEdges())
                    {
                        var     position3D = Vector3.Transform(faceEdge.FirstVertex.Position, matrix);
                        Vector2 position   = new Vector2(position3D.X, position3D.Y);
                        position += offset;
                        position *= scale;
                        if (first)
                        {
                            polygonProjected.MoveTo(position.X, position.Y);
                            first = false;
                        }
                        else
                        {
                            polygonProjected.LineTo(position.X, position.Y);
                        }
                    }
                    graphics2D.Render(polygonProjected, silhouetteColor);
                }
            }
            graphics2D.Rasterizer.gamma(new gamma_none());
        }
Ejemplo n.º 25
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                var sides = Sides.ClampIfNotCalculated(this, 3, 180, ref valuesChanged);
                using (new CenterAndHeightMaintainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(Width.Value(this) / 2, 0);

                    for (int i = 1; i < sides; i++)
                    {
                        var angle = MathHelper.Tau * i / 2 / (sides - 1);
                        path.LineTo(Math.Cos(angle) * Width.Value(this) / 2, Math.Sin(angle) * Width.Value(this) / 2);
                    }

                    var mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this));
                    mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
                    Mesh = mesh;
                }
            }

            Invalidate(InvalidateType.DisplayValues);

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Ejemplo n.º 26
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                var path = new VertexStorage();
                path.MoveTo(Width / 2, 0);

                for (int i = 1; i < Sides; i++)
                {
                    var angle = MathHelper.Tau * i / 2 / (Sides - 1);
                    path.LineTo(Math.Cos(angle) * Width / 2, Math.Sin(angle) * Width / 2);
                }

                var mesh = VertexSourceToMesh.Extrude(path, Depth);
                mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
                Mesh = mesh;

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
Ejemplo n.º 27
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            double height        = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
            var    diameter      = Diameter.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
            var    diameterTop   = DiameterTop.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
            var    sides         = Sides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
            var    startingAngle = StartingAngle.ClampIfNotCalculated(this, 0, 360 - .01, ref valuesChanged);
            var    endingAngle   = EndingAngle.ClampIfNotCalculated(this, StartingAngle.Value(this) + .01, 360, ref valuesChanged);

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    if (!Advanced)
                    {
                        var path = new VertexStorage();
                        path.MoveTo(0, -height / 2);
                        path.LineTo(diameter / 2, -height / 2);
                        path.LineTo(diameter / 2, height / 2);
                        path.LineTo(0, height / 2);

                        Mesh = VertexSourceToMesh.Revolve(path, sides);
                    }
                    else
                    {
                        var path = new VertexStorage();
                        path.MoveTo(0, -height / 2);
                        path.LineTo(diameter / 2, -height / 2);
                        path.LineTo(diameterTop / 2, height / 2);
                        path.LineTo(0, height / 2);

                        Mesh = VertexSourceToMesh.Revolve(path, sides, MathHelper.DegreesToRadians(startingAngle), MathHelper.DegreesToRadians(endingAngle));
                    }
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Ejemplo n.º 28
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref changed);
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref changed);

                var aabb = this.GetAxisAlignedBoundingBox();

                var startingAngle = StartingAngle;
                var endingAngle   = EndingAngle;
                if (!Advanced)
                {
                    startingAngle = 0;
                    endingAngle   = 360;
                }

                var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);

                var path = new VertexStorage();
                path.MoveTo(OuterDiameter / 2, -Height / 2);
                path.LineTo(OuterDiameter / 2, Height / 2);
                path.LineTo(innerDiameter / 2, Height / 2);
                path.LineTo(innerDiameter / 2, -Height / 2);
                path.LineTo(OuterDiameter / 2, -Height / 2);

                var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            if (changed)
            {
                base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties));
            }
        }
Ejemplo n.º 29
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                var latitudeSides  = LatitudeSides.ClampIfNotCalculated(this, 3, 180, ref valuesChanged);
                var longitudeSides = LongitudeSides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
                var diameter       = Diameter.Value(this);

                using (new CenterAndHeightMaintainer(this))
                {
                    if (longitudeSides != lastLongitudeSides ||
                        latitudeSides != lastLatitudeSides ||
                        diameter != lastDiameter)
                    {
                        var radius     = diameter / 2;
                        var angleDelta = MathHelper.Tau / 4 / latitudeSides;
                        var angle      = 0.0;
                        var path       = new VertexStorage();
                        path.MoveTo(0, 0);
                        path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                        for (int i = 0; i < latitudeSides; i++)
                        {
                            angle += angleDelta;
                            path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                        }

                        Mesh = VertexSourceToMesh.Revolve(path, longitudeSides);
                    }

                    lastDiameter       = diameter;
                    lastLongitudeSides = longitudeSides;
                    lastLatitudeSides  = latitudeSides;
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Ejemplo n.º 30
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            Sides         = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
            Height        = agg_basics.Clamp(Height, .01, 1000000, ref valuesChanged);
            Diameter      = agg_basics.Clamp(Diameter, .01, 1000000, ref valuesChanged);
            StartingAngle = agg_basics.Clamp(StartingAngle, 0, 360 - .01, ref valuesChanged);
            EndingAngle   = agg_basics.Clamp(EndingAngle, StartingAngle + .01, 360, ref valuesChanged);

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    if (!Advanced)
                    {
                        var path = new VertexStorage();
                        path.MoveTo(0, -Height / 2);
                        path.LineTo(Diameter / 2, -Height / 2);
                        path.LineTo(Diameter / 2, Height / 2);
                        path.LineTo(0, Height / 2);

                        Mesh = VertexSourceToMesh.Revolve(path, Sides);
                    }
                    else
                    {
                        var path = new VertexStorage();
                        path.MoveTo(0, -Height / 2);
                        path.LineTo(Diameter / 2, -Height / 2);
                        path.LineTo(DiameterTop / 2, Height / 2);
                        path.LineTo(0, Height / 2);

                        Mesh = VertexSourceToMesh.Revolve(path, Sides, MathHelper.DegreesToRadians(StartingAngle), MathHelper.DegreesToRadians(EndingAngle));
                    }
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }