private static void GetIntersectionPointByPolyNode(PolyNode polyNode, int projectorResolutionY, SortedList <int, List <SliceLine2D> > modelPointsByY) { for (var contourLineIndex = 0; contourLineIndex < polyNode.Contour.Count; contourLineIndex++) { var contourLine = new SliceLine2D(); contourLine.p1 = new SlicePoint2D(polyNode.Contour[contourLineIndex]); if (contourLineIndex < polyNode.Contour.Count - 1) { contourLine.p2 = new SlicePoint2D(polyNode.Contour[contourLineIndex + 1]); } else { contourLine.p2 = new SlicePoint2D(polyNode.Contour[0]); } if (contourLine.p2.Y < contourLine.p1.Y) { //flip order var tempP1 = contourLine.p1; contourLine.p1 = contourLine.p2; contourLine.p2 = tempP1; } //check if line has a pixel intersecting a whole pixel var startLinePixelY = (int)Math.Ceiling(contourLine.p1.Y); var endLinePixelY = (int)Math.Floor(contourLine.p2.Y); if (endLinePixelY > projectorResolutionY - 1) { endLinePixelY = projectorResolutionY - 1; } if (startLinePixelY < projectorResolutionY && startLinePixelY <= endLinePixelY) { if (contourLine.p1.Y != contourLine.p2.Y) { for (var lineContainsIndexY = startLinePixelY; lineContainsIndexY <= endLinePixelY; lineContainsIndexY++) { if (!modelPointsByY.ContainsKey(lineContainsIndexY)) { modelPointsByY.Add(lineContainsIndexY, new List <SliceLine2D>()); } modelPointsByY[lineContainsIndexY].Add(contourLine); } } } } foreach (var child in polyNode.Childs) { GetIntersectionPointByPolyNode(child, projectorResolutionY, modelPointsByY); } }
private static Dictionary <int, List <SlicePoint2D> > GetSupportIntersectionPointsFromPolyNode(PolyNode polyNode, int projectorResolutionX, int projectorResolutionY) { var totalSupportStructureIntersectionPoints = new List <Dictionary <int, List <SlicePoint2D> > >(); var supportPointsByY = new SortedList <int, List <SliceLine2D> >(); for (var contourLineIndex = 0; contourLineIndex < polyNode.Contour.Count; contourLineIndex++) { var contourLine = new SliceLine2D(); contourLine.p1 = new SlicePoint2D(polyNode.Contour[contourLineIndex]); if (contourLineIndex < polyNode.Contour.Count - 1) { contourLine.p2 = new SlicePoint2D(polyNode.Contour[contourLineIndex + 1]); } else { contourLine.p2 = new SlicePoint2D(polyNode.Contour[0]); } if (contourLine.p2.Y < contourLine.p1.Y) { //flip order var tempP1 = contourLine.p1; contourLine.p1 = contourLine.p2; contourLine.p2 = tempP1; } //check if line has a pixel intersecting a whole pixel var startLinePixelY = (int)Math.Ceiling(contourLine.p1.Y); var endLinePixelY = (int)Math.Floor(contourLine.p2.Y); if (endLinePixelY > projectorResolutionY - 1) { endLinePixelY = projectorResolutionY - 1; } if (startLinePixelY < projectorResolutionY && startLinePixelY <= endLinePixelY) { if (contourLine.p1.Y != contourLine.p2.Y) { for (var lineContainsIndexY = startLinePixelY; lineContainsIndexY <= endLinePixelY; lineContainsIndexY++) { if (!supportPointsByY.ContainsKey(lineContainsIndexY)) { supportPointsByY.Add(lineContainsIndexY, new List <SliceLine2D>()); } supportPointsByY[lineContainsIndexY].Add(contourLine); } } } } //get intersectionPoints for this support cone var supportIntersectionPoints = new Dictionary <int, List <SlicePoint2D> >(); foreach (var supportPointIndex in supportPointsByY.Keys) { if (supportPointsByY[supportPointIndex] != null) { //beware zero based index GetIntersectingSupportPoints(supportPointIndex, supportPointsByY[supportPointIndex], ref supportIntersectionPoints); //get normal based intersection points //supportIntersectionPoints[supportPointIndex] = GetSupportPointsByNormal(supportIntersectionPoints[supportPointIndex], supportPointIndex); //do not sort! will be done in later stage } } return(supportIntersectionPoints); }
private static void GetModelRasterPoints(PolyNode polyNode, int projectorResolutionY, SortedList <int, List <SliceLine2D> > modelPointsByY) { var contourRasterPoints = new List <SlicePoint2D>(); for (var contourLineIndex = 0; contourLineIndex < polyNode.Contour.Count; contourLineIndex++) { var contourLine = new SliceLine2D(); contourLine.p1 = new SlicePoint2D(polyNode.Contour[contourLineIndex]); if (contourLineIndex < polyNode.Contour.Count - 1) { contourLine.p2 = new SlicePoint2D(polyNode.Contour[contourLineIndex + 1]); } else { contourLine.p2 = new SlicePoint2D(polyNode.Contour[0]); } //check if line has a pixel intersecting a whole pixel var startLinePixelY = (int)contourLine.p1.Y; var startLineY = contourLine.p1.Y; var endLinePixelY = (int)contourLine.p2.Y; var endLineY = contourLine.p2.Y; if (contourLine.p1.Y > contourLine.p2.Y) { startLinePixelY = (int)contourLine.p2.Y; startLineY = contourLine.p2.Y; endLinePixelY = (int)contourLine.p1.Y; endLineY = contourLine.p1.Y; } var rasterPoints = new List <SlicePoint2D>(); if (startLinePixelY != endLinePixelY) { //get intersectionpoints for (var i = startLinePixelY - 1; i <= endLinePixelY; i++) { if (i >= startLineY && i <= endLineY) { rasterPoints.Add(contourLine.IntersectY(i)); } } } //x raster points var startLinePixelX = (int)contourLine.p1.X; var startLineX = contourLine.p1.X; var endLinePixelX = (int)contourLine.p2.X; var endLineX = contourLine.p2.X; if (contourLine.p1.X > contourLine.p2.X) { startLinePixelX = (int)contourLine.p2.X; startLineX = contourLine.p2.X; endLinePixelX = (int)contourLine.p1.X; endLineX = contourLine.p1.X; } if (startLinePixelX != endLinePixelX) { //get intersectionpoints for (var i = startLinePixelX - 1; i <= endLinePixelX; i++) { if (i >= startLineX && i <= endLineX) { rasterPoints.Add(contourLine.IntersectX(i)); } } } if (rasterPoints.Count > 0) { //order by distance var rasterPointsOrdered = new SortedDictionary <float, SlicePoint2D>(); var lineStartPointAsVector2 = new Vector2(contourLine.p1.X, contourLine.p1.Y); foreach (var rasterPoint in rasterPoints) { var pointDistance = (new Vector2(rasterPoint.X, rasterPoint.Y) - (lineStartPointAsVector2)).Length; rasterPointsOrdered.Add(pointDistance, rasterPoint); } contourRasterPoints.AddRange(rasterPointsOrdered.Values); } } var bitmap = new Bitmap(1920, 1080); var g = Graphics.FromImage(bitmap); var path = new GraphicsPath(); var points = new List <PointF>(); foreach (var contourRasterPoint in contourRasterPoints) { points.Add(new PointF(contourRasterPoint.X, contourRasterPoint.Y)); } path.AddLines(points.ToArray()); g.DrawLines(new Pen(Color.Red, 1), points.ToArray()); points = new List <PointF>(); for (var contourRasterPointIndex = 0; contourRasterPointIndex < contourRasterPoints.Count - 1; contourRasterPointIndex++) { //calc rasterline volume var rasterPointStart = contourRasterPoints[contourRasterPointIndex]; if (contourRasterPointIndex == 0) { rasterPointStart = contourRasterPoints[contourRasterPoints.Count - 1]; } var rasterPointEnd = contourRasterPoints[contourRasterPointIndex + 1]; var rasterPointVolume = rasterPointStart.X - (int)rasterPointStart.X; rasterPointVolume += rasterPointStart.Y - (int)rasterPointStart.Y; rasterPointVolume += rasterPointEnd.X - (int)rasterPointEnd.X; rasterPointVolume += rasterPointEnd.Y - (int)rasterPointEnd.Y; rasterPointVolume /= 4; rasterPointVolume *= 100; if (rasterPointVolume < 1f) { rasterPointVolume = 1f; } rasterPointVolume = 255 / rasterPointVolume; g.DrawLine(new Pen(Color.FromArgb(255, (int)rasterPointVolume, 255, 255)), rasterPointStart.X, rasterPointStart.Y, rasterPointEnd.X, rasterPointEnd.Y); } bitmap.Save("t.png"); }