public static void Draw(BProperties boxProperties, HalfAxis.HAxis axis, PictureBox pictureBox) { // get horizontal angle double angle = 45; // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size); graphics.CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // draw Box box = new Box(0, boxProperties); // set axes HalfAxis.HAxis lengthAxis = HalfAxis.HAxis.AXIS_X_P; HalfAxis.HAxis widthAxis = HalfAxis.HAxis.AXIS_Y_P; switch (axis) { case HalfAxis.HAxis.AXIS_X_P: lengthAxis = HalfAxis.HAxis.AXIS_Z_P; widthAxis = HalfAxis.HAxis.AXIS_X_P; break; case HalfAxis.HAxis.AXIS_Y_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Z_N; break; case HalfAxis.HAxis.AXIS_Z_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Y_P; break; default: break; } box.LengthAxis = treeDiM.StackBuilder.Basics.HalfAxis.ToVector3D(lengthAxis); box.WidthAxis = treeDiM.StackBuilder.Basics.HalfAxis.ToVector3D(widthAxis); // draw box graphics.AddBox(box); graphics.Flush(); // set to picture box pictureBox.Image = graphics.Bitmap; }
public static void Draw(Packable packable, PictureBox pictureBox) { // get horizontal angle double angle = 45; // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size); graphics.CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // ### draw : begin ############################## if (packable is PackProperties) { Box box = new Pack(0, packable as PackProperties); graphics.AddBox(box); } else if (packable is BProperties) { Box box = new Box(0, packable as PackableBrick); graphics.AddBox(box); } else if (packable is CylinderProperties) { graphics.AddCylinder(new Cylinder(0, packable as CylinderProperties)); } // ### draw : end ################################# graphics.Flush(); // set to picture box pictureBox.Image = graphics.Bitmap; }
public void ScreenShotToClipboard() { var graphics = new Graphics3DImage(this.Size); try { double angleHorizRad = AngleHoriz * Math.PI / 180.0; double angleVertRad = AngleVert * Math.PI / 180.0; double cameraDistance = 100000.0; graphics.CameraPosition = new Vector3D( cameraDistance * Math.Cos(angleHorizRad) * Math.Cos(angleVertRad) , cameraDistance * Math.Sin(angleHorizRad) * Math.Cos(angleVertRad) , cameraDistance * Math.Sin(angleVertRad)); // set camera target graphics.Target = Vector3D.Zero; // set viewport (not actually needed) graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // show images graphics.ShowTextures = true; graphics.ShowDimensions = ShowDimensions; graphics.FontSizeRatio = 10.0f / (float)Size.Height; if (null != DrawingContainer) { try { DrawingContainer.Draw(this, graphics); } catch (Exception ex) { _log.Error(ex.ToString()); } } else if (null != Viewer) { try { Viewer.Draw(graphics, Transform3D.Identity); } catch (Exception ex) { graphics.Graphics.DrawString(ex.Message , new Font("Arial", 12) , new SolidBrush(Color.Red) , new Point(0, 0) , StringFormat.GenericDefault); _log.Error(ex.Message); } } graphics.Flush(); } catch (Exception ex) { _log.Error(ex.ToString()); } Clipboard.SetImage(BitmapHelpers.Crop(graphics.Bitmap)); }
public static void Draw(PackableBrick packable, HalfAxis.HAxis axis, PictureBox pictureBox) { try { // get horizontal angle double angle = 45; double cameraDistance = 100000; // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size) { CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * cameraDistance , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * cameraDistance , cameraDistance), Target = Vector3D.Zero }; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // draw Box box = null; if (packable is PackProperties) { box = new Pack(0, packable as PackProperties); } else { box = new Box(0, packable); } // set axes HalfAxis.HAxis lengthAxis = HalfAxis.HAxis.AXIS_X_P; HalfAxis.HAxis widthAxis = HalfAxis.HAxis.AXIS_Y_P; switch (axis) { case HalfAxis.HAxis.AXIS_X_P: lengthAxis = HalfAxis.HAxis.AXIS_Z_P; widthAxis = HalfAxis.HAxis.AXIS_X_P; break; case HalfAxis.HAxis.AXIS_Y_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Z_N; break; case HalfAxis.HAxis.AXIS_Z_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Y_P; break; default: break; } box.HLengthAxis = lengthAxis; box.HWidthAxis = widthAxis; // draw box graphics.AddBox(box); graphics.Flush(); // set to picture box pictureBox.Image = graphics.Bitmap; } catch (Exception ex) { Bitmap bmp = new Bitmap(pictureBox.Size.Width, pictureBox.Size.Height); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.DrawString("Invalid content", new Font("Arial", 8), new SolidBrush(Color.Red), new PointF(5, 10)); pictureBox.Image = bmp; _log.Error(ex.ToString()); } }
public static Bitmap Draw( IEnumerable <Box> boxes, Vector3D crateDimensions, Color crateColor, bool selected, bool showOuterDimensions, Size size) { var graphics = new Graphics3DImage(size) { MarginPercentage = 0.05 }; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); using (var viewer = new ViewerHLayeredCrate(crateDimensions, crateColor)) viewer.Draw(graphics, boxes, selected, showOuterDimensions); return(graphics.Bitmap); }
public static void Draw(Packable packable, HalfAxis.HAxis axis, PictureBox pictureBox) { // get horizontal angle double angle = 45; // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size); graphics.CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // draw Box box = null; if (packable is PackProperties) { box = new Pack(0, packable as PackProperties); } else { box = new Box(0, packable); } // set axes HalfAxis.HAxis lengthAxis = HalfAxis.HAxis.AXIS_X_P; HalfAxis.HAxis widthAxis = HalfAxis.HAxis.AXIS_Y_P; switch (axis) { case HalfAxis.HAxis.AXIS_X_P: lengthAxis = HalfAxis.HAxis.AXIS_Z_P; widthAxis = HalfAxis.HAxis.AXIS_X_P; break; case HalfAxis.HAxis.AXIS_Y_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Z_N; break; case HalfAxis.HAxis.AXIS_Z_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Y_P; break; default: break; } box.LengthAxis = treeDiM.StackBuilder.Basics.HalfAxis.ToVector3D(lengthAxis); box.WidthAxis = treeDiM.StackBuilder.Basics.HalfAxis.ToVector3D(widthAxis); // draw box graphics.AddBox(box); graphics.Flush(); // set to picture box pictureBox.Image = graphics.Bitmap; }
static void Main(string[] args) { ILog log = LogManager.GetLogger(typeof(Program)); XmlConfigurator.Configure(); try { // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(new Size(512, 512)); graphics.CameraPosition = new Vector3D(-10000.0, -10000.0, 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // load Bitmap string imageFilePath = @"..\..\Image16.bmp"; Bitmap bmp = new Bitmap(imageFilePath); Texture texture = new Texture(bmp, new Vector2D(100.0, 20.0), new Vector2D(40.0 * bmp.Size.Width / bmp.Size.Height, 40.0), 10.0); List<Texture> listTexture= new List<Texture>(); listTexture.Add(texture); // instantiate box and draw List<Box> boxList = new List<Box>(); Box box0 = new Box(0, 200.0, 160.0, 100.0); box0.Position = Vector3D.Zero; box0.SetAllFacesColor(Color.Chocolate); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_X_P, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_P, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Z_P, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_X_N, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_N, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Z_N, listTexture); boxList.Add(box0); Box box1 = new Box(1, 200.0, 160.0, 100.0); box1.Position = new Vector3D(210.0, 0.0, 0.0); box1.SetAllFacesColor(Color.Chocolate); box1.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_P, listTexture); boxList.Add(box1); Box box2 = new Box(2, 200.0, 160.0, 100.0); box2.Position = new Vector3D(0.0, 170.0, 0.0); box2.SetAllFacesColor(Color.Chocolate); boxList.Add(box2); Box box3 = new Box(3, 200.0, 160.0, 100.0); box3.Position = new Vector3D(0.0, 0.0, 110.0); box3.SetAllFacesColor(Color.Chocolate); boxList.Add(box3); // draw foreach (Box box in boxList) graphics.AddBox(box); graphics.Flush(); // Save as %TEMP%\Pallet.jpg string filePath = Path.Combine(Path.GetTempPath(), "Pallet.bmp"); graphics.SaveAs(filePath); bmp.Dispose(); // open file using (System.Diagnostics.Process proc = new System.Diagnostics.Process()) { proc.StartInfo.FileName = "mspaint.exe"; proc.StartInfo.Arguments = filePath; proc.Start(); } } catch (System.Exception ex) { log.Error(ex.ToString()); } }
static int Main(string[] args) { ILog log = LogManager.GetLogger(typeof(Program)); XmlConfigurator.Configure(); try { bool useSingleColor = false; // instantiate document Document doc = new Document("Test", "Test", "fga", DateTime.Now, null); // define pallet properties PalletProperties palletProperties = new PalletProperties(doc, "EUR2", 1200, 1000, 150); Console.WriteLine("=== Pallet properties ==="); Console.WriteLine(palletProperties.ToString()); bool testCylinder = false; if (!testCylinder) { // define box properties BoxProperties boxProperties = new BoxProperties(doc, 162, 210, 250); boxProperties.Name = "Box1"; boxProperties.Weight = 3.0; if (!useSingleColor) { boxProperties.SetColor(HalfAxis.HAxis.AXIS_X_N, Color.Red); boxProperties.SetColor(HalfAxis.HAxis.AXIS_X_P, Color.Red); boxProperties.SetColor(HalfAxis.HAxis.AXIS_Y_N, Color.Green); boxProperties.SetColor(HalfAxis.HAxis.AXIS_Y_P, Color.Green); boxProperties.SetColor(HalfAxis.HAxis.AXIS_Z_N, Color.Blue); boxProperties.SetColor(HalfAxis.HAxis.AXIS_Z_P, Color.Blue); } else boxProperties.SetColor(Color.Chocolate); Console.WriteLine(boxProperties.ToString()); InterlayerProperties interlayerProperties = null; // define constraints CasePalletConstraintSet constraintSet = new CasePalletConstraintSet(); constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_N, true); constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_P, true); constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_N, true); constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_P, true); constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_N, true); constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_P, true); constraintSet.SetAllowedPattern("Trilock"); constraintSet.AllowAlignedLayers = true; constraintSet.AllowAlternateLayers = false; constraintSet.MaximumPalletWeight = 2000; constraintSet.MaximumNumberOfItems = 2000; constraintSet.MaximumHeight = 2000.0; constraintSet.UseMaximumHeight = true; constraintSet.UseMaximumPalletWeight = true; constraintSet.UseMaximumWeightOnBox = false; constraintSet.AllowLastLayerOrientationChange = true; Console.WriteLine("=== Constraint set ==="); Console.WriteLine(constraintSet.ToString()); // initialize analysis CasePalletAnalysis analysis = new CasePalletAnalysis( boxProperties, palletProperties, interlayerProperties, null, null, null, null, constraintSet); // initialize solver CasePalletSolver solver = new CasePalletSolver(); solver.ProcessAnalysis(analysis); Console.WriteLine("=== Solutions ==="); int solIndex = 0; foreach (CasePalletSolution sol in analysis.Solutions) { // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(new Size(1000, 1000)); graphics.CameraPosition = new Vector3D(10000.0, 10000.0, 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // instantiate solution viewer CasePalletSolutionViewer sv = new CasePalletSolutionViewer(sol); sv.Draw(graphics); graphics.Flush(); // save string fileName = string.Format("Pallet_{0}.bmp", solIndex++); string filePath = Path.Combine(Path.GetTempPath(), fileName); Console.WriteLine("Saving file " + filePath + "..."); graphics.SaveAs(filePath); } } else { // cylinder Console.WriteLine("=== Cylinder properties ==="); CylinderProperties cylProperties = new CylinderProperties(doc, "Cylinder", "Default cylinder", 90, 45.0, 100, 1.5, Color.Gray, Color.SkyBlue, Color.SkyBlue); Console.WriteLine(cylProperties.ToString()); // constraint set Console.WriteLine("=== Constraint set ==="); CylinderPalletConstraintSet constraintSet = new CylinderPalletConstraintSet(); constraintSet.UseMaximumPalletHeight = true; constraintSet.MaximumPalletHeight = 1200.0; constraintSet.UseMaximumPalletWeight = true; constraintSet.MaximumPalletWeight = 2000; constraintSet.UseMaximumNumberOfItems = true; constraintSet.MaximumNumberOfItems = 2000; Console.WriteLine(constraintSet.ToString()); // cylinder analysis CylinderPalletAnalysis analysis = new CylinderPalletAnalysis(cylProperties, palletProperties, null, null, constraintSet); // initialize solver CylinderSolver solver = new CylinderSolver(); solver.ProcessAnalysis(analysis); Console.WriteLine("=== Solutions ==="); int solIndex = 0; foreach (CylinderPalletSolution sol in analysis.Solutions) { // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(new Size(512, 512)); graphics.CameraPosition = new Vector3D(10000.0, 10000.0, 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // instantiate solution viewer CylinderPalletSolutionViewer sv = new CylinderPalletSolutionViewer(sol); sv.Draw(graphics); string fileName = string.Format("Pallet_{0}.jpg", solIndex++); string filePath = Path.Combine(Path.GetTempPath(), fileName); Console.WriteLine("Saving file " + filePath + "..."); graphics.SaveAs(filePath); } } } catch (Exception ex) { log.Error(ex.ToString()); } return 0; }
private void DrawBox() { try { // get horizontal angle double angle = trackBarHorizAngle.Value; // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size); graphics.CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // draw BoxProperties boxProperties = new BoxProperties(null, _boxProperties.Length, _boxProperties.Width, _boxProperties.Height); boxProperties.SetAllColors(_boxProperties.Colors); boxProperties.TextureList = _textures; Box box = new Box(0, boxProperties); graphics.AddBox(box); graphics.Flush(); // set to picture box pictureBox.Image = graphics.Bitmap; } catch (Exception ex) { _log.Error(ex.ToString()); } }