diff --git a/CustomWidgets/PartThumbnailWidget.cs b/CustomWidgets/PartThumbnailWidget.cs index 9f1c1c46a..6cfa31324 100644 --- a/CustomWidgets/PartThumbnailWidget.cs +++ b/CustomWidgets/PartThumbnailWidget.cs @@ -48,6 +48,12 @@ namespace MatterHackers.MatterControl { public class PartThumbnailWidget : ClickWidget { + const int tooBigAndroid = 50000000; + const int tooBigDesktop = 250000000; + + const int renderOrthoAndroid = 20000000; + const int renderOrthoDesktop = 100000000; + // all the color stuff new public double BorderWidth = 0; @@ -318,10 +324,37 @@ namespace MatterHackers.MatterControl return imageFileName; } - private static RenderType GetRenderType(string pathToMeshFile) + private static RenderType GetRenderType(string fileLocation) { return RenderType.ORTHOGROPHIC; + + if (Is32Bit()) + { + long estimatedMemoryUse = 0; + if (File.Exists(fileLocation)) + { + estimatedMemoryUse = MeshFileIo.GetEstimatedMemoryUse(fileLocation); + + if (OsInformation.OperatingSystem == OSType.Android) + { + if (estimatedMemoryUse > renderOrthoAndroid) + { + return RenderType.ORTHOGROPHIC; + } + } + else + { + if (estimatedMemoryUse > renderOrthoDesktop) + { + return RenderType.ORTHOGROPHIC; + } + } + } + } + + return RenderType.RAY_TRACE; } + private static ImageBuffer LoadImageFromDisk(PartThumbnailWidget thumbnailWidget, string stlHashCode, Point2D size) { ImageBuffer tempImage = new ImageBuffer(size.x, size.y, 32, new BlenderBGRA()); @@ -406,6 +439,7 @@ namespace MatterHackers.MatterControl } break; + case RenderType.NONE: case RenderType.ORTHOGROPHIC: thumbnailWidget.thumbnailImage = new ImageBuffer(thumbnailWidget.buildingThumbnailImage); @@ -586,6 +620,19 @@ namespace MatterHackers.MatterControl UiThread.RunOnIdle(this.EnsureImageUpdated); return true; } + else if (MeshIsTooBigToLoad(this.PrintItem.FileLocation)) + { + CreateImage(this, Width, Height); + this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA()); + Graphics2D graphics = this.thumbnailImage.NewGraphics2D(); + Vector2 center = new Vector2(Width / 2.0, Height / 2.0); + double yOffset = 8 * Width / 50 * TextWidget.GlobalPointSizeScaleRatio * 1.5; + graphics.DrawString("Too Big\nto\nRender", center.x, center.y + yOffset, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White); + + UiThread.RunOnIdle(this.EnsureImageUpdated); + return true; + //GetRenderType(thumbnailWidget.PrintItem.FileLocation); + } string stlHashCode = this.PrintItem.FileHashCode.ToString(); @@ -617,6 +664,46 @@ namespace MatterHackers.MatterControl return true; } + + private static bool Is32Bit() + { + if (IntPtr.Size == 4) + { + return true; + } + + return false; + } + + private bool MeshIsTooBigToLoad(string fileLocation) + { + if (Is32Bit()) + { + long estimatedMemoryUse = 0; + if (File.Exists(fileLocation)) + { + estimatedMemoryUse = MeshFileIo.GetEstimatedMemoryUse(fileLocation); + + if (OsInformation.OperatingSystem == OSType.Android) + { + if (estimatedMemoryUse > tooBigAndroid) + { + return true; + } + } + else + { + if (estimatedMemoryUse > tooBigDesktop) + { + return true; + } + } + } + } + + return false; + } + private void TryLoad(object sender, DoWorkEventArgs e) { using (TimedLock.Lock(this, "TryLoad")) diff --git a/CustomWidgets/ThumbnailTracer.cs b/CustomWidgets/ThumbnailTracer.cs index 0f43ea467..89d1a473c 100644 --- a/CustomWidgets/ThumbnailTracer.cs +++ b/CustomWidgets/ThumbnailTracer.cs @@ -51,7 +51,7 @@ namespace MatterHackers.RayTracer private Transform allObjectsHolder; - private MeshGroup loadedMeshGroup; + private List loadedMeshGroups; //RayTracer raytracer = new RayTracer(AntiAliasing.None, true, true, true, true, true); //RayTracer raytracer = new RayTracer(AntiAliasing.Low, true, true, true, true, true); @@ -71,8 +71,8 @@ namespace MatterHackers.RayTracer trackballTumbleWidget.DoOpenGlDrawing = false; trackballTumbleWidget.LocalBounds = new RectangleDouble(0, 0, width, height); - loadedMeshGroup = meshGroups[0]; - SetRenderPosition(loadedMeshGroup); + loadedMeshGroups = meshGroups; + SetRenderPosition(loadedMeshGroups); trackballTumbleWidget.AnchorCenter(); } @@ -90,7 +90,7 @@ namespace MatterHackers.RayTracer raytracer.CopyColorBufferToImage(destImage, rect); } - public void SetRenderPosition(MeshGroup loadedMeshGroup) + public void SetRenderPosition(List loadedMeshGroups) { trackballTumbleWidget.TrackBallController.Reset(); trackballTumbleWidget.TrackBallController.Scale = .03; @@ -98,7 +98,7 @@ namespace MatterHackers.RayTracer trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(0, 0, MathHelper.Tau / 16))); trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .19, 0, 0))); - ScaleMeshToView(loadedMeshGroup); + ScaleMeshToView(loadedMeshGroups); } private void AddAFloor() @@ -161,20 +161,47 @@ namespace MatterHackers.RayTracer graphics2D.Rasterizer.gamma(new gamma_none()); } - private void AddTestMesh(MeshGroup meshGroup) + AxisAlignedBoundingBox GetAxisAlignedBoundingBox(List meshGroups) { - loadedMeshGroup = meshGroup; - AxisAlignedBoundingBox meshBounds = loadedMeshGroup.GetAxisAlignedBoundingBox(); - Vector3 meshCenter = meshBounds.Center; - loadedMeshGroup.Translate(-meshCenter); + AxisAlignedBoundingBox totalMeshBounds = new AxisAlignedBoundingBox(Vector3.NegativeInfinity, Vector3.NegativeInfinity); + bool first = true; + foreach (MeshGroup meshGroup in meshGroups) + { + AxisAlignedBoundingBox meshBounds = meshGroup.GetAxisAlignedBoundingBox(); + if (first) + { + totalMeshBounds = meshBounds; + first = false; + } + else + { + totalMeshBounds = AxisAlignedBoundingBox.Union(totalMeshBounds, meshBounds); + } + } - ScaleMeshToView(loadedMeshGroup); + return totalMeshBounds; + } - RGBA_Bytes partColor = new RGBA_Bytes(0, 130, 153); - partColor = RGBA_Bytes.White; - IPrimitive bvhCollection = MeshToBVH.Convert(loadedMeshGroup, new SolidMaterial(partColor.GetAsRGBA_Floats(), .01, 0.0, 2.0)); + private void AddTestMesh(List meshGroups) + { + if (meshGroups != null) + { + AxisAlignedBoundingBox totalMeshBounds = GetAxisAlignedBoundingBox(meshGroups); + loadedMeshGroups = meshGroups; + Vector3 meshCenter = totalMeshBounds.Center; + foreach (MeshGroup meshGroup in meshGroups) + { + meshGroup.Translate(-meshCenter); + } - renderCollection.Add(bvhCollection); + ScaleMeshToView(loadedMeshGroups); + + RGBA_Bytes partColor = new RGBA_Bytes(0, 130, 153); + partColor = RGBA_Bytes.White; + IPrimitive bvhCollection = MeshToBVH.Convert(loadedMeshGroups, new SolidMaterial(partColor.GetAsRGBA_Floats(), .01, 0.0, 2.0)); + + renderCollection.Add(bvhCollection); + } } private void CreateScene() @@ -184,7 +211,7 @@ namespace MatterHackers.RayTracer //scene.background = new Background(new RGBA_Floats(0.5, .5, .5), 0.4); scene.background = new Background(new RGBA_Floats(0, 0, 0, 0), 0.4); - AddTestMesh(loadedMeshGroup); + AddTestMesh(loadedMeshGroups); allObjects = BoundingVolumeHierarchy.CreateNewHierachy(renderCollection); allObjectsHolder = new Transform(allObjects); @@ -198,7 +225,7 @@ namespace MatterHackers.RayTracer scene.lights.Add(new PointLight(new Vector3(-5000, -5000, 3000), new RGBA_Floats(0.5, 0.5, 0.5))); } - private RectangleDouble GetScreenBounds(AxisAlignedBoundingBox meshBounds, MeshGroup loadedMeshGroup) + private RectangleDouble GetScreenBounds(AxisAlignedBoundingBox meshBounds) { RectangleDouble screenBounds = RectangleDouble.ZeroIntersection; @@ -227,11 +254,11 @@ namespace MatterHackers.RayTracer return false; } - private void ScaleMeshToView(MeshGroup loadedMeshGroup) + private void ScaleMeshToView(List loadedMeshGroups) { - if (loadedMeshGroup != null) + if (loadedMeshGroups != null) { - AxisAlignedBoundingBox meshBounds = loadedMeshGroup.GetAxisAlignedBoundingBox(); // get it now that we moved it. + AxisAlignedBoundingBox meshBounds = GetAxisAlignedBoundingBox(loadedMeshGroups); bool done = false; double scallFraction = .1; @@ -239,12 +266,12 @@ namespace MatterHackers.RayTracer goalBounds.Inflate(-10); while (!done) { - RectangleDouble partScreenBounds = GetScreenBounds(meshBounds, loadedMeshGroup); + RectangleDouble partScreenBounds = GetScreenBounds(meshBounds); if (!NeedsToBeSmaller(partScreenBounds, goalBounds)) { trackballTumbleWidget.TrackBallController.Scale *= (1 + scallFraction); - partScreenBounds = GetScreenBounds(meshBounds, loadedMeshGroup); + partScreenBounds = GetScreenBounds(meshBounds); // If it crossed over the goal reduct the amount we are adjusting by. if (NeedsToBeSmaller(partScreenBounds, goalBounds)) @@ -255,7 +282,7 @@ namespace MatterHackers.RayTracer else { trackballTumbleWidget.TrackBallController.Scale *= (1 - scallFraction); - partScreenBounds = GetScreenBounds(meshBounds, loadedMeshGroup); + partScreenBounds = GetScreenBounds(meshBounds); // If it crossed over the goal reduct the amount we are adjusting by. if (!NeedsToBeSmaller(partScreenBounds, goalBounds)) diff --git a/PrintQueue/QueueData.cs b/PrintQueue/QueueData.cs index 4627bd72e..d43434783 100644 --- a/PrintQueue/QueueData.cs +++ b/PrintQueue/QueueData.cs @@ -311,16 +311,7 @@ namespace MatterHackers.MatterControl.PrintQueue if (File.Exists(item.FileLocation) && checkSize == ValidateSizeOn32BitSystems.Required) { - switch (Path.GetExtension(item.FileLocation).ToUpper()) - { - case ".STL": - estimatedMemoryUse = StlProcessing.GetEstimatedMemoryUse(item.FileLocation); - break; - - case ".AMF": - estimatedMemoryUse = AmfProcessing.GetEstimatedMemoryUse(item.FileLocation); - break; - } + estimatedMemoryUse = MeshFileIo.GetEstimatedMemoryUse(item.FileLocation); if (OsInformation.OperatingSystem == OSType.Android) { diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index fb4bb9340..e2537da2f 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit fb4bb934052fc39dc38180a8dd17bcda6faf59a2 +Subproject commit e2537da2f53c63843ce8349ed81bfffc87e9f214