Esempio n. 1
0
 public void update()
 {
     if (outParams != null)
     {
         if (TimeMode)
         {
             if (timei >= 0 && timei < outParams.timeOutSet.Count)
             {
                 outSet = outParams.timeOutSet[timei];
             }
             else
             {
                 outSet = null;
             }
             if (timei >= 0 && timei < outParams.timeVisOutSet.Count)
             {
                 visOutSet = outParams.timeVisOutSet[timei];
             }
             else
             {
                 visOutSet = null;
             }
         }
         else
         {
             outSet    = outParams.outSet;
             visOutSet = outParams.visOutSet;
         }
     }
     else
     {
         outSet    = null;
         visOutSet = null;
     }
     updateSizes();
     redraw();
 }
Esempio n. 2
0
        public VisOutSet updateVisOutVar(OutSet outSet, ViewParams viewParams)
        {
            VisOutSet       visOutSet = new VisOutSet();
            List <VisSerie> visSeries;
            List <VisSerie> visRawSeries = null;
            VisSerie        visSerie;
            List <VisPoint> visPoints;

            OutCell[][]   rawOutCells = outSet.rawOutCells;
            OutCell[]     compRawOutCells;
            OutCell       outCell;
            OutComp       outComp;
            VisComp       visComp;
            VisAxes       visAxes = new VisAxes();
            VisAxis       visAxis;
            Axes          axes  = outSet.axes;
            Axis          xaxis = new Axis();
            Axis          yaxis = new Axis();
            PhaseType     phase = new PhaseType();
            int           nphases;
            int           ncomps;
            int           npoints;
            int           nseries;
            int           ncells;
            bool          previewMode  = (viewParams.viewType == ViewType.Setup);
            bool          dispDualTime = (viewParams.phaseDisplay == PhaseDisplayType.UpperLowerTime);
            bool          dispDual     = (viewParams.phaseDisplay == PhaseDisplayType.UpperLower || dispDualTime);
            bool          usePrefixes  = (viewParams.exponentType == ExponentType.Prefixes);
            bool          scaleDrawReverse;
            bool          scaleSet;
            bool          sum;
            float         maxcon = 0;
            float         con    = 0;
            float         rangey = 0;
            float         rangex = 0;
            float         range;
            float         rangey0;
            float         scaleu, scalel;
            float         miny, maxy;
            float         minvx     = 0;
            float         maxvx     = 0;
            float         minxlabel = 0;
            float         maxxlabel = 0;
            float         k;
            float         flow;
            float         pos;
            float         vceff;
            RectangleF    allrect = new RectangleF(0, 0, 1, 1);
            RectangleF    vrect = allrect;
            RectangleF    rawvrect = allrect;
            float         unitsize = 0.025f;
            float         vx, vy;
            int           s = 0;
            int           c;
            string        label         = "";
            MassUnitsType prefMassUnits = inParams.massUnits;
            int           prefMassUnitsi;
            float         multiplier = 1;

            // general vars
            if (dispDual && !previewMode)
            {
                nphases = 2;
            }
            else
            {
                nphases = 1;
            }
            ncomps  = inParams.comps.Count;
            nseries = outSet.outCells.Length;

            if (ncomps == 0)
            {
                return(visOutSet);
            }

            // update outComps units
            foreach (OutComp outComp0 in outSet.comps)
            {
                outComp0.units     = inParams.viewUnits;
                outComp0.volUnits  = inParams.volUnits;
                outComp0.timeUnits = inParams.timeUnits;
                outComp0.massUnits = inParams.massUnits;
            }

            // convert out to units
            outSet.unitsOutCells = new OutCell[outSet.outCells.Length][];
            for (s = 0; s < nseries; s++)
            {
                c = s / nphases;
                if (viewParams.phaseDisplay == PhaseDisplayType.Lower)
                {
                    phase = PhaseType.Lower;
                }
                else
                {
                    phase = PhaseType.Upper;
                }
                if (nphases > 1)
                {
                    phase = (PhaseType)((s % nphases) + 1);
                }
                ncells = outSet.outCells[s].Length;

                outSet.unitsOutCells[s] = new OutCell[ncells];
                for (int i = 0; i < ncells; i++)
                {
                    pos = inParams.convertUnit(outSet.outCells[s][i].pos, inParams.natUnits, viewParams.viewUnits, phase);
                    con = outSet.outCells[s][i].con;
                    outSet.unitsOutCells[s][i] = new OutCell(pos, con);
                }
            }

            // initialise vis series
            visSeries = new List <VisSerie>(nseries);
            if (viewParams.showProbUnits)
            {
                visRawSeries = new List <VisSerie>(nseries);
            }

            if (viewParams.showProbUnits)
            {
                if (dispDual)
                {
                    rawvrect.Height = unitsize * 2;
                }
                else
                {
                    rawvrect.Height = unitsize;
                }

                vrect.Y      = rawvrect.Bottom;
                vrect.Height = 1 - vrect.Y;
            }

            // Axes
            axes = outSet.axes;
            // Set maxcon / rangey
            if (viewParams.yScale == YScaleType.Absolute)
            {
                // * not exactly correct; should use maxcon from first (time) step
                maxcon = 0;
                for (int i = 0; i < outSet.comps.Count; i++)
                {
                    if (outSet.comps[i].m > maxcon)
                    {
                        maxcon = outSet.comps[i].m;
                    }
                }
                rangey = maxcon;
            }
            else if (viewParams.yScale == YScaleType.Normalised)
            {
                rangey = 0;
            }
            else             // Auto or Log scale
            {
                maxcon = 0;
                for (int i = 0; i < axes.maxcon.Count; i++)
                {
                    if (axes.maxcon[i] > maxcon)
                    {
                        maxcon = axes.maxcon[i];
                    }
                }
                if (viewParams.yScale == YScaleType.Automatic)
                {
                    rangey = maxcon;
                }
                else if (axes.logScale)
                {
                    maxcon = (float)Math.Ceiling(Math.Log(maxcon));                     // Nearest E power
                    rangey = 5;
                    // Scale: E^maxcon ... E^(maxcon-rangey)
                }
            }

            // Column lines
            if (viewParams.showProbUnits)
            {
                visAxis           = new VisAxis();
                visAxis.drawColor = Colors.LightGray;
                visAxis.point1    = new VisPoint(vrect.Left, rawvrect.Top);
                visAxis.point2    = new VisPoint(vrect.Left, rawvrect.Bottom);
                visAxes.visAxes.Add(visAxis);

                visAxis           = new VisAxis();
                visAxis.drawColor = Colors.LightGray;
                visAxis.point1    = new VisPoint(vrect.Right, rawvrect.Top);
                visAxis.point2    = new VisPoint(vrect.Right, rawvrect.Bottom);
                visAxes.visAxes.Add(visAxis);

                visAxis        = new VisAxis();
                visAxis.point1 = new VisPoint(vrect.Left, rawvrect.Top);
                visAxis.point2 = new VisPoint(vrect.Right, rawvrect.Top);
                visAxes.visAxes.Add(visAxis);

                visAxis        = new VisAxis();
                visAxis.point1 = new VisPoint(vrect.Left, rawvrect.Bottom);
                visAxis.point2 = new VisPoint(vrect.Right, rawvrect.Bottom);
                visAxes.visAxes.Add(visAxis);
            }
            if (axes.showCol)
            {
                visAxis           = new VisAxis();
                visAxis.drawColor = Colors.LightGray;
                vx             = axes.colstart / axes.rangex * allrect.Width + allrect.Left;
                visAxis.point1 = new VisPoint(vx, allrect.Top);
                visAxis.point2 = new VisPoint(vx, allrect.Bottom);
                visAxes.visAxes.Add(visAxis);

                visAxis           = new VisAxis();
                visAxis.drawColor = Colors.LightGray;
                vx             = axes.colend / axes.rangex * allrect.Width + allrect.Left;
                visAxis.point1 = new VisPoint(vx, allrect.Top);
                visAxis.point2 = new VisPoint(vx, allrect.Bottom);
                visAxes.visAxes.Add(visAxis);
            }
            if (axes.showDeadvolstart)
            {
                visAxis        = new VisAxis();
                vx             = axes.deadvolstart / axes.rangex * vrect.Width + vrect.Left;
                visAxis.point1 = new VisPoint(vx, vrect.Top);
                visAxis.point2 = new VisPoint(vx, vrect.Bottom);
                visAxes.visAxes.Add(visAxis);
            }
            if (axes.showDeadvolend)
            {
                visAxis        = new VisAxis();
                vx             = axes.deadvolend / axes.rangex * vrect.Width + vrect.Left;
                visAxis.point1 = new VisPoint(vx, vrect.Top);
                visAxis.point2 = new VisPoint(vx, vrect.Bottom);
                visAxes.visAxes.Add(visAxis);
            }
            if (axes.showDeadvolinsert)
            {
                visAxis        = new VisAxis();
                vx             = axes.deadvolinjectstart / axes.rangex * vrect.Width + vrect.Left;
                visAxis.point1 = new VisPoint(vx, vrect.Top);
                visAxis.point2 = new VisPoint(vx, vrect.Bottom);
                visAxes.visAxes.Add(visAxis);

                visAxis        = new VisAxis();
                vx             = axes.deadvolinjectend / axes.rangex * vrect.Width + vrect.Left;
                visAxis.point1 = new VisPoint(vx, vrect.Top);
                visAxis.point2 = new VisPoint(vx, vrect.Bottom);
                visAxes.visAxes.Add(visAxis);
            }

            // X Axis
            if (viewParams.syncScales && viewParams.viewUnits != QuantityType.ReS)
            {
                minxlabel = inParams.convertUnit(axes.scaleminulabel, inParams.natUnits, viewParams.viewUnits, PhaseType.Upper);
                maxxlabel = inParams.convertUnit(axes.scalemaxulabel, inParams.natUnits, viewParams.viewUnits, PhaseType.Upper);
                scaleu    = Math.Abs(maxxlabel - minxlabel);

                minxlabel = inParams.convertUnit(axes.scaleminllabel, inParams.natUnits, viewParams.viewUnits, PhaseType.Lower);
                maxxlabel = inParams.convertUnit(axes.scalemaxllabel, inParams.natUnits, viewParams.viewUnits, PhaseType.Lower);
                scalel    = Math.Abs(maxxlabel - minxlabel);

                if (scaleu != 0 && scalel != 0)
                {
                    axes.sync(scaleu, scalel);
                }
            }
            label = "";
            for (int phasei = 0; phasei < 2; phasei++)
            {
                if (dispDual)
                {
                    vy = vrect.Top + 0.5f * vrect.Height;
                    scaleDrawReverse = ((PhaseType)(phasei + 1) == PhaseType.Lower);
                }
                else
                {
                    vy = vrect.Bottom;
                    scaleDrawReverse = false;
                }
                scaleSet = false;
                if ((PhaseType)(phasei + 1) == PhaseType.Upper && (inParams.runMode != RunModeType.LowerPhase || (inParams.eeMode != EEModeType.None && inParams.isPosEEdir())) && viewParams.phaseDisplay != PhaseDisplayType.Lower)
                {
                    // show Up axis
                    minvx     = vrect.Left + axes.scaleminu / axes.rangexu * vrect.Width;
                    maxvx     = vrect.Left + axes.scalemaxu / axes.rangexu * vrect.Width;
                    minxlabel = inParams.convertUnit(axes.scaleminulabel, inParams.natUnits, viewParams.viewUnits, PhaseType.Upper);
                    maxxlabel = inParams.convertUnit(axes.scalemaxulabel, inParams.natUnits, viewParams.viewUnits, PhaseType.Upper);
                    rangex    = Math.Abs(axes.scalemaxu - axes.scaleminu);
                    scaleSet  = true;
                }
                else if ((PhaseType)(phasei + 1) == PhaseType.Lower && (inParams.runMode != RunModeType.UpperPhase || (inParams.eeMode != EEModeType.None && !inParams.isPosEEdir())) && viewParams.phaseDisplay != PhaseDisplayType.Upper)
                {
                    // show Lp axis
                    minvx     = vrect.Left + axes.scaleminl / axes.rangexl * vrect.Width;
                    maxvx     = vrect.Left + axes.scalemaxl / axes.rangexl * vrect.Width;
                    minxlabel = inParams.convertUnit(axes.scaleminllabel, inParams.natUnits, viewParams.viewUnits, PhaseType.Lower);
                    maxxlabel = inParams.convertUnit(axes.scalemaxllabel, inParams.natUnits, viewParams.viewUnits, PhaseType.Lower);
                    rangex    = Math.Abs(axes.scalemaxl - axes.scaleminl);
                    scaleSet  = true;
                }
                if (scaleSet)
                {
                    range = maxxlabel - minxlabel;
                    // if syncScales: use same divs/stepsize as other axis
                    if (phasei == 0 || !viewParams.syncScales || viewParams.phaseDisplay == PhaseDisplayType.Upper || viewParams.phaseDisplay == PhaseDisplayType.Lower)
                    {
                        xaxis.calcScale(range);
                    }
                    if (label == "")
                    {
                        // only do first label
                        label = inParams.getXaxisLegend();
                    }
                    else
                    {
                        label = "";
                    }
                    visAxes.addAxis(label,
                                    minvx, vy, maxvx, vy,
                                    false, true, true, !previewMode, !dispDual, scaleDrawReverse, false,
                                    false, 1,
                                    Colors.Black, 1,
                                    minxlabel, maxxlabel, xaxis.nMajorDivs, xaxis.majorStepSize, xaxis.nMinorDivs, xaxis.minorStepSize);
                    if (viewParams.viewUnits == QuantityType.ReS)
                    {
                        // ReS (K-values) scale: overwrite labels
                        visAxis = visAxes.visAxes[visAxes.visAxes.Count - 1];
                        visAxis.clearLabels();
                        for (int i = 0; i <= 8; i++)
                        {
                            if (i > 4)
                            {
                                k = (float)4 / (8 - i);
                            }
                            else
                            {
                                k = (float)i / 4;
                            }
                            flow = Equations.calcFlow(inParams.kDefinition, inParams.fu, -inParams.fl, k);
                            if (flow < 0 && inParams.runMode == RunModeType.DualMode)
                            {
                                vceff = inParams.injectPos * inParams.vc;
                            }
                            else
                            {
                                vceff = (1 - inParams.injectPos) * inParams.vc;
                            }
                            if (flow != 0)
                            {
                                if (float.IsInfinity(k))
                                {
                                    pos = Equations.calcInfPos(inParams.kDefinition, vceff, inParams.lf, inParams.uf, inParams.fu, inParams.fl);
                                }
                                else
                                {
                                    pos = Equations.calcPos(inParams.kDefinition, vceff, inParams.lf, inParams.uf, flow, k);
                                }
                                if ((PhaseType)(phasei + 1) == PhaseType.Lower)
                                {
                                    pos = -pos;
                                }
                                pos = inParams.convertUnit(pos, QuantityType.Time, inParams.natUnits, (PhaseType)(phasei + 1));
                                if (pos > 0 && !float.IsInfinity(pos))
                                {
                                    vx = minvx + pos / rangex * (maxvx - minvx);
                                    visAxis.addLabel(Util.toString(k, 2), vx, vy);
                                }
                            }
                        }
                    }
                }
            }
            // Y Axis
            range = rangey;
            if (!axes.logScale)
            {
                // normal scale
                yaxis.calcScale(range);
                rangey = yaxis.scale;
                miny   = 0;
                maxy   = rangey;
            }
            else
            {
                // log scale
                yaxis.majorStepSize = 1;
                yaxis.nMajorDivs    = (int)rangey;
                yaxis.minorStepSize = 0;
                yaxis.nMinorDivs    = 0;
                miny = maxcon - rangey;
                maxy = maxcon;
            }
            if (usePrefixes)
            {
                prefMassUnitsi = (int)inParams.massUnits;
                rangey0        = rangey;
                while (rangey0 >= 1000 && prefMassUnitsi < Enum.GetValues(typeof(MassUnitsType)).Length)
                {
                    rangey0    /= 1000;
                    multiplier /= 1000;
                    prefMassUnitsi++;
                }
                while (rangey0 < 1 && prefMassUnitsi > 0)
                {
                    rangey0    *= 1000;
                    multiplier *= 1000;
                    prefMassUnitsi--;
                }
                prefMassUnits = (MassUnitsType)prefMassUnitsi;
                label         = inParams.getYaxisLegend(prefMassUnits);
            }
            else
            {
                label = inParams.getYaxisLegend(null);
            }
            if (dispDual)
            {
                vy = vrect.Top + 0.5f * vrect.Height;
                // positive y scale
                visAxes.addAxis("Upper Phase " + label,
                                vrect.Left, vy, vrect.Left, vrect.Top,
                                !previewMode, true, true, !previewMode, !axes.logScale, false, axes.logScale,
                                !usePrefixes, multiplier,
                                Colors.Black, 1,
                                miny, maxy, yaxis.nMajorDivs, yaxis.majorStepSize, yaxis.nMinorDivs, yaxis.minorStepSize);
                // negative y scale
                if (!axes.logScale)
                {
                    yaxis.inverse();
                    miny = -miny;
                    maxy = -maxy;
                }
                visAxes.addAxis("Lower Phase " + label,
                                vrect.Left, vy, vrect.Left, vrect.Bottom,
                                !previewMode, true, true, !previewMode, false, false, axes.logScale,
                                !usePrefixes, multiplier,
                                Colors.Black, 1,
                                miny, maxy, yaxis.nMajorDivs, yaxis.majorStepSize, yaxis.nMinorDivs, yaxis.minorStepSize);
            }
            else
            {
                visAxes.addAxis(label,
                                vrect.Left, vrect.Bottom, vrect.Left, vrect.Top,
                                !previewMode, true, true, !previewMode, true, false, axes.logScale,
                                !usePrefixes, multiplier,
                                Colors.Black, 1,
                                miny, maxy, yaxis.nMajorDivs, yaxis.majorStepSize, yaxis.nMinorDivs, yaxis.minorStepSize);
            }

            // Raw Series (units)
            if (viewParams.showProbUnits)
            {
                for (s = 0; s < rawOutCells.Length; s++)
                {
                    compRawOutCells = rawOutCells[s];
                    npoints         = compRawOutCells.Length;
                    c = s / nphases;

                    visSerie            = new VisSerie();
                    visSerie.type       = VisSerieType.Units;
                    visSerie.visRect    = new Rect(rawvrect.X, rawvrect.Y, rawvrect.Width, rawvrect.Height);
                    visSerie.compi      = c;
                    visSerie.drawSize   = unitsize;
                    visSerie.drawWeight = outSet.comps[c].m;

                    visPoints = new List <VisPoint>();

                    if (viewParams.phaseDisplay == PhaseDisplayType.Lower)
                    {
                        phase = PhaseType.Lower;
                    }
                    else
                    {
                        phase = PhaseType.Upper;
                    }
                    if (nphases > 1)
                    {
                        phase = (PhaseType)((s % nphases) + 1);
                    }
                    if (phase == PhaseType.Upper)
                    {
                        rangex = axes.rangexu;
                    }
                    else
                    {
                        rangex = axes.rangexl;
                    }
                    if (c < ncomps)
                    {
                        visSerie.drawColor = Util.colorRange(c, ncomps);
                    }
                    else
                    {
                        visSerie.drawColor = Colors.Gray;
                    }

                    for (int i = 0; i < npoints; i++)
                    {
                        outCell = compRawOutCells[i];
                        vx      = rawvrect.Left + outCell.pos / rangex * rawvrect.Width;
                        if (s % nphases == 0)
                        {
                            vy = rawvrect.Top;
                        }
                        else
                        {
                            vy = rawvrect.Top + 0.5f * rawvrect.Height;
                        }

                        visPoints.Add(new VisPoint(vx, vy));
                    }
                    visSerie.visPoints = visPoints.ToArray();
                    visRawSeries.Add(visSerie);
                }
                visOutSet.visRawSeries = visRawSeries.ToArray();

                if (dispDual)
                {
                    visAxis        = new VisAxis();
                    visAxis.point1 = new VisPoint(rawvrect.Left, 0.5f * rawvrect.Height);
                    visAxis.point2 = new VisPoint(rawvrect.Right, 0.5f * rawvrect.Height);
                    visAxes.visAxes.Add(visAxis);
                }
            }
            visOutSet.visAxes = visAxes;

            // Series
            if (viewParams.yScale == YScaleType.Automatic)
            {
                maxcon = rangey;
            }
            for (s = 0; s < nseries; s++)
            {
                npoints = outSet.outCells[s].Length;
                c       = s / nphases;

                visSerie         = new VisSerie();
                visSerie.type    = VisSerieType.Graph;
                visSerie.visRect = new Rect(vrect.X, vrect.Y, vrect.Width, vrect.Height);
                visSerie.compi   = c;

                visPoints = new List <VisPoint>();

                if (nphases > 1)
                {
                    phase = (PhaseType)((s % nphases) + 1);
                }
                else if (viewParams.phaseDisplay == PhaseDisplayType.Lower)
                {
                    phase = PhaseType.Lower;
                }
                else
                {
                    phase = PhaseType.Upper;
                }
                if (phase == PhaseType.Upper)
                {
                    rangex = axes.rangexu;
                }
                else
                {
                    rangex = axes.rangexl;
                }
                if (c < ncomps)
                {
                    visSerie.drawWeight = outSet.comps[c].m;
                    visSerie.multiColor = false;
                    visSerie.drawColor  = Util.colorRange(c, ncomps);
                    sum = false;
                }
                else
                {
                    visSerie.multiColor = true;
                    visSerie.drawColor  = Colors.Gray;
                    sum = true;
                }
                if (viewParams.peaksDisplay != PeaksDisplayType.Sum || sum)
                {
                    // Sum graph: multi color
                    if (viewParams.yScale == YScaleType.Normalised)
                    {
                        maxcon = axes.maxcon[c];
                    }
                    for (int i = 0; i < npoints; i++)
                    {
                        outCell = outSet.outCells[s][i];
                        vx      = vrect.Left + outCell.pos / rangex * vrect.Width;
                        if (viewParams.yScale == YScaleType.Logarithmic)
                        {
                            if (outCell.con != 0 && maxcon != 0)
                            {
                                con = (float)(1 + (Math.Log(Math.Abs(outCell.con)) - maxcon) / rangey);
                                if (con < 0)
                                {
                                    con = 0;
                                }
                                if (outCell.con < 0)
                                {
                                    con = -con;
                                }
                            }
                            else
                            {
                                con = 0;
                            }
                        }
                        else
                        {
                            if (maxcon != 0)
                            {
                                con = outCell.con / maxcon;
                            }
                        }
                        if (dispDual)
                        {
                            vy = vrect.Top + (1 - con) / 2 * vrect.Height;
                        }
                        else
                        {
                            vy = vrect.Bottom - con * vrect.Height;
                        }
                        if (c < ncomps)
                        {
                            visPoints.Add(new VisPoint(vx, vy));
                        }
                        else
                        {
                            visPoints.Add(new VisPoint(vx, vy, outCell.color));
                        }
                    }
                    visSerie.visPoints = visPoints.ToArray();
                    visSeries.Add(visSerie);
                }
            }
            visOutSet.visSeries = visSeries.ToArray();

            // Peaks
            for (int i = 0; i < outSet.comps.Count; i++)
            {
                outComp = outSet.comps[i];
                if (outComp.phase == PhaseType.Upper)
                {
                    vx = vrect.Left + outComp.drawPosition / axes.rangexu * vrect.Width;
                }
                else if (outComp.phase == PhaseType.Lower)
                {
                    vx = vrect.Left + outComp.drawPosition / axes.rangexl * vrect.Width;
                }
                else
                {
                    vx = vrect.Left + outComp.drawPosition / axes.rangex * vrect.Width;
                }
                if (dispDual && outComp.phase == PhaseType.Lower)
                {
                    vy = vrect.Bottom;
                }
                else
                {
                    vy = vrect.Top;
                }
                visComp = new VisComp(new VisPoint(vx, vy, Util.colorRange(i, ncomps, 0.5f)), outComp.label, Util.colorRange(i, ncomps, 2));
                visOutSet.comps.Add(visComp);
            }

            visOutSet.posUnits      = inParams.getXaxisUnits();
            visOutSet.useMultiplier = usePrefixes;
            if (usePrefixes)
            {
                visOutSet.conMultiplier = multiplier;
                visOutSet.conUnits      = inParams.getYaxisUnits(prefMassUnits);
            }
            else
            {
                visOutSet.conMultiplier = 1;
                visOutSet.conUnits      = inParams.getYaxisUnits(null);
            }
            visOutSet.timeUnits = inParams.timeUnits.ToString();

            return(visOutSet);
        }
Esempio n. 3
0
        public OutSet storeOutVar(ViewParams viewParams)
        {
            // use predictive equations
            OutSet outSet = new OutSet(inParams);

            OutCell[][]  outCells;
            Axes         axes;
            Comp         comp;
            OutComp      outComp;
            OutComp      outCompt = null;
            float        pos, pos0, post;
            float        totposu, totposl;
            float        timepos;
            float        maxtime0;
            float        eepos = 0;
            float        intAmount = 0;
            float        sigma, sigma0;
            float        timesigma = 0;
            float        con, maxcon;
            float        amp0;
            float        div0;
            float        maxposu    = 0;
            float        maxposl    = 0;
            float        mindrawpos = 0;
            float        maxdrawpos = 0;
            float        range;
            float        stepsize;
            int          ncomps = inParams.comps.Count;
            int          nsize  = 1000;
            float        k;
            PhaseType    phase       = new PhaseType();
            KdefType     kdef        = inParams.kDefinition;
            RunModeType  runMode     = inParams.runMode;
            QuantityType natUnits    = inParams.natUnits;
            float        injectPos   = 0;
            float        lf          = inParams.lf;
            float        uf          = inParams.uf;
            float        px          = inParams.px;
            float        fu          = 0;
            float        fl          = 0;
            float        fnormu      = 0;
            float        fnorml      = 0;
            float        vc          = 0;
            float        mixspeed    = 0;
            float        efficiency  = 0;
            bool         allincol    = true;
            bool         timeMode    = (inParams.viewUnits == QuantityType.Time);
            bool         eeMode      = (inParams.eeMode != EEModeType.None);
            bool         intMode     = (inParams.runMode == RunModeType.Intermittent);
            bool         intCompMode = (inParams.intMode == IntModeType.Component);
            int          intit;
            bool         eluted;
            float        elutable;

            eeDone = false;

            if (inParams.model == ModelType.CCD)
            {
                // [steps]
                vc        = inParams.column;
                injectPos = inParams.getInjectPosNorm();
                if (runMode == RunModeType.CoCurrent)
                {
                    injectPos = (inParams.column - 1) - injectPos;
                }
                fnormu = inParams.fnormu;
                fnorml = inParams.fnorml;
                // always use normalised flows
                fu         = fnormu;
                fl         = fnorml;
                mixspeed   = 1;
                efficiency = Equations.calcEff1(inParams.efficiency);
            }
            else if (inParams.model == ModelType.Probabilistic)
            {
                // [volume]
                vc        = inParams.vc;
                injectPos = inParams.getInjectPosNorm();
                fu        = inParams.fu;
                fl        = inParams.fl;
                // normalise flow
                fnormu = inParams.fnormu;
                fnorml = inParams.fnorml;
                if (fnorml > fnormu)
                {
                    fnormu /= fnorml;
                    fnorml  = 1;
                }
                else
                {
                    fnorml /= fnormu;
                    fnormu  = 1;
                }
                mixspeed   = inParams.mixSpeed;
                efficiency = Equations.calcEff1(inParams.efficiency);
            }
            else if (inParams.model == ModelType.Transport)
            {
                // [time]
                natUnits  = QuantityType.Time;
                vc        = inParams.vc;
                injectPos = inParams.getInjectPosNorm();
                fu        = inParams.fu;
                fl        = inParams.fl;
                // normalise flow
                fnormu = fu / uf;
                fnorml = fl / lf;
                if (fnorml > fnormu)
                {
                    fnormu /= fnorml;
                    fnorml  = 1;
                }
                else
                {
                    fnorml /= fnormu;
                    fnormu  = 1;
                }
                mixspeed   = 1;
                efficiency = (float)Math.Sqrt(inParams.ka * 10);                 // **** make correct for f? dx? dt?
            }

            if (runMode != RunModeType.CoCurrent)
            {
                fl     = -fl;
                fnorml = -fnorml;
            }

            // Set maxpos
            for (int compi = 0; compi < ncomps; compi++)
            {
                comp    = inParams.comps[compi];
                outComp = outSet.comps[compi];

                elutable          = Equations.calcElutable(kdef, fu, fl, outComp.k);
                outComp.willElute = (elutable > 0.01);

                if (outComp.willElute)
                {
                    outCompt          = calcNewPos(comp, fu, fl, vc, injectPos, natUnits); // outcomp is reassigned
                    outComp           = outSet.comps[compi];                               // overwrite comp
                    outComp.willElute = true;                                              // restore willElute
                    if (comp.elute)
                    {
                        if (outCompt.retention < 0)
                        {
                            phase = PhaseType.Lower;
                            if (Math.Abs(outCompt.retention) > maxposl)
                            {
                                maxposl = Math.Abs(outCompt.retention);
                            }
                        }
                        else
                        {
                            phase = PhaseType.Upper;
                            if (Math.Abs(outCompt.retention) > maxposu)
                            {
                                maxposu = Math.Abs(outCompt.retention);
                            }
                        }
                        sigma = Equations.calcSigma(kdef, fnormu, fnorml, comp.k * px, outCompt.retentionTime, mixspeed, efficiency);
                        if (runMode == RunModeType.DualMode && inParams.model != ModelType.Transport)
                        {
                            sigma *= 2;
                        }
                        sigma = inParams.convertUnit(sigma, QuantityType.Time, natUnits, phase);
                    }
                }
                else
                {
                    if (intMode && inParams.intFinalElute)
                    {
                        outComp.willElute = true;
                    }
                }
            }
            if (intMode && !intCompMode)
            {
                intamountu = inParams.convertUnit(inParams.intUpSwitch, (QuantityType)inParams.intMode, natUnits, PhaseType.Upper);
                intamountl = inParams.convertUnit(inParams.intLpSwitch, (QuantityType)inParams.intMode, natUnits, PhaseType.Lower);
                if (inParams.model == ModelType.CCD)
                {
                    intamountut = intamountu;
                }
                else
                {
                    intamountut = inParams.convertUnit(inParams.intUpSwitch, (QuantityType)inParams.intMode, QuantityType.Time, PhaseType.Upper);
                }
                if (inParams.model == ModelType.CCD)
                {
                    intamountlt = intamountl;
                }
                else
                {
                    intamountlt = inParams.convertUnit(inParams.intLpSwitch, (QuantityType)inParams.intMode, QuantityType.Time, PhaseType.Lower);
                }
            }
            if (inParams.model == ModelType.CCD)
            {
                pos0 = vc / inParams.uf * inParams.maxIt;                 // in reality [steps]
            }
            else
            {
                pos0 = vc * inParams.maxIt;
            }
            if (inParams.doMaxIt && maxposu > pos0)
            {
                maxposu = pos0;
            }
            if (inParams.model == ModelType.CCD)
            {
                pos0 = vc / inParams.lf * inParams.maxIt;                 // in reality [steps]
            }
            else
            {
                pos0 = vc * inParams.maxIt;
            }
            if (inParams.doMaxIt && maxposl > pos0)
            {
                maxposl = pos0;
            }

            // init estmax [time/steps]
            previewParams.estmaxtime = 0;
            previewParams.estmaxstep = 0;

            // Set peaks
            // *** improve int mode: loop for [intit] with inner loop for [comps]: enable compmode and time scale correction
            for (int i = 0; i < ncomps; i++)
            {
                comp    = inParams.comps[i];
                outComp = outSet.comps[i];
                k       = comp.k;
                post    = 0;

                // Calculate pos
                if (intMode)
                {
                    // Int mode
                    intit   = 0;
                    eluted  = false;
                    totposu = 0;
                    totposl = 0;
                    timepos = 0;
                    pos     = injectPos;
                    phase   = inParams.intStartPhase;
                    while (intit / 2 < inParams.intMaxIt && !eluted)
                    {
                        if (phase == PhaseType.Upper)
                        {
                            if (!intCompMode)
                            {
                                if (natUnits == QuantityType.Steps)
                                {
                                    intAmount = intamountu;
                                }
                                else
                                {
                                    intAmount = intamountut;
                                }
                            }
                            outCompt = calcNewPos(comp, fu, 0, vc, pos, natUnits, !intCompMode, intAmount, QuantityType.Time);
                        }
                        else
                        {
                            if (!intCompMode)
                            {
                                if (natUnits == QuantityType.Steps)
                                {
                                    intAmount = intamountl;
                                }
                                else
                                {
                                    intAmount = intamountlt;
                                }
                            }
                            outCompt = calcNewPos(comp, 0, fl, vc, pos, natUnits, !intCompMode, intAmount, QuantityType.Time);
                        }
                        eluted = outCompt.eluted;
                        if (!eluted)
                        {
                            post += Math.Abs(outCompt.retention - pos);
                            pos   = outCompt.retention;
                            if (phase == PhaseType.Upper)
                            {
                                totposu += intamountu;
                                timepos += intamountut;
                            }
                            else
                            {
                                totposl += intamountl;
                                timepos += intamountlt;
                            }
                            // prepare for next iteration/phase
                            if (phase == PhaseType.Upper)
                            {
                                phase = PhaseType.Lower;
                            }
                            else
                            {
                                phase = PhaseType.Upper;
                            }
                            intit++;
                        }
                    }
                    if (inParams.intFinalElute && !eluted)
                    {
                        // elute
                        if (phase == PhaseType.Upper)
                        {
                            outCompt = calcNewPos(comp, fu, 0, vc, pos, natUnits);
                        }
                        else
                        {
                            outCompt = calcNewPos(comp, fl, 0, vc, pos, natUnits);
                        }
                        eluted = outCompt.eluted;
                    }
                    if (eluted)
                    {
                        // timepos is always positive
                        //timepos+= inparams.convertUnit(Math::Abs(outCompt.ret),natUnits,UnitsType.Time,phase);
                        timepos += Math.Abs(outCompt.retentionTime);
                        if (timeMode)
                        {
                            // use timepos to calc pos
                            if (inParams.model == ModelType.CCD)
                            {
                                pos = timepos;
                            }
                            else
                            {
                                pos = inParams.convertUnit(timepos, QuantityType.Time, natUnits, phase);
                            }
                            // correct negative pos
                            if (phase == PhaseType.Lower)
                            {
                                pos = -Math.Abs(pos);
                            }
                        }
                        else if (phase == PhaseType.Upper)
                        {
                            pos = totposu + outCompt.retention0;
                        }
                        else
                        {
                            pos = -totposl + outCompt.retention0;
                        }
                    }
                    outComp.intIt    = (float)intit / 2;
                    outComp.intItSet = true;
                }
                else
                {
                    // Normal (not Int) mode
                    outCompt = calcNewPos(comp, fu, fl, vc, injectPos, natUnits, true, Math.Max(maxposu, maxposl), QuantityType.Volume);
                    pos      = outCompt.retention;
                    post    += Math.Abs(pos - injectPos);
                    timepos  = Math.Abs(outCompt.retentionTime);
                    eluted   = outCompt.eluted;
                }
                outComp.eluted = eluted;
                outComp.outCol = eluted;

                pos0 = pos;
                if (!eluted && eeMode)
                {
                    // EE mode
                    eeDone = true;
                    if (inParams.isPosEEdir())
                    {
                        eepos = inParams.convertUnit(maxposu, natUnits, inParams.viewUnits, phase);
                        if (!timeMode)
                        {
                            eepos += (vc - pos0);
                        }
                        else
                        {
                            eepos = 0;
                        }
                        pos            = maxposu + (vc - pos0);
                        outCompt.phase = PhaseType.Upper;
                    }
                    else
                    {
                        eepos = inParams.convertUnit(maxposl, natUnits, inParams.viewUnits, phase);
                        if (!timeMode)
                        {
                            eepos += pos0;
                        }
                        else
                        {
                            eepos = 0;
                        }
                        pos            = -maxposl - pos0;
                        outCompt.phase = PhaseType.Lower;
                    }
                    outComp.outCol = true;
                }

                phase = outCompt.phase;
                // Calculate sigma
                if (outComp.outCol || outComp.willElute)
                {
                    // include ee outcol
                    timesigma = Equations.calcSigma(kdef, fnormu, fnorml, k * px, Math.Abs(timepos), mixspeed, efficiency);
                    if (runMode == RunModeType.DualMode)
                    {
                        timesigma *= 2;
                    }
                    if (natUnits == QuantityType.Steps)
                    {
                        // [steps]
                        sigma = timesigma;
                    }
                    else
                    {
                        // [volume]
                        if (!outComp.eluted)
                        {
                            sigma = inParams.convertColUnit(timesigma, QuantityType.Time, natUnits);
                        }
                        else
                        {
                            sigma = inParams.convertUnit(timesigma, QuantityType.Time, natUnits, phase);
                        }
                    }
                    if (!outComp.eluted)
                    {
                        // calc col sigma also for EE outcol
                        // [volume] or [steps]
                        sigma0 = sigma;
                        sigma  = Equations.calcColSigma(sigma0, outCompt.retention0, post, vc);
                    }
                    if (outComp.eluted)
                    {
                        if (phase == PhaseType.Lower)
                        {
                            pos0 = pos - 3 * sigma;
                            if (pos0 < mindrawpos)
                            {
                                mindrawpos = pos0;
                            }
                        }
                        else
                        {
                            pos0 = pos + 3 * sigma;
                            if (pos0 > maxdrawpos)
                            {
                                maxdrawpos = pos0;
                            }
                        }
                    }
                }
                else
                {
                    sigma = 1;
                    phase = PhaseType.None;
                }
                outComp.sigma = sigma;
                outComp.phase = phase;

                // set estmax [time]
                if (outComp.outCol)
                {
                    maxtime0 = Math.Abs(timepos) + 3 * timesigma;
                    if (maxtime0 > previewParams.estmaxtime)
                    {
                        previewParams.estmaxtime = maxtime0;
                    }
                }

                if (outComp.outCol)
                {
                    if (outComp.eluted)
                    {
                        outComp.retention = inParams.convertUnit(Math.Abs(pos), natUnits, viewParams.viewUnits, phase);
                        outComp.width     = inParams.convertUnit(4 * sigma, natUnits, viewParams.viewUnits, phase);
                    }
                    else
                    {
                        // not eluted but outcol (by EE)
                        outComp.retention = eepos;
                        outComp.width     = 4 * sigma;
                    }
                }
                else
                {
                    outComp.retention = inParams.convertColUnit(Math.Abs(pos), natUnits, viewParams.viewUnits);
                    outComp.width     = inParams.convertColUnit(4 * sigma, natUnits, viewParams.viewUnits);
                }
                outComp.drawPosition = pos;                 // convert to real value later
                // Calculate height
                if (float.IsInfinity(k) || sigma == 0)
                {
                    outComp.height = 1;
                }
                else
                {
                    outComp.height = Equations.calcHeight(sigma);                     // [volume]
                }
                outComp.height *= comp.m;
            }
            // set estmax [steps]
            if (inParams.doMaxIt)
            {
                // overwrite if maxit is set
                pos0 = 0;
                if (fu != 0)
                {
                    pos0 = inParams.convertUnit(inParams.maxIt * vc, QuantityType.Volume, QuantityType.Time, PhaseType.Upper);
                }
                if (fl != 0)
                {
                    pos0 = Math.Max(pos0, inParams.convertUnit(inParams.maxIt * vc, QuantityType.Volume, QuantityType.Time, PhaseType.Lower));
                }
                if (previewParams.estmaxtime > pos0)
                {
                    previewParams.estmaxtime = pos0;
                }
            }
            if (previewParams.estmaxtime == 0)
            {
                previewParams.estmaxtime = inParams.Tmnorm;
                previewParams.estmaxstep = inParams.column;
            }
            else
            {
                if (natUnits == QuantityType.Steps)
                {
                    // CCD mode: time units are actually step units
                    previewParams.estmaxstep = previewParams.estmaxtime;
                }
                else
                {
                    previewParams.estmaxstep = inParams.convertUnit(previewParams.estmaxtime, QuantityType.Time, QuantityType.Steps, phase);
                }
            }

            if (maxdrawpos == 0 && mindrawpos == 0)
            {
                if (inParams.doMaxIt)
                {
                    maxdrawpos = maxposu;
                    mindrawpos = -maxposl;
                }
            }
            if (eeMode)
            {
                if (inParams.isPosEEdir())
                {
                    maxdrawpos += vc;
                }
                else
                {
                    mindrawpos -= vc;
                }
            }
            range = maxdrawpos - mindrawpos + vc;
            // Correct drawpos
            for (int i = 0; i < ncomps; i++)
            {
                outComp = outSet.comps[i];
                pos0    = outComp.drawPosition;
                if (outComp.outCol)
                {
                    if (outComp.phase == PhaseType.Upper)
                    {
                        pos0 = maxdrawpos - pos0 + vc;
                    }
                    else
                    {
                        pos0 = mindrawpos - pos0;
                    }
                    allincol = false;
                }
                outComp.drawPosition = convModelToReal(pos0, mindrawpos);
            }

            // Set Axes
            axes          = outSet.axes;
            axes.rangex   = range;           //inparams->convertUnit(drawrange,UnitsType::Time,viewparams->viewUnits,PhaseType::Up);
            axes.showCol  = true;
            axes.colstart = convModelToReal(0, mindrawpos);
            axes.colend   = convModelToReal(vc, mindrawpos);

            axes.scaleminulabel = 0;
            axes.scalemaxulabel = inParams.convertUnit(maxdrawpos, natUnits, inParams.natUnits, PhaseType.Upper);
            axes.scaleminllabel = 0;
            axes.scalemaxllabel = inParams.convertUnit(-mindrawpos, natUnits, inParams.natUnits, PhaseType.Lower);
            axes.scaleminu      = convModelToReal(maxdrawpos + vc, mindrawpos);
            axes.scalemaxu      = convModelToReal(vc, mindrawpos);
            axes.scaleminl      = convModelToReal(mindrawpos, mindrawpos);
            axes.scalemaxl      = convModelToReal(0, mindrawpos);

            axes.logScale = (viewParams.yScale == YScaleType.Logarithmic);
            axes.update();

            // init outcells
            outCells = new OutCell[ncomps][];
            for (int compi = 0; compi < ncomps; compi++)
            {
                outCells[compi] = new OutCell[nsize];
            }
            axes.maxcon = new List <float>(ncomps);
            // Store outcells
            for (int compi = 0; compi < ncomps; compi++)
            {
                comp    = inParams.comps[compi];
                outComp = outSet.comps[compi];
                // Pre-calcs to improve performance
                pos0  = outComp.drawPosition;
                sigma = outComp.sigma;
                if (sigma == 0)
                {
                    sigma = 1;
                }
                amp0     = comp.m * Equations.calcHeight(sigma);
                div0     = 2 * (float)Math.Pow(sigma, 2);
                stepsize = range / nsize;
                maxcon   = 0;
                for (int i = 0; i < nsize; i++)
                {
                    pos = i * stepsize;                     // Real position
                    // make sure peak top gets drawn:
                    if (Math.Abs(pos - pos0) <= stepsize)
                    {
                        con = amp0;
                    }
                    else
                    {
                        con = amp0 * (float)Math.Exp(-Math.Pow(pos - pos0, 2) / div0);
                    }
                    if (con > maxcon && (outComp.outCol || allincol))
                    {
                        maxcon = con;
                    }
                    outCells[compi][i] = new OutCell(pos, con);
                }
                axes.maxcon.Add(maxcon);
                // Correct sigma:
                outComp.sigma = outComp.width / 4;
            }
            outSet.outCells = outCells;

            return(outSet);
        }
Esempio n. 4
0
        private OutSet storeOutVar(List <TransCon> conu0, List <TransCon> conl0, ViewParams viewparams, bool timeMode, float time)
        {
            OutSet   outSet = new OutSet(inParams);
            TransCon compconu;
            TransCon compconl;
            List <List <OutCell> > outcells;
            Axes axes;
            int  nseries;
            int  ncomps2;
            int  nphases;
            int  nstepsu, nstepsl, nsteps;
            int  ncomps = inParams.comps.Count;
            int  compi;
            bool dispDualTime = (viewparams.phaseDisplay == PhaseDisplayType.UpperLowerTime);
            bool dispDual     = (viewparams.phaseDisplay == PhaseDisplayType.UpperLower || dispDualTime);
            bool dispAll      = (viewparams.phaseDisplay == PhaseDisplayType.All);
            bool dispUP       = (viewparams.phaseDisplay == PhaseDisplayType.Upper);
            bool dispLP       = (viewparams.phaseDisplay == PhaseDisplayType.Lower);
            bool runDual      = (inParams.runMode == RunModeType.DualMode || inParams.runMode == RunModeType.Intermittent);
            bool runCo        = (inParams.runMode == RunModeType.CoCurrent);
            bool runUP        = (inParams.runMode == RunModeType.UpperPhase);
            bool runLP        = (inParams.runMode == RunModeType.LowerPhase);
            bool showCol      = ((runDual && (dispAll || viewparams.phaseDisplay == PhaseDisplayType.UpperLower)) || (timeMode && !dispDualTime));

            bool[]    inversePhase = new bool[2];
            int       offsetu, offsetl, offset;
            float     pos;
            float     con, con0, maxcon;
            PhaseType phase = new PhaseType();
            int       serie;
            Color     color;
            float     a, r, g, b;

            outSet.time = time;

            // inverse upper phase
            inversePhase[0] = !(runLP || (runDual && (dispAll || viewparams.phaseDisplay == PhaseDisplayType.UpperLower || dispLP)));
            // inverse lower phase
            if (runCo || (runDual && dispDualTime))
            {
                inversePhase[1] = inversePhase[0];
            }
            else
            {
                inversePhase[1] = !inversePhase[0];
            }

            if (!showCol && !(runDual && dispDualTime))
            {
                // show column if non-outcol peaks inside
                for (int i = 0; i < ncomps; i++)
                {
                    if (!compEluted[i])
                    {
                        showCol = true;
                    }
                }
            }

            nstepsu = 0;
            nstepsl = 0;
            for (compi = 0; compi < ncomps; compi++)
            {
                nstepsu = Math.Max(nstepsu, conu[0].Count);
                nstepsl = Math.Max(nstepsl, conl[0].Count);
            }

            /*
             *      // alternative method (in case simple length can't be used)
             *      if (inParams->fu != 0)
             *              nstepsu = (runcols + 1) * columnsteps;
             *      else
             *              nstepsu = columnsteps;
             *      if (inParams->fl != 0)
             *              nstepsl = (runcols + 1) * columnsteps;
             *      else
             *              nstepsl = columnsteps;
             */

            offset = 0;
            if (inversePhase[0])
            {
                offset = nstepsu;
            }
            if (inversePhase[1])
            {
                offset = Math.Max(offset, nstepsl);
            }

            if (inversePhase[0])
            {
                offsetu = nstepsu;
            }
            else
            {
                offsetu = offset - inParams.column2;
            }

            if (inversePhase[1])
            {
                offsetl = nstepsl;
            }
            else
            {
                offsetl = offset - inParams.column2;
            }

            if (inversePhase[0] != inversePhase[1] && !dispUP && !dispLP)
            {
                nsteps = nstepsu + nstepsl - inParams.column2;
            }
            else
            {
                if (dispUP && !runLP)
                {
                    nsteps = nstepsu;
                }
                else if (dispLP && !runUP)
                {
                    nsteps = nstepsl;
                }
                else
                {
                    nsteps = Math.Max(nstepsu, nstepsl);
                }
            }
            if (!showCol)
            {
                nsteps -= inParams.column2;
            }

            if (dispDual)
            {
                nphases = 2;
            }
            else
            {
                nphases = 1;
            }
            if (viewparams.peaksDisplay == PeaksDisplayType.PeaksSum || viewparams.peaksDisplay == PeaksDisplayType.Sum)
            {
                ncomps2 = ncomps + 1;
            }
            else
            {
                ncomps2 = ncomps;
            }
            nseries = nphases * ncomps2;

            // store axes
            axes         = outSet.axes;
            axes.showCol = showCol;
            if (showCol)
            {
                axes.colstart = offset - inParams.column2;
                axes.colend   = offset;

                if (inParams.vdeadInEnabled)
                {
                    axes.showDeadvolstart = true;
                    if (inParams.getNormalColDirection() == inversePhase[0])
                    {
                        axes.deadvolstart = axes.colstart + (inParams.column2 - inParams.getVdeadIn());
                    }
                    else
                    {
                        axes.deadvolstart = axes.colstart + inParams.getVdeadIn();
                    }
                }
                else
                {
                    axes.showDeadvolstart = false;
                }
                if (inParams.vdeadOutEnabled)
                {
                    axes.showDeadvolend = true;
                    if (inParams.getNormalColDirection() == inversePhase[0])
                    {
                        axes.deadvolend = axes.colstart + inParams.getVdeadOut();
                    }
                    else
                    {
                        axes.deadvolend = axes.colstart + (inParams.column2 - inParams.getVdeadOut());
                    }
                }
                else
                {
                    axes.showDeadvolend = false;
                }
                if (inParams.vdeadInjectEnabled)
                {
                    axes.showDeadvolinsert  = true;
                    axes.deadvolinjectstart = axes.colstart + inParams.getVdeadInjectStart();
                    axes.deadvolinjectend   = axes.colstart + inParams.getVdeadInjectEnd();
                }
                else
                {
                    axes.showDeadvolinsert = false;
                }
            }

            axes.rangex = nsteps;
            if (axes.rangex == 0)
            {
                axes.rangex = 1;                 // prevent div by zero
            }

            axes.scaleminulabel = 0;
            axes.scalemaxulabel = nstepsu - inParams.column2;
            axes.scaleminllabel = 0;
            axes.scalemaxllabel = nstepsl - inParams.column2;
            if (inversePhase[0])
            {
                axes.scaleminu = 0;
                axes.scalemaxu = nstepsu - inParams.column2;
            }
            else
            {
                axes.scaleminu = nsteps;
                axes.scalemaxu = offset;
            }
            if (inversePhase[1])
            {
                axes.scaleminl = 0;
                axes.scalemaxl = nstepsl - inParams.column2;
            }
            else
            {
                axes.scaleminl = nsteps;
                axes.scalemaxl = offset;
            }

            axes.logScale = (viewparams.yScale == YScaleType.Logarithmic);
            axes.update();

            axes.maxcon = new List <float>(ncomps);

            // store peaks
            outSet.comps = storePeaks(conu0, conl0, offsetu, offsetl, inversePhase, axes, viewparams, showCol);

            // init outcells
            outcells = new List <List <OutCell> >(nseries);
            for (int i = 0; i < nseries; i++)
            {
                outcells.Add(new List <OutCell>(nsteps));
            }
            for (compi = 0; compi < ncomps; compi++)
            {
                for (int phasei = 0; phasei < nphases; phasei++)
                {
                    serie    = compi * nphases + phasei;
                    compconu = conu0[compi];
                    compconl = conl0[compi];
                    maxcon   = 0;
                    for (int i = 0; i < nsteps; i++)
                    {
                        pos = i;
                        con = 0;
                        if (nphases > 1)
                        {
                            phase = (PhaseType)(phasei + 1);
                        }
                        else if (viewparams.phaseDisplay == PhaseDisplayType.Lower)
                        {
                            phase = PhaseType.Lower;
                        }
                        else
                        {
                            phase = PhaseType.Upper;
                        }
                        if (phase == PhaseType.Upper || dispAll)
                        {
                            con += compconu.getNormCon(i, offsetu, inversePhase[0]);
                        }
                        if (phase == PhaseType.Lower || dispAll)
                        {
                            con += compconl.getNormCon(i, offsetl, inversePhase[1]);
                        }
                        if (con > maxcon)
                        {
                            maxcon = con;
                        }
                        if (dispDual && (PhaseType)(phasei + 1) == PhaseType.Lower)
                        {
                            con = -con;
                        }
                        outcells[serie].Add(new OutCell(pos, con));
                    }
                    axes.maxcon.Add(maxcon);
                }
            }

            color = new Color();

            if (viewparams.peaksDisplay == PeaksDisplayType.PeaksSum || viewparams.peaksDisplay == PeaksDisplayType.Sum)
            {
                // add series for sum
                for (int i = 0; i < nsteps; i++)
                {
                    pos    = i;
                    maxcon = 0;
                    for (int phasei = 0; phasei < nphases; phasei++)
                    {
                        con = 0;
                        a   = 0;
                        r   = 0;
                        g   = 0;
                        b   = 0;
                        for (compi = 0; compi < ncomps; compi++)
                        {
                            serie = compi * nphases + phasei;
                            con0  = outcells[serie][i].con;
                            con  += con0;
                            color = Util.colorRange(compi, ncomps);
                            r    += color.ScR * Math.Abs(con0);
                            g    += color.ScG * Math.Abs(con0);
                            b    += color.ScB * Math.Abs(con0);
                        }
                        if (con != 0)
                        {
                            a  = 1;
                            r /= Math.Abs(con);
                            g /= Math.Abs(con);
                            b /= Math.Abs(con);
                        }
                        compi = ncomps;
                        serie = ncomps * nphases + phasei;
                        if (Math.Abs(con) > maxcon)
                        {
                            maxcon = Math.Abs(con);
                        }
                        outcells[serie].Add(new OutCell(pos, con, Color.FromScRgb(a, r, g, b)));
                    }
                    axes.maxcon.Add(maxcon);
                }
            }

            // convert List to array
            outSet.outCells = new OutCell[outcells.Count][];
            for (int i = 0; i < outcells.Count; i++)
            {
                outSet.outCells[i] = new OutCell[outcells[i].Count];
                for (int j = 0; j < outcells[i].Count; j++)
                {
                    outSet.outCells[i][j] = outcells[i][j];
                }
            }

            return(outSet);
        }
Esempio n. 5
0
 public void reset()
 {
     outSet    = new OutSet();
     visOutSet = new VisOutSet();
 }