Ejemplo n.º 1
0
        public static void test_json()
        {
            Features f = new Features();
            f.imagefile = "somefile.png";
            f.intlines = new List<IntLineFeature>();
            for (int i = 0; i < 3; ++i)
            {
                var l = new IntLineFeature();
                l.id = i;
                l.line.p.X = i;
                l.line.p.Y = i * 2;
                l.line.q.X = i + 10;
                l.line.q.Y = i * 2 + 10;
                f.intlines.Add(l);
            }
            string json = f.ToString();
            Console.WriteLine(json);

            Features g = Features.FromString(json);
            Console.WriteLine(string.Format("file: {0} line[1].p.X: {1} line[2].q.Y: {2}", g.imagefile, g.intlines[1].line.p.X, g.intlines[2].line.q.Y));

            bool same = json == g.ToString();
            Console.WriteLine(string.Format("same json: {0}", same));
            System.IO.File.WriteAllText("test.features.json", json);
        }
Ejemplo n.º 2
0
 public static Features FromString(string json)
 {
     var reader = new JsonReader();
     dynamic contents = reader.Read(json);
     Features f = new Features();
     f.imagefile = contents.imagefile;
     //try
     {
         f.intlines = new List<IntLineFeature>();
         foreach (dynamic l in contents.intlines)
         {
             IntLineFeature lf = new IntLineFeature();
             lf.id = l.id;
             int[] line = l.line;
             lf.line.p.X = l.line[0];
             lf.line.p.Y = line[1];
             lf.line.q.X = line[2];
             lf.line.q.Y = line[3];
             f.intlines.Add(lf);
         }
     }
     //catch { } //FIXME: catch the right thing
     return f;
 }
Ejemplo n.º 3
0
 bool matched(IntLineFeature feature)
 {
     IntLineFeature lf;
     return sister.features.find(feature.id, out lf);
 }
Ejemplo n.º 4
0
 public bool find(int id, out IntLineFeature found)
 {
     foreach (var lf in intlines)
     {
         if (lf.id == id)
         {
             found = lf;
             return true;
         }
     }
     found = new IntLineFeature();
     return false;
 }
Ejemplo n.º 5
0
 private void pictureBox_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (!inline)
         {
             newlinestart = new System.Drawing.Point(e.X, e.Y);
             newlineend = newlinestart;
             inline = true;
         }
         else
         {
             var lf = new IntLineFeature();
             int zoom = pictureBox.zmLevel;
             Rectangle ROI = pictureBox.ROI;
             lf.id = features.newId();
             lf.line.p.X = (newlinestart.X + ROI.Left * zoom) / zoom;
             lf.line.p.Y = (newlinestart.Y + ROI.Top * zoom) / zoom;
             lf.line.q.X = (newlineend.X + ROI.Left * zoom) / zoom;
             lf.line.q.Y = (newlineend.Y + ROI.Top * zoom) / zoom;
             features.intlines.Add(lf);
             inline = false;
         }
         pictureBox.Refresh();
     }
 }