Ejemplo n.º 1
0
        private static void TestSlicing()
        {
            var _slicer = new MSTLSlicer();

            _slicer.Load(@"C:\MSOLV\STLs\Ice Cream Type 2.stl");
            //_slicer.Load(@"C:\MSOLV\STLs\tray.stl");
            //_slicer.Load(@"C:\MSOLV\STLs\flange.stl");
            //_slicer.Load(@"C:\MSOLV\STLs\TestBinaryKIT.stl");

            List <ContourStructure>[]  control = new List <ContourStructure>[] { };
            List <MContourStructure>[] slices  = new List <MContourStructure>[] { };

            Console.WriteLine(
                PerformanceHelper.Compare(
                    () =>
            {
                control = _slicer.Slice();
            },
                    () =>
            {
                slices = _slicer.SliceParallel();
            },
                    compareRepeat: 5,
                    timingRepeat: 5,
                    tagA: "Control",
                    tagB: "Slices"
                    )
                );

            //PrintSlicesCount("Control", control);
            //PrintSlicesCount("Slices", slices);
        }
Ejemplo n.º 2
0
        public IEnumerable <MVertex> ToVertices()
        {
            if (MSTLSlicer.CompareEqual(IntersectionList.First.Value.ForwardEdge, IntersectionList.Last.Value.BackwardEdge))
            {
                return(IntersectionList.Select(ill => ill.ForwardEdgeIntersectionPoint).Append(IntersectionList.First.Value.ForwardEdgeIntersectionPoint));
            }

            return(IntersectionList.Select(ill => ill.ForwardEdgeIntersectionPoint));
        }
Ejemplo n.º 3
0
        public IEnumerable <MVertex> ToVertices()
        {
            // close contour if closed, i.e. first edge touches last edge
            if (MSTLSlicer.CompareEqual(IntersectionList.First.Value.ForwardEdge, IntersectionList.Last.Value.BackwardEdge))
            {
                return(IntersectionList.Select(ill => ill.ForwardEdgeIntersectionPoint).Append(IntersectionList.First.Value.ForwardEdgeIntersectionPoint));
            }

            return(IntersectionList.Select(ill => ill.ForwardEdgeIntersectionPoint));
        }
Ejemplo n.º 4
0
        private static void Obsolete2()
        {
            #region Section: Not Used
            //List<MarkGeometryPath> openGeometries = new List<MarkGeometryPath>();
            //List<IMarkGeometry> closedGeometries = new List<IMarkGeometry>();

            //foreach (var kv in GeometricArithmeticModule.ExtractLabelledGeometriesFromDXF(@"C:\Users\Chibuike.Okpaluba\Downloads\#PLR printer data input assesment2_LibrecadPOints.ipt.dxf"))
            //{
            //    for (int i = 0; i < kv.Value.Count; i++)
            //    {
            //        if (kv.Value[i] is MarkGeometryLine line)
            //        {
            //            openGeometries.Add(new MarkGeometryPath(line));
            //        }
            //        else if (kv.Value[i] is MarkGeometryArc arc)
            //        {
            //            if (Math.Abs(arc.Sweep % (2 * Math.PI)) <= 0.0001)
            //                closedGeometries.Add(new MarkGeometryPath(arc));
            //            else
            //                openGeometries.Add(new MarkGeometryPath(arc));
            //        }
            //        else if (kv.Value[i] is MarkGeometryPath path)
            //        {
            //            if (path.IsClosed)
            //                closedGeometries.Add(path);
            //            else
            //                openGeometries.Add(path);
            //        }
            //        else
            //        {
            //            closedGeometries.Add(kv.Value[i]);
            //        }
            //    }
            //}

            //while(openGeometries.Count > 0)
            //{
            //    MarkGeometryPath reference = openGeometries[0];
            //    openGeometries.RemoveAt(0);

            //    var (trace, ___) = Trace(reference, openGeometries, 0.001);

            //    closedGeometries.Add(trace);
            //}
            #endregion

            var slicer = new MSTLSlicer();

            //Timeit(
            //    "Load",
            //    () => {
            //        //slicer.Load(@"C:\MSOLV\STLs\TestASCII.stl");
            //        slicer.Load(@"C:\MSOLV\STLs\tray.stl");
            //    }
            //);

            //Console.WriteLine($"{slicer.Facets?.Count}");

            //Timeit(
            //    "Slice",
            //    () => {
            //        slicer.Slice(slicer.MinZ + 15, 0.1, 0.001);
            //    }
            //);
        }
Ejemplo n.º 5
0
        private static void TestQuadTree()
        {
            var _slicer = new MSTLSlicer();

            _slicer.Load(@"C:\MSOLV\STLs\Ice Cream Type 2.stl");
            //_slicer.Load(@"C:\MSOLV\STLs\tray.stl");
            var slices = _slicer.Slice();

            IEnumerable <MVertex> contour = slices[7][0].ToVertices().Concat(slices[5][0].ToVertices());
            //IEnumerable<MVertex> contour = slices[5][1].ToVertices();

            var reference        = ToPath(contour);
            var intersectingLine = new MarkGeometryLine(
                reference.Extents.MinimumPoint,
                reference.Extents.MaximumPoint
                );

            List <MarkGeometryPoint> controlResults  = new List <MarkGeometryPoint>();
            List <MarkGeometryPoint> quadTreeResults = new List <MarkGeometryPoint>();

            var lines           = ToLines(contour);
            var contourQuadTree = new ContourQuadTree(contour);

            Console.WriteLine(
                PerformanceHelper.Compare(
                    () =>
            {
                // setup up
                controlResults.Clear();

                MarkGeometryPoint intersection;
                for (int i = 0; i < lines.Count; i++)
                {
                    if ((
                            intersection = GeometricArithmeticModule.CalculateIntersection2D(
                                intersectingLine,
                                lines[i]
                                )) != null
                        )
                    {
                        controlResults.Add(intersection);
                    }
                }
            },
                    () =>
            {
                // setup up
                quadTreeResults.Clear();

                quadTreeResults = contourQuadTree.Intersect(intersectingLine).ToList();
            },
                    tagA: "Lines (Control)",
                    tagB: "Quad Tree"
                    )
                );

            Println("Control", controlResults);
            Println("Quad Tree Intersections", quadTreeResults);

            contourQuadTree.SaveImage(@"C:\Users\Chibuike.Okpaluba\Downloads\quad_tree_v2.png");
        }
Ejemplo n.º 6
0
        public List <MarkGeometryPoint> ToPoints(double deviationToleranceDeg = 1)
        {
            if (IntersectionList.Count <= 0)
            {
                return(new List <MarkGeometryPoint>());
            }
            else if (IntersectionList.Count <= 1)
            {
                return new List <MarkGeometryPoint> {
                           ToPoint(IntersectionList.First.Value.ForwardEdgeIntersectionPoint)
                }
            }
            ;

            MVertex previousPoint = null;
            var     lastEntry     = IntersectionList.First;
            var     points        = new List <MarkGeometryPoint> {
                ToPoint(lastEntry.Value.ForwardEdgeIntersectionPoint)
            };
            var current = lastEntry.Next;

            double referenceAngle = GetAngle(
                lastEntry.Value.ForwardEdgeIntersectionPoint,
                current.Value.ForwardEdgeIntersectionPoint
                );

            deviationToleranceDeg = GeometricArithmeticModule.ToRadians(deviationToleranceDeg);

            while (current != null)
            {
                var angle = GetAngle(
                    lastEntry.Value.ForwardEdgeIntersectionPoint,
                    current.Value.ForwardEdgeIntersectionPoint
                    );

                if (Math.Abs(referenceAngle - angle) > deviationToleranceDeg)
                {
                    lastEntry = current.Previous;
                    points.Add(ToPoint(lastEntry.Value.ForwardEdgeIntersectionPoint));

                    referenceAngle = GetAngle(
                        lastEntry.Value.ForwardEdgeIntersectionPoint,
                        current.Value.ForwardEdgeIntersectionPoint
                        );
                }

                previousPoint = current.Value.ForwardEdgeIntersectionPoint;
                current       = current.Next;
            }

            if (previousPoint != null)
            {
                points.Add(ToPoint(previousPoint));
            }

            // close contour if closed, i.e. first edge touches last edge
            if (MSTLSlicer.CompareEqual(IntersectionList.First.Value.ForwardEdge, IntersectionList.Last.Value.BackwardEdge))
            {
                points.Add(new MarkGeometryPoint(IntersectionList.First.Value.ForwardEdgeIntersectionPoint.X, IntersectionList.First.Value.ForwardEdgeIntersectionPoint.Y));
            }

            return(points);
        }
Ejemplo n.º 7
0
        private async Task <bool> FetchSTL(string filePathIn)
        {
            if (!File.Exists(filePathIn))
            {
                _stlSlices = new List <MSTLSlice>();
            }

            var stlModel = ImportModel3D(filePathIn);

            if (stlModel != null)
            {
                _stlModel       = stlModel;
                PatternFilePath = filePathIn;
                ThreeDeeModel   = _modelGroup;
                SliceThickness  = 0.1 * _stlModel.Bounds.SizeZ;

                NumberOfSlices = (int)Math.Ceiling(_stlModel.Bounds.SizeZ / SliceThickness);

                _slicePlanes.Clear();

                // calculate plane dimensions with padding
                double planeSizeX = 1.2 * _stlModel.Bounds.SizeX;
                double planeSizeY = 1.2 * _stlModel.Bounds.SizeY;
                double planeSizeZ = 0.1 * SliceThickness;

                double xPosition = _stlModel.Bounds.X + (0.5 * _stlModel.Bounds.SizeX);
                double yPosition = _stlModel.Bounds.Y + (0.5 * _stlModel.Bounds.SizeY);

                StlModelReferencePoint.X = xPosition;
                StlModelReferencePoint.Y = yPosition;

                GenerateFiducialPattern(0.05 * Math.Max(_stlModel.Bounds.SizeX, _stlModel.Bounds.SizeY));

                GridLinesOrigin    = new Point3D(xPosition, yPosition, _stlModel.Bounds.Z);
                GridLinesSize      = Math.Max(2 * planeSizeX, 2 * planeSizeY);
                GridLinesGridPitch = Math.Pow(10, Math.Log10(GridLinesSize) - 1);

                var _mSlicer = new MSTLSlicer();
                if (!_mSlicer.Load(filePathIn))
                {
                    throw new Exception("Failed to load STL");
                }

                var backgroundTasks = new List <Task <bool> >()
                {
                    Task.Run(
                        () =>
                    {
                        foreach (var contours in _mSlicer.SliceParallel(SliceThickness, StitchTolerance))
                        {
                            _stlSlices.Add(new MSTLSlice(contours));
                        }
                        return(true);
                    }
                        )
                };

                for (int i = 0; i < NumberOfSlices; i++)
                {
                    var modelBuilder = new MeshBuilder(false, false);
                    modelBuilder.AddBox(
                        new Point3D(
                            xPosition,
                            yPosition,
                            (i * SliceThickness) + _stlModel.Bounds.Z
                            ),
                        planeSizeX, planeSizeY, planeSizeZ
                        );

                    _slicePlanes.Add(
                        new GeometryModel3D
                    {
                        Geometry = modelBuilder.ToMesh(true),
                        Material = PlaneMaterial
                    }
                        );
                }

                await Task.WhenAll(backgroundTasks);

                // reverse slices - orientate from top to bottom
                // by defaults slices are from the bottom to the top
                // but we need this flipped for this process
                _slicePlanes.Reverse();
                _stlSlices.Reverse();

                // hatch and tile slices
                await HatchAllSlices();
                await TileAllSlices();

                // update slice size info
                SliceXSize = _stlSlices[CurrentSlice].Extents.Width;
                SliceYSize = _stlSlices[CurrentSlice].Extents.Height;

                if (_stlSlices[CurrentSlice] != null)
                {
                    SliceCount = _stlSlices[CurrentSlice].ContourLines.Count + _stlSlices[CurrentSlice].HatchLines.Count;
                }

                if (NumberOfSlices > 0)
                {
                    ShowSlice(0);
                }

                return(true);
            }

            return(false);
        }