protected override AbstractShape createShapes(string code) { AbstractShape shape = null; switch (code) { case "Circle": shape = new CCircle(); break; case "Rectangle": shape = new CRectangle(); break; case "Polygon": shape = new CPolygon(); break; case "Star": shape = new CStar(); break; case "Group": shape = new CGroup(); break; } return(shape); }
private void panel1_MouseDoubleClick(object sender, MouseEventArgs e) { if (radioButton1.Checked) { Pen q = new Pen(Color.Black); CCircle RR = new CCircle(e.X, e.Y, 10, q); storage.Add(RR); Label lb = new Label(); lb.Location = new System.Drawing.Point(e.X - 18, e.Y - 18); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); lb.BackColor = Color.Transparent; lb.Name = "label1"; lb.Size = new System.Drawing.Size(10, 12); lb.Text = n.ToString(); panel1.Controls.Add(lb); dataGridView1.RowCount = n + 1; dataGridView1.ColumnCount = n + 1; dataGridView1[0, 0].Value = 0; for (int i = 1; i < dataGridView1.Rows.Count; ++i) { dataGridView1[0, i].Value = i; } for (int i = 1; i < dataGridView1.Rows.Count; ++i) { dataGridView1[i, 0].Value = i; } n++; panel1.Invalidate(); } }
private void deselectOne() // Убираем один элемент из списка выбранных { CCircle circle = selectedStorage.getCurrent(); deselectPrintedCircle(circle.x, circle.y, circle.radius); selectedStorage.del(); }
private void deselectAll() // Убираем все элементы из списка выбранных { selectedStorage.setFirst(); for (int i = 0; i < selectedStorage.getSize(); i++, selectedStorage.next()) { CCircle circle = selectedStorage.getCurrent(); deselectPrintedCircle(circle.x, circle.y, circle.radius); } selectedStorage = new Storage <CCircle>(); }
public void AddStor(CCircle circ) { if (i < 1000) { arr[i] = circ; i++; } else { return; } }
public static void Main() { CCircle cc1; // 객체 아님. 참조 변수 CCircle cc2 = new CCircle(); // 객체 생성, 모든 멤버가 0으로 초기화 SCircle sc1; // 객체 생성. SCircle sc2 = new SCircle(); int n1 = cc1.center.x; // error. x가 메모리에 없음. int n2 = cc2.center.x; // ok. 0 int n3 = sc1.center.x; // error. x가 초기화 안됨. int n4 = sc2.center.x; // ok. x가 초기화 됨. }
private void pictureBox_MouseUp(object sender, MouseEventArgs e) { if (storage == null) // Если глобальные объекты не инициализированы, инициализируем их { storage = new Storage <CCircle>(); selectedStorage = new Storage <CCircle>(); image = new Bitmap(1920, 1080); g = Graphics.FromImage(image); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; } if (e.Button == MouseButtons.Left && ctrlIsPressed) // Если одновременно нажали на ЛКМ и Ctrl { CCircle circle = inTheAreaOfCircle(e.X, e.Y); // Проверяем, попали ли мы в окрестность круга if (circle != null) // Если попали { if (inTheCircle) // Проверяем, попали ли мы ровно на круг { if (selectedStorage.checkAndSetCurrent(circle) == true) // Если в хранилище выделенных объектов есть выбранный { deselectOne(); // Убираем его из списка выбранных } else { // Иначе добавляем его в хранилище выбранных и выводим на экран selectedStorage.add(circle); printSelectedCircle(circle.x, circle.y, circle.radius); } } // Если попали в пустую область рядом с кругом, ничего не делаем } } else if (e.Button == MouseButtons.Left) // Если просто нажали на ЛКМ { deselectAll(); // Убираем все элементы из списка выбранных CCircle circle = inTheAreaOfCircle(e.X, e.Y); // Проверяем, попали ли мы в окрестность круга if (circle == null) // Если не попали { circle = new CCircle(e.X, e.Y, radius); // Создадим объект storage.add(circle); // Добавим его в хранилище selectedStorage.add(circle); // Добавим его в хранилище выбранных printSelectedCircle(circle.x, circle.y, circle.radius); // И выведем на экран уже выбранным } else if (inTheCircle) // Если попали ровно по кругу { // Добавляем его в хранилище выбранных и выводим на экран selectedStorage.add(circle); printSelectedCircle(circle.x, circle.y, circle.radius); } // Если попали в область рядом с кругом, ничего не делаем } }
private void Panel1_MouseClick(object sender, MouseEventArgs e) { if (stor.Check(e.X, e.Y)) { for (int j = 0; j < stor.i; j++) { if (stor.arr[j] != null) { if (stor.arr[j].flag) { Rectangle rect = new Rectangle(stor.arr[j].x - 15, stor.arr[j].y - 15, 30, 30); panel1.CreateGraphics().DrawEllipse(aPen, rect); } else { Rectangle rect = new Rectangle(stor.arr[j].x - 15, stor.arr[j].y - 15, 30, 30); panel1.CreateGraphics().DrawEllipse(mPen, rect); } } } } else { CCircle circ = new CCircle(); circ.x = e.X; circ.y = e.Y; stor.AddStor(circ); for (int j = 0; j < stor.i; j++) { if (stor.arr[j] != null) { if (j != (stor.i - 1)) { stor.arr[j].flag = false; Rectangle rect = new Rectangle(stor.arr[j].x - 15, stor.arr[j].y - 15, 30, 30); panel1.CreateGraphics().DrawEllipse(mPen, rect); } else { Rectangle rect = new Rectangle(stor.arr[j].x - 15, stor.arr[j].y - 15, 30, 30); panel1.CreateGraphics().DrawEllipse(aPen, rect); } } } } }
private void deleteSelected() // Удаляем выбранные элементы { selectedStorage.setFirst(); for (int i = 0; i < selectedStorage.getSize(); i++, selectedStorage.next()) { CCircle circle = selectedStorage.getCurrent(); storage.setFirst(); for (int j = 0; j < storage.getSize(); j++, storage.next()) { if (circle.Equals(storage.getCurrent())) { storage.del(); break; } } g.FillEllipse(Brushes.White, circle.x - radius - 2, circle.y - radius - 2, 2 * (circle.radius + 2), 2 * (circle.radius + 2)); } selectedStorage = new Storage <CCircle>(); }
public override AShape CreateShape(string code) { AShape ans = null; if (code == "C") { ans = new CCircle(); } if (code == "S") { ans = new CSegment(); } if (code == "P") { ans = new Polygon(); } if (code == "G") { ans = new CGroup(); } return(ans); }
//Функция добавления объекта в хранилище public void AddObj(int index, ref CCircle NewObj, ref int Count, ref int item) { myStorage NewStorage = new myStorage(Count + 1); for (int i = 0; i < Count; ++i) { NewStorage.objects[i] = objects[i]; } for (int i = Count; i < (Count + 1) - 1; ++i) { NewStorage.objects[i] = null; } Count = Count + 1; Allocation(Count); for (int i = 0; i < Count; ++i) { objects[i] = NewStorage.objects[i]; } objects[index] = NewObj; item = index; }
private static bool CheckCircle_Circle(CCircle col1, CCircle col2, Transform2D trans1, Transform2D trans2) { return(Utils.TestCircleCircle( trans1.pos, col1.radius, trans2.pos, col2.radius)); }
//Функция обработки события нажатия курсора на панель private void Panel1_MouseDown(object sender, MouseEventArgs e) { //Создается объект класса CCircle CCircle circle = new CCircle(e.X, e.Y, Color.Black); //Получение индекса объекта int SellectedItem = CheckCircle(ref storage, storage.get_count(), circle.x, circle.y); if (SellectedItem != -1) { //Если нажат ctrl, выделяем несколько объектов if (Control.ModifierKeys == Keys.Control) { int x = e.X - circle.R;// присваиваем координаты курсора int y = e.Y - circle.R; for (int i = 0; i < storage.get_count(); ++i) { if (!storage.Empty(i)) { //проверка условия if (Math.Sqrt(Math.Pow((x - storage.objects[i].x), 2) + Math.Pow((y - storage.objects[i].y), 2)) <= storage.objects[i].R) { storage.objects[i].color = Color.Red; //установка цвета выделенного объекта DrawingCircles(ref storage, i); //перерисовка окружности } } } } else { //Иначе выделяем 1 объект и снимаем выделение у остальных объектов хранилища int x = e.X - circle.R; int y = e.Y - circle.R; SelectionRemove(ref storage); for (int i = 0; i < storage.get_count(); ++i) { if (!storage.Empty(i)) { if (Math.Sqrt(Math.Pow((x - storage.objects[i].x), 2) + Math.Pow((y - storage.objects[i].y), 2)) <= storage.objects[i].R) { storage.objects[i].color = Color.Red; //установка цвета выделенного объекта DrawingCircles(ref storage, i); //перерисовка окружности break; } } } //Перерисовываем окружность storage.objects[SellectedItem].color = Color.Red; DrawingCircles(ref storage, SellectedItem); } return; } //Добавляем окружность в хранилище storage.set_value(ref circle); //Снимаем выделение всех объектов хранилища SelectionRemove(ref storage); //Устанавливаем цвет выделяемого объекта на новый добавленный storage.objects[storage.get_count() - 1].color = Color.Red; //Отрисовываем окружность DrawingCircles(ref storage, (storage.get_count() - 1)); }
public void set_value(ref CCircle value) //добавление объекта в хранилище { objects[size] = value; //добавляем объект в свободную ячейку size++; return; }
private void button3_Click(object sender, EventArgs e) // Polygons { int nBits = CombIm.N_Bits; if (!EDGES) { MessageBox.Show("Click edge detection"); return; } if (!radioButton1.Checked && !radioButton2.Checked) { MessageBox.Show("Choose a radio button with 'Radii'"); return; } OrigIm.ImageToBitmapOld(BmpPictBox1, this); int maxL2 = 100000, maxV = 220000, maxArc = 40000; L = new CListLines(maxL2, maxV, maxArc); int marginX = (pictureBox2.Width - (int)(Scale1 * OrigIm.width)) / 2; int marginY = (pictureBox2.Height - (int)(Scale1 * OrigIm.height)) / 2; int PicBoxInd = 1; if (radioButton1.Checked) { Ins1 = new CInscript(PicBoxInd, 0.6, 0, 0, OrigIm.width, Color.Yellow, this); radio1_Checked = true; } else if (radioButton2.Checked) { Ins1 = new CInscript(PicBoxInd, 0.8, 0, 0, OrigIm.width, Color.Yellow, this); radio2_Checked = true; } PicBoxInd = 2; Ins2 = new CInscript(PicBoxInd, 0.5, 0, 0, OrigIm.width, Color.White, this); CombIm.nLoop = nLoop; CombIm.denomProg = denomProg; // 0 1 2 3 4 5 6 7 int[] minRad = { 10, 14, 23, 35, 53, 80, 120, 180 }; int[] maxRad = { 20, 30, 46, 70, 106, 160, 240, 360 }; double[] ProtEps = { 1.05, 1.15, 1.23, 1.35, 1.50, 1.67, 1.85, 2.0 }; double maxAngle1 = 0.0, maxAngle2 = 0.0; optVar1 = optVar2 = -1; optNcircle1 = optNcircle2 = 0; int nVar = 8; int maxCircle = 2000; nBest = 0; nCircle = new int[nVar]; Circle = new CCircle[nVar, maxCircle]; // declared in Form1 for (int iv = 0; iv < nVar; iv++) { for (int i = 0; i < maxCircle; i++) { Circle[iv, i] = new CCircle(); } } BestCircles1 = new CCircle[6000]; for (int i = 0; i < 600; i++) { BestCircles1[i] = new CCircle(); } BestCircles2 = new CCircle[600]; for (int i = 0; i < 600; i++) { BestCircles2[i] = new CCircle(); } int nArcs = 0, rv = 1; int iVarStart = 0, iVarEnd = 7; if (radioButton1.Checked) { iVarEnd = 4; } else if (radioButton2.Checked) { iVarStart = 3; } else { MessageBox.Show("Chose a radio button with 'Radii'"); } progressBar1.Value = 0; progressBar1.Visible = true; progressBar1.Step = 20; for (int iVar = iVarStart; iVar <= iVarEnd; iVar++) //=========================================== { progressBar1.PerformStep(); eps = ProtEps[iVar]; numericUpDown2.Value = (decimal)eps; rv = L.SearchPoly(ref CombIm, eps, this); if (rv < 0) { break; } double maxSinus = 0.7, maxProportion = 0.2; L.CheckSmooth(maxSinus, maxProportion); rv = L.DrawPolygons(pictureBox2, EdgeIm, this); EDGES = false; POLY = true; nArcs = L.MakeArcs3(pictureBox2, minRad[iVar], maxRad[iVar], eps, this); if (nArcs < 0) { break; } nBest = 0; nCircle[iVar] = 0; int[] iBestCircles1 = new int[100]; nCircle[iVar] = L.MakeCirclesEl(Circle, iVar, ref nCircle[iVar], minRad[iVar], maxRad[iVar], iBestCircles1, ref nBest); if (nCircle[iVar] < 0) { break; } double SumAngle; //if (nCircle[iVar] > 0) SumAngle = TestCircles(Circle, iVar, nCircle[iVar]); if (nCircle[iVar] > 0) { SumAngle = TestCircles(Circle, iVar, nCircle); } else { SumAngle = 0.0; } if (radioButton1.Checked) { int cnt = 0; if (SumAngle > maxAngle1) { cnt = 0; for (int iCircle = 0; iCircle < nCircle[iVar]; iCircle++) { if (Circle[iVar, iCircle].good) { BestCircles1[cnt] = Circle[iVar, iCircle]; cnt++; } } maxAngle1 = SumAngle; optVar1 = iVar; optNcircle1 = cnt; } } if (radioButton2.Checked) { int cnt = 0; if (SumAngle > maxAngle2) { cnt = 0; for (int iCircle = 0; iCircle < nCircle[iVar]; iCircle++) { if (Circle[iVar, iCircle].good) { BestCircles2[cnt] = Circle[iVar, iCircle]; cnt++; } } maxAngle2 = SumAngle; optVar2 = iVar; optNcircle2 = cnt; } } } //=========================== end for (int iVar... ================================== if (rv < 0) { return; } progressBar1.Visible = false; if (radioButton1.Checked) { nBest = L.ShowBestCircles3(BestCircles1, optNcircle1, 2.0, this); MessageBox.Show("Form1: Number of recognized circles is " + nBest); } if (radioButton2.Checked) { nBest = L.ShowBestCircles3(BestCircles2, optNcircle2, 1.0, this); MessageBox.Show("Form1: Number of recognized circles is " + nBest); } label5.Visible = true; label5.Text = "Recognized circles"; label6.Visible = true; label6.Text = "Polygons"; button4.Visible = true; button5.Visible = true; groupBox2.Visible = true; } //*************************** end Polygons *******************************
private static bool CheckSeg_Circle(CSegment col1, CCircle col2, Transform2D trans1, Transform2D trans2) { return(false); }
private static bool CheckCircle_Polygon(CCircle col1, CPolygon col2, Transform2D trans1, Transform2D trans2) { return(false); }
private static bool CheckCircle_OBB(CCircle col1, COBB col2, Transform2D trans1, Transform2D trans2) { return(Utils.TestCircleOBB( trans1.pos, col1.radius, trans2.pos, col2.radius, col2.size, col2.up)); }
public CCircle(CCircle circle) { this.x = circle.x; this.y = circle.y; this.radius = circle.radius; }
private static bool CheckRay_Circle(CRay col1, CCircle col2, Transform2D trans1, Transform2D trans2) { return(false); }
//Функция обработки события нажатия курсора на панель private void Circle_Panel_MouseDown(object sender, MouseEventArgs e) { //Создается объект класса CCircle CCircle circle = new CCircle(e.X, e.Y, DefaultColor); //Получение индекса объекта int SellectedItem = CheckCircle(ref storage, amtCells, circle.x, circle.y); if (SellectedItem != -1) { //Если нажат ctrl, выделяем несколько объектов if (Control.ModifierKeys == Keys.Control) { int x = e.X - circle.R; int y = e.Y - circle.R; for (int i = 0; i < amtCells; ++i) { if (!storage.Empty(i)) { //проверка условия if (Math.Sqrt(Math.Pow((x - storage.objects[i].x), 2) + Math.Pow((y - storage.objects[i].y), 2)) <= storage.objects[i].R) { storage.objects[i].color = SelectedColor; //установка цвета выделенного объекта DrawingCircles(ref storage, i); //перерисовка окружности } } } } else { //Иначе выделяем 1 объект и снимаем выделение у остальных объектов хранилища int x = e.X - circle.R; int y = e.Y - circle.R; SelectionRemove(ref storage); for (int i = 0; i < amtCells; ++i) { if (!storage.Empty(i)) { if (Math.Sqrt(Math.Pow((x - storage.objects[i].x), 2) + Math.Pow((y - storage.objects[i].y), 2)) <= storage.objects[i].R) { storage.objects[i].color = SelectedColor; //установка цвета выделенного объекта DrawingCircles(ref storage, i); //перерисовка окружности break; } } } //Перерисовываем окружность storage.objects[SellectedItem].color = SelectedColor; DrawingCircles(ref storage, SellectedItem); } return; } //Добавляем окружность в хранилище storage.AddObj(CountElem, ref circle, ref amtCells, ref item); //Снимаем выделение всех объектов хранилища SelectionRemove(ref storage); //Устанавливаем цвет выделяемого объекта на новый добавленный storage.objects[item].color = SelectedColor; //Отрисовываем окружность DrawingCircles(ref storage, item); //Увеличиваем счетчик количества объектов хранилища ++CountElem; }