예제 #1
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private void RenderNode(ElementNode node)
        {
            //Collect all the points first.
            double[] allPointsTimeOrdered = _GetAllSignificantDataPoints().ToArray();
            foreach (ElementNode elementNode in node.GetLeafEnumerator())
            {
                // this is probably always going to be a single element for the given node, as
                // we have iterated down to leaf nodes in RenderNode() above. May as well do
                // it this way, though, in case something changes in future.
                if (elementNode == null || elementNode.Element == null)
                {
                    continue;
                }

                ElementColorType colorType = ColorModule.getColorTypeForElementNode(elementNode);

                if (colorType == ElementColorType.FullColor)
                {
                    addIntentsToElement(elementNode.Element, allPointsTimeOrdered);
                }
                else
                {
                    IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false)
                                                 .Intersect(ColorGradient.GetColorsInGradient());
                    foreach (Color color in colors)
                    {
                        addIntentsToElement(elementNode.Element, allPointsTimeOrdered, color);
                    }
                }
            }
        }
예제 #2
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        public static EffectIntents RenderNode(ElementNode node, Curve levelCurve, ColorGradient colorGradient, TimeSpan duration, bool isDiscrete, bool allowZeroIntensity = false)
        {
            //Collect all the points first.
            double[] allPointsTimeOrdered = _GetAllSignificantDataPoints(levelCurve, colorGradient).ToArray();
            var      elementData          = new EffectIntents();

            foreach (ElementNode elementNode in node.GetLeafEnumerator())
            {
                // this is probably always going to be a single element for the given node, as
                // we have iterated down to leaf nodes in RenderNode() above. May as well do
                // it this way, though, in case something changes in future.
                if (elementNode == null || elementNode.Element == null)
                {
                    continue;
                }

                //ElementColorType colorType = ColorModule.getColorTypeForElementNode(elementNode);

                if (isDiscrete && IsElementDiscrete(node))
                {
                    IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false)
                                                 .Intersect(colorGradient.GetColorsInGradient());
                    foreach (Color color in colors)
                    {
                        AddIntentsToElement(elementNode.Element, allPointsTimeOrdered, levelCurve, colorGradient, duration, elementData, allowZeroIntensity, color);
                    }
                }
                else
                {
                    AddIntentsToElement(elementNode.Element, allPointsTimeOrdered, levelCurve, colorGradient, duration, elementData, allowZeroIntensity);
                }
            }

            return(elementData);
        }
예제 #3
0
        /// <summary>
        /// Convienience method to generate intents that knows how to deal with discrete colors.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="gradient"></param>
        /// <param name="level"></param>
        /// <param name="startPos"></param>
        /// <param name="endPos"></param>
        /// <param name="duration"></param>
        /// <param name="startTime"></param>
        /// <param name="isDiscrete"></param>
        /// <returns></returns>
        protected EffectIntents GenerateEffectIntents(ElementNode node, ColorGradient gradient, Curve level, double startPos, double endPos,
                                                      TimeSpan duration, TimeSpan startTime, bool isDiscrete)
        {
            EffectIntents result = new EffectIntents();

            if (isDiscrete)
            {
                IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(node, false)
                                             .Intersect(gradient.GetColorsInGradient());
                foreach (Color color in colors)
                {
                    double proportion     = gradient.GetProportionOfColorAt(startPos, color);
                    var    startIntensity = (level.GetValue(startPos * 100) / 100) * proportion;
                    proportion = gradient.GetProportionOfColorAt(endPos, color);
                    var endIntensity = (level.GetValue(endPos * 100) / 100) * proportion;
                    if (startIntensity > 0 && endIntensity > 0)
                    {
                        var intent = CreateDiscreteIntent(color, startIntensity, endIntensity, duration);
                        result.AddIntentForElement(node.Element.Id, intent, startTime);
                    }
                }
            }
            else
            {
                var startIntensity = level.GetValue(startPos * 100) / 100;
                var endIntensity   = level.GetValue(endPos * 100) / 100;
                if (startIntensity > 0 && endIntensity > 0)
                {
                    var intent = CreateIntent(gradient.GetColorAt(startPos), gradient.GetColorAt(endPos), startIntensity, endIntensity, duration);
                    result.AddIntentForElement(node.Element.Id, intent, startTime);
                }
            }

            return(result);
        }
예제 #4
0
파일: Alternating.cs 프로젝트: komby/vixen
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            // check for sane default colors when first rendering it
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

            //Validate Color 1
            if (validColors.Any() &&
                (!validColors.Contains(_data.Color1.ToArgb()) || !_data.ColorGradient1.GetColorsInGradient().IsSubsetOf(validColors)))
            {
                Color1         = validColors.First();
                ColorGradient1 = new ColorGradient(validColors.First());
            }

            //Validate color 2
            if (validColors.Any() &&
                (!validColors.Contains(_data.Color2.ToArgb()) || !_data.ColorGradient2.GetColorsInGradient().IsSubsetOf(validColors)))
            {
                if (validColors.Count > 1)
                {
                    Color2         = validColors.ElementAt(1);
                    ColorGradient2 = new ColorGradient(validColors.ElementAt(1));
                }
                else
                {
                    Color2         = validColors.First();
                    ColorGradient2 = new ColorGradient(validColors.First());
                }
            }
        }
예제 #5
0
 private void RenderPulseSegment(TimeSpan startTime, TimeSpan duration, Curve c, ColorGradient cg, IElementNode elementNode)
 {
     ColorValue[] values;
     if (HasDiscreteColors && IsElementDiscrete(elementNode))
     {
         IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false)
                                      .Intersect(cg.GetColorsInGradient());
         foreach (Color color in colors)
         {
             if (!_colorValueSet.TryGetValue(color, out values))
             {
                 values = new ColorValue[(int)(TimeSpan.TotalMilliseconds / FrameTime)];
                 _colorValueSet.Add(color, values);
             }
             RenderPulseSegment(values, startTime, duration, c, cg, color);
         }
     }
     else
     {
         if (_colorValueSet.TryGetValue(Color.Empty, out values))
         {
             RenderPulseSegment(values, startTime, duration, c, cg);
         }
     }
 }
예제 #6
0
        /// <summary>
        /// Gets the list of valid colors this effect can use and sets the hasDiscreteColors flag if any of it's targeted elements are discrete and have a restricted list.
        /// </summary>
        /// <returns></returns>
        protected HashSet <Color> GetValidColors()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any())
            {
                HasDiscreteColors = true;
            }
            return(validColors);
        }
예제 #7
0
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any() && !_data.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors))
            {
                //Our color is not valid for any elements we have.
                //Try to set a default color gradient from our available colors
                _data.ColorGradient = new ColorGradient(validColors.First());
            }
        }
예제 #8
0
파일: SetLevel.cs 프로젝트: thorhs/vixen
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any() && !validColors.Contains(_data.color.ToArgb()))
            {
                //Our color is not valid for any elements we have.
                //Set a default color
                Color = validColors.First();
            }
        }
예제 #9
0
 private void EnsureFaceMapColors(IElementNode node)
 {
     foreach (var elementNode in node.GetNodeEnumerator())
     {
         var fm = FaceModule.GetFaceModuleForElement(elementNode);
         if (fm != null)
         {
             var color = ColorModule.getValidColorsForElementNode(elementNode, true).FirstOrDefault();
             fm.DefaultColor = color;
         }
     }
 }
예제 #10
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

            if (validColors.Any() &&
                (!validColors.Contains(_data.StaticColor) || !_data.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors)))                 //Discrete colors specified
            {
                _data.ColorGradient = new ColorGradient(validColors.DefaultIfEmpty(Color.White).First());
                _data.StaticColor   = validColors.First();
            }
        }
예제 #11
0
        protected EffectIntents CreateIntentsForElement(ElementNode element, double intensity, Color color, TimeSpan duration)
        {
            EffectIntents effectIntents = new EffectIntents();

            foreach (ElementNode elementNode in element.GetLeafEnumerator())
            {
                if (HasDiscreteColors && IsElementDiscrete(elementNode))
                {
                    IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false);
                    if (!colors.Contains(color))
                    {
                        continue;
                    }
                }

                IIntent intent = CreateIntent(elementNode, color, intensity, duration);
                effectIntents.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero);
            }

            return(effectIntents);
        }
예제 #12
0
        private void AddNodes(List <Element> elements, ElementNode elementNode)
        {
            var element = new Element
            {
                Id   = elementNode.Id,
                Name = elementNode.Name
            };

            element.Colors = ColorModule.getValidColorsForElementNode(elementNode, true).Select(ColorTranslator.ToHtml).ToList();

            elements.Add(element);
            if (!elementNode.IsLeaf)
            {
                var children = new List <Element>();
                element.Children = children;
                foreach (var childNode in elementNode.Children)
                {
                    AddNodes(children, childNode);
                }
            }
        }
예제 #13
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private EffectIntents RenderNode(ElementNode node)
        {
            EffectIntents effectIntents = new EffectIntents();

            foreach (ElementNode elementNode in node.GetLeafEnumerator())
            {
                if (HasDiscreteColors && IsElementDiscrete(elementNode))
                {
                    IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false);
                    if (!colors.Contains(Color))
                    {
                        continue;
                    }
                }

                IIntent intent = CreateIntent(elementNode, Color, IntensityLevel, TimeSpan);
                effectIntents.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero);
            }

            return(effectIntents);
        }
예제 #14
0
        protected HashSet <Color> GetDiscreteColors(Object component)
        {
            HashSet <Color> validColors = new HashSet <Color>();

            if (component is IEffect)
            {
                IEffect effect = (IEffect)component;
                validColors.AddRange(effect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            }
            else if (component is Array)
            {
                foreach (var item in (Array)component)
                {
                    if (item is IEffect)
                    {
                        IEffect effect = (IEffect)item;
                        validColors.AddRange(effect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
                    }
                }
            }

            return(validColors);
        }
예제 #15
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        //we only need to check against 1 color variable,
        //it should be checked at a later time than what this is doing currently
        private void CheckForInvalidColorData()
        {
            // check for sane default colors when first rendering it
            var validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

            if (validColors.Any())
            {
                bool changed = false;
                foreach (GradientLevelPair t in Colors)
                {
                    if (!t.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors))
                    {
                        t.ColorGradient = new ColorGradient(validColors.First());
                        changed         = true;
                    }
                }
                if (changed)
                {
                    OnPropertyChanged("Colors");
                }
            }
        }