Пример #1
0
        void SetCenterColor()
        {
            int        c1    = GetNeuronValueInt(null, na.Width / 2, 0);
            int        c2    = GetNeuronValueInt(null, na.Width / 2, 1);
            ModuleUKSN nmUKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN));

            if (nmUKS != null && nmUKS.Labeled("Color") != null)
            {
                List <Thing> colors = nmUKS.Labeled("Color").Children;
                //if (c1 != 0)
                {
                    nmUKS.Fire(nmUKS.Valued(c1, colors));
                }
                //if (c2 != 0)
                {
                    nmUKS.Fire(nmUKS.Valued(c2, colors));
                }
            }
        }
Пример #2
0
        //maintain a list of objects in the current visual field
        public void FireVisibleObjects()
        {
            ModuleView naUKS = theNeuronArray.FindAreaByLabel("Module2DUKS");

            if (naUKS == null)
            {
                return;
            }
            ModuleUKSN UKS = (ModuleUKSN)naUKS.TheModule;

            if (UKSSegments == null)
            {
                return;
            }
            //Thing tVisible = UKS.Labeled("Visible");

            //clear all visiblility references
            //for (int i = 0; i < UKSSegments.Count; i++)
            //    UKSSegments[i].RemoveReference(tVisible);

            ModuleView naVision = theNeuronArray.FindAreaByLabel("Module2DVision");

            if (naVision == null)
            {
                return;
            }
            int   possibleViewAngles = naVision.Width;
            float deltaTheta         = Module2DVision.fieldOfView / possibleViewAngles;

            for (int i = 0; i < possibleViewAngles; i++)
            {
                float     theta = (float)-Module2DVision.fieldOfView / 2 + (i * deltaTheta);
                PointPlus P     = new PointPlus {
                    R = 10, Theta = theta
                };
                foreach (Thing t in UKSSegments)
                {
                    Segment s = SegmentFromUKSThing(t);
                    if (s == null)
                    {
                        continue;
                    }
                    Utils.FindIntersection(new Point(0, 0), P.P, s.P1.P, s.P2.P,
                                           out bool lines_intersect, out bool segments_intersect,
                                           out Point intersection, out Point close_p1, out Point closep2, out double collisionAngle);
                    if (segments_intersect)
                    {
                        //TODO...only fire the closest at each point
                        UKS.Fire(t);
                        //                        t.AddReference(tVisible);
                    }
                }
            }
        }
Пример #3
0
        //TODO: rewrite again
        public Thing AddSegmentFromVision(PointPlus P1, PointPlus P2, ColorInt theColor, bool moved)
        {
            Thing retVal = null;

            Debug.WriteLine("AddSegment: " + P1 + P2 + theColor);
            //determine if the segment is already in the UKS.
            //Correct it if it is there, add it if it is not.
            //FUTURE: detect motion
            if (theColor == 0)
            {
                return(null);
            }
            Segment newSegment = new Segment()
            {
                P1 = P1, P2 = P2, theColor = theColor
            };
            ModuleUKSN UKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN));

            GetSegmentsFromUKS();
            if (UKS != null)
            {
                //it's easier if we sort by theta
                OrderSegment(newSegment);
                retVal = MostLikelySegment(newSegment);
                if (retVal != null)
                {
                    //UKS.Fire(match);
                    //OrderSegment(match);
                    //Segment s = SegmentFromUKSThing(match);
                    //float newVisualWidth = newSegment.VisualWidth();
                    //float matchVisualWidth = s.VisualWidth();
                    ////if the newVisualWidth is bigger, an adjustment is needed
                    ////this happens if the initial view was occluded but now it is less
                    //Thing match1 = MostLikelyPoint(newSegment.P1, newSegment.theColor);
                    //Thing match2 = MostLikelyPoint(newSegment.P2, newSegment.theColor);
                    //if (match1 != null && match2 != null)
                    //{
                    //    if (newSegment.P1.Conf < s.P1.Conf)
                    //    {
                    //        s.P1.Conf = newSegment.P1.Conf;
                    //        s.P1.R = newSegment.P1.R;
                    //        s.P1.Theta = newSegment.P1.Theta;
                    //    }
                    //    if (newSegment.P2.Conf < s
                    //        .P2.Conf)
                    //    {
                    //        s.P2.Conf = newSegment.P2.Conf;
                    //        s.P2.R = newSegment.P2.R;
                    //        s.P2.Theta = newSegment.P2.Theta;
                    //    }
                    //}

                    ////there is a significant point mismatch...
                    //else
                    //{
                    //    if (match1 == null && newSegment.P1.R > s.P1.R)
                    //    {
                    //        s.P1.Conf = newSegment.P1.Conf;
                    //        s.P1.R = newSegment.P1.R;
                    //        s.P1.Theta = newSegment.P1.Theta;
                    //    }
                    //    if (match2 == null && newSegment.P2.R > s.P2.R)
                    //    {
                    //        s.P2.Conf = newSegment.P2.Conf;
                    //        s.P2.R = newSegment.P2.R;
                    //        s.P2.Theta = newSegment.P2.Theta;
                    //    }
                    //}
                }
                else
                {
                    retVal = AddSegmentToUKS(P1, P2, theColor);
                    UKS.Fire(retVal);
                }
                UpdateDialog();
            }
            return(retVal);
        }