Exemplo n.º 1
0
 private void FinalizeImageFromViewParameters(viewParameters vParam, Graphics3DImage graphics)
 {
     graphics.Flush();
     // attempt to create directory
     string dirPath = Path.GetDirectoryName(vParam.path);
     try { Directory.CreateDirectory(dirPath); }
     catch (Exception ex) { _log.Error(ex.Message); }
     // check that directory exists
     if (!Directory.Exists(dirPath))
         throw new Exception(string.Format("Directory {0} does not exist!\n Can not generate output file!", Path.GetDirectoryName(vParam.path)));
     // save image
     graphics.SaveAs(vParam.path);
     _log.Info(string.Format("Successfully saved file {0}", vParam.path));
 }
Exemplo n.º 2
0
        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());
            }
        }
Exemplo n.º 3
0
        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;
        }