Ejemplo n.º 1
0
        public MSTLSlice(List <MContourStructure> contours)
            : this()
        {
            NumberOfContours = contours.Count;

            MarkGeometryPoint lastPoint = null;

            foreach (var contourStructure in contours)
            {
                var(lines, minLineLength, perimeter) = GeometricArithmeticModule.GetLinesAndStatistics(
                    contourStructure.ToPoints()
                    );

                ContourLines.AddRange(
                    lines
                    );

                if (minLineLength < MinVectorLength)
                {
                    MinVectorLength = minLineLength;
                }

                _totalContourMarkDistance += perimeter;
                NumberOfJoints            += (lines.Count - 1);

                if (lines.Count > 0)
                {
                    if (lastPoint != null)
                    {
                        // measure and track the jump distance between the last contour and this
                        _totalContourJumpDistance += GeometricArithmeticModule.ABSMeasure(lastPoint, lines[0].StartPoint);
                    }

                    lastPoint = lines[0].StartPoint;
                }
            }

            _contourQuadTree = new ContourQuadTree(ContourLines);
            Extents          = GeometricArithmeticModule.CalculateExtents(ContourLines);
        }
Ejemplo n.º 2
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");
        }