예제 #1
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FPinInVertices.PinIsChanged || FPinInCenter.PinIsChanged || FPinInRadius.PinIsChanged)
            {
                /*
                 * FHost.Log(TLogType.Debug, "FPinInVertices.SliceCount " + FPinInVertices.SliceCount);
                 * FHost.Log(TLogType.Debug, "FPinInCenter.SliceCount " + FPinInCenter.SliceCount);
                 * FHost.Log(TLogType.Debug, "FPinInRadius.SliceCount " + FPinInRadius.SliceCount);
                 */
                FPinOutVertices.SliceCount = FPinInVertices.SliceCount * FPinInCenter.SliceCount * FPinInRadius.SliceCount;
                int    index = 0;
                double pointX, pointY;
                double radius;
                double centerX, centerY;
                double inversionFactor;

                //loop for all slices
                for (int i = 0; i < FPinInVertices.SliceCount; i++)
                {
                    FPinInVertices.GetValue2D(i, out pointX, out pointY);
                    for (int j = 0; j < FPinInCenter.SliceCount; j++)
                    {
                        FPinInCenter.GetValue2D(j, out centerX, out centerY);
                        pointX -= centerX;
                        pointY -= centerY;

                        for (int k = 0; k < FPinInRadius.SliceCount; k++)
                        {
                            FPinInRadius.GetValue(k, out radius);
                            inversionFactor = radius * radius / (pointX * pointX + pointY * pointY);
                            pointX         *= inversionFactor;
                            pointY         *= inversionFactor;

                            pointX += centerX;
                            pointY += centerY;

                            FPinOutVertices.SetValue2D(index, pointX, pointY);
                            index++;
                        }
                    }
                }
            }
        }
예제 #2
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FPositionInput.PinIsChanged || FVectorSizeInput.PinIsChanged || FP1Input.PinIsChanged ||
                FP2Input.PinIsChanged || FP3Input.PinIsChanged || FP4Input.PinIsChanged)
            {
                //get vector size
                double vs;
                FVectorSizeInput.GetValue(0, out vs);
                int vectorSize = (int)vs;

                SpreadMax = Math.Max(SpreadMax, FPositionInput.SliceCount * vectorSize);

                //first set slicecounts for all outputs
                //the incoming int SpreadMax is the maximum slicecount of all input pins, which is a good default
                FValueOutput.SliceCount = SpreadMax;

                //the variables to fill with the input data
                Vector2D vectorSlice;
                double   p1Slice;
                double   p2Slice;
                double   p3Slice;
                double   p4Slice;

                //loop for all slices
                for (int i = 0; i < SpreadMax; i++)
                {
                    //read data from inputs
                    FPositionInput.GetValue2D(i / vectorSize, out vectorSlice.x, out vectorSlice.y);
                    FP1Input.GetValue(i, out p1Slice);
                    FP2Input.GetValue(i, out p2Slice);
                    FP3Input.GetValue(i, out p3Slice);
                    FP4Input.GetValue(i, out p4Slice);

                    //function per slice
                    p1Slice = VMath.Bilerp(vectorSlice, p1Slice, p2Slice, p3Slice, p4Slice);

                    //write data to outputs
                    FValueOutput.SetValue(i, p1Slice);
                }
            }
        }
예제 #3
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FDistortion.PinIsChanged ||
                FFocalLength.PinIsChanged ||
                FPrincipalPoint.PinIsChanged ||
                FResolution.PinIsChanged)
            {
                //get the distortion values
                FDistortion.GetValue4D(0, out FDist.x, out FDist.y, out FDist.z, out FDist.w);
                FFocalLength.GetValue2D(0, out FFocal.x, out FFocal.y);
                FPrincipalPoint.GetValue2D(0, out FPrincipal.x, out FPrincipal.y);
                FResolution.GetValue2D(0, out FReso.x, out FReso.y);
            }

            //set slicecounts for output
            //here its the same as the input
            SpreadMax          = FInput.SliceCount;
            FOutput.SliceCount = SpreadMax;
            FTries.SliceCount  = SpreadMax;

            //the variable to fill with the input data
            Vector2D currentPosition;

            //loop for all slices
            for (int i = 0; i < SpreadMax; i++)
            {
                //read data from inputs
                FInput.GetValue2D(i, out currentPosition.x, out currentPosition.y);

                int tries;

                //function per slice
                currentPosition = Undistort(currentPosition, FFocal, FPrincipal, FDist, FReso, out tries);

                //write data to outputs
                FOutput.SetValue2D(i, currentPosition.x, currentPosition.y);
                FTries.SetValue(i, tries);
            }
        }
예제 #4
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FPositionInput.PinIsChanged || FOctavesInput.PinIsChanged ||
                FFrequencyInput.PinIsChanged || FPersistanceInput.PinIsChanged)
            {
                //first set slicecounts for all outputs
                //the incoming int SpreadMax is the maximum slicecount of all input pins, which is a good default
                FOutput.SliceCount = SpreadMax;

                double octaves, freq, pers;
                FOctavesInput.GetValue(0, out octaves);
                FFrequencyInput.GetValue(0, out freq);
                FPersistanceInput.GetValue(0, out pers);

                //the variable to fill with the input position
                Vector2D pos;

                //loop for all slices
                for (int i = 0; i < SpreadMax; i++)
                {
                    //read position from inputs
                    FPositionInput.GetValue2D(i, out pos.x, out pos.y);

                    //noise function per slice
                    double noiseVal = 0;

                    for (int o = 0; o <= (int)octaves; o++)
                    {
                        double comul = Math.Pow(freq, o);
                        noiseVal += SimplexNoise.noise(pos.x * comul, pos.y * comul) * Math.Pow(pers, o);
                    }

                    //write data to outputs
                    FOutput.SetValue(i, noiseVal);
                }
            }
        }
예제 #5
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FJointNameInput.PinIsChanged)
            {
                string name;
                FJointNameInput.GetString(0, out name);
                if (!string.IsNullOrEmpty(name))
                {
                    FRootJoint.Name = name;
                    FSkeleton.BuildJointTable();
                    FSkeletonOutput.MarkPinAsChanged();
                }
            }

            if (FChildPins.Any(c => c.PinIsChanged))
            {
                FSkeleton.ClearAll();
                FSkeleton.Root = FRootJoint;
                FSkeleton.BuildJointTable();

                for (int i = 0; i < FChildPins.Count; i++)
                {
                    if (true)             //childPinsList[i].PinIsChanged)
                    {
                        FSkeletonOutput.MarkPinAsChanged();
                        if (FChildPins[i].IsConnected)
                        {
                            object currInterface;
                            FChildPins[i].GetUpstreamInterface(out currInterface);
                            ISkeleton subSkeleton = (ISkeleton)currInterface;
                            IJoint    child       = subSkeleton.Root.DeepCopy();
                            FSkeleton.InsertJoint(FSkeleton.Root.Name, child);
                            FSkeleton.BuildJointTable();
                        }
                    }
                }

                // re-calculate the IDs ...
                int currId = 0;
                foreach (KeyValuePair <string, IJoint> pair in FSkeleton.JointTable)
                {
                    pair.Value.Id = currId;
                    currId++;
                }
            }

            if (FBaseTransformInput.PinIsChanged)
            {
                Matrix4x4 baseTransform;
                FBaseTransformInput.GetMatrix(0, out baseTransform);
                FRootJoint.BaseTransform = baseTransform;
                FSkeletonOutput.MarkPinAsChanged();
            }

            if (FRotationConstraintsInput.PinIsChanged)
            {
                FRootJoint.Constraints.Clear();
                for (int i = 0; i < 3; i++)
                {
                    double from, to;
                    FRotationConstraintsInput.GetValue2D(i, out from, out to);
                    FRootJoint.Constraints.Add(new Vector2D(from, to));
                }
                FSkeletonOutput.MarkPinAsChanged();
            }

            FSkeletonOutput.SetInterface(FSkeleton);
        }
예제 #6
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs

            bool recalculate = false;

            if (FJointNameInput.PinIsChanged || FBaseTransformInput.PinIsChanged || FOffsetModeInput.PinIsChanged || FParentNameInput.PinIsChanged || FConstraintsInput.PinIsChanged || recalculate)
            {
                skeleton = new Skeleton();

                int currId = 0;
                for (int i = 0; i < FJointNameInput.SliceCount; i++)
                {
                    string jointName;
                    string parentName;
                    FJointNameInput.GetString(i % FJointNameInput.SliceCount, out jointName);
                    FParentNameInput.GetString(i % FParentNameInput.SliceCount, out parentName);
                    IJoint    currJoint = new JointInfo(jointName);
                    Matrix4x4 baseTransform;
                    FBaseTransformInput.GetMatrix(i % FBaseTransformInput.SliceCount, out baseTransform);
                    currJoint.BaseTransform = baseTransform;             //VMath.Translate(basePositionX, basePositionY, basePositionZ);
                    currJoint.Constraints.Clear();
                    for (int j = i * 3; j < i * 3 + 3; j++)
                    {
                        double constraintMin, constraintMax;
                        FConstraintsInput.GetValue2D(j % FConstraintsInput.SliceCount, out constraintMin, out constraintMax);
                        currJoint.Constraints.Add(new Vector2D(constraintMin, constraintMax));
                    }
                    if (string.IsNullOrEmpty(parentName))
                    {
                        if (skeleton.Root == null)
                        {
                            skeleton.Root = currJoint;
                            currJoint.Id  = currId;
                            currId++;
                            skeleton.BuildJointTable();
                        }
                    }
                    else
                    {
                        if (skeleton.JointTable.ContainsKey(parentName))
                        {
                            currJoint.Parent = skeleton.JointTable[parentName];
                            currJoint.Id     = currId;
                            currId++;
                        }
                        skeleton.BuildJointTable();
                    }
                }

                int positionInWorldSpace = 0;
                FOffsetModeInput.GetOrd(0, out positionInWorldSpace);
                if (positionInWorldSpace > 0)
                {
                    List <Vector3D> offsetList = new List <Vector3D>();
                    foreach (KeyValuePair <string, IJoint> pair in skeleton.JointTable)
                    {
                        Vector3D worldPos = pair.Value.BaseTransform * (new Vector3D(0));
                        Vector3D parentWorldPos;
                        if (pair.Value.Parent != null)
                        {
                            parentWorldPos = pair.Value.Parent.BaseTransform * (new Vector3D(0));
                        }
                        else
                        {
                            parentWorldPos = new Vector3D(0);
                        }
                        Vector3D offset = worldPos - parentWorldPos;
                        offsetList.Add(offset);
                    }
                    int i = 0;
                    foreach (KeyValuePair <string, IJoint> pair in skeleton.JointTable)
                    {
                        pair.Value.BaseTransform = VMath.Translate(offsetList[i]);
                        i++;
                    }
                }


                FSkeletonOutput.MarkPinAsChanged();
            }

            FSkeletonOutput.SetInterface(skeleton);
        }
예제 #7
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            double width; FPinWidth.GetValue(0, out width);
            double height; FPinHeight.GetValue(0, out height);

            // if something changed, recreate Trafo
            if (FInputGridFrom.PinIsChanged || FInputGridTo.PinIsChanged || width != FWidth || height != FHeight)
            {
                // prepare GridTransformer
                FTrafo = new GridTransformer();

                int     i, j;
                Point2D p1, p2, p3;

                FWidth  = (int)width;
                FHeight = (int)height;

                // check Input ranges
                FBufSize = (int)height * (int)width * 2;
                if (FInputGridFrom.SliceCount != FBufSize || FInputGridTo.SliceCount != FBufSize)
                {
                    return;
                }


                // loop through points and create triangles
                for (i = 0; i < FHeight - 1; ++i)
                {
                    for (j = 0; j < FWidth - 1; ++j)
                    {
                        int index = j + i * FWidth;

                        // upper triangle
                        FInputGridFrom.GetValue2D(index, out p1.x, out p1.y);
                        FInputGridFrom.GetValue2D(index + 1, out p2.x, out p2.y);
                        FInputGridFrom.GetValue2D(index + FWidth, out p3.x, out p3.y);
                        Triangle triFrom1 = new Triangle(p1, p2, p3);

                        FInputGridTo.GetValue2D(index, out p1.x, out p1.y);
                        FInputGridTo.GetValue2D(index + 1, out p2.x, out p2.y);
                        FInputGridTo.GetValue2D(index + FWidth, out p3.x, out p3.y);
                        Triangle triTo1 = new Triangle(p1, p2, p3);

                        FTrafo.Insert(triFrom1, triTo1);

                        // lower triangle
                        FInputGridFrom.GetValue2D(index + 1, out p1.x, out p1.y);
                        FInputGridFrom.GetValue2D(index + FWidth, out p2.x, out p2.y);
                        FInputGridFrom.GetValue2D(index + FWidth + 1, out p3.x, out p3.y);
                        Triangle triFrom2 = new Triangle(p1, p2, p3);

                        FInputGridTo.GetValue2D(index + 1, out p1.x, out p1.y);
                        FInputGridTo.GetValue2D(index + FWidth, out p2.x, out p2.y);
                        FInputGridTo.GetValue2D(index + FWidth + 1, out p3.x, out p3.y);
                        Triangle triTo2 = new Triangle(p1, p2, p3);

                        FTrafo.Insert(triFrom2, triTo2);
                    }
                }
            }

            ///////////////////////////////////////////////////////
            // do transformation

            // prepare data
            int            sliceCount = FInputPoints.SliceCount;
            Point2D        pIn, pOut;
            List <Point2D> pList = new List <Point2D>();

            int[] hitter;
            hitter = new int[sliceCount / 2];
            int number = (sliceCount / 2);

            // loop throug input points and calc Transformation
            for (int i = 0; i < sliceCount / 2; ++i)
            {
                FInputPoints.GetValue2D(i, out pIn.x, out pIn.y);
                if (FTrafo.Transform(pIn, out pOut))   // inside ?
                {
                    pList.Add(pOut);
                    hitter[i] = 1;
                }
                else
                {
                    hitter[i] = 0;
                }
            }

            // set final slicecount
            FOutputPoints.SliceCount = pList.Count * 2;
            FOutputHit.SliceCount    = number;
            // set output
            for (int i = 0; i < pList.Count; ++i)
            {
                FOutputPoints.SetValue2D(i, pList[i].x, pList[i].y);
                FOutputHit.SetValue(i, hitter[i]);
            }
            for (int i = 0; i < number; ++i)
            {
                FOutputHit.SetValue(i, hitter[i]);
            }
        }