public static LinkedList <shape> addLine(LinkedList <shape> s, int a, int b) { shape old = null; foreach (shape sh in s) { if (sh.points.Contains(a) && sh.points.Contains(b)) { old = sh; } } s.Remove(old); shape new1 = new shape(new int[] {}); shape new2 = new shape(new int[0]); foreach (int i in old.points) { if (i <= a || i >= b) { new1.points.AddLast(i); } if (i >= a && i <= b) { new2.points.AddLast(i); } } s.AddLast(new1); s.AddLast(new2); return(s); }
void motor_preSolve(cpConstraint motor, cpSpace space) { float dt = space.GetCurrentTimeStep(); float target_x = CCMouse.Instance.Position.x; paint = new shape { point1 = new cpVect(target_x, -1000.0f), point2 = new cpVect(target_x, 1000.0f), }; float max_v = 500.0f; float target_v = cp.cpfclamp(cp.bias_coef(0.5f, dt / 1.2f) * (target_x - balance_body.GetPosition().x) / dt, -max_v, max_v); float error_v = (target_v - balance_body.GetVelocity().x); float target_sin = 3.0e-3f * cp.bias_coef(0.1f, dt) * error_v / dt; float max_sin = cp.cpfsin(0.6f); balance_sin = cp.cpfclamp(balance_sin - 6.0e-5f * cp.bias_coef(0.2f, dt) * error_v / dt, -max_sin, max_sin); float target_a = (float)Math.Asin(cp.cpfclamp(-target_sin + balance_sin, -max_sin, max_sin)); float angular_diff = (float)Math.Asin(cpVect.cpvcross(balance_body.GetRotation(), cpVect.cpvforangle(target_a))); float target_w = cp.bias_coef(0.1f, dt / 0.4f) * (angular_diff) / dt; float max_rate = 50.0f; float rate = cp.cpfclamp(wheel_body.GetAngularVelocity() + balance_body.GetAngularVelocity() - target_w, -max_rate, max_rate); motor.SetRate(cp.cpfclamp(rate, -max_rate, max_rate)); motor.SetMaxForce(8.0e4f); }
static void Main(string[] args) { shape sh=new shape(); sh.sum(); square sh =new square(); sh.sum(); }
public static Shape CreateObject(shape Shape, renderType RenderType, Transform transform, float radius) { switch (Shape) { case shape.SPHERE: if (RenderType == renderType.WIRE_FRAME) { return(new WireFrameSphere(transform, radius)); } else { return(new ShadedSphere(transform, radius)); } break; case shape.CUBE: if (RenderType == renderType.WIRE_FRAME) { return(new WireFrameCube(transform, radius)); } else { return(new ShadedCube(transform, radius)); } break; default: return(null); break; } }
public static ndarray ToCategorial(ndarray y, int?num_classes = null, dtype dtype = null) { var input_shape = y.shape; List <long> new_shape = new List <long>(); if (input_shape.lastDim == 1 && input_shape.iDims.Length > 1) { new_shape = input_shape.iDims.Take(input_shape.iDims.Length - 1).ToList(); } else { new_shape = input_shape.iDims.ToList(); } y = y.ravel(); if (num_classes.HasValue) { num_classes = (int)np.max(y) + 1; } var n = y.shape.iDims[0]; var categorical = np.zeros((n, num_classes), dtype: dtype); categorical[np.arange(n), y] = 1; new_shape.Add(num_classes.Value); var output_shape = new shape(new_shape); categorical = np.reshape(categorical, output_shape); return(categorical); }
internal void AssertShape(shape s, int s0, int s1, int s2) { Assert.AreEqual(s.iDims.Length, 3); Assert.AreEqual(s.iDims[0], s0); Assert.AreEqual(s.iDims[1], s1); Assert.AreEqual(s.iDims[2], s2); }
private void panelDrawing_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { return; } if (radioButtonFreeHand.Checked) { return; } if (radioButtonText.Checked) { return; } if (radioButtonEraser.Checked) { return; } if (radioButtonSelector.Checked) { return; } ArrayList shapes = getPage(); Graphics g = panelDrawing.CreateGraphics(); Point p = new Point(e.X, e.Y); shape s = (shape)shapes[shapes.Count - 1]; s.Update(g, p); }
public void SetObject(int index, shape obj) { if (index < size) { objs[index] = obj; } }
private void button3_Click(object sender, EventArgs e) { //float x = match_shape(ab, bc); ////richTextBox1.AppendText(Environment.NewLine); //textBox1.Text = Convert.ToString(x); for (int i = 0; i < lst.Count(); i++) { b2 = new Bitmap(lst[i]); i2 = b2; bc = new shape(b2); bc.measure(); matches[i] = match_shape(ab, bc); richTextBox1.AppendText(matches[i].ToString()); richTextBox1.AppendText(Environment.NewLine); } for (int i = 0; i < lst.Count(); i++) { if (matches[i] > max) { max = matches[i]; index = i; } } textBox1.Text = lst[index]; }
private void buttonCleer_Click(object sender, EventArgs e) { SelectorShape = null; ArrayList lines = getPage(); lines.RemoveRange(0, lines.Count); panelDrawing.Invalidate(); }
public ActionResult DeleteConfirmed(int id) { shape shape = db.shapes.Find(id); db.shapes.Remove(shape); db.SaveChanges(); return(RedirectToAction("Index")); }
internal void AssertShape(shape s, int s0, int s1, int s2, int s3, int s4) { Assert.AreEqual(s.iDims.Length, 5); Assert.AreEqual(s.iDims[0], s0); Assert.AreEqual(s.iDims[1], s1); Assert.AreEqual(s.iDims[2], s2); Assert.AreEqual(s.iDims[3], s3); Assert.AreEqual(s.iDims[4], s4); }
private void button1_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); b1 = new Bitmap(openFileDialog1.FileName); i1 = b1; ab = new shape(b1); ab.measure(); textBox2.Text = openFileDialog1.FileName; }
static void Main(string[] args) { shape shape = new shape(); Subscriber1 sub1 = new Subscriber1(shape); Subscriber2 sub2 = new Subscriber2(shape); shape.Draw(); Console.Read(); }
public ActionResult Edit(shape shape) { if (ModelState.IsValid) { db.Entry(shape).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shape)); }
public float match_shape(shape s1, shape s2) { //the last function int[,] m; int total_pixels, matched_pixels; float match; total_pixels = matched_pixels = 0; s1.measure(); s2.measure(); s2.scale(s2.diag_length / s1.diag_length); s2.measure(); s1.fit(); s2.fit(); s1.measure(); s2.measure(); int w = s1.width; if (s2.width < w) { w = s2.width; } int h = s1.height; if (s2.height < h) { h = s2.height; } m = new int[w, h]; for (int j = 0; j < h - 1; j++) { for (int i = 0; i < w - 1; i++) { try { m[i, j] = s1.match_matrix[i, j] * s2.match_matrix[i, j]; } catch (IndexOutOfRangeException e) { return(0); } } } total_pixels = w * h; for (int j = 0; j < h - 1; j++) { for (int i = 0; i < w - 1; i++) { matched_pixels += m[i, j]; } } match = (float)matched_pixels / (float)s1.pixels * 100; return(match); //return 0; }
public static bool IsInShape(shape s, int i, int j) { if (s == shape.square) { return((Math.Pow((i - 7), 2) + Math.Pow((j - 7), 2)) <= 12); } else { return(j - i > 0 && j + i < 6); } }
public ActionResult Create(shape shape) { if (ModelState.IsValid) { db.shapes.Add(shape); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shape)); }
public ShapeResponse AddShape(ShapeRequest request) { var response = new ShapeResponse(); var context = new RuleTestEntities(); try { var newShape = new shape(); newShape.name = request.ShapeDto.name; newShape.coordinates = request.ShapeDto.coordinates; newShape.area = request.Area; newShape.date_created = DateTime.Now; newShape.is_valid = 1; context.AddObject("shapes", newShape); context.SaveChanges(); response.ShapeId = newShape.id_shape; response.Acknowledge = AcknowledgeType.Success; } catch (InvalidOperationException exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } catch (ArgumentNullException exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } catch (NullReferenceException exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } catch (OptimisticConcurrencyException exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } catch (Exception exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } finally { context.Dispose(); } return(response); }
public int CheckObject(shape obj) { for (int i = 0; i < size; i++) { if (objs[i] == obj) { return(i); } } return(-1); }
private void addShape(shape s) { ArrayList shapes = getPage(); shapes.Add(s); int page = int.Parse(textBoxNumberPage.Text); ArrayList al = new ArrayList(); al.Add(page); al.Add(s); _undo.Insert(0, al); }
public ShapeColorObject(double area, shape type, Hsv color, int x, int y) { this.area = area; this.type = type; this.color = color; this.x = x; this.y = y; lineSegments = new List <LineSegment2D>(); previousPosition = pos; prev = this; objIndex = 0; }
public ShapeResponse AddShape(ShapeRequest request) { var response = new ShapeResponse(); var context = new RuleTestEntities(); try { var newShape = new shape(); newShape.name = request.ShapeDto.name; newShape.coordinates = request.ShapeDto.coordinates; newShape.area = request.Area; newShape.date_created = DateTime.Now; newShape.is_valid = 1; context.AddObject("shapes",newShape); context.SaveChanges(); response.ShapeId = newShape.id_shape; response.Acknowledge = AcknowledgeType.Success; } catch (InvalidOperationException exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } catch (ArgumentNullException exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } catch (NullReferenceException exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } catch (OptimisticConcurrencyException exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } catch (Exception exc) { log.Error(exc); response.Message = exc.Message; response.Acknowledge = AcknowledgeType.Failure; } finally { context.Dispose(); } return response; }
private void Eraser_Click(object sender, EventArgs e) { CurrentShape = shape.eraser; Eraser.BackColor = SystemColors.GradientActiveCaption; Pen_Button.BackColor = SystemColors.Control; Line_Button.BackColor = SystemColors.Control; Square_Button.BackColor = SystemColors.Control; Elipse_Button.BackColor = SystemColors.Control; Eraser_Size_Box.Visible = true; Filling_Box.Visible = false; Line_Box.Visible = false; Line_Style_Box.Visible = false; }
private void button1_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); textBox1.Text = openFileDialog1.SafeFileName; b1 = new Bitmap(openFileDialog1.FileName); i1 = b1; pictureBox1.Image = i1; //gen_map(b1, im1); ab = new shape(b1); ab.measure(); //ab.fit(); //ab.scale(2f); //ab.fit(); //ab.measure(); /*for (int i = 0; i < ab.pixels; i++) * { * richTextBox1.AppendText(Convert.ToString(ab.x[i])); * richTextBox1.AppendText(","); * richTextBox1.AppendText(Convert.ToString(ab.y[i])); * richTextBox1.AppendText(" "); * } * richTextBox1.AppendText(" "); * richTextBox1.AppendText(Convert.ToString(ab.diag_length)); * richTextBox1.AppendText(" "); * richTextBox1.AppendText(Convert.ToString(ab.diag_slope)); * richTextBox1.AppendText(" "); * richTextBox1.AppendText(Convert.ToString(ab.up)); * richTextBox1.AppendText(" "); * richTextBox1.AppendText(Convert.ToString(ab.down)); * richTextBox1.AppendText(" "); * richTextBox1.AppendText(Convert.ToString(ab.left)); * richTextBox1.AppendText(" "); * richTextBox1.AppendText(Convert.ToString(ab.right)); * richTextBox1.AppendText(" "); * richTextBox1.AppendText(Convert.ToString(ab.width)); * richTextBox1.AppendText(" "); * richTextBox1.AppendText(Convert.ToString(ab.height)); */ /*richTextBox1.AppendText(Environment.NewLine); * for (int j = 0; j < ab.height-1; j++) * { * for (int i = 0; i < ab.width-1; i++) * { * if (ab.match_matrix[i, j] == 1) richTextBox1.AppendText("--"); * else richTextBox1.AppendText("//"); * } * richTextBox1.AppendText(Environment.NewLine); * }*/ }
static void Main(string[] args) { double allArea = 0; for (int i = 0; i < 10; i++) { Console.Write("第" + (i + 1) + "个图形:"); shape sp = ShapeFactory.generateRandomShape(i); allArea += sp.getArea(); Console.WriteLine("this area=" + sp.getArea()); Console.WriteLine("allArea=" + allArea); } Console.WriteLine("十个图形总面积(含不合法图形)为:" + allArea); }
public override IShape GetShape(shape shape) { switch (shape) { case shape.Circle: return(new Circle()); case shape.Square: return(new Square()); default: throw new ApplicationException(string.Format("can not create the object for {0} type", shape)); } }
public override shape GetShape(string shape) { shape colors = null; if (shape == "RECTANGLE") { colors = new Rectangle(); } else if (shape == "CIRCLE") { colors = new circle(); } return(colors); }
private void radioButtonToolBox_CheckedChanged(object sender, EventArgs e) { if (radioButtonFreeHand.Checked) { panelDrawing.Cursor = new Cursor(GetType(), "Cursor1.cur"); } if (radioButtonLine.Checked) { panelDrawing.Cursor = Cursors.Cross; } if (radioButtonEraser.Checked || radioButtonSelector.Checked) { panelDrawing.Cursor = Cursors.Arrow; } SelectorShape = null; panelWidths.Visible = true; if (radioButtonText.Checked) { panelDrawing.Cursor = Cursors.IBeam; buttonFont.Visible = true; panelWidths.Visible = false; } else { buttonFont.Visible = false; } checkedWidthsVisible(); if (textBoxContent.Visible) { shape s = handleText(); addShape(s); } panelFilledOrNonFilled.Visible = false; if (radioButtonRectangle.Checked == true || radioButtonEllipse.Checked == true) { panelDrawing.Cursor = Cursors.Cross; HandleBackColorAndShape(panelFilled); HandleBackColorAndShape(panelNonFilled); panelNonFilled.Invalidate(); panelFilled.Invalidate(); panelFilledOrNonFilled.Visible = true; } }
static void Main(string[] args) { double totalArea = 0; Random random = new Random(); string[] a = { "正方形", "矩形", "三角形" }; for (int i = 0; i <= 10; i++) { int rand = random.Next(0, 3); shape Sp = ShapeFactory.createShape(a[rand]); Sp.set(); totalArea += Sp.getMeasure(); } Console.WriteLine(totalArea); }
public void Add(shape obj) { shape[] objs1; objs1 = new shape[++size]; for (int i = 0; i < size - 1; i++) { objs1[i] = objs[i]; } objs1[size - 1] = obj; objs = new shape[size]; for (int i = 0; i < size; i++) { objs[i] = objs1[i]; } }
void determineShape(int num_of_turning_point) { if (num_of_turning_point >= 1) { if (Vector2.Distance(mypointList[0], mypointList[mypointList.Count - 1]) > distOffset) { //check if the first and last point is in the same area Debug.Log("no shape turning point: " + turningPointList.Count); } else { //mean first and last point is sort of connected Debug.Log("turning point: " + turningPointList.Count); if (turningPointList.Count == 3) { myshape = shape.triangle; Debug.Log("triangle"); } else if (turningPointList.Count >= 4) { // Debug.Log("gradient list: " + allGradientList.Count.ToString()); if (allGradientList[0] == allGradientList[2] && allGradientList[1] == allGradientList[3]) { if (allGradientList[0] == direction.horizontal || allGradientList[0] == direction.vertical) { if (allGradientList[1] == direction.horizontal || allGradientList[1] == direction.vertical) { myshape = shape.square; Debug.Log("square"); return; } } else { if (allGradientList[1] == direction.positive || allGradientList[1] == direction.negative) { myshape = shape.diamond; Debug.Log("diamond"); return; } } } else { myshape = shape.no_shape; } } else { myshape = shape.no_shape; } } } else//num_of_turning_point is zero { //we know this is a line float gradient = getGradient(mypointList[0], mypointList[mypointList.Count - 1]);//first and last point getDirection(gradient); // Debug.Log("gradient: " + gradient.ToString()); //Debug.Log("current: " + current_direction.ToString()); if (current_direction == direction.horizontal) { myshape = shape.horizontal_line; Debug.Log("horizontal line"); } else if (current_direction == direction.vertical) { myshape = shape.vertical_line; Debug.Log("vertical line"); } else if(current_direction == direction.positive) { Debug.Log("positive"); myshape = shape.diagonal_BLTR; } else if(current_direction == direction.negative) { Debug.Log("negative"); myshape = shape.diagonal_TLBR; } else { myshape = shape.no_shape; Debug.Log("this is a bug"); } } }
public void resetShape() { myshape = shape.no_shape; }
void Start() { isMousePressed = false; myline = GetComponent<LineRenderer>(); mypointList = new List<Vector2>(); turningPointList = new List<Vector2>(); allAngle = new List<float>(); allLineVector = new List<Vector2>(); allGradientList = new List<direction>(); mytime = -1; mytFadeTmer = 1.0f; myshape = shape.no_shape; //GameObject[] temp; //temp = GameObject.FindGameObjectsWithTag("Main Player"); //foreach (GameObject a in temp) //{ // if (a.name.Contains("Clone") == true) // GameObject.Destroy(a); // else // mycharbase = a.GetComponent<CharacterBase>(); //} mycharbase = GameObject.FindGameObjectWithTag("Main Player").GetComponent<CharacterBase>(); drawCam = GameObject.Find("draw camera").GetComponent<Camera>(); myline.SetColors(drawColor, drawColor); }
private List<shape> getCameraData() { List<shape> shapeList = new List<shape>(); System.IO.StreamReader sr; string s; if (!connected) { if (!rr.connect("localhost")) { Console.WriteLine("Could not connect to localhost!"); return null; } connected = true; } takeNewCameraImage(); //sometimes the next roborealm loadProgram() gets stuck, regardless of which program it is //the sleep_counter thing in the wait loop below is a hack to restart roborealm in this case //Thread.Sleep(100); //begin red obstacles ///*Start blob processing if (!rr.loadProgram("c:\\Documents and Settings\\cs266\\Desktop\\API\\API\\Python\\Red_blobs.robo")) Console.WriteLine("Red Blobs Program didn't run.\n"); rr.run("on");//unknown whether this should be "once" or "on". "once" gets stuck sometimes int sleep_counter = 0; while (rr.getVariable("ObProgram") != "1") { Thread.Sleep(50); Console.WriteLine("sleeping in obstacles"+" roborealm running.. " + rr.getVariable("counter")); sleep_counter++; if (sleep_counter > 20) { Console.WriteLine("Roborealm seems to stuck, rerun.."); rr.run("off"); rr.run("on"); } } rr.run("off"); System.IO.StreamReader sblob = System.IO.File.OpenText("c:\\Documents and Settings\\cs266\\Desktop\\API\\API\\Python\\Obstacles.out"); //int[] Blobx = new int[100]; //int[] Bloby = new int[100]; s = ""; //int bcount = 0; while ((s = sblob.ReadLine()) != null) { shape obs = new shape(); obs.shapetype = "boundary"; obs.id = 0; string[] toks = s.Split(' '); //Blobx[bcount] = int.Parse(toks[0]); //Bloby[bcount] = int.Parse(toks[1]);7 obs.x = double.Parse(toks[0]) - 100; obs.y = double.Parse(toks[1]) - 280; obs.orientation = 0; if (obs != null) shapeList.Add(obs); //bcount ++; } // End red obstacles //begin blue robots // TODO: Make the location of the vision output VARIABLE! do { if (!rr.loadProgram("c:\\Documents and Settings\\cs266\\Desktop\\API\\API\\Python\\BlueStuff_smoothLarge_test.robo")) Console.WriteLine("Blue Program didn't run.\n"); rr.run("once"); while (rr.getVariable("BProgram") != "1") { Thread.Sleep(50); Console.WriteLine("sleeping in blue robots"); } rr.run("off"); if (rr.getVariable("berror") != "0") { Console.WriteLine("Fail recognition. Retake camera image, might take a longer time.\n"); takeNewCameraImage(); } } while (rr.getVariable("berror") != "0"); sr = System.IO.File.OpenText("c:\\Documents and Settings\\cs266\\Desktop\\API\\API\\Python\\Blue.out"); s = ""; //System.Console.WriteLine("hey"); while ((s = sr.ReadLine()) != null) { // print out for testing //System.Console.WriteLine("blue shapes"); //System.Console.WriteLine(s); Console.WriteLine("reading line " +s); shape sh = parseShapes(s); if (sh != null) shapeList.Add(sh); } sr.Close(); //end blue robots ///*Start food processing if (!rr.loadProgram("c:\\Documents and Settings\\cs266\\Desktop\\API\\API\\Python\\Blue_blobs.robo")) Console.WriteLine("Blue Blobs Program didn't run.\n"); rr.run("once"); while (rr.getVariable("FoProgram") != "1") { Thread.Sleep(50); Console.WriteLine("sleeping in blue blobs"); } rr.run("off"); System.IO.StreamReader sfood = System.IO.File.OpenText("c:\\Documents and Settings\\cs266\\Desktop\\API\\API\\Python\\Food.out"); //int[] Blobx = new int[100]; //int[] Bloby = new int[100]; s = ""; //int bcount = 0; while ((s = sfood.ReadLine()) != null) { shape food = new shape(); food.shapetype = "robot"; food.id = 8; string[] toks = s.Split(' '); //Blobx[bcount] = int.Parse(toks[0]); //Bloby[bcount] = int.Parse(toks[1]);7 food.x = double.Parse(toks[0]) - 100; food.y = double.Parse(toks[1]) - 280; food.orientation = 0; if (food != null) shapeList.Add(food); //bcount ++; } // end of food /* //start of red robot processing do { if (!rr.loadProgram("c:\\Documents and Settings\\cs266\\Desktop\\API\\API\\Python\\RedStuff_smoothLarge_test.robo")) Console.WriteLine("Red Program didn't run.\n"); rr.run("once"); while (rr.getVariable("RProgram") != "1") { Thread.Sleep(50); Console.WriteLine("sleeping in red robots"); } rr.run("off"); if(rr.getVariable("rerror") != "0") { Console.WriteLine("Fail recognition. Retake camera image, might take a longer time.\n"); takeNewCameraImage(); } } while (rr.getVariable("rerror") != "0"); sr = System.IO.File.OpenText("c:\\Documents and Settings\\cs266\\Desktop\\API\\API\\Python\\Red.out"); s = ""; while ((s = sr.ReadLine()) != null) { // print out for testing //System.Console.WriteLine("Printing red"); //System.Console.WriteLine(s); shape sh = parseShapes(s); if (sh != null) shapeList.Add(sh); } //end of red robot processing */ //shape s_stored = new shape(); //s_stored.id = -1; //for (int i = 1; i <= 10; i++) //{ // foreach (shape sha in shapeList) // { // if (sha.shapetype == "robot") // { // if (s_stored.id == -1 && sha.id==i) // { // s_stored = sha; // } // else if(sha.id==i) // { // if (s_stored.confidence < sha.confidence) // shapeList.Remove(s_stored); // else // shapeList.Remove(sha); // } // } // } //} sr.Close(); /* List<shape> anOldshapeList = shapeList; int[] foundb = new int[bcount]; for(int i = 0; i < bcount; i++) foundb[i] = -1; int foundcount = 0; for(int i = 0; i < bcount; i++) { int found = -1; foreach (shape sh in shapeList) { if ((Blobx[i] - 15 <= sh.x && Blobx[i] + 15 >= sh.x) && (Bloby[i] - 15 <= sh.y && Bloby[i] + 15 >= sh.y)) { found = 1; } } if(found != 1) { shape myShape = new shape(); double distance = -1; foreach (shape sh in oldShapeList){ double mydistance = Math.Sqrt( ((Blobx[i] - sh.x)*(Blobx[i] - sh.x)) + ((Bloby[i] - sh.y)*(Bloby[i] - sh.y))); if(distance == -1 || mydistance < distance) { distance = mydistance; myShape = sh; } } if(distance < 300) shapeList.Add(myShape); } } oldShapeList = anOldshapeList; */ //Console.WriteLine("VISION: Number of detected objects: "+shapeList.Count+"\n"); return shapeList; }
private shape parseShapes(string s) { //this is only called for robot shapes string[] line = s.Split(' '); if (line.Length < 2) return null; shape sh = new shape(); sh.orientation = (450+double.Parse(line[1]))%360; if (sh.orientation > 180) sh.orientation -= 360; //line 2,3,4,5 are the limits of the bounding box, these lines find the center //line 2,4 is bottom left //line 3,5 is the top right //bounding box does not take into account robot orientation sh.x = double.Parse(line[2]) + (double.Parse(line[3]) - double.Parse(line[2])) / 2; sh.y = double.Parse(line[4]) + (double.Parse(line[5]) - double.Parse(line[4])) / 2; //these are pixel offsets to place (0,0) //when this isn't called (eg for an obstacle), the offset must still be done sh.x -= 100; sh.y -= 280; sh.confidence = double.Parse(line[0]); // need to update this once there are more shapes //does this ever happen? parseShapes() is only called for robots if (line[6] == "square") { //sh.shapetype = "boundary"; //sh.id = 0; } else if (line[6] == "food") { //Console.WriteLine("DSLFKJS:DLFKJS:DLFKJS:DLFKJS SAW FOOD"); //sh.shapetype = "robot"; //sh.id = 8; } else //always { //Console.WriteLine("++++++++++++++Line 6:" + line[6]); sh.shapetype = "robot"; try { sh.id = int.Parse(line[6]); } catch (Exception e) { return null; } } if (sh.x > 1200) { Console.WriteLine("VISION: coordinate problem " + sh.id + " x " + sh.x + "\n"); Thread.Sleep(10000); } if (sh.y > 600) { Console.WriteLine("VISION: coordinate problem " + sh.id + " y " + sh.y + "\n"); Thread.Sleep(10000); } // RIGHT NOW WIDTH AND HEIGHT AREN'T DEFINED //Console.WriteLine("==========================new camera data=================================="); //System.Console.WriteLine("testing"); //System.Console.WriteLine(sh.id); //System.Console.WriteLine(sh.shapetype); //System.Console.WriteLine("xmin" + line[2]); //System.Console.WriteLine("xmax" + line[3]); //System.Console.WriteLine("ymin" + line[4]); //System.Console.WriteLine("ymax" + line[5]); //System.Console.WriteLine(sh.x); //System.Console.WriteLine(sh.y); //System.Console.WriteLine("orientation unfixed" + double.Parse(line[1])); //System.Console.WriteLine("orientation"+sh.orientation); //System.Console.WriteLine(sh.width); //System.Console.WriteLine(sh.height); return sh; }