Example #1
0
 public void AddImage(uint pickId, SubContent content, Vector3D vDimensions, BoxPosition boxPosition)
 {
     ListImageInst.Add(new ImageInst(pickId, content, vDimensions, boxPosition));
 }
Example #2
0
        /// <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);
                }
            }
        }