Example #1
0
        public void OnUpdateColorDefinition(UpdateColorDefinition update)
        {
            ColorDefinition def = update.Body;

            if (!def.Validate())
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.OperationFailed,
                        "ColorDefinition is not valid."
                        )
                    );
                return;
            }

            ColorSet set = _state.Colors.Find(def.Compare);

            if (set == null)
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.UnknownEntry,
                        "ColorSet List does not contain an entry for: " + def.Name
                        )
                    );
                return;
            }

            int index = set.Colors.FindIndex(def.CompareColor);

            if (index >= 0)
            {
                set.Colors[index] = def;
                update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
                _state.UpdateColorSetMap();
                SendNotification(_submgrPort, update, Filter.ColorDefinitions.ToString());
            }
            else
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.UnknownEntry,
                        "ColorSet Definition List does not contain an entry for: " + def.Name
                        )
                    );
            }
        }
Example #2
0
        public static ColorDefinition FromColor(Color color, string name)
        {
            ColorDefinition definition = new ColorDefinition();

            definition._name = name;

            definition._r = color.R;
            definition._g = color.G;
            definition._b = color.B;

            definition.Validate();

            return(definition);
        }
Example #3
0
        public void OnAddColorDefinition(AddColorDefinition add)
        {
            ColorDefinition insert = add.Body;

            if (insert.Validate() == false)
            {
                add.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.OperationFailed,
                        "ColorDefinition is invalid"
                        )
                    );
                return;
            }

            ColorSet set = _state.Colors.Find(insert.Compare);

            if (set != null)
            {
                if (set.Colors.Exists(insert.CompareColor))
                {
                    add.ResponsePort.Post(
                        Fault.FromCodeSubcodeReason(
                            FaultCodes.Receiver,
                            DsspFaultCodes.DuplicateEntry,
                            "ColorSet Definition List already contains an entry for: " + insert.Name
                            )
                        );
                    return;
                }

                set.Colors.Add(insert);
                _state.UpdateColorSetMap();
                add.ResponsePort.Post(DefaultInsertResponseType.Instance);
            }
            else
            {
                set      = new ColorSet();
                set.Name = insert.Name;
                set.Colors.Add(insert);
                _state.Colors.Add(set);
                _state.UpdateColorSetMap();
                add.ResponsePort.Post(DefaultInsertResponseType.Instance);
            }

            SendNotification(_submgrPort, add, Filter.ColorDefinitions.ToString());
        }
Example #4
0
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new ColorSegmentState();
            }
            else
            {
                for (int set = 0; set < _state.Colors.Count; set++)
                {
                    ColorSet colorSet = _state.Colors[set];

                    for (int index = 0; index < colorSet.Colors.Count; index++)
                    {
                        ColorDefinition color = colorSet.Colors[index];
                        if (!color.Validate())
                        {
                            colorSet.Colors.RemoveAt(index);
                            index--;
                        }
                    }

                    if (colorSet.Colors.Count == 0)
                    {
                        _state.Colors.RemoveAt(set);
                        set--;
                    }
                }
                _state.UpdateColorSetMap();
                _state.ImageSource     = null;
                _state.Processing      = false;
                _state.FrameCount      = 0;
                _state.DroppedFrames   = 0;
                _state.FoundColorAreas = null;
            }

            _utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            _fwdPort = ServiceForwarder <ColorSegmentOperations>(ServiceInfo.Service);

            base.Start();

            Activate <ITask>(
                Arbiter.Receive <webcam.UpdateFrame>(true, _webcamNotify, OnWebcamUpdateFrame)
                );
            _webcamPort.Subscribe(_webcamNotify, typeof(webcam.UpdateFrame));
        }