Exemplo n.º 1
0
        /*
         * DynamicStruct ConvertDynamic(DynamicObject dyn)
         * {
         *  Type t = dyn.GetType();
         *  DynamicStruct ret = new DynamicStruct();
         *  ret.Type = GetTypeRef(t);
         *  TypeStruct ts = types.GetValue(ret.Type);
         *  ret.MemberValues = new ValueStruct[ts.Members.Length];
         *  int slot = 0;
         *  foreach (var member in ts.Members)
         *  {
         *      string name = strings.GetValue(member);
         *      var p = t.GetProperty(name);
         *      if (p != null)
         *      {
         *          ret.MemberValues[slot] = Convert(p.GetValue(dyn));
         *      }
         *      else
         *          ret.MemberValues[slot] = Convert(t.GetField(name).GetValue(dyn));
         *      slot++;
         *  }
         *  string[] dynnames=dyn.GetDynamicMemberNames().ToArray();
         *  ret.DynamicMembers = new ushort[dynnames.Length];
         *  ret.DynamicMemberValues = new ValueStruct[dynnames.Length];
         *  for(int i=0;i<dynnames.Length;i++)
         *  {
         *      ret.DynamicMembers[i] = GetStringRef(dynnames[i]);
         *
         *      object obj;
         *
         *  }
         *  return ret;
         * }
         */
        ObjectStruct ConvertObject(object dyn)
        {
            Type         t   = dyn.GetType();
            ObjectStruct ret = new ObjectStruct();

            ret.Type = GetTypeRef(t);
            TypeStruct ts = types.GetValue(ret.Type);

            ret.Values = new ValueStruct[ts.Members.Length];
            int slot = 0;

            foreach (var member in ts.Members)
            {
                string name = strings.GetValue(member);
                var    p    = t.GetProperty(name);
                if (p != null)
                {
                    ret.Values[slot] = Convert(p.GetValue(dyn));
                }
                else
                {
                    ret.Values[slot] = Convert(t.GetField(name).GetValue(dyn));
                }
                slot++;
            }
            return(ret);
        }
Exemplo n.º 2
0
        //private bool CheckObjectStruct(ObjectStruct based, ObjectStruct current)
        //{
        //    int err = 10;
        //    int errR = 21;
        //    if (current.Color.R > based.Color.R - errR && current.Color.R < based.Color.R + errR)
        //        if (current.Color.G > based.Color.G - err && current.Color.G < based.Color.G + err)
        //            if (current.Color.B > based.Color.B - err && current.Color.B < based.Color.B + err)
        //            {
        //                if (current.Radius > based.Radius - 10 && current.Radius < based.Radius + 10) return true;
        //            }

        //    return false;
        //}


        private bool CheckObjectStruct(ObjectStruct based, ObjectStruct current)
        {
            if (current.Tone != null && based.Tone != null)
            {
                double err        = 0.5f;
                int    index      = 0;
                int    considence = 0;
                foreach (var tone in current.Tone)
                {
                    if (based.Tone.Length == current.Tone.Length)
                    {
                        if (tone.Hue >= based.Tone[index].Hue - 9 && tone.Hue <= based.Tone[index].Hue + 9)//8
                        {
                            if (tone.Saturation >= based.Tone[index].Saturation - 0.3f && tone.Saturation <= based.Tone[index].Saturation + 0.3f)
                            {
                                considence++;
                            }
                        }
                        index++;
                    }
                }
                //  Debug.Write(string.Format("{0}%", considence));

                int per = (int)(((double)considence / based.Tone.Length) * 100);
                Debug.Write(string.Format("{0}%, ", per));
                if (per >= 65)
                {
                    if (current.Radius > based.Radius - 10 && current.Radius < based.Radius + 10)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        private BitmapImage ImageFromStruct(ObjectStruct obj)
        {
            int size = (int)Math.Sqrt(obj.Tone.Length);

            Bitmap img   = new Bitmap(size, size);
            int    index = 0;

            for (int x = 0; x < img.Height; x++)
            {
                for (int y = 0; y < img.Width; y++)
                {
                    double hue   = obj.Tone[index].Hue;
                    double sat   = obj.Tone[index].Saturation;
                    double val   = obj.Tone[index].Value;
                    Color  color = WebCamConnect.ColorFromHSV(hue, sat, val);
                    img.SetPixel(x, y, color);
                    index++;
                }
            }

            BitmapImage btm = new BitmapImage();

            using (MemoryStream memStream2 = new MemoryStream())
            {
                (img).Save(memStream2, System.Drawing.Imaging.ImageFormat.Png);
                memStream2.Position = 0;
                btm.BeginInit();
                btm.CacheOption  = BitmapCacheOption.OnLoad;
                btm.UriSource    = null;
                btm.StreamSource = memStream2;
                btm.EndInit();
            }

            return(btm);
        }
Exemplo n.º 4
0
 private static bool CheckObjectPalette(ObjectStruct based, ObjectStruct current)
 {
     if (current.Tone != null && based.Tone != null)
     {
         int err        = 9;
         int index      = 0;
         int considence = 0;
         foreach (var tone in current.Tone)
         {
             if (based.Tone.Length == current.Tone.Length)
             {
                 if (tone.Hue >= based.Tone[index].Hue - err && tone.Hue <= based.Tone[index].Hue + err)//8
                 {
                     if (tone.Saturation >= based.Tone[index].Saturation - 0.3f && tone.Saturation <= based.Tone[index].Saturation + 0.3f)
                     {
                         considence++;
                     }
                 }
                 index++;
             }
         }
         int per = (int)(((double)considence / based.Tone.Length) * 100);
         if (per >= 65)
         {
             if (current.Radius > based.Radius - 10 && current.Radius < based.Radius + 10)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 5
0
 void WriteObject(ObjectStruct obj)
 {
     WriteVInt(obj.Type);
     foreach (var m in obj.Values)
     {
         WriteValue(m);
     }
 }
Exemplo n.º 6
0
 /* This is of particular interest when passing parameters to methods.
  * In C#, parameters are (by default) passed by value, meaning that they are implicitly copied when passed to the method.
  */
 void ChangingValueTest0(ObjectStruct objS, ObjectClass objC)
 {
     /* For value-type parameters, this means physically copying the instance (in the same way of a struct was copied),
      * while for reference-types it means copying a reference (in the same way of a reference was copied).
      */
     objS.NameObject = "ChangedTest0Name";
     objC.NameObject = "ChangedTest0Name";
     objC            = null;
 }
Exemplo n.º 7
0
        public void can_create_objects()
        {
            ObjectStruct objStruct = new ObjectStruct("Struct0");

            Assert.That(objStruct.NameObject == "Struct0");
            Assert.That(objStruct.Type == "Value");

            ObjectClass objClass = new ObjectClass("Class0");

            Assert.That(objClass.NameObject == "Class0");
            Assert.That(objClass.Type == "Reference");
        }
Exemplo n.º 8
0
        private static ObjectStruct GetDominantColorFromBlob(Bitmap source, Blob blob)
        {
            int rX = blob.Rectangle.Width / 2;
            int rY = blob.Rectangle.Height / 2;
            // int r = blob.Rectangle.Width > 200 ? 40 : 2;
            int r = blob.Rectangle.Width / 4;



            IColorQuantizer quantizer = new MedianCutQuantizer();

            for (int x = 0; x < blob.Rectangle.Width - 1; x++)
            {
                for (int y = 0; y < blob.Rectangle.Height - 1; y++)
                {
                    Color color = source.GetPixel(blob.Rectangle.Location.X + x, blob.Rectangle.Location.Y + y);

                    if (x > rX - r && x < rX + r && y > rY - r && y < rY + r)
                    {
                        double hue;
                        double saturation;
                        double value;
                        ColorToHSV(color, out hue, out saturation, out value);
                        Color alignedСolor = ColorFromHSV(hue, saturation, value);

                        quantizer.AddColor(alignedСolor);
                    }
                }
            }
            //   int paletteLenght = blob.Rectangle.Width > 200 ? 24 : 24; 36 64
            int paletteLenght = 256;

            Color[] color1 = quantizer.GetPalette(paletteLenght);

            ObjectStruct obj    = new ObjectStruct();
            int          lenght = paletteLenght;

            obj.Tone = new HSVColor[lenght];
            int index = 0;

            foreach (Color color in color1)
            {
                double hue;
                double saturation;
                double value;
                ColorToHSV(color, out hue, out saturation, out value);
                obj.Tone[index] = new HSVColor(hue, saturation, value);
                index++;
            }
            obj.Radius = rX;
            return(obj);
        }
Exemplo n.º 9
0
        public static void Main_Visitor()
        {
            var os = new ObjectStruct();

            os.AddElement(new ConcreteElement1());
            os.AddElement(new ConcreteElement1());

            var vis1 = new ConcreteVisotor1();

            os.Accept(vis1);

            Console.ReadLine();
        }
Exemplo n.º 10
0
        private static void ObjectComparison(ref ObjectStruct based, ObjectStruct newObject)
        {
            List <int?> newId = new List <int?>();
            int?        id    = null;

            foreach (var basedId in based.Id)
            {
                id = newObject.Id.Find(o => o == basedId);
                if (id != null)
                {
                    newId.Add(id);
                }
            }

            if (newId.Count > 0)
            {
                ObjectList.ForEach(ob => newId.ForEach(i => ob.Id.Remove(i)));
                based.Id = newId;
            }
            ;
        }
Exemplo n.º 11
0
        public void test_changing_properties()
        {
            ObjectStruct objStruct    = new ObjectStruct("Struct0");
            ObjectStruct tmpVarStruct = objStruct;

            tmpVarStruct.NameObject = "ChangedName";
            tmpVarStruct.Type       = "ChangedType";

            Assert.That(objStruct.NameObject == "Struct0");
            Assert.That(objStruct.Type == "Value");

            Assert.That(tmpVarStruct.NameObject == "ChangedName");
            Assert.That(tmpVarStruct.Type == "ChangedType");

            ObjectClass objClass    = new ObjectClass("Class0");
            ObjectClass tmpVarClass = objClass;

            tmpVarClass.NameObject = "ChangedName";
            tmpVarClass.Type       = "ChangedType";

            Assert.That(objClass.NameObject == "ChangedName");
            Assert.That(objClass.Type == "ChangedType");

            Assert.That(tmpVarClass.NameObject == "ChangedName");
            Assert.That(tmpVarClass.Type == "ChangedType");

            ChangingValueTest0(tmpVarStruct, tmpVarClass);
            Assert.That(tmpVarStruct.NameObject == "ChangedName");
            Assert.That(tmpVarStruct.Type == "ChangedType");
            Assert.That(tmpVarClass.NameObject == "ChangedTest0Name");
            Assert.That(objClass.NameObject == "ChangedTest0Name");
            Assert.That(objClass.Type == "Reference");

            ChangingValueTest1(ref tmpVarStruct, ref tmpVarClass);
            Assert.That(tmpVarStruct.NameObject == "ChangedTest1Name");
            Assert.That(tmpVarClass == null);
            Assert.That(objClass == null);
        }
Exemplo n.º 12
0
 void ChangingValueTest1(ref ObjectStruct objS, ref ObjectClass objC)
 {
     objS.NameObject = "ChangedTest1Name";
     objC.NameObject = "ChangedTest1Name";
     objC            = null;
 }