void createThumbnailWorker_DoWork(object sender, DoWorkEventArgs e) { PartThumbnailWidget thumbnailWidget = e.Argument as PartThumbnailWidget; if (thumbnailWidget != null) { if (thumbnailWidget.printItem == null) { thumbnailWidget.image = new ImageBuffer(thumbnailWidget.noThumbnailImage); } else // generate the image { Mesh loadedMesh = StlProcessing.Load(thumbnailWidget.printItem.FileLocation); thumbnailWidget.image = new ImageBuffer(thumbnailWidget.buildingThumbnailImage); thumbnailWidget.Invalidate(); if (loadedMesh != null) { ImageBuffer tempImage = new ImageBuffer(thumbnailWidget.image.Width, thumbnailWidget.image.Height, 32, new BlenderBGRA()); Graphics2D partGraphics2D = tempImage.NewGraphics2D(); 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 = thumbnailWidget.image.Width / (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((thumbnailWidget.image.Width / scale - bounds2D.Width) / 2 - bounds2D.Left, (thumbnailWidget.image.Height / scale - bounds2D.Height) / 2 - bounds2D.Bottom), scale, thumbnailWidget.FillColor); thumbnailWidget.image = new ImageBuffer(tempImage); loadedMesh = new Mesh(); } else { thumbnailWidget.image = new ImageBuffer(thumbnailWidget.noThumbnailImage); } } thumbnailWidget.Invalidate(); } }
void createThumbnailWorker_DoWork(object sender, DoWorkEventArgs e) { PartThumbnailWidget thumbnailWidget = e.Argument as PartThumbnailWidget; if (thumbnailWidget != null) { if (thumbnailWidget.printItem == null) { thumbnailWidget.thumbnailImage = new ImageBuffer(thumbnailWidget.noThumbnailImage); thumbnailWidget.Invalidate(); return; } if (thumbnailWidget.PrintItem.FileLocation == QueueData.SdCardFileName) { switch (thumbnailWidget.Size) { case ImageSizes.Size115x115: { StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_115x115", partExtension), thumbnailWidget.thumbnailImage); } break; case ImageSizes.Size50x50: { StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_50x50", partExtension), thumbnailWidget.thumbnailImage); } break; default: throw new NotImplementedException(); } thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA()); Graphics2D graphics = thumbnailWidget.thumbnailImage.NewGraphics2D(); Ellipse outline = new Ellipse(new Vector2(Width / 2.0, Height / 2.0), Width / 2 - Width / 12); graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White); UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); return; } else if (Path.GetExtension(thumbnailWidget.PrintItem.FileLocation).ToUpper() == ".GCODE") { CreateImage(thumbnailWidget, Width, Height); thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA()); Graphics2D graphics = thumbnailWidget.thumbnailImage.NewGraphics2D(); Vector2 center = new Vector2(Width / 2.0, Height / 2.0); Ellipse outline = new Ellipse(center, Width / 2 - Width / 12); graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White); graphics.DrawString("GCode", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White); UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); return; } else if (!File.Exists(thumbnailWidget.PrintItem.FileLocation)) { CreateImage(thumbnailWidget, Width, Height); thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA()); Graphics2D graphics = thumbnailWidget.thumbnailImage.NewGraphics2D(); Vector2 center = new Vector2(Width / 2.0, Height / 2.0); graphics.DrawString("Missing", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White); UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); return; } string stlHashCode = thumbnailWidget.PrintItem.FileHashCode.ToString(); Point2D bigRenderSize = new Point2D(460, 460); ImageBuffer bigRender = LoadImageFromDisk(thumbnailWidget, stlHashCode, bigRenderSize); if (bigRender == null) { if (!File.Exists(thumbnailWidget.PrintItem.FileLocation)) { return; } List <MeshGroup> loadedMeshGroups = MeshFileIo.Load(thumbnailWidget.PrintItem.FileLocation); thumbnailWidget.thumbnailImage = new ImageBuffer(thumbnailWidget.buildingThumbnailImage); thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); bigRender = BuildImageFromMeshGroups(loadedMeshGroups, stlHashCode, bigRenderSize); if (bigRender == null) { bigRender = new ImageBuffer(thumbnailWidget.noThumbnailImage); } } switch (thumbnailWidget.Size) { case ImageSizes.Size50x50: { ImageBuffer halfWay1 = new ImageBuffer(200, 200, 32, new BlenderBGRA()); halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height); ImageBuffer halfWay2 = new ImageBuffer(100, 100, 32, new BlenderBGRA()); halfWay2.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay2.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)halfWay2.Width / halfWay1.Width, (double)halfWay2.Height / halfWay1.Height); thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA()); thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); thumbnailWidget.thumbnailImage.NewGraphics2D().Render(halfWay2, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / halfWay2.Width, (double)thumbnailWidget.thumbnailImage.Height / halfWay2.Height); } break; case ImageSizes.Size115x115: { ImageBuffer halfWay1 = new ImageBuffer(230, 230, 32, new BlenderBGRA()); halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height); thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA()); thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); thumbnailWidget.thumbnailImage.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / halfWay1.Width, (double)thumbnailWidget.thumbnailImage.Height / halfWay1.Height); } break; default: throw new NotImplementedException(); } UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); } }
void createThumbnailWorker_DoWork(object sender, DoWorkEventArgs e) { PartThumbnailWidget thumbnailWidget = e.Argument as PartThumbnailWidget; if (thumbnailWidget != null) { if (thumbnailWidget.printItem == null) { thumbnailWidget.tumbnailImage = new ImageBuffer(thumbnailWidget.noThumbnailImage); thumbnailWidget.Invalidate(); return; } string stlHashCode = thumbnailWidget.PrintItem.StlFileHashCode.ToString(); Point2D bigRenderSize = new Point2D(460, 460); ImageBuffer bigRender = LoadImageFromDisk(thumbnailWidget, stlHashCode, bigRenderSize); if (bigRender == null) { Mesh loadedMesh = StlProcessing.Load(thumbnailWidget.PrintItem.FileLocation); thumbnailWidget.tumbnailImage = new ImageBuffer(thumbnailWidget.buildingThumbnailImage); thumbnailWidget.tumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); bigRender = BuildImageFromSTL(loadedMesh, stlHashCode, bigRenderSize); if (bigRender == null) { bigRender = new ImageBuffer(thumbnailWidget.noThumbnailImage); } } switch (thumbnailWidget.Size) { case ImageSizes.Size50x50: { ImageBuffer halfWay1 = new ImageBuffer(200, 200, 32, new BlenderBGRA()); halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height); ImageBuffer halfWay2 = new ImageBuffer(100, 100, 32, new BlenderBGRA()); halfWay2.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay2.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)halfWay2.Width / halfWay1.Width, (double)halfWay2.Height / halfWay1.Height); thumbnailWidget.tumbnailImage = new ImageBuffer(50, 50, 32, new BlenderBGRA()); thumbnailWidget.tumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); thumbnailWidget.tumbnailImage.NewGraphics2D().Render(halfWay2, 0, 0, 0, (double)thumbnailWidget.tumbnailImage.Width / halfWay2.Width, (double)thumbnailWidget.tumbnailImage.Height / halfWay2.Height); } break; case ImageSizes.Size115x115: { ImageBuffer halfWay1 = new ImageBuffer(230, 230, 32, new BlenderBGRA()); halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height); thumbnailWidget.tumbnailImage = new ImageBuffer(115, 115, 32, new BlenderBGRA()); thumbnailWidget.tumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); thumbnailWidget.tumbnailImage.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)thumbnailWidget.tumbnailImage.Width / halfWay1.Width, (double)thumbnailWidget.tumbnailImage.Height / halfWay1.Height); } break; default: throw new NotImplementedException(); } UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); } }
static void CreateThumbnailsThread() { while (true) { if (listOfWidgetsNeedingThumbnails.Count > 0) { PartThumbnailWidget thumbnailWidget = listOfWidgetsNeedingThumbnails[0]; if (thumbnailWidget.printItem == null) { thumbnailWidget.image = new ImageBuffer(thumbnailWidget.noThumbnailImage); } else // generate the image { Mesh loadedMesh = StlProcessing.Load(thumbnailWidget.printItem.FileLocation); thumbnailWidget.image = new ImageBuffer(thumbnailWidget.buildingThumbnailImage); thumbnailWidget.Invalidate(); if (loadedMesh != null) { ImageBuffer tempImage = new ImageBuffer(thumbnailWidget.image.Width, thumbnailWidget.image.Height, 32, new BlenderBGRA()); Graphics2D partGraphics2D = tempImage.NewGraphics2D(); List <MeshEdge> nonManifoldEdges = loadedMesh.GetNonManifoldEdges(); if (nonManifoldEdges.Count > 0) { if (File.Exists("RunUnitTests.txt")) { partGraphics2D.Circle(4, 4, 4, RGBA_Bytes.Red); } } AxisAlignedBoundingBox aabb = loadedMesh.GetAxisAlignedBoundingBox(); double maxSize = Math.Max(aabb.XSize, aabb.YSize); double scale = thumbnailWidget.image.Width / (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((thumbnailWidget.image.Width / scale - bounds2D.Width) / 2 - bounds2D.Left, (thumbnailWidget.image.Height / scale - bounds2D.Height) / 2 - bounds2D.Bottom), scale, thumbnailWidget.FillColor); thumbnailWidget.image = new ImageBuffer(tempImage); } else { thumbnailWidget.image = new ImageBuffer(thumbnailWidget.noThumbnailImage); } } thumbnailWidget.Invalidate(); using (TimedLock.Lock(listOfWidgetsNeedingThumbnails, "CreateThumbnailsThread()")) { listOfWidgetsNeedingThumbnails.RemoveAt(0); foreach (PartThumbnailWidget part in listOfWidgetsNeedingThumbnails) { // mark them so we try to add them again if needed part.thumbNailHasBeenRequested = false; } listOfWidgetsNeedingThumbnails.Clear(); } } Thread.Sleep(100); } }