Exemplo n.º 1
0
 public ValueInput(IValueIn pin)
 {
     FPin = pin;
     pin.GetValuePointer(out lenptr, out dataptr);
 }
Exemplo n.º 2
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public unsafe void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FIn.PinIsChanged || FVectorSize.PinIsChanged || FBinSize.PinIsChanged)
            {
                double *inVals;
                int     inC;
                FIn.GetValuePointer(out inC, out inVals);

                double tmpVec;
                FVectorSize.GetValue(0, out tmpVec);
                int vecSize = Math.Max((int)Math.Round(tmpVec), 1);
                int vecMax  = (int)Math.Ceiling(inC / (decimal)vecSize);

                double firstBin;
                FBinSize.GetValue(0, out firstBin);
                int        total   = 0;
                List <int> binList = new List <int>();
                if (!(FBinSize.SliceCount == 1 && firstBin == 0))
                {
                    int  binIncr = 0;
                    bool end     = false;
                    while (!end)
                    {
                        double tmpBin;
                        FBinSize.GetValue(binIncr, out tmpBin);
                        int curBin = (int)Math.Round(tmpBin);
                        if (curBin < 0)
                        {
                            curBin = vecMax / Math.Abs(curBin);
                        }
                        binList.Add(curBin);
                        binIncr++;
                        total += curBin;
                        if (binIncr % FBinSize.SliceCount == 0 && total >= vecMax)
                        {
                            end = true;
                        }
                    }
                }

                FOut.SliceCount = vecMax * vecSize;
                double *outVals;
                FOut.GetValuePointer(out outVals);
                int outIncr = 0;
                foreach (int b in binList)
                {
                    for (int i = 0; i < b * vecSize; i++)
                    {
                        int prev = i - vecSize;
                        int next = i + vecSize;
                        if (prev < 0)
                        {
                            outVals[i + outIncr] = (inVals[(outIncr + next) % inC] - inVals[(i + outIncr) % inC]);
                        }
                        else if (next >= b * vecSize)
                        {
                            outVals[i + outIncr] = (inVals[(i + outIncr) % inC] - inVals[(outIncr + prev) % inC]);
                        }
                        else
                        {
                            outVals[i + outIncr]  = (inVals[(outIncr + next) % inC] - inVals[(i + outIncr) % inC]) / 2;
                            outVals[i + outIncr] += (inVals[(i + outIncr) % inC] - inVals[(outIncr + prev) % inC]) / 2;
                        }
                    }
                    outIncr += b * vecSize;
                }
            }
        }
Exemplo n.º 3
0
        public void Evaluate(int SpreadMax)
        {
            double *oldvals;

            this.FPinOutput.GetValuePointer(out oldvals);

            this.FPinOutput.SliceCount = SpreadMax;
            this.FPinOutIdx.SliceCount = SpreadMax;

            for (int i = 0; i < this.FPinInMode.Count; i++)
            {
                string val;
                this.FPinInMode[i].GetString(0, out val);
                this.FModes[i] = (eLTPTakeOverMode)Enum.Parse(typeof(eLTPTakeOverMode), val);
            }

            if (this.FPinInPickUpEpsilon.PinIsChanged)
            {
                this.FPinInPickUpEpsilon.GetValue(0, out this.FEps);
                //Keep absolute value here
                this.FEps = Math.Abs(this.FEps);
            }

            if (this.FFirstFrame)
            {
                //On first frame, we take the first input only (highest priority)
                double *ptr;
                int     ptrcnt;
                this.FPinInputs[0].GetValuePointer(out ptrcnt, out ptr);

                for (int i = 0; i < SpreadMax; i++)
                {
                    this.FPinOutput.SetValue(i, ptr[i % ptrcnt]);
                    this.FPinOutIdx.SetValue(i, 0);
                }
                this.FFirstFrame = false;
            }
            else
            {
                bool[] updated = new bool[SpreadMax];

                for (int i = 0; i < SpreadMax; i++)
                {
                    for (int j = 0; j < this.FPinInputs.Count; j++)
                    {
                        if (!updated[i])
                        {
                            double dblval;
                            this.FPinInputs[j].GetValue(i, out dblval);
                            double oldval = this.FOldValues[j][i % this.FOldValues[j].Length];

                            double currval = oldvals[i];
                            if (dblval != oldval)
                            {
                                if (this.FModes[j] == eLTPTakeOverMode.Immediate)
                                {
                                    this.FPinOutput.SetValue(i, dblval);
                                    this.FPinOutIdx.SetValue(i, j);
                                    updated[i] = true;
                                }
                                else
                                {
                                    if ((dblval <= currval + this.FEps && oldval >= currval - this.FEps) ||
                                        (dblval >= currval - this.FEps && oldval <= currval + this.FEps))
                                    {
                                        this.FPinOutput.SetValue(i, dblval);
                                        this.FPinOutIdx.SetValue(i, j);
                                        updated[i] = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }


            //Save old values
            this.FOldValues.Clear();
            for (int i = 0; i < this.FPinInputs.Count; i++)
            {
                IValueIn pin = this.FPinInputs[i];
                double[] dbl = new double[pin.SliceCount];

                double *ptr;
                int     ptrcnt;
                pin.GetValuePointer(out ptrcnt, out ptr);

                for (int j = 0; j < pin.SliceCount; j++)
                {
                    dbl[j] = ptr[j];
                }
                this.FOldValues.Add(dbl);
            }
        }
Exemplo n.º 4
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public unsafe void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FInput.PinIsChanged ||
                FPts.PinIsChanged ||
                FCtrl.PinIsChanged ||
                FVecSize.PinIsChanged ||
                FPtPC.PinIsChanged ||
                FInPC.PinIsChanged ||
                FClosed.PinIsChanged)
            {
                double tmpVecSize;
                FVecSize.GetValue(0, out tmpVecSize);
                int vecSize = Math.Max(1, (int)Math.Round(tmpVecSize));

                double inBins;
                FInPC.GetValue(0, out inBins);
                inBins = Math.Round(inBins);
                int        inTotal   = 0;
                List <int> inBinList = new List <int>();
                if (FInPC.SliceCount > 1 || inBins != 0)
                {
                    int  inBinIncr = 0;
                    bool inEnd     = false;
                    while (!inEnd)
                    {
                        FInPC.GetValue(inBinIncr, out inBins);
                        int curInBin = (int)Math.Round(inBins);
                        if (curInBin < 0)
                        {
                            curInBin = (int)Math.Ceiling(FInput.SliceCount / (double)Math.Abs(curInBin));
                        }
                        inBinList.Add(curInBin);
                        inBinIncr++;
                        inTotal += curInBin;
                        if (inBinIncr % FInPC.SliceCount == 0 && inTotal >= FInput.SliceCount)
                        {
                            inEnd = true;
                        }
                    }
                }

                double ptBins;
                FPtPC.GetValue(0, out ptBins);
                ptBins = Math.Round(ptBins);
                int        curvesTotal = 0;
                List <int> ptBinList   = new List <int>();
                if (FPtPC.SliceCount > 1 || ptBins != 0)
                {
                    int ptsMax = Math.Max(FPts.SliceCount, FCtrl.SliceCount);
                    ptsMax = (int)Math.Ceiling(ptsMax / (double)vecSize);
                    int  ptBinIncr = 0;
                    bool ptEnd     = false;
                    while (!ptEnd)
                    {
                        FPtPC.GetValue(ptBinIncr, out ptBins);
                        int curBin = (int)Math.Round(ptBins);
                        if (curBin < 0)
                        {
                            curBin = (int)Math.Ceiling(ptsMax / (double)Math.Abs(curBin));
                        }
                        ptBinList.Add(curBin);
                        ptBinIncr++;
                        curvesTotal += curBin;
                        if (ptBinIncr % FPtPC.SliceCount == 0 && curvesTotal >= ptsMax)
                        {
                            ptEnd = true;
                        }
                    }
                }

                FCurveC.SliceCount = 1;
                FCurveC.SetValue(0, (double)ptBinList.Count);
                int maxLoop = Math.Max(ptBinList.Count, inBinList.Count);
                maxLoop = Math.Max(maxLoop, FClosed.SliceCount);



                double *ins, pts, ctrls;
                int     inC, ptC, ctrlC;
                FInput.GetValuePointer(out inC, out ins);
                FPts.GetValuePointer(out ptC, out pts);
                FCtrl.GetValuePointer(out ctrlC, out ctrls);

                double[] returnArr = new double[0];
                int      iIncr = 0, pIncr = 0;
                for (int c = 0; c < maxLoop; c++)
                {
                    int iCount = inBinList[c % inBinList.Count];
                    int pCount = ptBinList[c % ptBinList.Count];
                    Array.Resize(ref returnArr, returnArr.Length + (iCount * vecSize));

                    double[] inArr = new double[iCount];
                    for (int i = 0; i < iCount; i++)
                    {
                        inArr[i] = ins[(iIncr + i) % inC];
                    }


                    for (int v = 0; v < vecSize; v++)
                    {
                        double[] ptArr   = new double[pCount];
                        double[] ctrlArr = new double[pCount];
                        for (int p = 0; p < pCount; p++)
                        {
                            int ptId = pIncr + (p * vecSize) + v;
                            ptArr[p]   = pts[ptId % ptC];
                            ctrlArr[p] = ctrls[ptId % ctrlC];
                        }

                        double closed;
                        FClosed.GetValue(c, out closed);
                        bool isClosed = closed > 0.5;

                        double[] outArr = PolyBezier(inArr, ptArr, ctrlArr, isClosed);
                        for (int o = 0; o < outArr.Length; o++)
                        {
                            returnArr[(iIncr + o) * vecSize + v] = outArr[o];
                        }
                    }

                    iIncr += iCount;
                    pIncr += pCount * vecSize;
                }

                double *outVal;
                FOutput.SliceCount = returnArr.Length;
                FOutput.GetValuePointer(out outVal);
                for (int i = 0; i < returnArr.Length; i++)
                {
                    outVal[i] = returnArr[i];
                }
            }
        }
Exemplo n.º 5
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public unsafe void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FSpreadC.PinIsChanged ||
                FPts.PinIsChanged ||
                FCtrl.PinIsChanged ||
                FVecSize.PinIsChanged ||
                FBinSize.PinIsChanged ||
                FFactor.PinIsChanged ||
                FPhase.PinIsChanged ||
                FClosed.PinIsChanged)
            {
                double tmpVecSize;
                FVecSize.GetValue(0, out tmpVecSize);
                int vecSize = Math.Max(1, (int)Math.Round(tmpVecSize));

                double ptBins;
                FBinSize.GetValue(0, out ptBins);
                ptBins = Math.Round(ptBins);
                int        ptsTotal  = 0;
                List <int> ptBinList = new List <int>();
                if (FFactor.SliceCount > 1 || ptBins != 0)
                {
                    int ptsMax = Math.Max(FPts.SliceCount, FCtrl.SliceCount);
                    ptsMax = (int)Math.Ceiling(ptsMax / (double)vecSize);
                    int  binIncr = 0;
                    bool end     = false;
                    while (!end)
                    {
                        FBinSize.GetValue(binIncr, out ptBins);
                        int curBin = (int)Math.Round(ptBins);
                        if (curBin < 0)
                        {
                            curBin = (int)Math.Ceiling(ptsMax / (double)Math.Abs(curBin));
                        }
                        ptBinList.Add(curBin);
                        binIncr++;
                        ptsTotal += curBin;
                        if (binIncr % FBinSize.SliceCount == 0 && ptsTotal >= ptsMax)
                        {
                            end = true;
                        }
                    }
                }

                int maxLoop = Math.Max(ptBinList.Count, FPhase.SliceCount);
                maxLoop = Math.Max(maxLoop, FFactor.SliceCount);
                maxLoop = Math.Max(maxLoop, FClosed.SliceCount);
                maxLoop = Math.Max(maxLoop, FSpreadC.SliceCount);



                double *pts, ctrls, spread;
                int     ptC, ctrlC, spreadC;
                FPts.GetValuePointer(out ptC, out pts);
                FCtrl.GetValuePointer(out ctrlC, out ctrls);
                FSpreadC.GetValuePointer(out spreadC, out spread);

                int      pIncr = 0, oIncr = 0;
                double[] returnArr = new double[0];
                for (int c = 0; c < maxLoop; c++)
                {
                    double phase, factor;
                    FPhase.GetValue(c, out phase);
                    FFactor.GetValue(c, out factor);

                    int curSpreadC = (int)Math.Round(spread[c % spreadC]);
                    Array.Resize(ref returnArr, returnArr.Length + curSpreadC * vecSize);
                    double[] inArr = new double[curSpreadC];
                    for (int i = 0; i < curSpreadC; i++)
                    {
                        inArr[i] = ((i / (double)curSpreadC) * factor) + phase;
                    }

                    int pCount = ptBinList[c % ptBinList.Count];
                    for (int v = 0; v < vecSize; v++)
                    {
                        double[] ptArr   = new double[pCount];
                        double[] ctrlArr = new double[pCount];
                        for (int p = 0; p < pCount; p++)
                        {
                            int ptId = pIncr + (p * vecSize) + v;
                            ptArr[p]   = pts[ptId % ptC];
                            ctrlArr[p] = ctrls[ptId % ctrlC];
                        }

                        double closed;
                        FClosed.GetValue(c, out closed);
                        bool isClosed = closed > 0.5;

                        double[] outArr = PolyBezier(inArr, ptArr, ctrlArr, isClosed);

                        for (int o = 0; o < outArr.Length; o++)
                        {
                            returnArr[(oIncr + o) * vecSize + v] = outArr[o];
                        }
                    }

                    oIncr += curSpreadC;
                    pIncr += pCount * vecSize;
                }

                double *outVal;
                FOutput.SliceCount = returnArr.Length;
                FOutput.GetValuePointer(out outVal);
                for (int i = 0; i < returnArr.Length; i++)
                {
                    outVal[i] = returnArr[i];
                }
            }
        }