Example #1
0
        /// <summary>
        /// Сгенерировать и показать треугольную сетку
        /// </summary>
        /// <param name="box"></param>
        private void GenerateMesh(EntityBox box)
        {
            Delaunay delaunay = new Delaunay();

            List <Point2D> points = new List <Point2D>();

            //
            // Получить ключевые точки
            //

            foreach (Entity entity in box.GetEntities())
            {
                if (entity.IsVias())
                {
                    Point   p     = box.LambdaToScreen(entity.LambdaX, entity.LambdaY);
                    Point2D point = new Point2D(p.X, p.Y);
                    points.Add(point);
                }
            }

            if (points.Count < 3)
            {
                MessageBox.Show("3 or more keypoints required!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //
            // Добавить ключевые точки по углам
            //

            AddCornerKeypoints(ref points, 25, 25);

            //
            // Триангулируем
            //

            List <Triangle> mesh = delaunay.GenMesh(points);

            //
            // Отобразить треугольную сетку
            //

            Random rnd = new Random();

            foreach (Triangle tri in mesh)
            {
                Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));

                AddTriangle(box, tri, randomColor);
            }
        }
Example #2
0
        private bool IsKeypointExists(EntityBox box, string name)
        {
            List <Entity> _entities = box.GetEntities();

            for (int i = 0; i < _entities.Count - 1; i++)
            {
                Entity entity = _entities[i];

                if (entity.IsVias() && entity.Label == name)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        private List <Point2D> GetKeypoints(EntityBox box)
        {
            List <Point2D> points = new List <Point2D>();

            foreach (Entity entity in box.GetEntities())
            {
                if (entity.IsVias())
                {
                    Point   p     = box.LambdaToImage(entity.LambdaX, entity.LambdaY);
                    Point2D point = new Point2D(p.X, p.Y);
                    point.name = entity.Label;
                    points.Add(point);
                }
            }

            return(points);
        }
Example #4
0
        /// <summary>
        /// Сохранить контрольные точки в XML
        /// </summary>
        /// <param name="box"></param>
        /// <param name="filename"></param>
        private void SaveKeypoints(EntityBox box, string filename)
        {
            List <Entity> kps = new List <Entity>();

            foreach (Entity entity in box.GetEntities())
            {
                if (entity.IsVias())
                {
                    kps.Add(entity);
                }
            }

            XmlSerializer ser = new XmlSerializer(typeof(List <Entity>));

            using (FileStream fs = new FileStream(filename, FileMode.Create))
            {
                ser.Serialize(fs, kps);
            }
        }
Example #5
0
        /// <summary>
        /// Очистить треугольную сетку
        /// </summary>
        /// <param name="box"></param>
        private void ClearMesh(EntityBox box)
        {
            List <Entity> ents = new List <Entity>();

            foreach (Entity entity in box.GetEntities())
            {
                if (entity.IsRegion())
                {
                    ents.Add(entity);
                }
            }

            foreach (Entity entity in ents)
            {
                entity.parent.Children.Remove(entity);
            }

            box.Invalidate();
        }
Example #6
0
        /// <summary>
        /// Удалить контрольные точки
        /// </summary>
        /// <param name="box"></param>
        private void RemoveKeypoints(EntityBox box, bool left)
        {
            List <Entity> kps = new List <Entity>();

            foreach (Entity entity in box.GetEntities())
            {
                if (entity.IsVias())
                {
                    kps.Add(entity);
                }
            }

            foreach (Entity entity in kps)
            {
                entity.parent.Children.Remove(entity);
                ListRemoveKeypoint(entity, left);
            }

            box.Invalidate();
        }
Example #7
0
        /// <summary>
        /// Удалить контрольную точку по имени
        /// </summary>
        /// <param name="box"></param>
        /// <param name="name"></param>
        private void RemoveKeypointByName(EntityBox box, string name)
        {
            Entity kp = null;

            foreach (Entity entity in box.GetEntities())
            {
                if (entity.IsVias())
                {
                    if (entity.Label == name)
                    {
                        kp = entity;
                    }
                }
            }

            if (kp != null)
            {
                kp.parent.Children.Remove(kp);
                box.Invalidate();
            }
        }