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()); } }
static void Main(string[] args) { XmlConfigurator.Configure(); try { Size sz = new Size(1000, 1000); Graphics3DImage g = new Graphics3DImage(sz) { CameraPosition = new Vector3D(-10000.0, -10000.0, 10000.0), Target = Vector3D.Zero }; g.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); Box b1 = new Box(0, 400, 300, 200, new BoxPosition(Vector3D.Zero, HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P)) { }; b1.SetAllFacesColor(Color.Chocolate); Box b2 = new Box(1, 400, 300, 200, new BoxPosition(new Vector3D(600.0, 0.0, 0.0), HalfAxis.HAxis.AXIS_Z_P, HalfAxis.HAxis.AXIS_Y_P)) { }; b2.SetAllFacesColor(Color.BurlyWood); Box b3 = new Box(2, 400, 300, 200, new BoxPosition(new Vector3D(300.0, 300.0, 0.0), HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N)) { }; b3.SetAllFacesColor(Color.Chartreuse); Box b4 = new Box(3, 300, 200, 50, new BoxPosition(new Vector3D(50.0, 50.0, 200.0), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P)) { }; b4.SetAllFacesColor(Color.Coral); Box b5 = new Box(4, 300, 200, 50, new BoxPosition(new Vector3D(50.0, 250.0, 200.0), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P)) { }; b5.SetAllFacesColor(Color.Aquamarine); Box b6 = new Box(5, 400, 250, 150, new BoxPosition(new Vector3D(575.0, 0.0, 400.0), HalfAxis.HAxis.AXIS_Z_P, HalfAxis.HAxis.AXIS_Y_P)) { }; b6.SetAllFacesColor(Color.Yellow); List <Box> boxes = new List <Box> { b1, b2, b3, b4, b5, b6 }; BSPTree bspTree = new BSPTree(); foreach (Box b in boxes) { bspTree.InsertBox(b); } bspTree.Draw(g); g.Bitmap.Save(@"D:\GitHub\StackBuilder\Sources\Test\treeDiM.StackBuilder.Graphics.TestBSPTree\bin\Release\output.png"); } catch (Exception ex) { _log.Error(ex.ToString()); } }
private void DrawBoxPosition(BProperties boxProperties, HalfAxis.HAxis axis, PictureBox pictureBox) { // get horizontal angle double angle = 45; // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size) { CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 100000.0 , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 100000.0 , 10000.0), 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.HLengthAxis = lengthAxis; box.HWidthAxis = widthAxis; // draw box graphics.AddBox(box); graphics.Flush(); // set to picture box pictureBox.Image = graphics.Bitmap; }
private void Draw() { try { // sanity check if (pictureBoxSolution.Size.Width < 1 || pictureBoxSolution.Size.Height < 1) { return; } // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBoxSolution.Size); // set camera position double angleHorizRad = trackBarAngleHoriz.Value * Math.PI / 180.0; double angleVertRad = trackBarAngleVert.Value * Math.PI / 180.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; // instantiate solution viewer CasePalletSolutionViewer sv = new CasePalletSolutionViewer(CurrentSolution); sv.Draw(graphics); // show generated bitmap on picture box control pictureBoxSolution.Image = graphics.Bitmap; } catch (Exception ex) { _log.Error(ex.ToString()); } }
private static void RunBoxTest(bool useSingleColor, Document doc, PalletProperties palletProperties) { // define box properties var boxProperties = new BoxProperties(doc, 162, 210, 250); //boxProperties.Name = "Box1"; boxProperties.SetWeight(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 var 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 var analysis = new CasePalletAnalysis( boxProperties, palletProperties, interlayerProperties, null, null, null, null, constraintSet); // initialize solver var 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); } }
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()); } }
private void Draw() { // ### draw case definition try { // sanity check if (pbBoxesLayout.Size.Width < 1 || pbBoxesLayout.Size.Height < 1) { return; } // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pbBoxesLayout.Size); // set camera position graphics.CameraPosition = Graphics3D.Corner_0; // set camera target graphics.Target = new Vector3D(0.0, 0.0, 0.0); // set viewport (not actually needed) graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // show images graphics.ShowTextures = true; // get selected solution CaseOptimSolution solution = SelectedSolution; if (null == solution) { return; } // instantiate case definition viewer CaseDefinitionViewer cdv = new CaseDefinitionViewer(SelectedSolution.CaseDefinition, SelectedBox, BuildCaseOptimConstraintSet()); cdv.Orientation = SelectedSolution.PalletSolution.FirstCaseOrientation; cdv.Draw(graphics); // show generated bitmap on picture box control pbBoxesLayout.Image = graphics.Bitmap; } catch (Exception ex) { _log.Error(ex.ToString()); } // ### draw associated pallet solution try { // sanity check if (pbPalletSolution.Size.Width < 1 || pbPalletSolution.Size.Height < 1) { return; } // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pbPalletSolution.Size); // set camera position graphics.CameraPosition = Graphics3D.Corner_0; // set camera target graphics.Target = new Vector3D(0.0, 0.0, 0.0); // set viewport (not actually needed) graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // show images graphics.ShowTextures = true; // get selected solution CaseOptimSolution solution = SelectedSolution; // get selected box BoxProperties boxProperties = SelectedBox; // get selected pallet PalletProperties palletProperties = SelectedPallet; if (null != solution && null != boxProperties && null != palletProperties) { Vector3D outerDim = solution.CaseDefinition.OuterDimensions(boxProperties, BuildCaseOptimConstraintSet()); BoxProperties caseProperties = new BoxProperties(null, outerDim.X, outerDim.Y, outerDim.Z); caseProperties.SetColor(Color.Chocolate); CasePalletSolutionViewer.Draw(graphics, solution.PalletSolution, caseProperties, null, palletProperties); } // show generated bitmap or picture box control pbPalletSolution.Image = graphics.Bitmap; } catch (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); }