public override List <BoxGeneric> GetSortedList() { // first sort by Z BoxComparerZ boxComparerZ = new BoxComparerZ(); Boxes.Sort(boxComparerZ); List <BoxGeneric> sortedList = new List <BoxGeneric>(); if (Boxes.Count == 0) { return(sortedList); } // build same Z layers int index = 0; double zCurrent = Boxes[index].PtMin.Z; List <BoxGeneric> tempList = new List <BoxGeneric>(); while (index < Boxes.Count) { if (Math.Abs(zCurrent - Boxes[index].PtMin.Z) < _epsilon) { tempList.Add(Boxes[index]); } else { // sort layer SortLayer(ref tempList); // add to sorted list sortedList.AddRange(tempList); // start new layer zCurrent = Boxes[index].PtMin.Z; tempList.Clear(); tempList.Add(Boxes[index]); } ++index; } // processing last layer SortLayer(ref tempList); sortedList.AddRange(tempList); return(sortedList); }
/// <summary> /// Draw all entities stored in buffer /// </summary> public void Flush() { // initialize Vector3D vLight = CameraPosition - Target; vLight.Normalize(); _boxDrawingCounter = 0; CurrentTransf = null; System.Drawing.Graphics g = Graphics; g.Clear(BackgroundColor); if (EnableFaceSorting) { // sort face list FaceComparison faceComparer = new FaceComparison(GetWorldToEyeTransformation()); Faces.Sort(faceComparer); } // draw background segments foreach (Segment s in SegmentsBackground) { Draw(s); } // draw background faces foreach (Face face in _facesBackground) { Draw(face, FaceDir.FRONT); } // draw all faces using solid / transparency foreach (Face face in Faces) { Draw(face, FaceDir.BACK); } // draw triangles foreach (Triangle tr in Triangles) { Draw(tr, FaceDir.FRONT); } // sort box list if (UseBoxelOrderer) { BoxelOrderer boxelOrderer = new BoxelOrderer(Boxes) { Direction = Target - CameraPosition }; Boxes = boxelOrderer.GetSortedList(); } else { Boxes.Sort(new BoxComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); } // sort cylinder list Cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); if (Cylinders.Count > 0) { // sort by Z List <Drawable> drawableList = new List <Drawable>(); drawableList.AddRange(Boxes); drawableList.AddRange(Cylinders); drawableList.Sort(new DrawableComparerSimplifiedPainterAlgo()); List <Box> boxes = new List <Box>(); List <Cylinder> cylinders = new List <Cylinder>(); bool processingBox = drawableList[0] is Box; foreach (Drawable drawable in drawableList) { Box b = drawable as Box; Cylinder c = drawable as Cylinder; if ((null != b) && processingBox) { boxes.Add(b); } else if ((null == b) && !processingBox) { cylinders.Add(c); } else { if (boxes.Count > 0) { BoxelOrderer boxelOrderer = new BoxelOrderer(boxes) { Direction = Target - CameraPosition }; boxes = boxelOrderer.GetSortedList(); // draw boxes foreach (Box bb in boxes) { Draw(bb); } // clear boxes.Clear(); } if (cylinders.Count > 0) { cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); // draw cylinders foreach (Cylinder cc in cylinders) { Draw(cc); } // clear cylinders.Clear(); } if (null != b) { boxes.Add(b); processingBox = true; } else { cylinders.Add(c); processingBox = false; } } } // remaining boxes BoxelOrderer boxelOrdererRem = new BoxelOrderer(boxes) { Direction = Target - CameraPosition }; boxes = boxelOrdererRem.GetSortedList(); // draw boxes foreach (Box bb in boxes) { Draw(bb); } // remaining cylinders cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); // draw cylinders foreach (Cylinder cc in cylinders) { Draw(cc); } // clear boxes.Clear(); } else { // draw all boxes foreach (Box box in Boxes) { Draw(box); } // draw all triangles foreach (Triangle tr in Triangles) { Draw(tr, FaceDir.FRONT); } } // images inst if (_listImageInst.Count > 0) { // --- sort image inst AnalysisHomo analysis = _listImageInst[0].Analysis; BBox3D bbox = analysis.Solution.BBoxGlobal; List <Box> boxesImage = new List <Box>(); foreach (ImageInst imageInst in _listImageInst) { boxesImage.Add(imageInst.ToBox()); } if (UseBoxelOrderer && false) // NOT WORKING ? { BoxelOrderer boxelOrderer = new BoxelOrderer(boxesImage) { TuneParam = 10.0, Direction = Target - CameraPosition }; boxesImage = boxelOrderer.GetSortedList(); } else { boxesImage.Sort(new BoxComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); } // --- List <ImageInst> listImageInstSorted = new List <ImageInst>(); foreach (Box b in boxesImage) { listImageInstSorted.Add(new ImageInst(analysis, new Vector3D(b.Length, b.Width, b.Height), b.BPosition)); } // draw image inst foreach (ImageInst im in listImageInstSorted) { Draw(im); } } // draw faces : end foreach (Face face in Faces) { Draw(face, FaceDir.FRONT); } // draw segment list (e.g. hatching) foreach (Segment seg in Segments) { Draw(seg); } // draw cotation cubes if (ShowDimensions) { foreach (DimensionCube qc in _dimensions) { qc.Draw(this); } } }
/// <summary> /// Draw all entities stored in buffer /// </summary> public void Flush() { // initialize Vector3D vLight = CameraPosition - Target; vLight.Normalize(); CurrentTransf = null; System.Drawing.Graphics g = Graphics; g.Clear(BackgroundColor); if (EnableFaceSorting) { // sort face list FaceComparison faceComparer = new FaceComparison(GetWorldToEyeTransformation()); Faces.Sort(faceComparer); } // draw background segments foreach (Segment s in SegmentsBackground) { Draw(s); } // draw background faces foreach (Face face in _facesBackground) { Draw(face, FaceDir.FRONT); } // draw all faces using solid / transparency foreach (Face face in Faces) { Draw(face, FaceDir.BACK); } // draw triangles foreach (Triangle tr in Triangles) { Draw(tr, FaceDir.FRONT); } var boxesImage1 = new List <BoxGeneric>(); foreach (var imageInst in ListImageInst) { var b = imageInst.ToBox(); boxesImage1.Add(b); } // sort box list if (UseBoxelOrderer) { BoxelOrderer boxelOrderer = new BoxelOrderer(Boxes, ViewDirection); Boxes = boxelOrderer.GetSortedList(); var boxelOrderer2 = new BoxelOrderer(boxesImage1, ViewDirection); boxesImage1 = boxelOrderer2.GetSortedList(); } else { Boxes.Sort(new DrawableComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); } // sort cylinder list Cylinders.Sort(new DrawableComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); if (Cylinders.Count > 0) { // sort by Z var drawableList = new List <Drawable>(); drawableList.AddRange(Boxes); drawableList.AddRange(Cylinders); drawableList.Sort(new DrawableComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); var boxes = new List <BoxGeneric>(); var cylinders = new List <Cyl>(); var processingBox = drawableList[0] is Box; foreach (Drawable drawable in drawableList) { if ((drawable is Box box) && processingBox) { boxes.Add(box); } else if (drawable is Cyl cyl && !processingBox) { cylinders.Add(cyl); }
/// <summary> /// Draw all entities stored in buffer /// </summary> public void Flush() { // initialize Vector3D vLight = CameraPosition - Target; vLight.Normalize(); CurrentTransf = null; System.Drawing.Graphics g = Graphics; g.Clear(BackgroundColor); if (EnableFaceSorting) { // sort face list FaceComparison faceComparer = new FaceComparison(GetWorldToEyeTransformation()); Faces.Sort(faceComparer); } // draw background segments foreach (Segment s in SegmentsBackground) { Draw(s); } // draw background faces foreach (Face face in _facesBackground) { Draw(face, FaceDir.FRONT); } // draw all faces using solid / transparency foreach (Face face in Faces) { Draw(face, FaceDir.BACK); } // draw triangles foreach (Triangle tr in Triangles) { Draw(tr, FaceDir.FRONT); } List <Box> boxesImage1 = new List <Box>(); foreach (ImageInst imageInst in ListImageInst) { Box b = imageInst.ToBox(); boxesImage1.Add(b); } // sort box list if (UseBoxelOrderer) { BoxelOrderer boxelOrderer = new BoxelOrderer(Boxes, ViewDirection); Boxes = boxelOrderer.GetSortedList(); BoxelOrderer boxelOrderer2 = new BoxelOrderer(boxesImage1, ViewDirection); boxesImage1 = boxelOrderer2.GetSortedList(); } else { Boxes.Sort(new DrawableComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); } // sort cylinder list Cylinders.Sort(new DrawableComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); if (Cylinders.Count > 0) { // sort by Z List <Drawable> drawableList = new List <Drawable>(); drawableList.AddRange(Boxes); drawableList.AddRange(Cylinders); drawableList.Sort(new DrawableComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); List <Box> boxes = new List <Box>(); List <Cyl> cylinders = new List <Cyl>(); bool processingBox = drawableList[0] is Box; foreach (Drawable drawable in drawableList) { Box b = drawable as Box; Cyl c = drawable as Cyl; if ((null != b) && processingBox) { boxes.Add(b); } else if ((null == b) && !processingBox) { cylinders.Add(c); } else { if (boxes.Count > 0) { BoxelOrderer boxelOrderer = new BoxelOrderer(boxes, ViewDirection); boxes = boxelOrderer.GetSortedList(); // draw boxes foreach (Box bb in boxes) { bb.Draw(this); } // clear boxes.Clear(); } if (cylinders.Count > 0) { cylinders.Sort(new DrawableComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); // draw cylinders foreach (Cyl cc in cylinders) { cc.Draw(this); } // clear cylinders.Clear(); } if (null != b) { boxes.Add(b); processingBox = true; } else { cylinders.Add(c); processingBox = false; } } } // remaining boxes BoxelOrderer boxelOrdererRem = new BoxelOrderer(boxes, ViewDirection); boxes = boxelOrdererRem.GetSortedList(); // draw boxes foreach (Box bb in boxes) { bb.Draw(this); } // remaining cylinders cylinders.Sort(new DrawableComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation())); // draw cylinders foreach (var cc in cylinders) { cc.Draw(this); } // clear boxes.Clear(); } else { // draw all boxes foreach (Box box in Boxes) { box.Draw(this); } // draw all triangles foreach (Triangle tr in Triangles) { Draw(tr, FaceDir.FRONT); } } // images inst if (ListImageInst.Count > 0) { // --- sort image inst List <ImageInst> listImageInstSorted = new List <ImageInst>(); foreach (Box b in boxesImage1) { var imageInst = ListImageInst.Find(i => i.PickId == b.PickId); listImageInstSorted.Add(new ImageInst(b.PickId, imageInst.Content, b.Dim, b.BPosition)); } // draw image inst foreach (ImageInst im in listImageInstSorted) { Draw(im); } ListImageInst.Clear(); } // draw faces : end foreach (Face face in Faces) { Draw(face, FaceDir.FRONT); } // draw segment list (e.g. hatching) foreach (Segment seg in Segments) { Draw(seg); } // draw cotation cubes if (ShowDimensions) { foreach (DimensionCube qc in Dimensions) { qc.Draw(this); } } }