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 Pack(uint pickId, PackProperties packProperties) : base(pickId, packProperties.Length, packProperties.Width, packProperties.Height) { _packProperties = packProperties; _arrangement = _packProperties.Arrangement; _innerBox = new Box(0, packProperties.Box); }
public void TestIsPointBehind() { Box b1 = new Box(1, 100.0, 100.0, 100.0); Vector3D viewDir = new Vector3D(1.0, 1.0, -1.0); Assert.True(b1.PointBehind(new Vector3D(50.0, 150.0, 50.0), viewDir)); Assert.False(b1.PointBehind(new Vector3D(50.0, -150.0, 50.0), viewDir)); }
public void TestBoxInFront() { Vector3D vCameraPos = new Vector3D(-10000.0, -10000.0, 10000.0); Vector3D vTarget = new Vector3D(0.0, 0.0, 0.0); Vector3D vDir = vTarget - vCameraPos; Box b1 = new Box(1, 100.0, 100.0, 100.0); b1.Position = new Vector3D(900.0, 900.0, 0.0); Box b2 = new Box(2, 100.0, 100.0, 100.0); b2.Position = new Vector3D(800.0, 900.0, 0.0); Box b3 = new Box(3, 100.0, 100.0, 100.0); b3.Position = new Vector3D(900.0, 800.0, 0.0); Box b4 = new Box(3, 100.0, 100.0, 100.0); b4.Position = new Vector3D(800.0, 800.0, 0.0); Box b5 = new Box(3, 1000.0, 100.0, 100.0); b5.Position = new Vector3D(0.0, 900.0, 0.0); Box b6 = new Box(3, 100.0, 1000.0, 100.0); b6.Position = new Vector3D(900.0, 0.0, 0.0); Assert.False(b2.BoxInFront(b1, vDir)); Assert.False(b3.BoxInFront(b1, vDir)); Assert.False(b4.BoxInFront(b1, vDir)); Assert.False(b4.BoxInFront(b2, vDir)); Assert.False(b4.BoxInFront(b3, vDir)); Assert.False(b3.BoxInFront(b5, vDir)); Assert.False(b2.BoxInFront(b6, vDir)); }
public void TestCompareOrtho() { Vector3D vCameraPos = new Vector3D(-10000.0, -10000.0, 10000.0); Vector3D vTarget = new Vector3D(0.0, 0.0, 0.0); BoxComparer comparer = new BoxComparer(vCameraPos, vTarget); Box b1 = new Box(1, 100.0, 100.0, 100.0); b1.Position = new Vector3D(900.0, 900.0, 0.0); Box b2 = new Box(2, 100.0, 100.0, 100.0); b2.Position = new Vector3D(800.0, 900.0, 0.0); Box b3 = new Box(3, 100.0, 100.0, 100.0); b3.Position = new Vector3D(900.0, 800.0, 0.0); Box b4 = new Box(4, 100.0, 100.0, 100.0); b4.Position = new Vector3D(800.0, 800.0, 0.0); Assert.AreEqual(0, comparer.Compare(b1, b1)); Assert.AreEqual(-1, comparer.Compare(b1, b2)); Assert.AreEqual(1, comparer.Compare(b2, b1)); Assert.AreEqual(-1, comparer.Compare(b1, b3)); Assert.AreEqual(1, comparer.Compare(b3, b1)); Assert.AreEqual(-1, comparer.Compare(b1, b4)); Assert.AreEqual(1, comparer.Compare(b4, b1)); Assert.AreEqual(-1, comparer.Compare(b2, b4)); Assert.AreEqual(1, comparer.Compare(b4, b2)); Assert.AreEqual(-1, comparer.Compare(b3, b4)); Assert.AreEqual(1, comparer.Compare(b4, b3)); }
public Pack(uint pickId, PackProperties packProperties, BoxPosition position) : base(pickId, packProperties, position) { _packProperties = packProperties; _arrangement = _packProperties.Arrangement; _innerBox = new Box(0, packProperties.Box); _forceTransparency = false; }
public void TestNormals() { Box b = new Box(1, 100.0, 100.0, 100.0); Assert.AreEqual(-Vector3D.XAxis, b.Faces[0].Normal); Assert.AreEqual(Vector3D.XAxis, b.Faces[1].Normal); Assert.AreEqual(-Vector3D.YAxis, b.Faces[2].Normal); Assert.AreEqual(Vector3D.YAxis, b.Faces[3].Normal); Assert.AreEqual(-Vector3D.ZAxis, b.Faces[4].Normal); Assert.AreEqual(Vector3D.ZAxis, b.Faces[5].Normal); }
public void TestCompareEqualRank() { BoxComparer comparer = new BoxComparer(new Vector3D(-10000.0, -10000.0, 10000.0), new Vector3D(0.0, 0.0, 0.0)); Box b1 = new Box(1, 200.0, 100.0, 100.0); b1.Position = new Vector3D(800.0, 200.0, 0.0); Box b2 = new Box(2, 200.0, 100.0, 100.0); b2.Position = new Vector3D(200.0, 800.0, 0.0); Assert.AreEqual(0, comparer.Compare(b1, b2)); Assert.AreEqual(0, comparer.Compare(b2, b1)); }
public void TestCompareDifferent() { BoxComparer comparer = new BoxComparer(new Vector3D(-10000.0, -10000.0, 10000.0), new Vector3D(0.0, 0.0, 0.0)); Box b1 = new Box(1, 1000.0, 100.0, 100.0); b1.Position = new Vector3D(0.0, 900.0, 0.0); Box b2 = new Box(2, 100.0, 100.0, 100.0); b2.Position = new Vector3D(400.0, 800.0, 0.0); Assert.AreEqual(-1, comparer.Compare(b1, b2)); Assert.AreEqual(1, comparer.Compare(b2, b1)); }
public void DrawBox(Box box) { System.Drawing.Graphics g = Graphics; // get points Point[] pt = TransformPoint( box.TopFace.Points); // draw solid face Brush brushSolid = new SolidBrush(box.TopFace.ColorFill); g.FillPolygon(brushSolid, pt); Brush brushPath = new SolidBrush(box.TopFace.ColorPath); Pen penPath = new Pen(brushPath); g.DrawPolygon(penPath, pt); }
/// <summary> /// Use this method when drawing a solution that belongs an analysis /// </summary> public void Draw(Graphics3D graphics) { if (null == _solution) return; // initialize Graphics3D object if (!graphics.ShowBoxIds) { // draw pallet Pallet pallet = new Pallet(_analysis.PalletProperties); pallet.Draw(graphics, Transform3D.Identity); } // draw solution uint pickId = 0; foreach (ILayer layer in _solution) { CylinderLayer cylLayer = layer as CylinderLayer; if (null != cylLayer) { foreach (Vector3D pos in cylLayer) graphics.AddCylinder( new Cylinder(pickId++, _analysis.CylinderProperties, new CylPosition(pos, HalfAxis.HAxis.AXIS_Z_P)) ); } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { Box box = new Box(pickId++, _analysis.InterlayerProperties); // set position box.Position = new Vector3D( 0.5 * (_analysis.PalletProperties.Length - _analysis.InterlayerProperties.Length) , 0.5 * (_analysis.PalletProperties.Width - _analysis.InterlayerProperties.Width) , interlayerPos.ZLow); // draw graphics.AddBox(box); } } if (_showDimensions) { if (_showDimensions) { graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1) , Color.Black, false)); graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2) , Color.Red, true)); } } }
/// <summary> /// Draw case solution /// </summary> public void Draw(Graphics3D graphics) { if (null == _caseSolution) throw new Exception("No case solution defined!"); // load pallet solution BoxProperties caseProperties; CasePalletSolution palletSolution = _caseSolution.PalletSolutionDesc.LoadPalletSolution(); if (null == palletSolution) caseProperties = new BoxProperties(null, _caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight); else { CasePalletAnalysis palletAnalysis = palletSolution.Analysis; // retrieve case properties caseProperties = palletAnalysis.BProperties as BoxProperties; } if (null == caseProperties) return; // draw case (inside) Case case_ = new Case(caseProperties); case_.DrawInside(graphics); // get case analysis BoxCasePalletAnalysis caseAnalysis = _caseSolution.ParentCaseAnalysis; // draw solution uint pickId = 0; foreach (ILayer layer in _caseSolution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) graphics.AddBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition)); } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { Box box = new Box(pickId++, caseAnalysis.InterlayerProperties); // set position box.Position = new Vector3D(0.0, 0.0, interlayerPos.ZLow); // draw graphics.AddBox(box); } } // get case analysis if (_showDimensions) graphics.AddDimensions(new DimensionCube(_caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight)); }
public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { if (null == _dt) return; DataCase dtCase = _dt as DataCase; if (null != dtCase) { Box b = new Box(0, ToCase(dtCase)); graphics.AddBox(b); graphics.AddDimensions(new DimensionCube(dtCase.OuterDimensions)); } DataBox dtBox = _dt as DataBox; if (null != dtBox) { Box b = new Box(0, ToBox(dtBox)); graphics.AddBox(b); graphics.AddDimensions(new DimensionCube(dtBox.Dimensions)); } DataPallet dtPallet = _dt as DataPallet; if (null != dtPallet) { Pallet pallet = new Pallet(ToPallet(dtPallet)); pallet.Draw(graphics, Sharp3D.Math.Core.Transform3D.Identity); graphics.AddDimensions(new DimensionCube(dtPallet.Dimensions)); } DataInterlayer dtInterlayer = _dt as DataInterlayer; if (null != dtInterlayer) { graphics.AddBox(new Box(0, ToInterlayer(dtInterlayer))); graphics.AddDimensions(new DimensionCube(dtInterlayer.Dimensions)); } DataPalletCap dtPalletCap = _dt as DataPalletCap; if (null != dtPalletCap) { PalletCap palletCap = new PalletCap(0, ToPalletCap(dtPalletCap), Sharp3D.Math.Core.Vector3D.Zero); palletCap.Draw(graphics); graphics.AddDimensions(new DimensionCube(dtPalletCap.Dimensions)); } DataCylinder dtCylinder = _dt as DataCylinder; if (null != dtCylinder) { Cylinder cyl = new Cylinder(0, ToCylinder(dtCylinder)); graphics.AddCylinder(cyl); } }
public void Draw(Graphics3D graphics) { // sanity check if (null == _solution) return; InterlayerProperties interlayerProperties = _analysis.InterlayerProperties; // draw pallet Pallet pallet = new Pallet(_analysis.PalletProperties); pallet.Draw(graphics, Transform3D.Identity); // draw solution uint pickid = 0; for (int iLayerIndex = 0; iLayerIndex < _solution.LayerCount; ++iLayerIndex) { bool hasInterlayer = false; double zInterlayer = 0.0; BoxLayer blayer = _solution.GetBoxLayer(iLayerIndex, ref hasInterlayer, ref zInterlayer); if (hasInterlayer && (null != interlayerProperties)) { // instantiate box Box box = new Box(pickid++, interlayerProperties); // set position box.Position = new Vector3D( 0.5 * (_analysis.PalletProperties.Length - interlayerProperties.Length) , 0.5 * (_analysis.PalletProperties.Width - interlayerProperties.Width) , zInterlayer); // draw graphics.AddBox(box); } foreach (BoxPosition bPosition in blayer) graphics.AddBox(new Pack(pickid++, _analysis.PackProperties, bPosition)); if (_showDimensions) { graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1) , Color.Black, false)); graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2) , Color.Red, true)); } } }
/// <summary> /// Use this method when solution does not refer an analysis (e.g. when displaying CaseOptimizer result) /// </summary> public static void Draw(Graphics3D graphics , CasePalletSolution solution , BoxProperties boxProperties, InterlayerProperties interlayerProperties, PalletProperties palletProperties) { // draw pallet Pallet pallet = new Pallet(palletProperties); pallet.Draw(graphics, Transform3D.Identity); // draw solution uint pickId = 0; foreach (ILayer layer in solution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) graphics.AddBox(new Box(pickId++, boxProperties, bPosition)); } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos && null != interlayerProperties) { Box box = new Box(pickId++, interlayerProperties); // set position box.Position = new Vector3D( 0.5 * (palletProperties.Length - interlayerProperties.Length) , 0.5 * (palletProperties.Width - interlayerProperties.Width) , interlayerPos.ZLow); // draw graphics.AddBox(box); } } // always show dimensions BoxLayer bLayer = solution[solution.Count - 1] as BoxLayer; double palletHeight = solution[solution.Count - 1].ZLow + (null != bLayer ? bLayer.Thickness(boxProperties) : 0.0); // show dimensions graphics.AddDimensions(new DimensionCube(solution.BoundingBox, Color.Black, false)); graphics.AddDimensions(new DimensionCube(solution.LoadBoundingBox, Color.Red, true)); }
private void SortLayer(ref List <Box> layerList) { foreach (Box b in layerList) { b.ApplyElong(-_tuneParam); } // build y list List <double> yList = new List <double>(); foreach (Box b in layerList) { if (!yList.Contains(b.YMin)) { yList.Add(b.YMin); } if (!yList.Contains(b.YMax)) { yList.Add(b.YMax); } } yList.Sort(); if (_direction.Y < 0) { yList.Reverse(); } List <Box> treeList = new List <Box>(); List <Box> resList = new List <Box>(); // sweep stage foreach (double y in yList) { // clean treelist if (_direction.Y > 0.0) { CleanByYMax(treeList, y); // add new List <Box> listYMin = GetByYMin(layerList, y); foreach (Box by in listYMin) { treeList.Add(by); if (_direction.X > 0.0) { treeList.Sort(new BoxComparerXMin(_direction)); } else { treeList.Sort(new BoxComparerXMax(_direction)); } // find successor of by int id = treeList.FindIndex(delegate(Box b) { return(b.PickId == by.PickId); }); Box successor = null; if (id < treeList.Count - 1) { successor = treeList[id + 1]; } // insert by if (null == successor) { resList.Add(by); } else { int idBefore = resList.FindIndex(delegate(Box b) { return(b.PickId == successor.PickId); }); resList.Insert(idBefore, by); } } } else { CleanByYMin(treeList, y); // add new List <Box> listYMax = GetByYMax(layerList, y); foreach (Box by in listYMax) { treeList.Add(by); if (_direction.X > 0.0) { treeList.Sort(new BoxComparerXMin(_direction)); } else { treeList.Sort(new BoxComparerXMax(_direction)); } // find successor of by int id = treeList.FindIndex(delegate(Box b) { return(b.PickId == by.PickId); }); Box successor = null; if (id < treeList.Count - 1) { successor = treeList[id + 1]; } // insert by if (null == successor) { resList.Add(by); } else { int idBefore = resList.FindIndex(delegate(Box b) { return(b.PickId == successor.PickId); }); resList.Insert(idBefore, by); } } } } layerList.Clear(); resList.Reverse(); layerList.AddRange(resList); foreach (Box b in layerList) { b.ApplyElong(_tuneParam); } }
public void Add(Box b) { _boxes.Add(b); }
public void Draw(Graphics3D graphics, Vector3D dimensions, Color color, Transform3D t) { double coefX = dimensions.X / _defaultDimensions.X; double coefY = dimensions.Y / _defaultDimensions.Y; double coefZ = dimensions.Z / _defaultDimensions.Z; uint pickId = 0; foreach (Position pos in _positions) { double coef0 = coefX, coef1 = coefY, coef2 = coefZ; if (pos.Axis1 == HalfAxis.HAxis.AXIS_X_P && pos.Axis2 == HalfAxis.HAxis.AXIS_Y_P) { coef0 = coefX; coef1 = coefY; } else if (pos.Axis1 == HalfAxis.HAxis.AXIS_Y_P && pos.Axis2 == HalfAxis.HAxis.AXIS_X_N) { coef0 = coefY; coef1 = coefX; } Vector3D dim = _lumbers[pos.Index]; Box box = new Box(pickId++, dim.X * coef0, dim.Y * coef1, dim.Z * coef2); box.SetAllFacesColor(color); box.Position = t.transform(new Vector3D(pos.XYZ.X * coefX, pos.XYZ.Y * coefY, pos.XYZ.Z * coefZ)); box.LengthAxis = Basics.HalfAxis.ToVector3D(HalfAxis.Transform(pos.Axis1, t)); ; box.WidthAxis = Basics.HalfAxis.ToVector3D(HalfAxis.Transform(pos.Axis2, t)); ; graphics.AddBox(box); } }
public void AddBox(Box box) { if (!box.IsValid) throw new GraphicsException("Box is invalid and cannot be drawn!"); _boxes.Add(box); }
internal void Draw(Box box) { System.Drawing.Graphics g = Graphics; if (box is Pack) { Pack pack = box as Pack; pack.Draw(this); } else { Vector3D[] points = box.Points; Face[] faces = box.Faces; for (int i = 0; i < 6; ++i) { // Face Face face = faces[i]; // face normal Vector3D normal = face.Normal; // visible ? if (!faces[i].IsVisible(_vTarget - _vCameraPos)) continue; // color faces[i].ColorFill = box.Colors[i]; double cosA = System.Math.Abs(Vector3D.DotProduct(faces[i].Normal, VLight)); Color color = Color.FromArgb((int)(faces[i].ColorFill.R * cosA), (int)(faces[i].ColorFill.G * cosA), (int)(faces[i].ColorFill.B * cosA)); // points Vector3D[] points3D = faces[i].Points; Point[] pt = TransformPoint(GetCurrentTransformation(), points3D); // draw solid face Brush brush = new SolidBrush(color); g.FillPolygon(brush, pt); // draw textures if (null != face.Textures && ShowTextures) foreach (Texture texture in face.Textures) { Point[] ptsImage = TransformPoint(GetCurrentTransformation(), box.PointsImage(i, texture)); Point[] pts = new Point[3]; pts[0] = ptsImage[3]; pts[1] = ptsImage[2]; pts[2] = ptsImage[0]; g.DrawImage(texture.Bitmap, pts); } // draw path Brush brushPath = new SolidBrush(faces[i].ColorPath); Pen penPathThick = new Pen(brushPath, box.IsBundle ? 2.0f : 1.5f); int ptCount = pt.Length; for (int j = 1; j < ptCount; ++j) g.DrawLine(penPathThick, pt[j - 1], pt[j]); g.DrawLine(penPathThick, pt[ptCount - 1], pt[0]); // draw bundle lines if (box.IsBundle && i < 4) { Pen penPathThin = new Pen(brushPath, 1.5f); int noSlice = Math.Min(box.BundleFlats, 4); for (int iSlice = 0; iSlice < noSlice - 1; ++iSlice) { Vector3D[] ptSlice = new Vector3D[2]; ptSlice[0] = points3D[0] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[3] - points3D[0]); ptSlice[1] = points3D[1] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[2] - points3D[1]); Point[] pt2D = TransformPoint(GetCurrentTransformation(), ptSlice); g.DrawLine(penPathThin, pt2D[0], pt2D[1]); } } } // draw box tape if (box.ShowTape && faces[5].IsVisible(_vTarget - _vCameraPos)) { // get color double cosA = System.Math.Abs(Vector3D.DotProduct(faces[5].Normal, VLight)); Color color = Color.FromArgb((int)(box.TapeColor.R * cosA), (int)(box.TapeColor.G * cosA), (int)(box.TapeColor.B * cosA)); // instantiate brush Brush brushTape = new SolidBrush(color); // get tape points Point[] pts = TransformPoint(GetCurrentTransformation(), box.TapePoints); // fill polygon g.FillPolygon(brushTape, pts); // draw path Brush brushPath = new SolidBrush(faces[5].ColorPath); Pen penPathThick = new Pen(brushPath, 1.5f); int ptCount = pts.Length; for (int j = 1; j < ptCount; ++j) g.DrawLine(penPathThick, pts[j - 1], pts[j]); g.DrawLine(penPathThick, pts[ptCount - 1], pts[0]); } } if (_showBoxIds) { // draw box id Point ptId = TransformPoint(GetCurrentTransformation(), box.TopFace.Center); g.DrawString( box.PickId.ToString() , new Font("Arial", 8.0f) , Brushes.Black , new Rectangle(ptId.X - 15, ptId.Y - 10, 30, 20) , StringFormat.GenericDefault); g.DrawString( _boxDrawingCounter.ToString() , new Font("Arial", 8.0f) , Brushes.Red , new Rectangle(ptId.X + 5, ptId.Y - 10, 30, 20) , StringFormat.GenericDefault); } ++_boxDrawingCounter; }
// list of boxes public List<Box> BuildListOfBoxes(Vector3D dimensions, Color color, Transform3D t) { List<Box> listPalletLumbers = new List<Box>(); double coefX = dimensions.X / _defaultDimensions.X; double coefY = dimensions.Y / _defaultDimensions.Y; double coefZ = dimensions.Z / _defaultDimensions.Z; uint pickId = 0; foreach (Position pos in _positions) { double coef0 = coefX, coef1 = coefY, coef2 = coefZ; if (pos.Axis1 == HalfAxis.HAxis.AXIS_X_P && pos.Axis2 == HalfAxis.HAxis.AXIS_Y_P) { coef0 = coefX; coef1 = coefY; } else if (pos.Axis1 == HalfAxis.HAxis.AXIS_Y_P && pos.Axis2 == HalfAxis.HAxis.AXIS_X_N) { coef0 = coefY; coef1 = coefX; } Vector3D dim = _lumbers[pos.Index]; Box box = new Box(pickId++, dim.X * coef0, dim.Y * coef1, dim.Z * coef2); box.SetAllFacesColor(color); box.Position = t.transform(new Vector3D(pos.XYZ.X * coefX, pos.XYZ.Y * coefY, pos.XYZ.Z * coefZ)); box.LengthAxis = Basics.HalfAxis.ToVector3D(HalfAxis.Transform(pos.Axis1, t)); ; box.WidthAxis = Basics.HalfAxis.ToVector3D(HalfAxis.Transform(pos.Axis2, t)); ; listPalletLumbers.Add(box); } return listPalletLumbers; }
private void AppendBoxElement(BoxProperties boxProperties, XmlElement elemCaseAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // box element XmlElement elemBox = CreateElement("box", null, elemCaseAnalysis, xmlDoc, ns); // name CreateElement("name", boxProperties.Name, elemBox, xmlDoc, ns); // description CreateElement("description", boxProperties.Description, elemBox, xmlDoc, ns); AppendElementValue(xmlDoc, elemBox, "length", UnitsManager.UnitType.UT_LENGTH, boxProperties.Length); AppendElementValue(xmlDoc, elemBox, "width", UnitsManager.UnitType.UT_LENGTH, boxProperties.Width); AppendElementValue(xmlDoc, elemBox, "height", UnitsManager.UnitType.UT_LENGTH, boxProperties.Height); AppendElementValue(xmlDoc, elemBox, "weight", UnitsManager.UnitType.UT_MASS, boxProperties.Weight); // view_box_iso // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Box box = new Box(0, boxProperties); graphics.AddBox(box); graphics.AddDimensions(new DimensionCube(box.Length, box.Width, box.Height)); graphics.Flush(); // --- // view_box_iso XmlElement elemImage = xmlDoc.CreateElement("view_box_iso", ns); TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style"); styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemBox.AppendChild(elemImage); // save image ? SaveImageAs(graphics.Bitmap, "view_box_iso.png"); }
protected mesh CreateCaseMesh(BoxProperties caseProperties) { // build box Box box = new Box(0, caseProperties); // build list of vertices / normals / UVs ulong vertexCount = 0, normalCount = 0, uvCount = 0; List<double> doubleArrayPosition = new List<double>(), doubleArrayNormal = new List<double>(), doubleArrayUV = new List<double>(); foreach (Vector3D p in box.PointsSmallOffset) { doubleArrayPosition.Add(p.X); doubleArrayPosition.Add(p.Y); doubleArrayPosition.Add(p.Z); ++vertexCount; } foreach (Vector3D n in box.Normals) { doubleArrayNormal.Add(n.X); doubleArrayNormal.Add(n.Y); doubleArrayNormal.Add(n.Z); ++normalCount; } foreach (Vector2D uv in box.UVs) { doubleArrayUV.Add(uv.X); doubleArrayUV.Add(uv.Y); ++uvCount; } mesh caseMesh = new mesh(); // position source source casePositionSource = new source() { id = "case_position", name = "case_position" }; float_array farrayPosition = new float_array { id = "case_position_float_array", count = (ulong)doubleArrayPosition.Count, Values = doubleArrayPosition.ToArray() }; casePositionSource.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 3, count = vertexCount, source = "#case_position_float_array", param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } } } }; casePositionSource.Item = farrayPosition; // normal source source casePositionNormal = new source() { id = "case_normal", name = "case_normal" }; float_array farrayNormal = new float_array { id = "case_normal_float_array", count = (ulong)doubleArrayNormal.Count, Values = doubleArrayNormal.ToArray() }; casePositionNormal.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 3, count = normalCount, source = "#case_normal_float_array", param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } } } }; casePositionNormal.Item = farrayNormal; // uv source source casePositionUV = new source() { id = "case_UV", name = "pallet_UV" }; float_array farrayUV = new float_array { id = "case_UV_float_array", count = (ulong)doubleArrayUV.Count, Values = doubleArrayUV.ToArray() }; casePositionUV.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 2, count = vertexCount, source = "#case_UV_float_array", param = new param[] { new param() { name = "S", type = "float" }, new param() { name = "T", type = "float" } } } }; casePositionUV.Item = farrayUV; // insert sources caseMesh.source = new source[] { casePositionSource, casePositionNormal, casePositionUV }; // vertices InputLocal verticesInput = new InputLocal() { semantic = "POSITION", source = "#case_position" }; caseMesh.vertices = new vertices() { id = "case_vertex", input = new InputLocal[] { verticesInput } }; List<object> trianglesList = new List<object>(); // build list of triangles foreach (HalfAxis.HAxis axis in HalfAxis.All) { triangles trianglesCase = new triangles() { material = string.Format("materialCase{0}", (uint)axis), count = 2 }; trianglesCase.input = new InputLocalOffset[] { new InputLocalOffset() { semantic="VERTEX", source="#case_vertex", offset=0} , new InputLocalOffset() { semantic="NORMAL", source="#case_normal", offset=1} , new InputLocalOffset() { semantic="TEXCOORD", source="#case_UV", offset=2, set=0, setSpecified=true } }; string triangle_string = string.Empty; foreach (TriangleIndices tr in box.TrianglesByFace(axis)) triangle_string += tr.ConvertToString(0); trianglesCase.p = triangle_string; trianglesList.Add(trianglesCase); } // build list of lines lines linesCase = new lines() { material = "materialCaseLines", count = 12, input = new InputLocalOffset[] { new InputLocalOffset() { semantic="VERTEX", source="#case_vertex", offset=0} }, p = "0 1 1 2 2 3 3 0 4 5 5 6 6 7 7 4 0 4 1 5 2 6 3 7" }; trianglesList.Add(linesCase); caseMesh.Items = trianglesList.ToArray(); return caseMesh; }
private void AppendInsideBoxElement(CasePalletAnalysis analysis, CasePalletSolution sol, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get caseOfBoxProperties CaseOfBoxesProperties caseOfBoxes = analysis.BProperties as CaseOfBoxesProperties; // get box properties BoxProperties boxProperties = caseOfBoxes.InsideBoxProperties; // elemBoxes XmlElement elemBox = xmlDoc.CreateElement("box", ns); elemPalletAnalysis.AppendChild(elemBox); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = boxProperties.Name; elemBox.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = boxProperties.Description; elemBox.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemBox, "length", UnitsManager.UnitType.UT_LENGTH, boxProperties.Length); AppendElementValue(xmlDoc, elemBox, "width", UnitsManager.UnitType.UT_LENGTH, boxProperties.Width); AppendElementValue(xmlDoc, elemBox, "height", UnitsManager.UnitType.UT_LENGTH, boxProperties.Height); AppendElementValue(xmlDoc, elemBox, "weight", UnitsManager.UnitType.UT_MASS, boxProperties.Weight); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Box box = new Box(0, boxProperties); graphics.AddBox(box); DimensionCube dc = new DimensionCube(box.Length, box.Width, box.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // --- // view_box_iso XmlElement elemImage = xmlDoc.CreateElement("view_box_iso", ns); TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style"); styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemBox.AppendChild(elemImage); // save image ? SaveImageAs(graphics.Bitmap, "view_box_iso.png"); }
private void AppendInterlayerElement(InterlayerProperties interlayerProp, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { // sanity check if (null == interlayerProp) return; // namespace string ns = xmlDoc.DocumentElement.NamespaceURI; // interlayer XmlElement elemInterlayer = xmlDoc.CreateElement("interlayer", ns); elemPalletAnalysis.AppendChild(elemInterlayer); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = interlayerProp.Name; elemInterlayer.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = interlayerProp.Description; elemInterlayer.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemInterlayer, "length", UnitsManager.UnitType.UT_LENGTH, interlayerProp.Length); AppendElementValue(xmlDoc, elemInterlayer, "width", UnitsManager.UnitType.UT_LENGTH, interlayerProp.Width); AppendElementValue(xmlDoc, elemInterlayer, "thickness", UnitsManager.UnitType.UT_LENGTH, interlayerProp.Thickness); AppendElementValue(xmlDoc, elemInterlayer, "weight", UnitsManager.UnitType.UT_MASS, interlayerProp.Weight); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; Box box = new Box(0, interlayerProp); graphics.AddBox(box); graphics.Flush(); // --- // view_interlayer_iso XmlElement elemImage = xmlDoc.CreateElement("view_interlayer_iso", ns); TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style"); styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemInterlayer.AppendChild(elemImage); // save image ? SaveImageAs(graphics.Bitmap, "view_interlayer_iso.png"); }
private void AppendCaseOfBoxesElement(CasePalletAnalysis analysis, CasePalletSolution sol, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get CaseOfBoxProperties CaseOfBoxesProperties caseOfBoxes = analysis.BProperties as CaseOfBoxesProperties; if (null == caseOfBoxes) return; // elemCaseOfBoxes XmlElement elemCaseOfBoxes = xmlDoc.CreateElement("caseOfBoxes", ns); elemPalletAnalysis.AppendChild(elemCaseOfBoxes); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = caseOfBoxes.Name; elemCaseOfBoxes.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = caseOfBoxes.Description; elemCaseOfBoxes.AppendChild(elemDescription); // length XmlElement elemNoX = xmlDoc.CreateElement("noX", ns); elemNoX.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iLength); elemCaseOfBoxes.AppendChild(elemNoX); // width XmlElement elemNoY = xmlDoc.CreateElement("noY", ns); elemNoY.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iWidth); elemCaseOfBoxes.AppendChild(elemNoY); // height XmlElement elemNoZ = xmlDoc.CreateElement("noZ", ns); elemNoZ.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iHeight); elemCaseOfBoxes.AppendChild(elemNoZ); // number of boxes XmlElement elemNoBoxes = xmlDoc.CreateElement("numberOfBoxes", ns); elemNoBoxes.InnerText = string.Format("{0}", caseOfBoxes.NumberOfBoxes); elemCaseOfBoxes.AppendChild(elemNoBoxes); // dim0 XmlElement eltDim0 = xmlDoc.CreateElement("dim0", ns); eltDim0.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Dim0); elemCaseOfBoxes.AppendChild(eltDim0); // dim1 XmlElement eltDim1 = xmlDoc.CreateElement("dim1", ns); eltDim1.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Dim1); elemCaseOfBoxes.AppendChild(eltDim1); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerLength", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideLength); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerWidth", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideWidth); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerHeight", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideHeight); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerVolume", UnitsManager.UnitType.UT_VOLUME, caseOfBoxes.InsideVolume * UnitsManager.FactorCubeLengthToVolume); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerLength", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Length); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerWidth", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Width); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerHeight", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Height); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerVolume", UnitsManager.UnitType.UT_VOLUME, caseOfBoxes.Volume * UnitsManager.FactorCubeLengthToVolume); AppendElementValue(xmlDoc, elemCaseOfBoxes, "emptyWeight", UnitsManager.UnitType.UT_MASS, caseOfBoxes.WeightEmpty); AppendElementValue(xmlDoc, elemCaseOfBoxes, "weight", UnitsManager.UnitType.UT_MASS, caseOfBoxes.Weight); // type converter TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); // view case of boxes iso1 Graphics3DImage graphics1 = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics1.CameraPosition = Graphics3D.Corner_0; CaseDefinitionViewer viewer = new CaseDefinitionViewer(caseOfBoxes.CaseDefinition, caseOfBoxes.InsideBoxProperties, caseOfBoxes.CaseOptimConstraintSet); viewer.CaseProperties = caseOfBoxes; viewer.Orientation = sol.FirstCaseOrientation; viewer.Draw(graphics1); graphics1.Flush(); // view case of boxes iso2 Graphics3DImage graphics2 = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics2.CameraPosition = Graphics3D.Corner_0; Box box = new Box(0, caseOfBoxes); graphics2.AddBox(box); graphics2.AddDimensions(new DimensionCube(caseOfBoxes.Length, caseOfBoxes.Width, caseOfBoxes.Height)); graphics2.Flush(); // view_caseOfBoxes_iso1 XmlElement elemImage1 = xmlDoc.CreateElement("view_caseOfBoxes_iso1", ns); elemImage1.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics1.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute1 = xmlDoc.CreateAttribute("style"); styleAttribute1.Value = string.Format("width:{0}pt;height:{1}pt", graphics1.Bitmap.Width / 3, graphics1.Bitmap.Height / 3); elemImage1.Attributes.Append(styleAttribute1); elemCaseOfBoxes.AppendChild(elemImage1); // save image SaveImageAs(graphics1.Bitmap, "view_caseOfBoxes_iso1.png"); // view_caseOfBoxes_iso2 XmlElement elemImage2 = xmlDoc.CreateElement("view_caseOfBoxes_iso2", ns); elemImage2.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics2.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute2 = xmlDoc.CreateAttribute("style"); styleAttribute2.Value = string.Format("width:{0}pt;height:{1}pt", graphics2.Bitmap.Width / 3, graphics2.Bitmap.Height / 3); elemImage2.Attributes.Append(styleAttribute2); elemCaseOfBoxes.AppendChild(elemImage2); // save image SaveImageAs(graphics2.Bitmap, "view_caseOfBoxes_iso2.png"); }
public void Export(string filePath) { PalletProperties palletProperties = _palletSolution.Analysis.PalletProperties; COLLADA model = new COLLADA(); // asset model.asset = new asset() { created = DateTime.Now, modified = DateTime.Now }; model.asset.keywords = "StackBuilder Pallet Case"; model.asset.title = _palletSolution.Title; model.asset.unit = new assetUnit() { name = "millimeters", meter = 0.001 }; model.asset.up_axis = UpAxisType.Z_UP; library_images images = new library_images(); library_materials materials = new library_materials(); library_effects effects = new library_effects(); library_geometries geometries = new library_geometries(); library_nodes nodes = new library_nodes(); library_cameras cameras = new library_cameras(); library_animations animations = new library_animations(); library_visual_scenes scenes = new library_visual_scenes(); COLLADAScene colladaScene = new COLLADAScene(); model.Items = new Object[] { images, materials, effects, geometries, nodes, cameras, animations, scenes }; model.scene = colladaScene; // colors and materials List<effect> listEffects = new List<effect>(); List<material> listMaterials = new List<material>(); List<image> listImages = new List<image>(); // effects effect effectPallet; material materialPallet; CreateMaterial(palletProperties.Color, null, null, "Pallet", out effectPallet, out materialPallet); listEffects.Add(effectPallet); listMaterials.Add(materialPallet); Box box = new Box(0, _palletSolution.Analysis.BProperties); // build list of effects / materials / images uint faceIndex = 0; foreach (Face face in box.Faces) { // build texture image if any string textureName = null; if (face.HasBitmap) { textureName = string.Format("textureFace_{0}", faceIndex); string texturePath = System.IO.Path.Combine( System.IO.Path.GetDirectoryName(filePath) , textureName + ".jpg"); double dimX = 0.0, dimY = 0.0; switch (faceIndex) { case 0: dimX = box.Width; dimY = box.Height; break; case 1: dimX = box.Width; dimY = box.Height; break; case 2: dimX = box.Length; dimY = box.Height; break; case 3: dimX = box.Length; dimY = box.Height; break; case 4: dimX = box.Length; dimY = box.Width; break; case 5: dimX = box.Length; dimY = box.Width; break; default: break; } face.ExtractFaceBitmap(dimX, dimY, _bmpWidth, texturePath); // create image listImages.Add( new image() { id = textureName + ".jpg", name = textureName + ".jpg", Item = @".\" + textureName + @".jpg" } ); } material materialCase; effect effectCase; CreateMaterial(face.ColorFill, textureName, "0", string.Format("Case{0}", faceIndex), out effectCase, out materialCase); listEffects.Add(effectCase); listMaterials.Add(materialCase); ++faceIndex; } // add to image list images.image = listImages.ToArray(); // case lines material effect effectCaseLines; material materialCaseLines; CreateMaterial(Color.Black, null, null, "CaseLines", out effectCaseLines, out materialCaseLines); listEffects.Add(effectCaseLines); listMaterials.Add(materialCaseLines); effects.effect = listEffects.ToArray(); materials.material = listMaterials.ToArray(); // geometries geometry geomPallet = new geometry() { id = "palletGeometry", name = "palletGeometry" }; geometry geomCase = new geometry() { id = "caseGeometry", name = "caseGeometry" }; geometries.geometry = new geometry[] { geomPallet, geomCase }; // pallet mesh meshPallet = CreatePalletMesh(palletProperties); geomPallet.Item = meshPallet; // case mesh meshCase = CreateCaseMesh(_palletSolution.Analysis.BProperties as BoxProperties); geomCase.Item = meshCase; // library_animations animation animationMain = new animation() { id = "animationMain_ID", name = "animationMain" }; animations.animation = new animation[] { animationMain }; List<object> listAnimationSource = new List<object>(); // library_visual_scenes visual_scene mainScene = new visual_scene() { id = "MainScene", name = "MainScene" }; scenes.visual_scene = new visual_scene[] { mainScene }; List<node> sceneNodes = new List<node>(); sceneNodes.Add(new node() { id = "PalletNode", name = "PalletNode", instance_geometry = new instance_geometry[] { new instance_geometry() { url = "#palletGeometry", bind_material = new bind_material() { technique_common = new instance_material[] { new instance_material() { symbol="materialPallet", target=string.Format("#{0}", materialPallet.id) } } } } } }); uint caseIndex = 0; foreach (ILayer layer in _palletSolution) { BoxLayer bLayer = layer as BoxLayer; if (null == bLayer) continue; foreach (BoxPosition bp in bLayer) { Vector3D translation = bp.Position; Vector3D rotations = bp.Transformation.Rotations; node caseNode = new node() { id = string.Format("CaseNode_{0}_ID", caseIndex), name = string.Format("CaseNode_{0}", caseIndex), ItemsElementName = new ItemsChoiceType2[] { ItemsChoiceType2.translate, ItemsChoiceType2.rotate, ItemsChoiceType2.rotate, ItemsChoiceType2.rotate }, Items = new object[] { new TargetableFloat3() { Values = new double[] { translation.X, translation.Y, translation.Z }, sid = "t", }, new rotate() { Values = new double[] { 1.0, 0.0, 0.0, rotations.X }, sid = "rx" }, new rotate() { Values = new double[] { 0.0, 1.0, 0.0, rotations.Y }, sid = "ry" }, new rotate() { Values = new double[] { 0.0, 0.0, 1.0, rotations.Z }, sid = "rz" } }, instance_geometry = new instance_geometry[] { new instance_geometry() { url="#caseGeometry", bind_material = new bind_material() { technique_common = new instance_material[] { new instance_material() { symbol="materialCase0", target="#material_Case0_ID" }, new instance_material() { symbol="materialCase1", target="#material_Case1_ID" }, new instance_material() { symbol="materialCase2", target="#material_Case2_ID" }, new instance_material() { symbol="materialCase3", target="#material_Case3_ID" }, new instance_material() { symbol="materialCase4", target="#material_Case4_ID" }, new instance_material() { symbol="materialCase5", target="#material_Case5_ID" }, new instance_material() { symbol="materialCaseLines", target="#material_CaseLines_ID"} } } } } }; sceneNodes.Add(caseNode); // animations CreateAnimation(caseIndex, (uint)_palletSolution.CaseCount, listAnimationSource, bp); // increment case index ++caseIndex; } } // add nodes mainScene.node = sceneNodes.ToArray(); animationMain.Items = listAnimationSource.ToArray(); // library_cameras camera cameraCamera = new camera() { id = "Camera-Camera", name = "Camera-Camera" }; cameraOpticsTechnique_commonPerspective cameraPerspective = new cameraOpticsTechnique_commonPerspective() { znear = new TargetableFloat() { sid = "znear", Value = 1.0 }, zfar = new TargetableFloat() { sid = "zfar", Value = 10000.0 } }; cameraCamera.optics = new cameraOptics() { technique_common = new cameraOpticsTechnique_common() { Item = cameraPerspective } }; cameras.camera = new camera[] { cameraCamera }; // colladaScene colladaScene.instance_visual_scene = new InstanceWithExtra() { url = "#MainScene" }; model.Save(filePath); model.Save(System.IO.Path.ChangeExtension(filePath, "xml")); }
static void Main(string[] args) { // instantiate BoxelOrderer orderer0 = new BoxelOrderer(); // fill BoxelOrderer class Box b0 = new Box(0, 400.0, 300.0, 200.0); b0.Position = new Vector3D(300.0, 0.0, 0.0); b0.LengthAxis = Vector3D.YAxis; b0.WidthAxis = -Vector3D.XAxis; orderer0.Add(b0); Box b1 = new Box(1, 400.0, 300.0, 200.0); b1.Position = new Vector3D(600.0, 0.0, 0.0); b1.LengthAxis = Vector3D.YAxis; b1.WidthAxis = -Vector3D.XAxis; orderer0.Add(b1); Box b2 = new Box(2, 400.0, 300.0, 200.0); b2.Position = new Vector3D(300.0, 400.0, 0.0); b2.LengthAxis = Vector3D.YAxis; b2.WidthAxis = -Vector3D.XAxis; orderer0.Add(b2); Box b3 = new Box(3, 400.0, 300.0, 200.0); b3.Position = new Vector3D(600.0, 400.0, 0.0); b3.LengthAxis = Vector3D.YAxis; b3.WidthAxis = -Vector3D.XAxis; orderer0.Add(b3); Box b4 = new Box(4, 400.0, 300.0, 200.0); b4.Position = new Vector3D(300.0, 800.0, 0.0); b4.LengthAxis = Vector3D.YAxis; b4.WidthAxis = -Vector3D.XAxis; orderer0.Add(b4); Box b5 = new Box(5, 400.0, 300.0, 200.0); b5.Position = new Vector3D(600.0, 800.0, 0.0); b5.LengthAxis = Vector3D.YAxis; b5.WidthAxis = -Vector3D.XAxis; orderer0.Add(b5); Box b6 = new Box(6, 400.0, 300.0, 200.0); b6.Position = new Vector3D(600.0, 0.0, 0.0); b6.LengthAxis = Vector3D.XAxis; b6.WidthAxis = Vector3D.YAxis; orderer0.Add(b6); Box b7 = new Box(7, 400.0, 300.0, 200.0); b7.Position = new Vector3D(600.0, 300.0, 0.0); b7.LengthAxis = Vector3D.XAxis; b7.WidthAxis = Vector3D.YAxis; orderer0.Add(b7); Box b8 = new Box(8, 400.0, 300.0, 200.0); b8.Position = new Vector3D(600.0, 600.0, 0.0); b8.LengthAxis = Vector3D.XAxis; b8.WidthAxis = Vector3D.YAxis; orderer0.Add(b8); Box b9 = new Box(9, 400.0, 300.0, 200.0); b9.Position = new Vector3D(600.0, 900.0, 0.0); b9.LengthAxis = Vector3D.XAxis; b9.WidthAxis = Vector3D.YAxis; orderer0.Add(b9); Vector3D target = Vector3D.Zero; // set direction 0 Vector3D camera = new Vector3D(-1000.0, -1000.0, 1000.0); orderer0.Direction = target - camera; List<Box> orderedList = orderer0.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 1 camera = new Vector3D(1000.0, -1000.0, 1000.0); orderer0.Direction = target - camera; orderedList = orderer0.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 2 camera = new Vector3D(1000.0, 1000.0, 1000.0); orderer0.Direction = target - camera; orderedList = orderer0.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 3 camera = new Vector3D(-1000.0, 1000.0, 1000.0); orderer0.Direction = target - camera; orderedList = orderer0.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); Console.WriteLine("########################################################"); // instantiate BoxelOrderer orderer1 = new BoxelOrderer(); // fill BoxelOrderer class Box b16 = new Box(0, 400.0, 300.0, 200.0); b16.Position = new Vector3D(0.0, 0.0, 0.0); b16.LengthAxis = Vector3D.XAxis; b16.WidthAxis = Vector3D.YAxis; orderer1.Add(b16); Box b17 = new Box(1, 400.0, 300.0, 200.0); b17.Position = new Vector3D(0.0, 300.0, 0.0); b17.LengthAxis = Vector3D.XAxis; b17.WidthAxis = Vector3D.YAxis; orderer1.Add(b17); Box b18 = new Box(2, 400.0, 300.0, 200.0); b18.Position = new Vector3D(0.0, 600.0, 0.0); b18.LengthAxis = Vector3D.XAxis; b18.WidthAxis = Vector3D.YAxis; orderer1.Add(b18); Box b19 = new Box(3, 400.0, 300.0, 200.0); b19.Position = new Vector3D(0.0, 900.0, 0.0); b19.LengthAxis = Vector3D.XAxis; b19.WidthAxis = Vector3D.YAxis; orderer1.Add(b19); Box b10 = new Box(4, 400.0, 300.0, 200.0); b10.Position = new Vector3D(700.0, 0.0, 0.0); b10.LengthAxis = Vector3D.YAxis; b10.WidthAxis = -Vector3D.XAxis; orderer1.Add(b10); Box b11 = new Box(5, 400.0, 300.0, 200.0); b11.Position = new Vector3D(1000.0, 0.0, 0.0); b11.LengthAxis = Vector3D.YAxis; b11.WidthAxis = -Vector3D.XAxis; orderer1.Add(b11); Box b12 = new Box(6, 400.0, 300.0, 200.0); b12.Position = new Vector3D(700.0, 400.0, 0.0); b12.LengthAxis = Vector3D.YAxis; b12.WidthAxis = -Vector3D.XAxis; orderer1.Add(b12); Box b13 = new Box(7, 400.0, 300.0, 200.0); b13.Position = new Vector3D(1000.0, 400.0, 0.0); b13.LengthAxis = Vector3D.YAxis; b13.WidthAxis = -Vector3D.XAxis; orderer1.Add(b13); Box b14 = new Box(8, 400.0, 300.0, 200.0); b14.Position = new Vector3D(700.0, 800.0, 0.0); b14.LengthAxis = Vector3D.YAxis; b14.WidthAxis = -Vector3D.XAxis; orderer1.Add(b14); Box b15 = new Box(9, 400.0, 300.0, 200.0); b15.Position = new Vector3D(1000.0, 800.0, 0.0); b15.LengthAxis = Vector3D.YAxis; b15.WidthAxis = -Vector3D.XAxis; orderer1.Add(b15); // set direction 0 camera = new Vector3D(-1000.0, -1000.0, 1000.0); orderer1.Direction = target - camera; orderedList = orderer1.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 1 camera = new Vector3D(1000.0, -1000.0, 1000.0); orderer1.Direction = target - camera; orderedList = orderer1.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 2 camera = new Vector3D(1000.0, 1000.0, 1000.0); orderer1.Direction = target - camera; orderedList = orderer1.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 3 camera = new Vector3D(-1000.0, 1000.0, 1000.0); orderer1.Direction = target - camera; orderedList = orderer1.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); Console.WriteLine("########################################################"); // ##################################################################################### // instantiate BoxelOrderer orderer3 = new BoxelOrderer(); // fill BoxelOrderer class Box b_0 = new Box(0, 400.0, 300.0, 200.0); b_0.Position = new Vector3D(1200.0, 0.0, 200.0); b_0.LengthAxis = Vector3D.YAxis; b_0.WidthAxis = -Vector3D.XAxis; orderer3.Add(b_0); Box b_1 = new Box(1, 400.0, 300.0, 200.0); b_1.Position = new Vector3D(900.0, 0.0, 200.0); b_1.LengthAxis = Vector3D.YAxis; b_1.WidthAxis = -Vector3D.XAxis; orderer3.Add(b_1); Box b_2 = new Box(2, 400.0, 300.0, 200.0); b_2.Position = new Vector3D(600.0, 0.0, 200.0); b_2.LengthAxis = Vector3D.YAxis; b_2.WidthAxis = -Vector3D.XAxis; orderer3.Add(b_2); Box b_3 = new Box(3, 400.0, 300.0, 200.0); b_3.Position = new Vector3D(300.0, 0.0, 200.0); b_3.LengthAxis = Vector3D.YAxis; b_3.WidthAxis = -Vector3D.XAxis; orderer3.Add(b_3); Box b_4 = new Box(4, 400.0, 300.0, 200.0); b_4.Position = new Vector3D(1200.0, 700.0, 200.0); b_4.LengthAxis = -Vector3D.XAxis; b_4.WidthAxis = -Vector3D.YAxis; orderer3.Add(b_4); Box b_5 = new Box(5, 400.0, 300.0, 200.0); b_5.Position = new Vector3D(800.0, 700.0, 200.0); b_5.LengthAxis = -Vector3D.XAxis; b_5.WidthAxis = -Vector3D.YAxis; orderer3.Add(b_5); Box b_6 = new Box(6, 400.0, 300.0, 200.0); b_6.Position = new Vector3D(400.0, 700.0, 200.0); b_6.LengthAxis = -Vector3D.XAxis; b_6.WidthAxis = -Vector3D.YAxis; orderer3.Add(b_6); Box b_7 = new Box(7, 400.0, 300.0, 200.0); b_7.Position = new Vector3D(1200.0, 1000.0, 200.0); b_7.LengthAxis = -Vector3D.XAxis; b_7.WidthAxis = -Vector3D.YAxis; orderer3.Add(b_7); Box b_8 = new Box(8, 400.0, 300.0, 200.0); b_8.Position = new Vector3D(800.0, 1000.0, 200.0); b_8.LengthAxis = -Vector3D.XAxis; b_8.WidthAxis = -Vector3D.YAxis; orderer3.Add(b_8); Box b_9 = new Box(9, 400.0, 300.0, 200.0); b_9.Position = new Vector3D(400.0, 1000.0, 200.0); b_9.LengthAxis = -Vector3D.XAxis; b_9.WidthAxis = -Vector3D.YAxis; orderer3.Add(b_9); // set direction 0 camera = new Vector3D(-1000.0, -1000.0, 1000.0); orderer3.Direction = target - camera; orderedList = orderer3.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 1 camera = new Vector3D(1000.0, -1000.0, 1000.0); orderer3.Direction = target - camera; orderedList = orderer3.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 2 camera = new Vector3D(1000.0, 1000.0, 1000.0); orderer3.Direction = target - camera; orderedList = orderer3.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); // set direction 3 camera = new Vector3D(-1000.0, 1000.0, 1000.0); orderer3.Direction = target - camera; orderedList = orderer3.GetSortedList(); Console.WriteLine("******************************"); foreach (Box b in orderedList) Console.Write("{0} ", b.PickId); Console.WriteLine(); Console.WriteLine("########################################################"); }
public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { BoxProperties boxProperties = new BoxProperties(null, (double)nudLength.Value, (double)nudWidth.Value, (double)nudHeight.Value); boxProperties.SetAllColors(_faceColors); boxProperties.TextureList = _textures; boxProperties.ShowTape = ShowTape; boxProperties.TapeColor = TapeColor; boxProperties.TapeWidth = TapeWidth; Box box = new Box(0, boxProperties); graphics.AddBox(box); graphics.AddDimensions(new DimensionCube((double)nudLength.Value, (double)nudWidth.Value, (double)nudHeight.Value)); }
private void AppendBundleElement(BundleProperties bundleProp, XmlElement elemAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; if (null == bundleProp) return; // bundle XmlElement elemBundle = CreateElement("bundle", null, elemAnalysis, xmlDoc, ns); elemAnalysis.AppendChild(elemBundle); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = bundleProp.Name; elemBundle.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = bundleProp.Description; elemBundle.AppendChild(elemDescription); // length / width / number of flats / unit thickness / unit weight / total thickness / total weight AppendElementValue(xmlDoc, elemBundle, "length", UnitsManager.UnitType.UT_LENGTH, bundleProp.Length); AppendElementValue(xmlDoc, elemBundle, "width", UnitsManager.UnitType.UT_LENGTH, bundleProp.Width); AppendElementValue(xmlDoc, elemBundle, "numberOfFlats", bundleProp.NoFlats); AppendElementValue(xmlDoc, elemBundle, "unitThickness", UnitsManager.UnitType.UT_LENGTH, bundleProp.UnitThickness); AppendElementValue(xmlDoc, elemBundle, "unitWeight", UnitsManager.UnitType.UT_MASS, bundleProp.UnitWeight); AppendElementValue(xmlDoc, elemBundle, "totalThickness", UnitsManager.UnitType.UT_LENGTH, bundleProp.UnitThickness * bundleProp.NoFlats); AppendElementValue(xmlDoc, elemBundle, "totalWeight", UnitsManager.UnitType.UT_MASS, bundleProp.UnitWeight * bundleProp.NoFlats); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; Box box = new Box(0, bundleProp); graphics.AddBox(box); DimensionCube dc = new DimensionCube(bundleProp.Length, bundleProp.Width, bundleProp.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // --- // view_bundle_iso XmlElement elemImage = xmlDoc.CreateElement("view_bundle_iso", ns); TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style"); styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemBundle.AppendChild(elemImage); // save images ? SaveImageAs(graphics.Bitmap, "view_bundle_iso.png"); }
private void Draw() { try { // get current descriptor PalletSolutionDesc desc = CurrentSolutionDesc; // sanity check if (null == desc || pictureBoxCase.Size.Width < 1 || pictureBoxCase.Size.Height < 1 || pictureBoxSolution.Size.Width < 1 || pictureBoxSolution.Size.Height < 1) return; // load document Document document = new Document(desc.FullFilePath, null); if (document.Analyses.Count == 0) return; // get analysis and solution CasePalletAnalysis analysis = document.Analyses[0]; { Graphics3DImage graphics = new Graphics3DImage(pictureBoxCase.Size); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Box box = new Box(0, analysis.BProperties); graphics.AddBox(box); graphics.AddDimensions(new DimensionCube(box.Length, box.Width, box.Height)); graphics.Flush(); pictureBoxCase.Image = graphics.Bitmap; } { // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBoxSolution.Size); // set camera position graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; // instantiate solution viewer CasePalletSolutionViewer sv = new CasePalletSolutionViewer(analysis.Solutions[0]); sv.Draw(graphics); // show generated bitmap on picture box control pictureBoxSolution.Image = graphics.Bitmap; } } catch (Exception ex) { _log.Error(ex.ToString()); } }
protected mesh CreateComplexCaseMesh(BoxProperties caseProperties) { // build box Box box = new Box(0, caseProperties); // build list of vertex double ct = 5.0; Vector3D[] vertices = new Vector3D[16]; // 1st layer vertices[0] = new Vector3D(ct, ct, 0.0); vertices[1] = new Vector3D(box.Length - ct, ct, 0.0); vertices[2] = new Vector3D(box.Length - ct, box.Width - ct, 0.0); vertices[3] = new Vector3D(ct, box.Width - ct, 0.0); // 2nd layer (8) vertices[4] = new Vector3D(0.0, 0.0, ct); vertices[5] = new Vector3D(box.Length, 0.0, ct); vertices[6] = new Vector3D(box.Length, box.Width, ct); vertices[7] = new Vector3D(0.0, box.Width, ct); // 3rd later (8) vertices[8] = new Vector3D(0.0, 0.0, box.Height - ct); vertices[9] = new Vector3D(box.Length, 0.0, box.Height - ct); vertices[10] = new Vector3D(box.Length, box.Width, box.Height - ct); vertices[11] = new Vector3D(0.0, box.Width, box.Height - ct); // 4th layer vertices[12] = new Vector3D(ct, ct, box.Height); vertices[13] = new Vector3D(box.Length - ct, ct, box.Height); vertices[14] = new Vector3D(box.Length - ct, box.Width - ct, box.Height); vertices[15] = new Vector3D(ct, box.Width - ct, box.Height); // build list of loops Loop[] loops = new Loop[14]; mesh caseMesh = new mesh(); return caseMesh; }