Пример #1
0
        public static TriangleContourInfo ImportFromWorkspaceFile(WorkspaceSTLModelContour workspaceSTLModelContour)
        {
            var contour = new TriangleContourInfo();

            contour._outlineDistanceFactor = workspaceSTLModelContour.OutlineDistanceFactor;
            contour._outlineOffsetDistance = workspaceSTLModelContour.OutlineOffsetDistance;
            contour._infillDistanceFactor  = workspaceSTLModelContour.InfillDistanceFactor;
            contour._infillOffsetDistance  = workspaceSTLModelContour.InfillOffsetDistance;

            contour._supportConeTopHeight    = workspaceSTLModelContour.SupportConeTopHeight;
            contour._supportConeTopRadius    = workspaceSTLModelContour.SupportConeTopRadius;
            contour._supportConeMiddleRadius = workspaceSTLModelContour.SupportConeMiddleRadius;
            contour._supportConeBottomRadius = workspaceSTLModelContour.SupportConeBottomRadius;
            contour._supportConeBottomHeight = workspaceSTLModelContour.SupportConeBottomHeight;

            contour.OuterPath.AddRange(workspaceSTLModelContour.OuterPath);
            //contour.OuterPoints.AddRange(workspaceSTLModelContour.OuterPoints);
            contour.SupportPoints.AddRange(workspaceSTLModelContour.OuterSupportPoints);
            foreach (var innerPath in workspaceSTLModelContour.InnerPaths)
            {
                contour.InnerPaths.Add(innerPath);
            }

            foreach (var innerPoints in workspaceSTLModelContour.InnerPoints)
            {
                contour.InnerPoints.Add(innerPoints);
            }

            if (workspaceSTLModelContour.InfillContour != null)
            {
                contour.InfillContour = TriangleContourInfo.ImportFromWorkspaceFile(workspaceSTLModelContour.InfillContour);
            }

            return(contour);
        }
Пример #2
0
        public void CalcInfillContour(TriangleContourInfo parentContour)
        {
            if (this.InfillContour != null)
            {
                this.InfillContour.SupportStructure.Clear();
            }


            //convert to clipper polygon
            var decimalCorrectionFactor = 10000f;

            var clipperOffset = new Helpers.ContourHelper.ClipperOffset();
            var path          = new List <Helpers.ContourHelper.IntPoint>();
            var results       = new List <List <Helpers.ContourHelper.IntPoint> >();


            //do
            var zHeight = 0;

            foreach (var contourLine in this.OuterPoints)
            {
                path.Add(new Helpers.ContourHelper.IntPoint(contourLine.FirstPoint.X * decimalCorrectionFactor, contourLine.FirstPoint.Y * decimalCorrectionFactor, zHeight * decimalCorrectionFactor));
                zHeight++;
            }

            clipperOffset.AddPath(path, Helpers.ContourHelper.JoinType.jtMiter, Helpers.ContourHelper.EndType.etClosedPolygon);
            clipperOffset.Execute(ref results, -(this._infillOffsetDistance * decimalCorrectionFactor));

            var mostLeftPointX   = 10000f;
            var mostLeftIndex    = 0;
            var currentLeftIndex = 0;

            //calc outerline infill
            var contours = new List <TriangleContourInfo>();

            foreach (var result in results)
            {
                if (result.Count > 0)
                {
                    foreach (var resultPoint in result)
                    {
                        if (resultPoint.X < mostLeftPointX)
                        {
                            mostLeftPointX = resultPoint.X;
                            mostLeftIndex  = currentLeftIndex;
                        }
                    }

                    var infillContour = new TriangleContourInfo(parentContour.SupportConeTopRadius, parentContour.SupportConeTopHeight, parentContour.SupportConeMiddleRadius, parentContour.SupportConeBottomRadius, parentContour.SupportConeBottomHeight,
                                                                parentContour.OutlineDistanceFactor, parentContour.OutlineOffsetDistance, parentContour.InfillOffsetDistance, parentContour.InfillDistanceFactor);
                    var contourTopPoint = 0f;
                    if (this.OuterPath.Count > 0)
                    {
                        contourTopPoint = this.OuterPoints[0].FirstPoint.Z;
                    }

                    infillContour.OuterPath = result;

                    contours.Add(infillContour);

                    currentLeftIndex++;
                }
            }

            if (contours.Count > 0)
            {
                var topPoint = 0f;
                foreach (var outsideVector in this.OuterPoints)
                {
                    topPoint = Math.Max(topPoint, outsideVector.FirstPoint.Z);
                }

                var infillContour = new TriangleContourInfo(this.SupportConeTopRadius, this.SupportConeTopHeight, this.SupportConeMiddleRadius, this.SupportConeBottomRadius, this.SupportConeBottomHeight,
                                                            this.OutlineDistanceFactor, this.OutlineOffsetDistance, this.InfillOffsetDistance, this.InfillDistanceFactor);
                infillContour.OuterPath   = contours[mostLeftIndex].OuterPath;
                infillContour.OuterPoints = contours[mostLeftIndex].OuterPoints;

                //innerpath
                for (var contourIndex = 0; contourIndex < contours.Count; contourIndex++)
                {
                    //if (contourIndex != mostLeftIndex)
                    //{
                    infillContour.InnerPaths.Add(contours[contourIndex].OuterPath);

                    //convert innerpath to inner points using opposite normal
                    clipperOffset = new Helpers.ContourHelper.ClipperOffset();
                    results       = new List <List <Helpers.ContourHelper.IntPoint> >();


                    clipperOffset.AddPath(contours[contourIndex].OuterPath, Helpers.ContourHelper.JoinType.jtMiter, Helpers.ContourHelper.EndType.etClosedPolygon);
                    clipperOffset.Execute(ref results, (this._infillOffsetDistance * decimalCorrectionFactor));

                    foreach (var result in results)
                    {
                        var innerPoints = new List <Vector3>();
                        foreach (var point in result)
                        {
                            var correctedPointX = point.X / decimalCorrectionFactor;
                            var correctedPointY = point.Y / decimalCorrectionFactor;
                            innerPoints.Add(new Vector3(correctedPointX, correctedPointY, topPoint));
                        }

                        infillContour.InnerPoints.Add(innerPoints);
                    }
                    //}
                }

                //calc holes offset
                for (var innerContourIndex = 0; innerContourIndex < this.InnerPaths.Count; innerContourIndex++)
                {
                    //convert innerpath to inner points using opposite normal
                    clipperOffset = new Helpers.ContourHelper.ClipperOffset();
                    results       = new List <List <Helpers.ContourHelper.IntPoint> >();

                    clipperOffset.AddPath(this.InnerPaths[innerContourIndex], Helpers.ContourHelper.JoinType.jtMiter, Helpers.ContourHelper.EndType.etClosedPolygon);
                    clipperOffset.Execute(ref results, (this._infillOffsetDistance * decimalCorrectionFactor));

                    foreach (var result in results)
                    {
                        infillContour.InnerPaths.Add(result);
                    }
                }

                this.InfillContour = infillContour;
            }
        }