Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

phosphorescent in MS 2015

After upgrading to 2015, my phosphorescent code stopped working properly. What I'm trying to do is to make plot where I can enable/disable phosphor effect and control its duration.

 

Currently I'm doing it like this:

 

// create renderer with effect disabled

 

            var brush = new SolidColorBrush(color);

            if (useRamp)
            {
                Phosphor.SetMode(brush, PhosphorMode.None);
                Phosphor.SetColorRamp(brush, new FadeRamp() { FadeColor = Colors.Red, DurationKind = DurationKind.Frames, Duration = 0 });
            }

            return new LinePlotRenderer() { Stroke = brush, StrokeThickness = thickness, StrokeDashArray = dash };

 

// enable effect when needed:

                if (Plot != null)
                {
                    var renderer = Plot.Renderer;

                    if (renderer is PointPlotRenderer)
                    {
                        PointPlotRenderer ppr = renderer as PointPlotRenderer;
                        if (ppr.Stroke is SolidColorBrush)
                            Phosphor.SetMode(ppr.Stroke as SolidColorBrush, enabled ? PhosphorMode.Deferred : PhosphorMode.None );
                    }
                    else if (renderer is LinePlotRenderer)
                    {
                        LinePlotRenderer lpr = renderer as LinePlotRenderer;
                        if (lpr.Stroke is SolidColorBrush)
                            Phosphor.SetMode(lpr.Stroke as SolidColorBrush, enabled ? PhosphorMode.Deferred : PhosphorMode.None);
                    }
                    else if (renderer is PlotRendererGroup)
                    {
                        foreach (var r in (renderer as PlotRendererGroup).PlotRenderers)
                        {
                            var rr = (PlotRenderer)r.Clone();

                            if (r is PointPlotRenderer)
                            {
                                PointPlotRenderer ppr = rr as PointPlotRenderer;
                                if (ppr.Stroke is SolidColorBrush)
                                    Phosphor.SetMode(ppr.Stroke as SolidColorBrush, enabled ? PhosphorMode.Deferred : PhosphorMode.None);
                            }
                            else if (r is LinePlotRenderer)
                            {
                                LinePlotRenderer lpr = rr as LinePlotRenderer;
                                if (lpr.Stroke is SolidColorBrush)
                                    Phosphor.SetMode(lpr.Stroke as SolidColorBrush, enabled ? PhosphorMode.Deferred : PhosphorMode.None);
                            }
                        }
                    }

                }

But this doesn't enable the effect at all (or doesn't disable if I start with PhosphorMode.Deferred)

 

 

In MS 2013 I was using this code to enable/disable the effect:

 

 if (enabled)
                {
                    graph.RenderMode = RenderMode.Raster;
                    var ramp = BrushRamp.CreateSingleGradientBrushRamp(/*getPlotColor(Plot)*/Colors.Orange, Colors.Red);
                    ramp.Duration = m_historyDepth;
                    ramp.DurationKind = NationalInstruments.Controls.Rendering.DurationKind.Frames;
                    graph.PhosphorColorRamp = ramp;
                }
                else
                {
                    graph.PhosphorColorRamp = null;
                }

What's the proper way now?

0 Kudos
Message 1 of 7
(4,705 Views)

 tried this to get gradient ramp:

            var brush = new SolidColorBrush(color);

            if (useRamp)
            {
                Phosphor.SetMode(brush, PhosphorMode.Deferred);
                var ramp = BrushRamp.CreateSingleGradientBrushRamp(color, Colors.Red);
                ramp.DurationKind = DurationKind.Frames;
                ramp.Duration = 0;
                Phosphor.SetColorRamp(brush, ramp);
            }

            return new LinePlotRenderer() { Stroke = brush, StrokeThickness = thickness, StrokeDashArray = dash };

and all history plots are the same color as the main one (shold be interpolating from yellow to red, but everything is yellow)

0 Kudos
Message 2 of 7
(4,703 Views)

When you say "everything is yellow", do you mean that each of your renderers uses yellow as their stroke color, or do you mean you are seeing phosphor but it is always yellow? If the former, I think this is due to using a Duration of zero on your color ramps, which indicates the phosphor effect should remain constant and never change. In your 2013 example code, you were using m_historyDepth: was that always zero?

~ Paul H
0 Kudos
Message 3 of 7
(4,675 Views)

I use history depth of 20. And by everything yellow I mean I see few history plots, and they all are the same color: http://screencast.com/t/6s0lllMj

 

Actually, if I start with depth 20, it looks like this: http://screencast.com/t/OZGUR1OAQII

 

So I think the issue is that PhosphorMode and Duration properties aren't updated, or maybe graph doesn't get that they were updated. There is my code again, that tries to set them:

 

        public int HistoryDepth
        {
            set
            {
                m_historyDepth = value;

                if(Plot != null)
                {
                    var renderer = Plot.Renderer;

                    if (renderer is PointPlotRenderer)
                    {
                        PointPlotRenderer ppr = renderer as PointPlotRenderer;
                        if (ppr.Stroke is SolidColorBrush)
                        {
                            var ramp = Phosphor.GetColorRamp(ppr.Stroke as SolidColorBrush);
                            if (ramp != null)
                                ramp.Duration = m_historyDepth;
                        }
                    }
                    else if (renderer is LinePlotRenderer)
                    {
                        LinePlotRenderer lpr = renderer as LinePlotRenderer;
                        if (lpr.Stroke is SolidColorBrush)
                        {
                            var ramp = Phosphor.GetColorRamp(lpr.Stroke as SolidColorBrush);
                            if (ramp != null)
                                ramp.Duration = m_historyDepth;
                        }
                    }
                    else if (renderer is PlotRendererGroup)
                    {
                        foreach (var r in (renderer as PlotRendererGroup).PlotRenderers)
                        {
                            var rr = (PlotRenderer)r.Clone();

                            if (r is PointPlotRenderer)
                            {
                                PointPlotRenderer ppr = rr as PointPlotRenderer;
                                if (ppr.Stroke is SolidColorBrush)
                                {
                                    var ramp = Phosphor.GetColorRamp(ppr.Stroke as SolidColorBrush);
                                    if (ramp != null)
                                        ramp.Duration = m_historyDepth;
                                }
                            }
                            else if (r is LinePlotRenderer)
                            {
                                LinePlotRenderer lpr = rr as LinePlotRenderer;
                                if (lpr.Stroke is SolidColorBrush)
                                {
                                    var ramp = Phosphor.GetColorRamp(lpr.Stroke as SolidColorBrush);
                                    if(ramp != null)
                                        ramp.Duration = m_historyDepth;
                                }
                            }
                        }
                    }


                    //if (graph.PhosphorColorRamp != null)
                    //    graph.PhosphorColorRamp.Duration = m_historyDepth;
                }
            }
        }

        public void removePlots(Graph graph)
        {

        }

        public void setTraceEnabled(Graph graph, HLGraphTraceType type, bool enabled)
        {
            EnabledTraces[type] = enabled;

            if (enabled)
            {
                switch (type)
                {
                    case HLGraphTraceType.MIN:
                        graph.Data[PlotMin.Index] = graph.Data[Plot.Index];
                        break;

                    case HLGraphTraceType.MAX:
                        graph.Data[PlotMax.Index] = graph.Data[Plot.Index];
                        break;

                    case HLGraphTraceType.AVERAGE:
                        graph.Data[PlotAvg.Index] = graph.Data[Plot.Index];
                        break;

                }
            }

            if (type == HLGraphTraceType.HISTORY)
            {
                if (Plot != null)
                {
                    var renderer = Plot.Renderer;

                    if (renderer is PointPlotRenderer)
                    {
                        PointPlotRenderer ppr = renderer as PointPlotRenderer;
                        if (ppr.Stroke is SolidColorBrush)
                            Phosphor.SetMode(ppr.Stroke as SolidColorBrush, enabled ? PhosphorMode.Deferred : PhosphorMode.None );
                    }
                    else if (renderer is LinePlotRenderer)
                    {
                        LinePlotRenderer lpr = renderer as LinePlotRenderer;
                        if (lpr.Stroke is SolidColorBrush)
                            Phosphor.SetMode(lpr.Stroke as SolidColorBrush, enabled ? PhosphorMode.Deferred : PhosphorMode.None);
                    }
                    else if (renderer is PlotRendererGroup)
                    {
                        foreach (var r in (renderer as PlotRendererGroup).PlotRenderers)
                        {
                            var rr = (PlotRenderer)r.Clone();

                            if (r is PointPlotRenderer)
                            {
                                PointPlotRenderer ppr = rr as PointPlotRenderer;
                                if (ppr.Stroke is SolidColorBrush)
                                    Phosphor.SetMode(ppr.Stroke as SolidColorBrush, enabled ? PhosphorMode.Deferred : PhosphorMode.None);
                            }
                            else if (r is LinePlotRenderer)
                            {
                                LinePlotRenderer lpr = rr as LinePlotRenderer;
                                if (lpr.Stroke is SolidColorBrush)
                                    Phosphor.SetMode(lpr.Stroke as SolidColorBrush, enabled ? PhosphorMode.Deferred : PhosphorMode.None);
                            }
                        }
                    }


                    //if (graph.PhosphorColorRamp != null)
                    //    graph.PhosphorColorRamp.Duration = m_historyDepth;
                }


                if (enabled)
                {
                    graph.RenderMode = RenderMode.Hardware;



                    //var ramp = BrushRamp.CreateSingleGradientBrushRamp(/*getPlotColor(Plot)*/Colors.Orange, Colors.Red);
                    //ramp.Duration = m_historyDepth;
                    //ramp.DurationKind = NationalInstruments.Controls.Rendering.DurationKind.Frames;
                    //graph.PhosphorColorRamp = ramp;
                }
                else
                {
                    //graph.PhosphorColorRamp = null;
                }
            }

            setVisible(true);
        }

 

0 Kudos
Message 4 of 7
(4,661 Views)

Based on the screenshots, your description of the problem seems accurate. Unfortunately, I am having trouble reproding the issue locally. I have attached the code I am using, slightly simplified from the sample code you gave.

~ Paul H
0 Kudos
Message 5 of 7
(4,652 Views)

Well, I've made a sample by myself, and it's working fine. So I'm trying to find the difference.

 

Anyway, is it possible to have both gradient and fading? Can I use gradiend from solid yellow to transparent red for example?

0 Kudos
Message 6 of 7
(4,642 Views)

Yes, that should work fine:


    Color endColor = Colors.Red;
    endColor.A = 0;
    var ramp = BrushRamp.CreateSingleGradientBrushRamp( Colors.Yellow, endColor );

~ Paul H
0 Kudos
Message 7 of 7
(4,638 Views)