예제 #1
0
        private float calcSlopeWidth(TransCon compconu, TransCon compconl, int offsetu, int offsetl, bool inverseu, bool inversel, float nsteps, float peakpos)
        {
            // outComp width : look for slopes closest to max outComp value
            float width;
            float pos1 = peakpos;
            float pos2 = peakpos;
            float maxpos = peakpos;
            float maxpos0 = peakpos;
            float maxcon = 0;
            float maxcon0 = 0;
            float cu, cl;
            float con;
            float con0 = 0;
            float dcon, maxdcon;

            maxdcon = 0;
            for (int i = (int)peakpos; i > 0; i--)
            {
                cu  = compconu.getNormCon(i, offsetu, inverseu);
                cl  = compconl.getNormCon(i, offsetl, inversel);
                con = cu + cl;
                if (i != peakpos)
                {
                    dcon = con0 - con;
                    if (dcon > maxdcon)
                    {
                        maxdcon = dcon;
                        maxcon  = con;
                        maxcon0 = con0;
                        maxpos  = i;
                        maxpos0 = i + 1;
                    }
                }
                con0 = con;
            }
            // extrapolate slope (y = 0)
            pos1 = Util.calcCorX(maxpos0, maxpos, maxcon0, maxcon, 0);

            maxdcon = 0;
            for (int i = (int)peakpos; i < nsteps; i++)
            {
                cu  = compconu.getNormCon(i, offsetu, inverseu);
                cl  = compconl.getNormCon(i, offsetl, inversel);
                con = cu + cl;
                if (i != peakpos)
                {
                    dcon = con0 - con;
                    if (dcon > maxdcon)
                    {
                        maxdcon = dcon;
                        maxcon  = con;
                        maxcon0 = con0;
                        maxpos  = i;
                        maxpos0 = i - 1;
                    }
                }
                con0 = con;
            }
            // extrapolate slope (y = 0)
            pos2 = Util.calcCorX(maxpos0, maxpos, maxcon0, maxcon, 0);

            width = Math.Abs(pos2 - pos1);
            return(width);
        }
예제 #2
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);
        }