public void DisplaySizeInfo(Graphics2D graphics2D, Vector2 widthDisplayCenter, double size)
        {
            string displayString = formatString.FormatWith(size);

            if (measureDisplayImage == null || measureDisplayedString != displayString)
            {
                measureDisplayedString = displayString;
                TypeFacePrinter printer           = new TypeFacePrinter(measureDisplayedString, 16);
                TypeFacePrinter unitPrinter       = new TypeFacePrinter(unitsString, 10);
                Double          unitPrinterOffset = 1;

                BorderDouble margin = new BorderDouble(5);
                printer.Origin = new Vector2(margin.Left, margin.Bottom);
                RectangleDouble bounds = printer.LocalBounds;

                unitPrinter.Origin = new Vector2(bounds.Right + unitPrinterOffset, margin.Bottom);
                RectangleDouble unitPrinterBounds = unitPrinter.LocalBounds;

                measureDisplayImage = new ImageBuffer((int)(bounds.Width + margin.Width + unitPrinterBounds.Width + unitPrinterOffset), (int)(bounds.Height + margin.Height));
                // make sure the texture has mipmaps (so it can reduce well)
                ImageGlPlugin glPlugin      = ImageGlPlugin.GetImageGlPlugin(measureDisplayImage, true);
                Graphics2D    widthGraphics = measureDisplayImage.NewGraphics2D();
                widthGraphics.Clear(new RGBA_Bytes(RGBA_Bytes.White, 128));
                printer.Render(widthGraphics, RGBA_Bytes.Black);
                unitPrinter.Render(widthGraphics, RGBA_Bytes.Black);
            }

            widthDisplayCenter -= new Vector2(measureDisplayImage.Width / 2, measureDisplayImage.Height / 2);
            graphics2D.Render(measureDisplayImage, widthDisplayCenter);
        }
예제 #2
0
        private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics)
        {
            plateGraphics.Clear(RGBA_Bytes.White);

            double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM;

            string logoPathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "PartSheetLogo.png");

            if (File.Exists(logoPathAndFile))
            {
                ImageBuffer logoImage = new ImageBuffer();
                ImageBMPIO.LoadImageData(logoPathAndFile, logoImage);
                currentlyPrintingHeightPixels -= logoImage.Height;
                plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels);
            }

            currentlyPrintingHeightPixels -= PartPaddingPixels;

            double          underlineHeightMM = 1;
            RectangleDouble lineBounds        = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM);

            lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height);
            plateGraphics.FillRectangle(lineBounds, RGBA_Bytes.Black);

            return(currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels));
        }
예제 #3
0
파일: script.cs 프로젝트: Frank-Buss/utest
    void Update()
    {
        // update animation counter
        x += Time.deltaTime;
        while (x > 1.0f)
        {
            x -= 1.0f;
        }

        // clear background with white
        Graphics2D g = buffer.NewGraphics2D();

        g.Clear(RGBA_Bytes.White);

        // draw some lines
        float w = buffer.Width * x;

        for (int i = 0; i < 10; i++)
        {
            g.Line(x1: 0, y1: buffer.Height * i / 10,
                   x2: w - w * i / 10, y2: 0,
                   color: RGBA_Bytes.Black, strokeWidth: 3);
        }

        // draw some text
        TypeFacePrinter textPrinter    = new TypeFacePrinter("Hello World!", 30, justification: Justification.Center);
        IVertexSource   translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(buffer.Width / 2, 5));

        g.Render(translatedText, RGBA_Bytes.Blue);

        // update texture data
        byte[] pixels = buffer.GetBuffer();
        texture.LoadRawTextureData(pixels);
        texture.Apply();
    }
예제 #4
0
        private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics)
        {
            plateGraphics.Clear(Color.White);

            double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM;

            string logoPathAndFile = Path.Combine("Images", "PartSheetLogo.png");

            if (StaticData.Instance.FileExists(logoPathAndFile))
            {
                ImageBuffer logoImage = StaticData.Instance.LoadImage(logoPathAndFile);
                currentlyPrintingHeightPixels -= logoImage.Height;
                plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels);
            }

            currentlyPrintingHeightPixels -= PartPaddingPixels;

            double underlineHeightMM = 1;

            var lineBounds = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM);

            lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height);
            plateGraphics.FillRectangle(lineBounds, Color.Black);

            return(currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels));
        }
예제 #5
0
        public override void Draw(Graphics2D g)
        {
            int width  = 800;
            int height = 600;

            //clear the image to white
            g.Clear(ColorRGBA.White);
            // draw a circle

            Ellipse ellipsePro = new Ellipse(0, 0, 100, 50);

            for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
            {
                var mat = Affine.NewMatix(
                    AffinePlan.Rotate(MathHelper.DegreesToRadians(angleDegrees)),
                    AffinePlan.Translate(width / 2, 150));

                VertexStore sp1 = mat.TransformToVxs(ellipsePro.MakeVxs());

                g.Render(sp1, ColorRGBA.Yellow);

                //Stroke ellipseOutline = new Stroke(sp1, 3);
                g.Render(StrokeHelp.MakeVxs(sp1, 3), ColorRGBA.Blue);
            }

            // and a little polygon
            PathWriter littlePoly = new PathWriter();

            littlePoly.MoveTo(50, 50);
            littlePoly.LineTo(150, 50);
            littlePoly.LineTo(200, 200);
            littlePoly.LineTo(50, 150);
            littlePoly.LineTo(50, 50);
            g.Render(littlePoly.MakeVertexSnap(), ColorRGBA.Cyan);

            // draw some text
            // draw some text



            var textPrinter = new TextPrinter();

            textPrinter.CurrentFont = SvgFontStore.LoadFont(SvgFontStore.DEFAULT_SVG_FONTNAME, 30);
            //new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);

            VertexStore vxs   = textPrinter.CreateVxs("Printing from a printer".ToCharArray());
            var         affTx = Affine.NewTranslation(width / 2, height / 4 * 3);
            VertexStore s1    = affTx.TransformToVxs(vxs);


            g.Render(s1, ColorRGBA.Black);
            g.Render(StrokeHelp.MakeVxs(s1, 1), ColorRGBA.Red);


            var aff2 = Affine.NewMatix(
                AffinePlan.Rotate(MathHelper.DegreesToRadians(90)),
                AffinePlan.Translate(40, height / 2));

            g.Render(aff2.TransformToVertexSnap(vxs), ColorRGBA.Black);
        }
        private void CreateCircularBedGridImage(int linesInX, int linesInY, int increment = 1)
        {
            Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY);

            BedImage = new ImageBuffer(1024, 1024);
            Graphics2D graphics2D = BedImage.NewGraphics2D();

            graphics2D.Clear(bedBaseColor);
            {
                double lineDist = BedImage.Width / (double)linesInX;

                int count     = 1;
                int pointSize = 16;
                graphics2D.DrawString(count.ToString(), 4, 4, pointSize, color: bedMarkingsColor);
                double  currentRadius = lineDist;
                Vector2 bedCenter     = new Vector2(BedImage.Width / 2, BedImage.Height / 2);
                for (double linePos = lineDist + BedImage.Width / 2; linePos < BedImage.Width; linePos += lineDist)
                {
                    int linePosInt = (int)linePos;
                    graphics2D.DrawString((count * increment).ToString(), linePos + 2, BedImage.Height / 2, pointSize, color: bedMarkingsColor);

                    Ellipse circle  = new Ellipse(bedCenter, currentRadius);
                    Stroke  outline = new Stroke(circle);
                    graphics2D.Render(outline, bedMarkingsColor);
                    currentRadius += lineDist;
                    count++;
                }

                graphics2D.Line(0, BedImage.Height / 2, BedImage.Width, BedImage.Height / 2, bedMarkingsColor);
                graphics2D.Line(BedImage.Width / 2, 0, BedImage.Width / 2, BedImage.Height, bedMarkingsColor);
            }
        }
예제 #7
0
        private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics)
        {
            plateGraphics.Clear(RGBA_Bytes.White);

            double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM;

            // TODO: Application should not save data back to StaticDataPath - use application data dir instead
            string logoPathAndFile = "PartSheetLogo.png";

            if (StaticData.Instance.FileExists(logoPathAndFile))
            {
                ImageBuffer logoImage = StaticData.Instance.LoadImage(logoPathAndFile);
                currentlyPrintingHeightPixels -= logoImage.Height;
                plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels);
            }

            currentlyPrintingHeightPixels -= PartPaddingPixels;

            double          underlineHeightMM = 1;
            RectangleDouble lineBounds        = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM);

            lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height);
            plateGraphics.FillRectangle(lineBounds, RGBA_Bytes.Black);

            return(currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels));
        }
예제 #8
0
        private void CreateRectangularBedGridImage(Vector3 displayVolumeToBuild, Vector2 bedCenter)
        {
            int linesInX = (int)Math.Ceiling(displayVolumeToBuild.x / 10);
            int linesInY = (int)Math.Ceiling(displayVolumeToBuild.y / 10);

            lock (lastCreatedBedImage)
            {
                Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY);

                BedImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA());
                Graphics2D graphics2D = BedImage.NewGraphics2D();
                graphics2D.Clear(bedBaseColor);
                {
                    double lineDist = BedImage.Width / (displayVolumeToBuild.x / 10.0);

                    double xPositionCm    = (-(displayVolume.x / 2.0) + bedCenter.x) / 10.0;
                    int    xPositionCmInt = (int)Math.Round(xPositionCm);
                    double fraction       = xPositionCm - xPositionCmInt;
                    int    pointSize      = 20;
                    graphics2D.DrawString(xPositionCmInt.ToString(), 4, 4, pointSize, color: bedMarkingsColor);
                    for (double linePos = lineDist * (1 - fraction); linePos < BedImage.Width; linePos += lineDist)
                    {
                        xPositionCmInt++;
                        int linePosInt = (int)linePos;
                        int lineWidth  = 1;
                        if (xPositionCmInt == 0)
                        {
                            lineWidth = 2;
                        }
                        graphics2D.Line(linePosInt, 0, linePosInt, BedImage.Height, bedMarkingsColor, lineWidth);
                        graphics2D.DrawString(xPositionCmInt.ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor);
                    }
                }
                {
                    double lineDist = BedImage.Height / (displayVolumeToBuild.y / 10.0);

                    double yPositionCm    = (-(displayVolume.y / 2.0) + bedCenter.y) / 10.0;
                    int    yPositionCmInt = (int)Math.Round(yPositionCm);
                    double fraction       = yPositionCm - yPositionCmInt;
                    int    pointSize      = 20;
                    for (double linePos = lineDist * (1 - fraction); linePos < BedImage.Height; linePos += lineDist)
                    {
                        yPositionCmInt++;
                        int linePosInt = (int)linePos;
                        int lineWidth  = 1;
                        if (yPositionCmInt == 0)
                        {
                            lineWidth = 2;
                        }
                        graphics2D.Line(0, linePosInt, BedImage.Height, linePosInt, bedMarkingsColor, lineWidth);

                        graphics2D.DrawString(yPositionCmInt.ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor);
                    }
                }

                lastCreatedBedImage = BedImage;
                lastLinesCount      = new Point2D(linesInX, linesInY);
            }
        }
예제 #9
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Clear the map canvas with given color.
         * @param color the color to fill the whole map canvas.
         */
        public override void ClearCanvas(int color)
        {
            if (SharedGraphics2D != null)
            {
                SharedGraphics2D.Clear(new Color(color));
                _mapNameHolder.Clear();
            }
        }
예제 #10
0
 private void drawInternal(Graphics2D graphics)
 {
     lock (drawSync)
     {
         graphics.Clear(Color4.Black);
         foreach (var item in drawCommands)
         {
             item(graphics);
         }
     }
 }
        public void TakePhoto(string imageFileName)
        {
            ImageBuffer noCameraImage = new ImageBuffer(640, 480);
            Graphics2D  graphics      = noCameraImage.NewGraphics2D();

            graphics.Clear(Color.White);
            graphics.DrawString("No Camera Detected", 320, 240, pointSize: 24, justification: Agg.Font.Justification.Center);
            graphics.DrawString(DateTime.Now.ToString(), 320, 200, pointSize: 12, justification: Agg.Font.Justification.Center);
            AggContext.ImageIO.SaveImageData(imageFileName, noCameraImage);

            PictureTaken?.Invoke(null, null);
        }
예제 #12
0
        private static void CreateButtonImages(out ImageBuffer togetherBig, out ImageBuffer appartBig)
        {
            PathStorage upArrow = new PathStorage();

            upArrow.MoveTo(0, 0);
            upArrow.LineTo(.5, -.5);
            upArrow.LineTo(.25, -.5);
            upArrow.LineTo(.25, -1);
            upArrow.LineTo(-.25, -1);
            upArrow.LineTo(-.25, -.5);
            upArrow.LineTo(-.5, -.5);

            int buttonSize = 32;
            int arrowSize  = buttonSize / 3;

            togetherBig = new ImageBuffer(buttonSize, buttonSize, 32, new BlenderBGRA());
            Graphics2D togetherBigGraphics = togetherBig.NewGraphics2D();

            togetherBigGraphics.Clear(RGBA_Bytes.White);

            int margin    = buttonSize / 16;
            int lineWidth = buttonSize / 16;

            togetherBigGraphics.FillRectangle(margin, buttonSize / 2 + margin, buttonSize - margin, buttonSize / 2 + margin + lineWidth, RGBA_Bytes.Black);
            togetherBigGraphics.FillRectangle(margin, buttonSize / 2 - margin, buttonSize - margin, buttonSize / 2 - margin - lineWidth, RGBA_Bytes.Black);

            appartBig = new ImageBuffer(togetherBig);

            // point up
            Affine totalTransform = Affine.NewScaling(arrowSize, arrowSize);

            totalTransform *= Affine.NewTranslation(buttonSize / 2, buttonSize / 2 - margin - lineWidth);
            togetherBigGraphics.Render(new VertexSourceApplyTransform(upArrow, totalTransform), RGBA_Bytes.Black);

            // point down
            totalTransform  = Affine.NewRotation(MathHelper.Tau / 2);
            totalTransform *= Affine.NewScaling(arrowSize, arrowSize);
            totalTransform *= Affine.NewTranslation(buttonSize / 2, buttonSize / 2 + margin + lineWidth);
            togetherBigGraphics.Render(new VertexSourceApplyTransform(upArrow, totalTransform), RGBA_Bytes.Black);

            Graphics2D appartBigGraphics = appartBig.NewGraphics2D();

            // point up
            totalTransform  = Affine.NewScaling(arrowSize, arrowSize);
            totalTransform *= Affine.NewTranslation(buttonSize / 2, buttonSize / 2 + margin + lineWidth + arrowSize + 1);
            appartBigGraphics.Render(new VertexSourceApplyTransform(upArrow, totalTransform), RGBA_Bytes.Black);

            // point down
            totalTransform  = Affine.NewRotation(MathHelper.Tau / 2);
            totalTransform *= Affine.NewScaling(arrowSize, arrowSize);
            totalTransform *= Affine.NewTranslation(buttonSize / 2, buttonSize / 2 - margin - lineWidth - arrowSize - 1);
            appartBigGraphics.Render(new VertexSourceApplyTransform(upArrow, totalTransform), RGBA_Bytes.Black);
        }
예제 #13
0
        private static ImageBuffer BuildImageFromMeshGroups(IObject3D loadedItem, int width, int height, bool debugNonManifoldEdges = false)
        {
            var visibleMeshes = loadedItem.VisibleMeshes().ToList();

            if (visibleMeshes?.Count > 0)
            {
                var        tempImage      = new ImageBuffer(width, height);
                Graphics2D partGraphics2D = tempImage.NewGraphics2D();
                partGraphics2D.Clear(new Color());

                AxisAlignedBoundingBox aabb = visibleMeshes[0].Mesh.GetAxisAlignedBoundingBox(visibleMeshes[0].WorldMatrix());

                for (int i = 1; i < visibleMeshes.Count; i++)
                {
                    aabb = AxisAlignedBoundingBox.Union(aabb, visibleMeshes[i].Mesh.GetAxisAlignedBoundingBox(visibleMeshes[i].WorldMatrix()));
                }

                double maxSize = Math.Max(aabb.XSize, aabb.YSize);
                double scale   = width / (maxSize * 1.2);

                var bounds2D = new RectangleDouble(aabb.MinXYZ.X, aabb.MinXYZ.Y, aabb.MaxXYZ.X, aabb.MaxXYZ.Y);
                foreach (var meshGroup in visibleMeshes)
                {
                    PolygonMesh.Rendering.OrthographicZProjection.DrawTo(
                        partGraphics2D,
                        meshGroup.Mesh,
                        meshGroup.WorldMatrix(),
                        new Vector2(
                            (width / scale - bounds2D.Width) / 2 - bounds2D.Left,
                            (height / scale - bounds2D.Height) / 2 - bounds2D.Bottom),
                        scale,
                        meshGroup.WorldColor());
                }

                if (debugNonManifoldEdges)
                {
                    foreach (var loadedMesh in visibleMeshes)
                    {
                        throw new NotImplementedException();
                        //List<MeshEdge> nonManifoldEdges = loadedMesh.Mesh.GetNonManifoldEdges();
                        //if (nonManifoldEdges.Count > 0)
                        //{
                        //	partGraphics2D.Circle(width / 4, width / 4, width / 8, Color.Red);
                        //}
                    }
                }

                // Force to all white and return
                return(tempImage);
            }

            return(null);
        }
예제 #14
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            CameraCalibrationWidget_OnDraw.Start();
            graphics2D.Clear(RGBA_Bytes.White);
            rect_d rect = new rect_d(Width - 40, 10, Width - 10, 40);

            graphics2D.Rectangle(rect, RGBA_Bytes.Black);
            Invalidate(rect);

            base.OnDraw(graphics2D);
            CameraCalibrationWidget_OnDraw.Stop();
        }
        private void CreateRectangularBedGridImage(Vector3 displayVolumeToBuild, Vector2 bedCenter, double divisor, double skip)
        {
            lock (lastCreatedBedImage)
            {
                BedImage = new ImageBuffer(1024, 1024);
                Graphics2D graphics2D = BedImage.NewGraphics2D();
                graphics2D.Clear(bedBaseColor);
                {
                    double lineDist = BedImage.Width / (displayVolumeToBuild.X / divisor);

                    double xPositionCm    = (-(displayVolume.X / 2.0) + bedCenter.X) / divisor;
                    int    xPositionCmInt = (int)Math.Round(xPositionCm);
                    double fraction       = xPositionCm - xPositionCmInt;
                    int    pointSize      = 20;
                    graphics2D.DrawString((xPositionCmInt * skip).ToString(), 4, 4, pointSize, color: bedMarkingsColor);
                    for (double linePos = lineDist * (1 - fraction); linePos < BedImage.Width; linePos += lineDist)
                    {
                        xPositionCmInt++;
                        int linePosInt = (int)linePos;
                        int lineWidth  = 1;
                        if (xPositionCmInt == 0)
                        {
                            lineWidth = 2;
                        }
                        graphics2D.Line(linePosInt, 0, linePosInt, BedImage.Height, bedMarkingsColor, lineWidth);
                        graphics2D.DrawString((xPositionCmInt * skip).ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor);
                    }
                }
                {
                    double lineDist = BedImage.Height / (displayVolumeToBuild.Y / divisor);

                    double yPositionCm    = (-(displayVolume.Y / 2.0) + bedCenter.Y) / divisor;
                    int    yPositionCmInt = (int)Math.Round(yPositionCm);
                    double fraction       = yPositionCm - yPositionCmInt;
                    int    pointSize      = 20;
                    for (double linePos = lineDist * (1 - fraction); linePos < BedImage.Height; linePos += lineDist)
                    {
                        yPositionCmInt++;
                        int linePosInt = (int)linePos;
                        int lineWidth  = 1;
                        if (yPositionCmInt == 0)
                        {
                            lineWidth = 2;
                        }
                        graphics2D.Line(0, linePosInt, BedImage.Height, linePosInt, bedMarkingsColor, lineWidth);

                        graphics2D.DrawString((yPositionCmInt * skip).ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor);
                    }
                }

                lastCreatedBedImage = BedImage;
            }
        }
예제 #16
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            MatterCadWidget_OnDraw.Start();
            graphics2D.Clear(RGBA_Bytes.White);
            rect_d rect = new rect_d(Width - 40, 10, Width - 10, 40);

            graphics2D.FillRectangle(rect, previewWindowRayTrace.mouseOverColor);
            graphics2D.Rectangle(rect, RGBA_Bytes.Black);
            Invalidate(rect);

            base.OnDraw(graphics2D);
            MatterCadWidget_OnDraw.Stop();
        }
        private static ImageBuffer BuildImageFromMeshGroups(List <MeshGroup> loadedMeshGroups, string stlHashCode, Point2D size)
        {
            if (loadedMeshGroups != null &&
                loadedMeshGroups.Count > 0 &&
                loadedMeshGroups[0].Meshes != null &&
                loadedMeshGroups[0].Meshes[0] != null)
            {
                ImageBuffer tempImage      = new ImageBuffer(size.x, size.y);
                Graphics2D  partGraphics2D = tempImage.NewGraphics2D();
                partGraphics2D.Clear(new RGBA_Bytes());

                AxisAlignedBoundingBox aabb = loadedMeshGroups[0].GetAxisAlignedBoundingBox();
                for (int meshGroupIndex = 1; meshGroupIndex < loadedMeshGroups.Count; meshGroupIndex++)
                {
                    aabb = AxisAlignedBoundingBox.Union(aabb, loadedMeshGroups[meshGroupIndex].GetAxisAlignedBoundingBox());
                }
                double          maxSize  = Math.Max(aabb.XSize, aabb.YSize);
                double          scale    = size.x / (maxSize * 1.2);
                RectangleDouble bounds2D = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                foreach (MeshGroup meshGroup in loadedMeshGroups)
                {
                    foreach (Mesh loadedMesh in meshGroup.Meshes)
                    {
                        PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh,
                                                                             new Vector2((size.x / scale - bounds2D.Width) / 2 - bounds2D.Left,
                                                                                         (size.y / scale - bounds2D.Height) / 2 - bounds2D.Bottom),
                                                                             scale, RGBA_Bytes.White);
                    }
                }

                if (File.Exists("RunUnitTests.txt"))
                {
                    foreach (Mesh loadedMesh in loadedMeshGroups[0].Meshes)
                    {
                        List <MeshEdge> nonManifoldEdges = loadedMesh.GetNonManifoldEdges();
                        if (nonManifoldEdges.Count > 0)
                        {
                            partGraphics2D.Circle(size.x / 4, size.x / 4, size.x / 8, RGBA_Bytes.Red);
                        }
                    }
                }

                tempImage.SetRecieveBlender(new BlenderPreMultBGRA());
                AllWhite.DoAllWhite(tempImage);

                // and give it back
                return(tempImage);
            }

            return(null);
        }
        private void LoadStl_Click(object sender, EventArgs e)
        {
            OpenFileDialogParams opeParams = new OpenFileDialogParams("STL Files|*.stl");

            FileDialog.OpenFileDialog(opeParams, (openParams) =>
            {
                var streamToLoadFrom = File.Open(openParams.FileName, FileMode.Open);

                if (streamToLoadFrom != null)
                {
                    var loadedFileName = openParams.FileName;

                    meshToRender = StlProcessing.Load(streamToLoadFrom);

                    ImageBuffer plateInventory = new ImageBuffer((int)(300 * 8.5), 300 * 11, 32, new BlenderBGRA());
                    Graphics2D plateGraphics   = plateInventory.NewGraphics2D();
                    plateGraphics.Clear(RGBA_Bytes.White);

                    double inchesPerMm          = 0.0393701;
                    double pixelsPerInch        = 300;
                    double pixelsPerMm          = inchesPerMm * pixelsPerInch;
                    AxisAlignedBoundingBox aabb = meshToRender.GetAxisAlignedBoundingBox();
                    Vector2 lowerLeftInMM       = new Vector2(-aabb.minXYZ.x, -aabb.minXYZ.y);
                    Vector3 centerInMM          = (aabb.maxXYZ - aabb.minXYZ) / 2;
                    Vector2 offsetInMM          = new Vector2(20, 30);

                    {
                        RectangleDouble bounds = new RectangleDouble(offsetInMM.x * pixelsPerMm,
                                                                     offsetInMM.y * pixelsPerMm,
                                                                     (offsetInMM.x + aabb.maxXYZ.x - aabb.minXYZ.x) * pixelsPerMm,
                                                                     (offsetInMM.y + aabb.maxXYZ.y - aabb.minXYZ.y) * pixelsPerMm);
                        bounds.Inflate(3 * pixelsPerMm);
                        RoundedRect rect = new RoundedRect(bounds, 3 * pixelsPerMm);
                        plateGraphics.Render(rect, RGBA_Bytes.LightGray);
                        Stroke rectOutline = new Stroke(rect, .5 * pixelsPerMm);
                        plateGraphics.Render(rectOutline, RGBA_Bytes.DarkGray);
                    }

                    OrthographicZProjection.DrawTo(plateGraphics, meshToRender, lowerLeftInMM + offsetInMM, pixelsPerMm);
                    plateGraphics.DrawString(Path.GetFileName(openParams.FileName), (offsetInMM.x + centerInMM.x) * pixelsPerMm, (offsetInMM.y - 10) * pixelsPerMm, 50, Agg.Font.Justification.Center);

                    //ImageBuffer logoImage = new ImageBuffer();
                    //ImageIO.LoadImageData("Logo.png", logoImage);
                    //plateGraphics.Render(logoImage, (plateInventory.Width - logoImage.Width) / 2, plateInventory.Height - logoImage.Height - 10 * pixelsPerMm);

                    //ImageIO.SaveImageData("plate Inventory.jpeg", plateInventory);
                }
            });
        }
예제 #19
0
        public override void Draw(Graphics2D g)
        {
            // Draw2(g);
            ////1.
            //// clear the image to white
            g.Clear(ColorRGBA.White);
            //------------------------------------
            g.UseSubPixelRendering = true;
            // draw some text
            string teststr = "ABCDE abcd 1230 Hello!";

            g.DrawString(teststr, 300, 400, 22);
            g.UseSubPixelRendering = false;
            g.DrawString(teststr, 300, 422, 22);
        }
예제 #20
0
        public void CompareToLionTGA()
        {
            LionShape   lionShape     = new LionShape();
            ImageBuffer renderedImage = new ImageBuffer(512, 400, 24, new BlenderBGR());
            byte        alpha         = (byte)(.1 * 255);

            for (int i = 0; i < lionShape.NumPaths; i++)
            {
                lionShape.Colors[i].Alpha0To255 = alpha;
            }

            Affine transform = Affine.NewIdentity();

            transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            transform *= Affine.NewTranslation(renderedImage.Width / 2, renderedImage.Height / 2);

            // This code renders the lion:
            VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(lionShape.Path, transform);
            Graphics2D renderer = renderedImage.NewGraphics2D();

            renderer.Clear(new RGBA_Floats(1.0, 1.0, 1.0, 1.0));
            renderer.Render(transformedPathStorage, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);

            ImageTgaIO.Save(renderedImage, "TestOutput.tga");

            Stream      imageStream = File.Open("LionRenderMaster.tga", FileMode.Open);
            ImageBuffer masterImage = new ImageBuffer();

            ImageTgaIO.LoadImageData(masterImage, imageStream, 24);

            bool sameWidth  = masterImage.Width == renderedImage.Width;
            bool sameHeight = masterImage.Height == renderedImage.Height;

            Assert.IsTrue(sameWidth && sameHeight);
            Assert.IsTrue(masterImage.BitDepth == renderedImage.BitDepth);
            int unused;

            byte[] masterBuffer   = masterImage.GetBuffer(out unused);
            byte[] renderedBuffer = renderedImage.GetBuffer(out unused);
            Assert.IsTrue(masterBuffer.Length == renderedBuffer.Length);
            for (int i = 0; i < masterBuffer.Length; i++)
            {
                if (masterBuffer[i] != renderedBuffer[i])
                {
                    Assert.IsTrue(false);
                }
            }
        }
예제 #21
0
        private void CreateRectangularBedGridImage(int linesInX, int linesInY)
        {
            using (TimedLock.Lock(lastCreatedBedImage, "CreateRectangularBedGridImage"))
            {
                if (linesInX == lastLinesCount.x && linesInY == lastLinesCount.y)
                {
                    BedImage = lastCreatedBedImage;
                    return;
                }
                Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY);

                BedImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA());
                Graphics2D graphics2D = BedImage.NewGraphics2D();
                graphics2D.Clear(bedBaseColor);
                {
                    double lineDist = BedImage.Width / (double)linesInX;

                    int count     = 1;
                    int pointSize = 20;
                    graphics2D.DrawString(count.ToString(), 4, 4, pointSize, color: bedMarkingsColor);
                    for (double linePos = lineDist; linePos < BedImage.Width; linePos += lineDist)
                    {
                        count++;
                        int linePosInt = (int)linePos;
                        graphics2D.Line(linePosInt, 0, linePosInt, BedImage.Height, bedMarkingsColor);
                        graphics2D.DrawString(count.ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor);
                    }
                }
                {
                    double lineDist = BedImage.Height / (double)linesInY;

                    int count     = 1;
                    int pointSize = 16;
                    for (double linePos = lineDist; linePos < BedImage.Height; linePos += lineDist)
                    {
                        count++;
                        int linePosInt = (int)linePos;
                        graphics2D.Line(0, linePosInt, BedImage.Height, linePosInt, bedMarkingsColor);
                        graphics2D.DrawString(count.ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor);
                    }
                }

                lastCreatedBedImage = BedImage;
                lastLinesCount      = new Point2D(linesInX, linesInY);
            }
        }
예제 #22
0
        //-----------------------------------------------------------------------------
        // Drawing
        //-----------------------------------------------------------------------------

        // Called every step to draw the game.
        public void Draw(Graphics2D g)
        {
            g.UseIntegerPrecision = true;

            // Render the game-state stack to a buffer.
            g.SetRenderTarget(GameData.RenderTargetGame);
            g.Begin(GameSettings.DRAW_MODE_DEFAULT);
            g.Clear(Color.Black);
            gameStateStack.Draw(g);
            g.End();

            // Draw the buffer to the screen scaled.
            g.SetRenderTarget(null);
            g.ResetTranslation();
            g.Begin(GameSettings.DRAW_MODE_DEFAULT);
            g.DrawImage(GameData.RenderTargetGame, Vector2F.Zero, Vector2F.Zero, new Vector2F(gameScale, gameScale), 0.0);
            g.End();
        }
예제 #23
0
        private static ImageBuffer BuildImageFromSTL(Mesh loadedMesh, string stlHashCode, Point2D size)
        {
            if (loadedMesh != null)
            {
                ImageBuffer tempImage      = new ImageBuffer(size.x, size.y, 32, new BlenderBGRA());
                Graphics2D  partGraphics2D = tempImage.NewGraphics2D();
                partGraphics2D.Clear(new RGBA_Bytes());

                List <MeshEdge> nonManifoldEdges = loadedMesh.GetNonManifoldEdges();
                if (nonManifoldEdges.Count > 0)
                {
                    if (File.Exists("RunUnitTests.txt"))
                    {
                        partGraphics2D.Circle(4, 4, 4, RGBA_Bytes.Red);
                    }
                }
                nonManifoldEdges = null;

                AxisAlignedBoundingBox aabb = loadedMesh.GetAxisAlignedBoundingBox();
                double          maxSize     = Math.Max(aabb.XSize, aabb.YSize);
                double          scale       = size.x / (maxSize * 1.2);
                RectangleDouble bounds2D    = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh,
                                                                     new Vector2((size.x / scale - bounds2D.Width) / 2 - bounds2D.Left,
                                                                                 (size.y / scale - bounds2D.Height) / 2 - bounds2D.Bottom),
                                                                     scale, RGBA_Bytes.White);

                // and save it to disk
                string applicationUserDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath;
                string folderToSavePrintsTo    = Path.Combine(applicationUserDataPath, "data", "temp", "thumbnails");
                string tgaFileName             = Path.Combine(folderToSavePrintsTo, "{0}_{1}x{2}.tga".FormatWith(stlHashCode, size.x, size.y));

                if (!Directory.Exists(folderToSavePrintsTo))
                {
                    Directory.CreateDirectory(folderToSavePrintsTo);
                }
                ImageTgaIO.SaveImageData(tgaFileName, tempImage);

                // and give it back
                return(tempImage);
            }

            return(null);
        }
예제 #24
0
        //-----------------------------------------------------------------------------
        // Overriden methods
        //-----------------------------------------------------------------------------

        protected override void Draw()
        {
            Graphics2D g = new Graphics2D(spriteBatch);

            //g.SetRenderTarget(GameData.RenderTargetGame);

            g.Begin(GameSettings.DRAW_MODE_DEFAULT);
            g.Clear(Color.White);
            g.Translate(new Vector2F(-this.HorizontalScroll.Value, -this.VerticalScroll.Value));
            g.DrawImage(Tileset.SpriteSheet.Image.GetVariant(Zone.ImageVariantID), Point2I.Zero);

            Point2I tilePoint = SelectedTile * (Tileset.SpriteSheet.CellSize + Tileset.SpriteSheet.Spacing);

            g.DrawRectangle(new Rectangle2I(tilePoint, Tileset.SpriteSheet.CellSize + 1), 1, Color.White);
            g.DrawRectangle(new Rectangle2I(tilePoint + 1, Tileset.SpriteSheet.CellSize - 1), 1, Color.Black);
            g.DrawRectangle(new Rectangle2I(tilePoint - 1, Tileset.SpriteSheet.CellSize + 3), 1, Color.Black);
            g.ResetTranslation();
            g.End();
        }
예제 #25
0
        public ImageBuffer CreateImage(string pngFileName)
        {
            graphics.Clear(Color.White);

            // draw all the mesh edges
            foreach (MeshEdge meshEdge in meshToRender.MeshEdges)
            {
                // draw the mesh edge
                DrawMeshEdge(meshEdge);
            }

            // draw all the vertices
            foreach (Vertex vertex in meshToRender.Vertices)
            {
                DrawVertex(vertex);
            }

            foreach (Face faceToRender in meshToRender.Faces)
            {
                Vector2 faceAverageCenter = new Vector2();
                int     vertexCount       = 0;
                // draw all the vertices
                foreach (Vertex vertex in faceToRender.Vertices())
                {
                    Vector2 imagePosition = GetImagePosition(vertex.Position);
                    faceAverageCenter += imagePosition;
                    vertexCount++;
                }
                faceAverageCenter /= vertexCount;

                foreach (FaceEdge faceEdge in faceToRender.FaceEdges())
                {
                    // draw the face edge
                    DrawFaceEdge(faceEdge, faceAverageCenter);
                }

                WriteStringAtPos(faceToRender.ID.ToString(), faceAverageCenter, faceColor);
                DrawRectangle(faceAverageCenter);
                WriteStringAtPos(faceToRender.firstFaceEdge.ID.ToString(), faceAverageCenter + new Vector2(0, -12), faceEdgeColor);
            }

            return(image);
        }
예제 #26
0
        public void OnDraw(Graphics2D graphics2D)
        {
            graphics2D.Clear(ColorRGBA.White);
#if true
            RenderGourand(graphics2D);
#else
            agg.span_allocator span_alloc = new span_allocator();
            span_gouraud_rgba  span_gen   = new span_gouraud_rgba(new rgba8(255, 0, 0, 255), new rgba8(0, 255, 0, 255), new rgba8(0, 0, 255, 255), 320, 220, 100, 100, 200, 100, 0);
            span_gouraud       test_sg    = new span_gouraud(new rgba8(0, 0, 0, 255), new rgba8(0, 0, 0, 255), new rgba8(0, 0, 0, 255), 320, 220, 100, 100, 200, 100, 0);
            ras.add_path(test_sg);
            renderer_scanlines.render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen);
            //renderer_scanlines.render_scanlines_aa_solid(ras, sl, ren_base, new rgba8(0, 0, 0, 255));
#endif


            graphics2D.ScanlineRasterizer.ResetGamma(new GammaNone());
            //m_dilation.Render(ras, sl, ren_base);
            //m_gamma.Render(ras, sl, ren_base);
            //m_alpha.Render(ras, sl, ren_base);
        }
예제 #27
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;

            if (firstTime)
            {
                firstTime   = false;
                m_SuperFast = new MatterHackers.Agg.UI.CheckBox(10, 10, "Run Super Fast");
                AddChild(m_SuperFast);
                m_Controller = new CController(backBuffer, 30, 40, .1, .7, .3, 4, 1, 2000);
            }

            graphics2D.Clear(new RGBA_Floats(1, 1, 1, 1));
            graphics2D.Rasterizer.SetVectorClipBox(0, 0, (int)Width, (int)Height);
            m_Controller.FastRender(m_SuperFast.Checked);
            m_Controller.Render(graphics2D);
            //m_SuperFast.Render(graphics2D);
            base.OnDraw(graphics2D);
        }
예제 #28
0
        void CreateBedGridImage(int linesInX, int linesInY)
        {
            Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY);

            bedCentimeterGridImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA());
            Graphics2D graphics2D = bedCentimeterGridImage.NewGraphics2D();

            graphics2D.Clear(RGBA_Bytes.White);
            {
                double lineDist = bedCentimeterGridImage.Width / (double)linesInX;

                int count     = 1;
                int pointSize = 20;
                graphics2D.DrawString(count.ToString(), 0, 0, pointSize);
                for (double linePos = lineDist; linePos < bedCentimeterGridImage.Width; linePos += lineDist)
                {
                    count++;
                    int linePosInt = (int)linePos;
                    graphics2D.Line(linePosInt, 0, linePosInt, bedCentimeterGridImage.Height, RGBA_Bytes.Black);
                    graphics2D.DrawString(count.ToString(), linePos, 0, pointSize);
                }
            }
            {
                double lineDist = bedCentimeterGridImage.Height / (double)linesInY;

                int count     = 1;
                int pointSize = 20;
                for (double linePos = lineDist; linePos < bedCentimeterGridImage.Height; linePos += lineDist)
                {
                    count++;
                    int linePosInt = (int)linePos;
                    graphics2D.Line(0, linePosInt, bedCentimeterGridImage.Height, linePosInt, RGBA_Bytes.Black);
                    graphics2D.DrawString(count.ToString(), 0, linePos, pointSize);
                }
            }
        }
예제 #29
0
        void CreateRectangularBedGridImage(int linesInX, int linesInY)
        {
            Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY);

            BedImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA());
            Graphics2D graphics2D = BedImage.NewGraphics2D();

            graphics2D.Clear(bedBaseColor);
            {
                double lineDist = BedImage.Width / (double)linesInX;

                int count     = 1;
                int pointSize = 20;
                graphics2D.DrawString(count.ToString(), 4, 4, pointSize, color: bedMarkingsColor);
                for (double linePos = lineDist; linePos < BedImage.Width; linePos += lineDist)
                {
                    count++;
                    int linePosInt = (int)linePos;
                    graphics2D.Line(linePosInt, 0, linePosInt, BedImage.Height, bedMarkingsColor);
                    graphics2D.DrawString(count.ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor);
                }
            }
            {
                double lineDist = BedImage.Height / (double)linesInY;

                int count     = 1;
                int pointSize = 16;
                for (double linePos = lineDist; linePos < BedImage.Height; linePos += lineDist)
                {
                    count++;
                    int linePosInt = (int)linePos;
                    graphics2D.Line(0, linePosInt, BedImage.Height, linePosInt, bedMarkingsColor);
                    graphics2D.DrawString(count.ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor);
                }
            }
        }
예제 #30
0
        private void Initialize(ImageBufferFloat sourceImage, RectangleInt boundsToCopyFrom)
        {
            if (sourceImage == this)
            {
                throw new Exception("We do not create a temp buffer for this to work.  You must have a source distinct from the dest.");
            }
            Deallocate();
            Allocate(boundsToCopyFrom.Width, boundsToCopyFrom.Height, boundsToCopyFrom.Width * sourceImage.BitDepth / 8, sourceImage.BitDepth);
            SetRecieveBlender(sourceImage.GetBlender());

            if (m_Width != 0 && m_Height != 0)
            {
                RectangleInt DestRect           = new RectangleInt(0, 0, boundsToCopyFrom.Width, boundsToCopyFrom.Height);
                RectangleInt AbsoluteSourceRect = boundsToCopyFrom;
                // The first thing we need to do is make sure the frame is cleared. LBB [3/15/2004]
                Graphics2D graphics2D = NewGraphics2D();
                graphics2D.Clear(new ColorF(0, 0, 0, 0));

                int x = -boundsToCopyFrom.Left - (int)sourceImage.OriginOffset.X;
                int y = -boundsToCopyFrom.Bottom - (int)sourceImage.OriginOffset.Y;

                graphics2D.Render(sourceImage, x, y, 0, 1, 1);
            }
        }
            /// <summary>
            /// Called when we've to draw the image.
            /// </summary>
            /// <param name="graphics">The graphics.</param>
            private void OnDraw(Graphics2D graphics)
            {
                if (IsDisposed) { throw new ObjectDisposedException("ImageDataFlowHelper"); }

                if (this.SyncBuffer == null) { return; }

                // Change bitmap contents if needed
                if (this.SyncBufferChanged)
                {
                    lock (this.SyncBufferLock)
                    {
                        // Recreate bitmap on need
                        if ((this.BitmapSize != this.SyncBufferSize) ||
                           (this.Bitmap == null))
                        {
                            CommonTools.SafeDispose(ref this.Bitmap);
                            this.Bitmap = new WriteableBitmapResource(
                                new Size2(this.SyncBufferSize.Width, this.SyncBufferSize.Height),
                                BitmapFormat.Bgra, AlphaMode.Ignore);
                            this.BitmapSize = this.SyncBufferSize;
                        }

                        // Write data from SyncBuffer to bitmap
                        this.Bitmap.SetBitmapContent(
                            graphics,
                            this.SyncBuffer.Pointer,
                            this.SyncBuffer.Pitch);
                    }
                }

                // Draw the bitmap on the screen
                if ((this.Bitmap != null) &&
                    (this.BitmapSize.Width > 0) &&
                    (this.BitmapSize.Height > 0))
                {
                    graphics.Clear(Color4.Transparent);

                    // Draw the current contents of the stream
                    RectangleF viewBounds = new RectangleF(
                        0f, 0f,
                        graphics.ScreenSize.Width, graphics.ScreenSize.Height);
                    graphics.DrawBitmap(this.Bitmap, viewBounds);

                    // Draw the stream's name
                    RectangleF titleBounds = new RectangleF(
                        viewBounds.Width / 2f - 100f,
                        10f,
                        200f, 30f);
                    graphics.FillRoundedRectangle(titleBounds, 5f, 5f, this.TextBackground);
                    graphics.DrawText(
                        this.StreamName, this.TextFormat,
                        titleBounds,
                        this.TextForeground);
                }
            }