示例#1
0
        //TODO add more properties to Stroke
        public Thing AddStrokeToUKS(PointPlus P1, PointPlus P2)
        {
            ModuleUKS uks = (ModuleUKS)FindModuleByType(typeof(ModuleUKS));

            if (uks is ModuleUKS UKS)
            {
                if (uks.Labeled("AbsStroke") == null)
                {
                    uks.AddThing("AbsStroke", "Visual");
                }
                Thing t1 = uks.Valued(P1);
                if (t1 == null)
                {
                    t1 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P1);
                }
                Thing t2 = uks.Valued(P2);
                if (t2 == null)
                {
                    t2 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P2);
                }
                Thing newThing = UKS.AddThing("s" + strokeCount++, new Thing[] { UKS.Labeled("AbsStroke") }, null, new Thing[] { t1, t2 });
                return(newThing);
            }
            return(null);
        }
示例#2
0
        private void SetAreasToUKS()
        {
            Thing currentlyVisibleParent = uks.GetOrAddThing("CurrentlyVisible", "Visual");

            uks.DeleteAllChilden(currentlyVisibleParent);
            Thing valueParent = uks.GetOrAddThing("Value", "Thing");

            foreach (Area a in areas)//all the areas currently visible
            {
                Thing theArea = uks.AddThing("Area*", currentlyVisibleParent);

                uks.SetValue(theArea, a.greatestLength, "Siz", 0);
                uks.SetValue(theArea, (float)a.orientation, "Ang", 2);
                uks.SetValue(theArea, (float)a.centroid.X, "CtrX", 0);
                uks.SetValue(theArea, (float)a.centroid.Y, "CtrY", 0);
                uks.SetValue(theArea, (float)a.avgColor.hue / 360f, "Hue", 2);
                uks.SetValue(theArea, (float)a.avgColor.saturation, "Sat", 2);
                uks.SetValue(theArea, (float)a.avgColor.luminance, "Lum", 2);

                List <Thing> theCorners = new List <Thing>();
                foreach (Corner c in a.areaCorners)
                {
                    theCorners.Add(uks.AddThing("Cnr*", theArea));

                    Thing theLocation = uks.Valued(c.loc, uks.Labeled("Point").Children);
                    if (theLocation == null)
                    {
                        theLocation   = uks.AddThing("p*", "Point");
                        theLocation.V = c.loc;
                    }
                    theLocation.AddParent(theCorners.Last());
                }
                //add the reference links
                if (theCorners.Count == 2)
                {
                    theCorners[0].AddReference(theCorners[1]); //add lengths to these?
                    theCorners[1].AddReference(theCorners[0]);
                }
                else
                {
                    for (int i = 0; i < theCorners.Count; i++)
                    {
                        int j = a.areaCorners.IndexOf(a.areaCorners[i].c1);
                        int k = a.areaCorners.IndexOf(a.areaCorners[i].c2);
                        if (k == -1 || j == -1 || j == k)
                        { // the area is not valid, delete it
                            uks.DeleteAllChilden(theArea);
                            uks.DeleteThing(theArea);
                            break;
                        }
                        theCorners[i].AddReference(theCorners[j]); //add lengths to these?
                        theCorners[i].AddReference(theCorners[k]);
                    }
                }
            }
        }