Exemplo n.º 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 (FShortcut.PinIsChanged)
            {
                FDestination.SliceCount = SpreadMax;

                string curSource;
                for (int i = 0; i < SpreadMax; i++)
                {
                    FShortcut.GetString(i, out curSource);
                    try
                    {
                        IWshShell    wsh         = new WshShellClass();
                        IWshShortcut curShortcut = (IWshShortcut)wsh.CreateShortcut(curSource);

                        FDestination.SetString(i, curShortcut.TargetPath);
                        FWorkingDir.SetString(i, curShortcut.WorkingDirectory);
                        FIcon.SetString(i, curShortcut.IconLocation);
                    }
                    catch
                    {
                        FHost.Log(TLogType.Error, "couldn't resolve shortcut " + curSource);
                        FDestination.SetString(i, string.Empty);
                        FWorkingDir.SetString(i, string.Empty);
                        FIcon.SetString(i, string.Empty);
                    }
                }
            }
        }
Exemplo n.º 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)
        {
            FCurrentDate.SliceCount = SpreadMax;
            FUTC.SliceCount         = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                if (FUpdate.PinIsChanged)
                {
                    FUpdate.GetValue(i, out FUpdateSlice);
                }

                DateTime CurrentDate = System.DateTime.Now;
                DateTime CurrentUTC  = System.DateTime.UtcNow;

                try
                {
                    if (FUpdateSlice > 0.5 || FFormate.PinIsChanged || FCulturInfo.PinIsChanged)
                    {
                        string currentFormatSlice;
                        string currentCultureInfo;
                        string currentDate = "";
                        string currentUTC  = "";

                        FFormate.GetString(i, out currentFormatSlice);
                        FCulturInfo.GetString(i, out currentCultureInfo);

                        if (currentFormatSlice != null && currentCultureInfo != null)
                        {
                            CultureInfo culture = new CultureInfo(currentCultureInfo);
                            currentDate = CurrentDate.ToString(currentFormatSlice, culture);
                            currentUTC  = CurrentUTC.ToString(currentFormatSlice, culture);
                        }
                        else if (currentFormatSlice != null)
                        {
                            currentDate = CurrentDate.ToString(currentFormatSlice);
                            currentUTC  = CurrentUTC.ToString(currentFormatSlice);
                        }
                        else if (currentCultureInfo != null)
                        {
                            CultureInfo culture = new CultureInfo(currentCultureInfo);
                            currentDate = CurrentDate.ToString(culture);
                            currentUTC  = CurrentUTC.ToString(culture);
                        }
                        else
                        {
                            currentDate = CurrentDate.ToString();
                            currentUTC  = CurrentUTC.ToString();
                        }

                        FCurrentDate.SetString(i, currentDate);
                        FUTC.SetString(i, currentUTC);
                    }
                }
                catch (Exception ex)
                {
                    FHost.Log(TLogType.Error, ex.Message);
                }
            }
        }
Exemplo n.º 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 (FSkeletonInput.PinIsChanged)
            {
                if (FSkeletonInput.IsConnected)
                {
                    object currInterface;
                    FSkeletonInput.GetUpstreamInterface(out currInterface);
                    inputSkeleton = (Skeleton)currInterface;
                }
                else
                {
                    inputSkeleton = null;
                }
            }

            if (FSkeletonInput.PinIsChanged || FJointNameInput.PinIsChanged)
            {
                if (inputSkeleton != null)
                {
                    string jointName;
                    IJoint currJoint;
                    FParentNameOutput.SliceCount         = FJointNameInput.SliceCount;
                    FBaseTransformOutput.SliceCount      = FJointNameInput.SliceCount;
                    FAnimationTransformOutput.SliceCount = FJointNameInput.SliceCount;
                    for (int i = 0; i < FJointNameInput.SliceCount; i++)
                    {
                        FJointNameInput.GetString(i, out jointName);
                        if (inputSkeleton.JointTable.ContainsKey(jointName))
                        {
                            currJoint = (IJoint)inputSkeleton.JointTable[jointName];
                            if (currJoint.Parent != null)
                            {
                                FParentNameOutput.SetString(i, currJoint.Parent.Name);
                            }
                            else
                            {
                                FParentNameOutput.SetString(i, "");
                            }

                            FJointIdOutput.SetValue(i, currJoint.Id);
                            FBaseTransformOutput.SetMatrix(i, VMath.Rotate(currJoint.Rotation) * currJoint.BaseTransform);
                            FAnimationTransformOutput.SetMatrix(i, currJoint.AnimationTransform);
                        }
                        else
                        {
                            FJointIdOutput.SetValue(i, -1);
                            FBaseTransformOutput.SetMatrix(i, VMath.IdentityMatrix);
                            FAnimationTransformOutput.SetMatrix(i, VMath.IdentityMatrix);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 public override bool Sync()
 {
     IsChanged = FAutoValidate ? FStringIn.PinIsChanged : FStringIn.Validate();
     if (IsChanged)
     {
         Length = FStringIn.SliceCount;
         using (var writer = GetWriter())
         {
             for (int i = 0; i < Length; i++)
             {
                 string result;
                 FStringIn.GetString(i, out result);
                 writer.Write(result ?? string.Empty);
             }
         }
     }
     return(base.Sync());
 }
Exemplo n.º 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 (FSource.PinIsChanged ||
                FDestination.PinIsChanged ||
                FDo.PinIsChanged)
            {
                //first set slicecounts for all outputs
                //the incoming int SpreadMax is the maximum slicecount of all input pins, which is a good default
                FDone.SliceCount = SpreadMax;

                //the variables to fill with the input data
                double curDo;
                string curSource, curDest;


                //loop for all slices
                for (int i = 0; i < SpreadMax; i++)
                {
                    //read data from inputs
                    FSource.GetString(i, out curSource);
                    FDestination.GetString(i, out curDest);
                    FDo.GetValue(i, out curDo);

                    double curDone = 0;
                    if (curDo == 1)
                    {
                        IWshShell    wsh         = new WshShellClass();
                        IWshShortcut curShortcut = (IWshShortcut)wsh.CreateShortcut(curDest + ".lnk");
                        curShortcut.WindowStyle = 1;                 //for default window, 3 for maximize, 7 for minimize
                        curShortcut.TargetPath  = curSource;         //for me, or any valid Path string
                        curShortcut.Save();
                        curDone = 1;
                    }

                    //write data to outputs
                    FDone.SetValue(i, curDone);
                }
            }
        }
Exemplo n.º 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 (FSpeedInput.PinIsChanged || FNarratorInput.PinIsChanged || FStringInput.PinIsChanged)
     {
         //loop for all slices
         for (int i = 0; i < SpreadMax; i++)
         {
             //read data from inputs
             double rate = 5.0;
             FSpeedInput.GetValue(i, out rate);
             vox.Rate = (int)rate;
             int voiceindex = 0;
             FNarratorInput.GetOrd(i, out voiceindex);
             vox.Voice = vox.GetVoices(string.Empty, string.Empty).Item(voiceindex);
             FStringInput.GetString(i, out input_string);
         }
     }
     if (FSpeakInput.PinIsChanged)
     {
         double speak = 0.0;
         FSpeakInput.GetValue(0, out speak);
         if (speak > 0.5)
         {
             vox.Speak(input_string, SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
         }
     }
     //remember that we are running with autoevaluate == true
     if (done == true)   //endstream was fired
     {
         done = false;
         FDoneOutput.SetValue(0, 1.0);
     }
     else
     {
         FDoneOutput.SetValue(0, 0.0);
     }
 }
Exemplo n.º 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)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FInput.PinIsChanged || FSet.PinIsChanged)
            {
                FIsHidden.SliceCount   = SpreadMax;
                FIsReadOnly.SliceCount = SpreadMax;
                FIsSystem.SliceCount   = SpreadMax;

                string curFile;
                double doSet, h, r, s;
                for (int i = 0; i < SpreadMax; i++)
                {
                    FInput.GetString(i, out curFile);
                    h = 0;
                    r = 0;
                    s = 0;
                    try
                    {
                        FileInfo f = new FileInfo(curFile);
                        if ((f.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                        {
                            h = 1;
                        }
                        if ((f.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        {
                            r = 1;
                        }
                        if ((f.Attributes & FileAttributes.System) == FileAttributes.System)
                        {
                            s = 1;
                        }

                        double _h, _r, _s;
                        FSet.GetValue(i, out doSet);
                        if (doSet > 0.5)
                        {
                            FHidden.GetValue(i, out _h);
                            FReadOnly.GetValue(i, out _r);
                            FSystem.GetValue(i, out _s);
                            if (h != _h)
                            {
                                f.Attributes ^= FileAttributes.Hidden;
                                h             = _h;
                            }
                            if (r != _r)
                            {
                                f.Attributes ^= FileAttributes.ReadOnly;
                                r             = _r;
                            }
                            if (s != _s)
                            {
                                f.Attributes ^= f.Attributes | FileAttributes.System;
                                s             = _s;
                            }
                        }

                        FIsHidden.SetValue(i, h);
                        FIsReadOnly.SetValue(i, r);
                        FIsSystem.SetValue(i, s);
                    }
                    catch
                    {
                        FHost.Log(TLogType.Debug, "AttributeFile: cannot handle " + curFile);
                    }
                }
            }
        }
Exemplo n.º 8
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 (FWindowWidth != this.Width)
            {
                FWindowWidth = this.Width;
                double columns;
                FColumns.GetValue(0, out columns);
                foreach (ComboBoxSpread cb in FComboList)
                {
                    cb.SetBox((int)columns, (int)(FWindowWidth / columns));
                }
                Refresh();
            }

            //set output Slicecount
            FSelectIndex.SliceCount = FComboList.Count;
            FItem.SliceCount        = FComboList.Count;

            if (selectedIndex.Count > FComboList.Count)
            {
                int diff = selectedIndex.Count - FComboList.Count;
                selectedIndex.RemoveRange(FComboList.Count, diff);
                selectedItem.RemoveRange(FComboList.Count, diff);
            }

            //if any of the inputs has changed
            //recompute the outputs
            int binIncrement = 0;

            for (int i = 0; i < FComboList.Count; i++)
            {
                double tmpBinSize;
                FBinSize.GetValue(i, out tmpBinSize);
                int curBinSize = (int)tmpBinSize;
                if (curBinSize < 0)
                {
                    curBinSize = FItems.SliceCount;
                }

                if (FItems.PinIsChanged || FComboList[i].Items.Count != curBinSize)
                {
                    List <string> curStringList = new List <string>();
                    for (int j = 0; j < curBinSize; j++)
                    {
                        string currentStringSlice;
                        FItems.GetString(binIncrement + j, out currentStringSlice);
                        curStringList.Add(currentStringSlice);
                    }

                    if (!FComboList[i].Items.Equals(curStringList))
                    {
                        FComboList[i].Items.Clear();
                        foreach (string s in curStringList)
                        {
                            FComboList[i].Items.Add(s);
                        }
                        curStringList.Clear();
                    }
                }
                binIncrement += curBinSize;

                if (selectedIndex.Count < i + 1)
                {
                    selectedIndex.Add(0);
                    selectedItem.Add("");
                }

                double curBangSelect;
                FDoSelect.GetValue(i, out curBangSelect);
                if (curBangSelect > 0)
                {
                    double currentValueSlice;
                    FSelectItem.GetValue(i, out currentValueSlice);
                    int selectIndex = (int)(currentValueSlice % FComboList[i].Items.Count);
                    FComboList[i].SelectedItem = FComboList[i].Items[selectIndex];
                }

                if (FComboList[i].SelectedItem != null && FComboList[i].isDropDown == false)
                {
                    selectedIndex[i] = FComboList[i].SelectedIndex;
                    selectedItem[i]  = FComboList[i].SelectedItem.ToString();
                }

                if (FComboList[i].SelectedItem == null)
                {
                    double curDefault;
                    FDefault.GetValue(i, out curDefault);
                    FComboList[i].SelectedItem = FComboList[i].Items[(int)curDefault];
                    selectedIndex[i]           = FComboList[i].SelectedIndex;
                    selectedItem[i]            = FComboList[i].SelectedItem.ToString();
                }

                FSelectIndex.SetValue(i, selectedIndex[i]);
                FItem.SetString(i, selectedItem[i]);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// The Mainloop
        /// </summary>
        public void Evaluate(int SpreadMax)
        {
            // Get Node Settings
            string        DirectoryPath         = "";
            double        IncludeSubdirectories = 0;
            List <string> Mask       = new List <string>();
            string        MaskRule   = "";
            string        CountOrder = "";
            bool          Update     = false;

            SetMessage("Please Update");
            double CountIn = 0;

            //Check if any pin is changed and setup a new search;
            if (FDirectory.PinIsChanged || FSubdirectories.PinIsChanged || FMask.PinIsChanged || FMaskRule.PinIsChanged || FCountIn.PinIsChanged || FShortFilenameIn.PinIsChanged || FCountOrder.PinIsChanged || FUpdate.PinIsChanged)
            {
                //Get the DirectoryPath String an check if it null, empty or exist. if not the function is returned
                FDirectory.GetString(0, out DirectoryPath);
                if (String.IsNullOrEmpty(DirectoryPath) || !Directory.Exists(DirectoryPath))
                {
                    FFiles.SliceCount            = 0;
                    FShortFilenameOut.SliceCount = 0;
                    FCountOut.SetValue(0, 0);

                    SetMessage("Please Enter a correct directory Path..");
                    return;
                }

                FSubdirectories.GetValue(0, out IncludeSubdirectories);
                FMaskRule.GetString(0, out MaskRule);;
                FCountIn.GetValue(0, out CountIn);
                FCountOrder.GetString(0, out CountOrder);

                //Get all Serach Masks
                for (int i = 0; i < FMask.SliceCount; i++)
                {
                    string MaskSlice;
                    FMask.GetString(i, out MaskSlice);

                    if (!String.IsNullOrEmpty(MaskSlice))
                    {
                        Mask.Add(MaskSlice);
                    }
                }

                //if there is no Mask create one, otherwise the Function getFiles crashes
                if (Mask.Count == 0)
                {
                    Mask.Add("*.*");
                }

                //Create a new Search with the given setup. If there exist a Search Object we are still Searching.
                if (FSearch == null)
                {
                    //Set if the Subdirectories are included or not and Create a new Search Process Object which handle all Files Searching and Sorting in a new Thread
                    if (IncludeSubdirectories <= 0)
                    {
                        FSearch = new SearchProcess(DirectoryPath, Mask.ToArray(), SearchOption.TopDirectoryOnly, MaskRule, CountIn, CountOrder);
                    }
                    else
                    {
                        FSearch = new SearchProcess(DirectoryPath, Mask.ToArray(), SearchOption.AllDirectories, MaskRule, CountIn, CountOrder);
                    }

                    if (FSearch != null)
                    {
                        //Start the Searching..
                        SetMessage(FSearch.Search());
                    }
                }
                else
                {
                    SetMessage("Still Searching... Please Wait...");
                }
            }

            //Read the Resulte of the SearchProcess
            if (FSearch != null)
            {
                string Message = FSearch.GetStatus();
                SetMessage(Message);

                string[] FullFilesNames = FSearch.GetFullFileNames();


                if (FullFilesNames != null)
                {
                    double IncludeShortFilename = 0;
                    FShortFilenameIn.GetValue(0, out IncludeShortFilename);

                    FFiles.SliceCount = FullFilesNames.Length;
                    FCountOut.SetValue(0, FullFilesNames.Length);

                    for (int i = 0; i < FullFilesNames.Length; i++)
                    {
                        string FilePath = FullFilesNames[i];
                        FFiles.SetString(i, FilePath);

                        if (IncludeShortFilename >= 0.5)
                        {
                            string[] ShortFilename = FSearch.GetShortFileNames();

                            FShortFilenameOut.SliceCount = ShortFilename.Length;
                            FShortFilenameOut.SetString(i, ShortFilename[i]);
                        }
                        else
                        {
                            FShortFilenameOut.SliceCount = 0;
                        }
                    }
                    FSearch = null;
                }
            }
        }
Exemplo n.º 10
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 (FTUIOPacketInput.PinIsChanged)
            {
                string currentPacket;
                FTUIOPacketInput.GetString(0, out currentPacket);
                if (currentPacket == "" || currentPacket == null)
                {
                    return;
                }
                int tuioPosition = currentPacket.IndexOf("#bundle");
                if (tuioPosition == -1)
                {
                    return;
                }


                while ((tuioPosition = currentPacket.IndexOf("#bundle")) >= 0)
                {
                    int    nextpos = currentPacket.IndexOf("#bundle", tuioPosition + 1);
                    string currentSeperatedPacket = "";
                    if (nextpos == -1)
                    {
                        currentSeperatedPacket = currentPacket;
                        currentPacket          = "";
                    }
                    else
                    {
                        currentSeperatedPacket = currentPacket.Substring(tuioPosition, nextpos - tuioPosition);
                        currentPacket          = currentPacket.Substring(nextpos);
                    }
                    OSC.NET.OSCPacket packet = OSC.NET.OSCPacket.Unpack(Encoding.Default.GetBytes(currentSeperatedPacket));
                    if (packet.IsBundle())
                    {
                        ArrayList messages = packet.Values;
                        for (int i = 0; i < messages.Count; i++)
                        {
                            FTuioClient.ProcessMessage((OSC.NET.OSCMessage)messages[i]);
                        }
                    }
                    else
                    {
                        FTuioClient.ProcessMessage((OSC.NET.OSCMessage)packet);
                    }
                }
            }
            List <TuioCursor> cursors = FTuioClient.getTuioCursors();
            List <TuioObject> objects = FTuioClient.getTuioObjects();
            List <TuioBlob>   blobs   = FTuioClient.getTuioBlobs();
            int slicecount            = cursors.Count + objects.Count + blobs.Count;

            FSessionIDOut.SliceCount            = slicecount;
            FClassIDOut.SliceCount              = slicecount;
            FUniqueIDOut.SliceCount             = slicecount;
            FPosXOut.SliceCount                 = slicecount;
            FPosYOut.SliceCount                 = slicecount;
            FWidthOut.SliceCount                = slicecount;
            FHeightOut.SliceCount               = slicecount;
            FAreaOut.SliceCount                 = slicecount;
            FAngleOut.SliceCount                = slicecount;
            FMovementXOut.SliceCount            = slicecount;
            FMovementYOut.SliceCount            = slicecount;
            FMotionAccelerationOut.SliceCount   = slicecount;
            FRotationAccelerationOut.SliceCount = slicecount;
            FMotionSpeedOut.SliceCount          = slicecount;
            FRotationSpeedOut.SliceCount        = slicecount;

            int curindex = 0;

            for (int i = 0; i < cursors.Count; i++)
            {
                TuioCursor cur = cursors[i];
                FSessionIDOut.SetValue(curindex, cur.getSessionID());
                FClassIDOut.SetValue(curindex, 0);
                FUniqueIDOut.SetValue(curindex, cur.getFingerID());
                FPosXOut.SetValue(curindex, cur.getPosition().getX() * 2 - 1);
                FPosYOut.SetValue(curindex, -cur.getPosition().getY() * 2 + 1);
                FAngleOut.SetValue(curindex, 0);
                FMovementXOut.SetValue(curindex, cur.getXSpeed());
                FMovementYOut.SetValue(curindex, cur.getYSpeed());
                FMotionAccelerationOut.SetValue(curindex, cur.getMotionAccel());
                FRotationAccelerationOut.SetValue(curindex, 0);
                FMotionSpeedOut.SetValue(curindex, cur.getMotionSpeed());
                FRotationSpeedOut.SetValue(curindex, 0);
                curindex++;
            }
            int objectOffset = 1000;

            for (int i = 0; i < objects.Count; i++)
            {
                TuioObject obj = objects[i];
                FSessionIDOut.SetValue(curindex, obj.getSessionID());
                FClassIDOut.SetValue(curindex, 1);
                FUniqueIDOut.SetValue(curindex, obj.getFiducialID() + objectOffset);
                FPosXOut.SetValue(curindex, obj.getPosition().getX() * 2 - 1);
                FPosYOut.SetValue(curindex, -obj.getPosition().getY() * 2 + 1);
                FAngleOut.SetValue(curindex, 1 - ((obj.getAngle()) / (Math.PI + Math.PI)));
                FMovementXOut.SetValue(curindex, obj.getXSpeed());
                FMovementYOut.SetValue(curindex, obj.getYSpeed());
                FMotionAccelerationOut.SetValue(curindex, obj.getMotionAccel());
                FRotationAccelerationOut.SetValue(curindex, obj.getRotationAccel());
                FMotionSpeedOut.SetValue(curindex, obj.getMotionSpeed());
                FRotationSpeedOut.SetValue(curindex, obj.getRotationSpeed());
                curindex++;
            }

            int blobOffset = 2000;

            for (int i = 0; i < blobs.Count; i++)
            {
                TuioBlob blb = blobs[i];
                FSessionIDOut.SetValue(curindex, blb.getSessionID());
                FClassIDOut.SetValue(curindex, 2);
                FUniqueIDOut.SetValue(curindex, blb.getBlobID() + blobOffset);
                FPosXOut.SetValue(curindex, blb.getPosition().getX() * 2 - 1);
                FPosYOut.SetValue(curindex, -blb.getPosition().getY() * 2 + 1);
                FWidthOut.SetValue(curindex, blb.getWidth());
                FHeightOut.SetValue(curindex, blb.getHeight());
                FAreaOut.SetValue(curindex, blb.getArea());
                FAngleOut.SetValue(curindex, 1 - ((blb.getAngle()) / (Math.PI + Math.PI)));
                FMovementXOut.SetValue(curindex, blb.getXSpeed());
                FMovementYOut.SetValue(curindex, blb.getYSpeed());
                FMotionAccelerationOut.SetValue(curindex, blb.getMotionAccel());
                FRotationAccelerationOut.SetValue(curindex, blb.getRotationAccel());
                FMotionSpeedOut.SetValue(curindex, blb.getMotionSpeed());
                FRotationSpeedOut.SetValue(curindex, blb.getRotationSpeed());
                curindex++;
            }
        }
Exemplo n.º 11
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //compute only on refresh
            if (FFile.PinIsChanged ||
                FCustomRoot.PinIsChanged ||
                FUpdate.PinIsChanged)
            {
                string currentFile;
                string curCustomRoot;
                double currentUpdate;

                FExists.SliceCount   = SpreadMax;
                FFileSize.SliceCount = SpreadMax;
                FReadOnly.SliceCount = SpreadMax;
                FHidden.SliceCount   = SpreadMax;

                string hostPath;
                FHost.GetHostPath(out hostPath);

                //loop for all slices
                for (int i = 0; i <= SpreadMax; i++)
                {
                    FFile.GetString(i, out currentFile);
                    FCustomRoot.GetString(i, out curCustomRoot);
                    FUpdate.GetValue(i, out currentUpdate);

                    int    exist    = 0;
                    double fileSize = 0;
                    int    readOnly = 0;
                    int    hidden   = 0;



                    if (!Path.IsPathRooted(currentFile))
                    {
                        if (curCustomRoot == string.Empty)
                        {
                            curCustomRoot = hostPath;
                        }
                        else
                        {
                            if (!Path.IsPathRooted(curCustomRoot))
                            {
                                string message = "\'";
                                message += curCustomRoot;
                                message += "\' is not a valid root-path";
                                FHost.Log(TLogType.Warning, message);
                                curCustomRoot = hostPath;
                            }
                        }
                        currentFile = Path.Combine(curCustomRoot, currentFile);
                    }

                    if (File.Exists(currentFile))
                    {
                        exist = 1;

                        FileInfo curFileInfo = new FileInfo(currentFile);
                        fileSize = (double)curFileInfo.Length;

                        if ((File.GetAttributes(currentFile) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        {
                            readOnly = 1;
                        }
                        if ((File.GetAttributes(currentFile) & FileAttributes.Hidden) == FileAttributes.Hidden)
                        {
                            hidden = 1;
                        }
                    }
                    FExists.SetValue(i, (double)exist);
                    FFileSize.SetValue(i, fileSize);
                    FReadOnly.SetValue(i, (double)readOnly);
                    FHidden.SetValue(i, (double)hidden);
                }
            }
        }
Exemplo n.º 12
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 val;
            double actualFPS = 0;
            double actualEXP = 0;
            bool   needsinit = false;

            if (FEnablePin.PinIsChanged)
            {
                FEnablePin.GetValue(0, out val);
                if (val < 0.5)
                {
                    if (FuEyeCam.IsOpen())
                    {
                        FuEyeCam.ExitCamera();
                        FreeImages();
                    }
                }
                else
                {
                    needsinit = true;
                }
            }

            if (FFormatPin.PinIsChanged)
            {
                int    format;
                double f;

                FFormatPin.GetValue(0, out f);
                format = (int)f;

                switch (format)
                {
                case 0:
                {
                    FColorMode = uEye.IS_SET_CM_RGB32;
                    FBytes     = 4;
                    FBits      = 32;
                    break;
                }

                case 1:
                {
                    FColorMode = uEye.IS_SET_CM_RGB24;
                    FBytes     = 3;
                    FBits      = 24;
                    break;
                }

                case 2:
                {
                    FColorMode = uEye.IS_SET_CM_RGB16;
                    FBytes     = 2;
                    FBits      = 16;
                    break;
                }

                case 3:
                {
                    FColorMode = uEye.IS_SET_CM_RGB15;
                    FBytes     = 2;
                    FBits      = 15;
                    break;
                }

                case 4:
                {
                    FColorMode = uEye.IS_SET_CM_BAYER;
                    FBytes     = 4;                                 //??
                    FBits      = 32;                                //??
                    break;
                }

                case 5:
                {
                    FColorMode = uEye.IS_SET_CM_Y8;
                    FBytes     = 1;
                    FBits      = 8;
                    break;
                }
                }

                if (FuEyeCam.IsOpen())
                {
                    needsinit = true;
                }
            }

            if (needsinit)
            {
                InitCam(0);
            }

            if (FuEyeCam == null)
            {
                return;
            }

            if (FSharedNamePin.PinIsChanged)
            {
                if (FSegment != null)
                {
                    FSegment.Dispose();
                }

                string name;
                FSharedNamePin.GetString(0, out name);

                FSegment = new Segment(name, SharedMemoryCreationFlag.Create, FWidth * FHeight * FBytes);
            }

            if (FPixelClockPin.PinIsChanged)
            {
                FPixelClockPin.GetValue(0, out val);
                FuEyeCam.SetPixelClock((int)val);
            }

            if (FFrameRatePin.PinIsChanged)
            {
                FFrameRatePin.GetValue(0, out val);
                FuEyeCam.SetFrameRate(val, ref actualFPS);
            }

            if (FExposureTimePin.PinIsChanged)
            {
                FExposureTimePin.GetValue(0, out val);
                FuEyeCam.SetExposureTime(val, ref actualEXP);
            }

            if (FFlashDelayPin.PinIsChanged || FFlashDurationPin.PinIsChanged)
            {
                FFlashDelayPin.GetValue(0, out val);
                double dur;
                FFlashDurationPin.GetValue(0, out dur);
                FuEyeCam.SetFlashDelay((int)val * 1000, (int)dur * 1000);
            }

            if (FFlashModePin.PinIsChanged)
            {
                FFlashModePin.GetValue(0, out val);
                FuEyeCam.SetFlashStrobe((int)val, 0);
            }

            FuEyeCam.GetFramesPerSecond(ref actualFPS);
            FActualFrameRatePin.SetValue(0, actualFPS);
        }
Exemplo n.º 13
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)
            {
                jointNames = new List <string>();
                string jointName;
                for (int i = 0; i < FJointNameInput.SliceCount; i++)
                {
                    FJointNameInput.GetString(i, out jointName);
                    jointNames.Add(jointName);
                }
                recalculate = true;
                if (jointNames.Count == 1 && string.IsNullOrEmpty(jointNames[0]))
                {
                    jointsSelected = false;
                }
                else
                {
                    jointsSelected = true;
                }
            }

            if (FSkeletonInput.PinIsChanged)
            {
                if (FSkeletonInput.IsConnected)
                {
                    object currInterface;
                    FSkeletonInput.GetUpstreamInterface(out currInterface);
                    inputSkeleton = (Skeleton)currInterface;

                    // if there are no specific joints selected via input pin, collect them all
                    if (jointNames == null || !jointsSelected)
                    {
                        jointNames = new List <string>();
                        foreach (KeyValuePair <string, IJoint> pair in inputSkeleton.JointTable)
                        {
                            // Only add those with a valid array index.
                            // It's not a must that all bones are used as skinning matrices.
                            if (pair.Value.Id >= 0)
                            {
                                jointNames.Add(pair.Key);
                            }
                        }
                    }
                }
                else
                {
                    inputSkeleton = null;
                }
                recalculate = true;
            }

            if (FInverseBindPoseInput.PinIsChanged)
            {
                recalculate = true;
            }

            if (FOutputModeInput.PinIsChanged)
            {
                FOutputModeInput.GetOrd(0, out outputMode);
                recalculate = true;
            }

            if (recalculate && inputSkeleton != null)
            {
                inputSkeleton.CalculateCombinedTransforms();
                int jointCount;
                if (outputMode == OUTPUT_MODE_DYNAMIC)
                {
                    jointCount = jointNames.Count;
                }
                else
                {
                    jointCount = 60;
                }
                FTransformOutput.SliceCount = jointCount;
                IJoint    currJoint;
                Matrix4x4 currIBPMatrix;
                int       i = 0;
                for (i = 0; i < jointNames.Count; i++)
                {
                    currJoint = inputSkeleton.JointTable[jointNames[i]];
                    if (currJoint != null)
                    {
                        int sliceIndex;
                        if (outputMode == OUTPUT_MODE_STATIC)
                        {
                            sliceIndex = currJoint.Id;
                        }
                        else
                        {
                            sliceIndex = i;
                        }
                        FInverseBindPoseInput.GetMatrix(sliceIndex, out currIBPMatrix);
                        FTransformOutput.SetMatrix(sliceIndex, currIBPMatrix * currJoint.CombinedTransform);
                    }
                }

                // Pad remaining slices with Identity Matrices
                for (int j = i; j < jointCount; j++)
                {
                    FTransformOutput.SetMatrix(j, VMath.IdentityMatrix);
                }
            }
        }
Exemplo n.º 14
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            bool doUpdate = false;

            if (FUpdate.PinIsChanged)
            {
                double curUpdate;
                FUpdate.GetValue(0, out curUpdate);
                if (curUpdate == 1)
                {
                    doUpdate = true;
                }
            }

            //if any of the inputs has changed
            //recompute the outputs
            if (FFilename.PinIsChanged ||
                FIndex.PinIsChanged ||
                FCount.PinIsChanged ||
                doUpdate ||
                FLineWiseChanged ||
                FAnsiUtfChanged)
            {
                doUpdate         = false;
                FLineWiseChanged = false;
                FAnsiUtfChanged  = false;

                //outSliceCount
                FContent.SliceCount = SpreadMax;

                //the variables to fill with the input data
                string curFilename;
                int    curIndex, curCount;

                Encoding enc = Encoding.GetEncoding(1252);
                if (FAnsiUtfTog != 0)
                {
                    enc = Encoding.UTF8;
                }

                //loop for all slices
                for (int i = 0; i < SpreadMax; i++)
                {
                    //read data from inputs
                    FFilename.GetString(i, out curFilename);

                    double tmpIndex, tmpCount;
                    FIndex.GetValue(i, out tmpIndex);
                    FCount.GetValue(i, out tmpCount);
                    curIndex = (int)Math.Floor(tmpIndex);
                    curCount = (int)Math.Floor(tmpCount);

                    string outString = string.Empty;

                    if (File.Exists(curFilename))
                    {
                        if (FLineWiseTog == 1)
                        {
                            string[] allLines = File.ReadAllLines(curFilename, enc);
                            int      maxlen   = Math.Min(allLines.Length, curIndex + curCount);
                            for (int j = curIndex; j < maxlen; j++)
                            {
                                outString += allLines[j];
                                if (j != maxlen - 1)
                                {
                                    outString += Environment.NewLine;
                                }
                            }
                        }
                        else
                        {
                            TextReader curFile = new StreamReader(curFilename, enc);
                            for (int j = 0; j < curIndex + curCount; j++)
                            {
                                int v = curFile.Read();
                                if (v == -1)
                                {
                                    break;
                                }
                                else if (j >= curIndex)
                                {
                                    outString += (char)v;
                                }
                            }
                            curFile.Close();
                        }
                    }

                    //write data to outputs
                    FContent.SetString(i, outString);
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// The Mainloop
        /// </summary>
        public void Evaluate(int SpreadMax)
        {
            string[] tAvailablePorts = SerialPort.GetPortNames();
            FPortsOut.SliceCount     = tAvailablePorts.Length;
            FConnectedOut.SliceCount = tAvailablePorts.Length;

            for (int i = 0; i < tAvailablePorts.Length; i++)
            {
                FPortsOut.SetValue(i, Convert.ToDouble(tAvailablePorts[i].Substring(3)));
            }


            if (FPortNumberIn.PinIsChanged)
            {
                if (_Driver != null)
                {
                    _Driver.StopThread = false;

                    while (_Driver.ThreadIsAlive())
                    {
                        Thread.Sleep(1);
                    }

                    _Driver.Dispose();
                    _Driver = null;
                }
            }



            double currentSliceEnabled;

            FEnableIn.GetValue(0, out currentSliceEnabled);



            if (currentSliceEnabled > 0.5)
            {
                try
                {
                    if (_Driver == null)
                    {
                        double currentSlicePortNumber;
                        FPortNumberIn.GetValue(0, out currentSlicePortNumber);
                        if ((new List <string>(SerialPort.GetPortNames())).Contains(String.Format("COM{0}", currentSlicePortNumber)))
                        {
                            string currentSliceIndentifier;
                            double currentSliceBaudrate;
                            double currentSliceDataFieldSize;
                            double currentTimeOutTime;

                            FEnableIn.GetValue(0, out currentSliceEnabled);
                            FIdentifier.GetString(0, out currentSliceIndentifier);
                            FDataFieldSize.GetValue(0, out currentSliceDataFieldSize);
                            FTimeOut.GetValue(0, out currentTimeOutTime);
                            FBaudrateIn.GetValue(0, out currentSliceBaudrate);

                            _Driver = new Driver((int)currentSlicePortNumber, (int)currentSliceBaudrate, Parity.None, 8, StopBits.One);

                            _Driver.SetParameters(currentSliceIndentifier, (int)currentSliceDataFieldSize, (int)currentTimeOutTime);

                            _Driver.StartThread();
                        }
                    }
                    else
                    {
                        string currentSliceIndentifier;
                        double currentSliceBaudrate;
                        double currentSliceDataFieldSize;
                        double currentTimeOutTime;


                        FIdentifier.GetString(0, out currentSliceIndentifier);
                        FDataFieldSize.GetValue(0, out currentSliceDataFieldSize);
                        FTimeOut.GetValue(0, out currentTimeOutTime);
                        FBaudrateIn.GetValue(0, out currentSliceBaudrate);

                        if (FBaudrateIn.PinIsChanged)
                        {
                            _Driver.Baudrate = (int)currentSliceBaudrate;
                        }

                        _Driver.SetParameters(currentSliceIndentifier, (int)currentSliceDataFieldSize, (int)currentTimeOutTime);

                        List <string> tData = new List <string>();
                        tData = _Driver.getData();

                        if (tData.Count > 0)
                        {
                            FDataOut.SliceCount = tData.Count;
                            string tSlice = String.Empty;

                            for (int i = 0; i < tData.Count; i++)
                            {
                                System.TimeSpan tDiff = System.DateTime.Now - tStart;

                                Debug.WriteLine(tDiff.TotalMilliseconds);
                                tSlice += tData[i];
                            }

                            FDataOut.SetString(0, tSlice);
                            tStart = System.DateTime.Now;
                        }
                        else
                        {
                            FDataOut.SliceCount = 0;
                            //FDataOut.SetString(0, "");
                        }

                        tData = null;
                    }
                }
                catch (Exception ex)
                {
                    FHost.Log(TLogType.Error, ex.Message);
                }
            }
            else
            {
                if (_Driver != null)
                {
                    _Driver.StopThread = false;

                    while (_Driver.ThreadIsAlive())
                    {
                        Thread.Sleep(1);
                    }

                    _Driver.Dispose();
                    _Driver = null;
                }
            }
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        protected void ProcessInputsSlice(int sliceIndex)
        {
            String inputStringSlice;
            double enabledValueSlice;
            double doSendValueSlice;
            String remoteHostStringSlice;
            double remotePortValueSlice;
            double holdOutputSlice;
            double receiveBufferSizeSlice;
            double receiveTimeoutSlice;
            double sendBufferSizeSlice;
            double sendTimeoutSlice;
            bool   remoteHostChangedSlice;
            bool   remotePortChangedSlice;

            TV4TcpClient tcpClientSlice = TClients[sliceIndex];

            //read data from inputs
            FInputStringInput.GetString(sliceIndex, out inputStringSlice);
            FEnableValueInput.GetValue(sliceIndex, out enabledValueSlice);
            FDoSendValueInput.GetValue(sliceIndex, out doSendValueSlice);
            FRemoteHostStringInput.GetString(sliceIndex, out remoteHostStringSlice);
            FRemotePortValueInput.GetValue(sliceIndex, out remotePortValueSlice);
            FHoldOutputInput.GetValue(sliceIndex, out holdOutputSlice);
            FReceiveBufferSizeInput.GetValue(sliceIndex, out receiveBufferSizeSlice);
            FReceiveTimeoutInput.GetValue(sliceIndex, out receiveTimeoutSlice);
            FSendBufferSizeInput.GetValue(sliceIndex, out sendBufferSizeSlice);
            FSendTimeoutInput.GetValue(sliceIndex, out sendTimeoutSlice);

            //if the remote server or remote port pin was changed on this slice we're going to have to close
            //the connection so we can create a new one to the new host and port
            if (tcpClientSlice.FRemoteHost != null && FRemoteHostStringInput.PinIsChanged)
            {
                remoteHostChangedSlice = !(tcpClientSlice.FRemoteHost.Equals(remoteHostStringSlice));
            }
            else
            {
                remoteHostChangedSlice = false;
            }
            if (FRemotePortValueInput.PinIsChanged)
            {
                remotePortChangedSlice = tcpClientSlice.FRemotePort != remotePortValueSlice;
            }
            else
            {
                remotePortChangedSlice = false;
            }

            //if the enabled value changed to zero, we need to close the connection
            //if the remote server or port pin was changed, we will need to connect to the new host and port
            if (tcpClientSlice.ConnectStatus != TConnectStatus.NeverConnected &&
                (enabledValueSlice <= 0.5 || remoteHostChangedSlice || remotePortChangedSlice))
            {
                //if the TcpClient object ever connected it cannot be used for another connection,
                //so we create a new one for any new connection that this slice might make
                tcpClientSlice.Close(true);
                tcpClientSlice = TClients[sliceIndex] = new TV4TcpClient();
                FOutputStringOutput.SetString(sliceIndex, "");
                FConnectedValueOutput.SetValue(sliceIndex, 0);
            }

            //we need the data every frame even if none of it has changed, so we store a persistent copy of everything
            tcpClientSlice.FInput            = inputStringSlice;
            tcpClientSlice.FEnabled          = enabledValueSlice > 0.5;
            tcpClientSlice.FDoSend           = doSendValueSlice > 0.5;
            tcpClientSlice.FRemoteHost       = remoteHostStringSlice;
            tcpClientSlice.FRemotePort       = (int)remotePortValueSlice;
            tcpClientSlice.FHoldOutput       = holdOutputSlice > 0.5;
            tcpClientSlice.ReceiveBufferSize = (int)receiveBufferSizeSlice;
            tcpClientSlice.ReceiveTimeout    = (int)(receiveTimeoutSlice * 1000.0);
            tcpClientSlice.SendBufferSize    = (int)sendBufferSizeSlice;
            tcpClientSlice.SendTimeout       = (int)(sendTimeoutSlice * 1000.0);
        }
Exemplo n.º 18
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //compute only on refresh
            if (FDir.PinIsChanged ||
                FCreate.PinIsChanged ||
                FDelete.PinIsChanged ||
                FNewDir.PinIsChanged ||
                FRename.PinIsChanged)
            {
                string currentDir;
                double currentCreate;
                double currentDelete;
                string curNewDir;
                double currentRename;

                FExists.SliceCount = SpreadMax;

                //loop for all slices
                for (int i = 0; i <= SpreadMax; i++)
                {
                    FDir.GetString(i, out currentDir);
                    FCreate.GetValue(i, out currentCreate);
                    FDelete.GetValue(i, out currentDelete);
                    FNewDir.GetString(i, out curNewDir);
                    FRename.GetValue(i, out currentRename);

                    string hostPath;
                    FHost.GetHostPath(out hostPath);
                    hostPath = Path.GetDirectoryName(hostPath);


                    if (!Path.IsPathRooted(currentDir))
                    {
                        currentDir = Path.Combine(hostPath, currentDir);
                    }

                    System.IO.DirectoryInfo curDirectory = new System.IO.DirectoryInfo(currentDir);

                    if (!curDirectory.Exists)
                    {
                        if (currentCreate == 1)
                        {
                            curDirectory.Create();
                            FExists.SetValue(i, 1.0);
                        }
                        else
                        {
                            FExists.SetValue(i, 0.0);
                        }
                    }
                    else
                    {
                        if (currentDelete == 1)
                        {
                            curDirectory.Delete();
                            FExists.SetValue(i, 0.0);
                        }
                        else
                        {
                            if (currentRename == 1)
                            {
                                if (!Path.IsPathRooted(curNewDir))
                                {
                                    curNewDir = Path.Combine(hostPath, curNewDir);
                                }
                                curDirectory.MoveTo(curNewDir);
                                FExists.SetValue(i, 0.0);
                            }
                            else
                            {
                                FExists.SetValue(i, 1.0);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 19
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;
            bool chainRangeChanged      = false;
            bool recalculateOrientation = false;

            if (FChainStart.PinIsChanged)
            {
                FChainStart.GetString(0, out chainStart);
                recalculate       = true;
                chainRangeChanged = true;
            }

            if (FChainEnd.PinIsChanged)
            {
                FChainEnd.GetString(0, out chainEnd);
                recalculate       = true;
                chainRangeChanged = true;
            }

            object currInterface;

            if (FPoseInput.PinIsChanged || chainRangeChanged)
            {
                if (FPoseInput.IsConnected)
                {
                    FPoseInput.GetUpstreamInterface(out currInterface);
                    Skeleton s = (Skeleton)currInterface;
                    if (outputSkeleton == null || !s.Uid.Equals(outputSkeleton.Uid))
                    {
                        outputSkeleton = (Skeleton)((Skeleton)currInterface).DeepCopy();
                        outputSkeleton.BuildJointTable();
                        workingSkeleton = (Skeleton)outputSkeleton.DeepCopy();
                        workingSkeleton.BuildJointTable();
                        chainRangeChanged = true;
                    }
                    else
                    {
                        foreach (KeyValuePair <string, IJoint> pair in s.JointTable)
                        {
                            if (!jointChain.Exists(delegate(IJoint j) { return(j.Name == pair.Key); }))
                            {
                                outputSkeleton.JointTable[pair.Key].BaseTransform       = pair.Value.BaseTransform;
                                outputSkeleton.JointTable[pair.Key].AnimationTransform  = pair.Value.AnimationTransform;
                                workingSkeleton.JointTable[pair.Key].BaseTransform      = pair.Value.BaseTransform;
                                workingSkeleton.JointTable[pair.Key].AnimationTransform = pair.Value.AnimationTransform;
                            }
                            outputSkeleton.JointTable[pair.Key].Constraints  = pair.Value.Constraints;
                            workingSkeleton.JointTable[pair.Key].Constraints = pair.Value.Constraints;
                        }
                    }
                    workingSkeleton.CalculateCombinedTransforms();
                    recalculate = true;
                }
                else
                {
                    outputSkeleton = null;
                }
            }

            if (FVelocityInput.PinIsChanged)
            {
                double x;
                FVelocityInput.GetValue(0, out x);
                iterationsPerFrame = (int)(x * 10);
            }

            if (iterationsPerFrame > 0)
            {
                if (FTargetInput.PinIsChanged)
                {
                    targetPosW = new Vector3D();
                    FTargetInput.GetValue3D(0, out targetPosW.x, out targetPosW.y, out targetPosW.z);
                    recalculate = true;
                }

                if (FEpsilonInput.PinIsChanged)
                {
                    FEpsilonInput.GetValue(0, out epsilon);
                    recalculate = true;
                }

                if (FPoleTargetInput.PinIsChanged || FEnablePoleTargetInput.PinIsChanged)
                {
                    double x;
                    FEnablePoleTargetInput.GetValue(0, out x);
                    enablePoleTarget = x > 0.0;
                    poleTargetW      = new Vector3D();
                    FPoleTargetInput.GetValue3D(0, out poleTargetW.x, out poleTargetW.y, out poleTargetW.z);
                    recalculateOrientation = true;
                }

                if (chainRangeChanged && outputSkeleton != null)
                {
                    initRotations();
                }

                double delta = VMath.Dist(endPosW, targetPosW);
                if ((delta > epsilon || recalculate) && outputSkeleton != null && !string.IsNullOrEmpty(chainStart) && !string.IsNullOrEmpty(chainEnd))
                {
                    List <Vector2D> constraints = new List <Vector2D>();
                    for (int i = 0; i < iterationsPerFrame; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            IJoint currJoint = workingSkeleton.JointTable[chainEnd];
                            endPosW = currJoint.CombinedTransform * new Vector3D(0);
                            while (currJoint.Name != chainStart)
                            {
                                currJoint = currJoint.Parent;
                                Vector3D rotationAxis = new Vector3D(0, 0, 0);
                                rotationAxis[j] = 1;
                                double   torque = calculateTorque(currJoint, rotationAxis);
                                Vector3D rot    = rotations[currJoint.Name];
                                if ((rot[j] + torque) < currJoint.Constraints[j].x * 2 * Math.PI || (rot[j] + torque) > currJoint.Constraints[j].y * 2 * Math.PI)
                                {
                                    torque = 0;
                                }
                                Matrix4x4 newTransform = VMath.Rotate(torque * rotationAxis.x, torque * rotationAxis.y, torque * rotationAxis.z) * currJoint.AnimationTransform;
                                Vector3D  testVec      = newTransform * new Vector3D(0);
                                if (!Double.IsInfinity(testVec.x) && !Double.IsNaN(testVec.x))                         // an evil bug fix, to avoid n.def. values in animation transform matrix. the actual reason, why this would happen has not been found yet.
                                {
                                    rot[j] += torque;
                                    rotations[currJoint.Name]    = rot;
                                    currJoint.AnimationTransform = newTransform;
                                    outputSkeleton.JointTable[currJoint.Name].AnimationTransform = currJoint.AnimationTransform;
                                }
                            }
                        }
                        try
                        {
                            Matrix4x4 pre;
                            if (workingSkeleton.JointTable[chainStart].Parent != null)
                            {
                                pre = workingSkeleton.JointTable[chainStart].Parent.CombinedTransform;
                            }
                            else
                            {
                                pre = VMath.IdentityMatrix;
                            }
                            ((JointInfo)workingSkeleton.JointTable[chainStart]).CalculateCombinedTransforms(pre);
                        }
                        catch (Exception)
                        {
                            workingSkeleton.CalculateCombinedTransforms();
                        }
                    }


                    FPoseOutput.MarkPinAsChanged();
                }

                if ((recalculate || recalculateOrientation) && enablePoleTarget && outputSkeleton != null && !string.IsNullOrEmpty(chainStart) && !string.IsNullOrEmpty(chainEnd))
                {
                    endPosW = workingSkeleton.JointTable[chainEnd].CombinedTransform * new Vector3D(0);
                    Vector3D poleTargetLocal = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * poleTargetW;
                    Vector3D t = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * endPosW;                                                                                  // endpoint in local coords
                    Vector3D a = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * (workingSkeleton.JointTable[chainStart].Children[0].CombinedTransform * new Vector3D(0)); // next child in local coords
                    Vector3D x = t * ((a.x * t.x + a.y * t.y + a.z * t.z) / Math.Pow(VMath.Dist(new Vector3D(0), t), 2));
                    Vector3D y = t * ((poleTargetLocal.x * t.x + poleTargetLocal.y * t.y + poleTargetLocal.z * t.z) / Math.Pow(VMath.Dist(new Vector3D(0), t), 2));

                    Vector3D c     = poleTargetLocal - y;
                    Vector3D b     = a - x;
                    double   angle = vectorAngle(b, c);
                    Vector3D n     = new Vector3D();
                    n.x = c.y * b.z - c.z * b.y;
                    n.y = c.z * b.x - c.x * b.z;
                    n.z = c.x * b.y - c.y * b.x;
                    n   = n / VMath.Dist(new Vector3D(0), n);
                    FDebugOutput.SetValue(0, angle);
                    chainRotation = RotateAroundAxis(angle, n);

                    FPoseOutput.MarkPinAsChanged();
                }
                if (!enablePoleTarget)
                {
                    chainRotation = VMath.IdentityMatrix;
                }

                outputSkeleton.JointTable[chainStart].AnimationTransform = chainRotation * outputSkeleton.JointTable[chainStart].AnimationTransform;
            }

            FPoseOutput.SetInterface(outputSkeleton);
        }
Exemplo n.º 20
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

            string           currLine;
            string           fileContents = "";
            NumberFormatInfo nf           = new CultureInfo("en-US", false).NumberFormat;

            if (FMyStringInput.PinIsChanged)
            {
                //first set slicecounts for all outputs
                //the incoming int SpreadMax is the maximum slicecount of all input pins, which is a good default

                //read data from inputs

                FMyStringInput.GetString(0, out fileName);

                tr = new StreamReader(fileName);
                if (tr != null)
                {
                    while ((currLine = tr.ReadLine()) != null)
                    {
                        fileContents += currLine;
                    }
                }

                skinWeights             = new Dictionary <int, Dictionary <int, double> >();
                inverseBindPoseMatrices = new Dictionary <int, Matrix4x4>();

                bindShapeMatrix = this.getBindShapeMatrix(fileContents);
                this.readJoints(fileContents);

                int sliceNum = 0;
                for (int i = 0; i < maxVertexIndex + 1; i++)
                {
                    if (!skinWeights.ContainsKey(i))
                    {
                        continue;
                    }
                    IDictionaryEnumerator boneEnum = skinWeights[i].GetEnumerator();
                    while (boneEnum.MoveNext())
                    {
                        FIndicesOutput.SliceCount     = sliceNum + 1;
                        FBindIndicesOutput.SliceCount = sliceNum + 1;
                        FSkinWeightsOutput.SliceCount = sliceNum + 1;
                        FIndicesOutput.SetValue(sliceNum, i);
                        FBindIndicesOutput.SetValue(sliceNum, (int)boneEnum.Key);
                        FSkinWeightsOutput.SetValue(sliceNum, (double)boneEnum.Value);
                        sliceNum++;
                    }
                }

                FInverseBindPoseOutput.SliceCount = inverseBindPoseMatrices.Count;
                for (int i = 0; i < inverseBindPoseMatrices.Count; i++)
                {
                    FInverseBindPoseOutput.SetMatrix(i, inverseBindPoseMatrices[i]);
                }
            }


            FSkeletonOutput.SetInterface(outputSkeleton);
        }
Exemplo n.º 21
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 (FSwitch.PinIsChanged || FEvaluate)
            {
                Array.Resize(ref FHit, SpreadMax);
                FOutput.SliceCount = SpreadMax;

                string curCase;
                for (int i = 0; i < SpreadMax; i++)
                {
                    FSwitch.GetString(i, out curCase);

                    int def = -1;
                    int hit = -1;
                    for (int s = 0; s < FCaseArr.Length; s++)
                    {
                        if (curCase == FCaseArr[s])
                        {
                            hit = s;
                        }
                        if (FCaseArr[s] == "default")
                        {
                            def = s;
                        }
                    }

                    if (hit < 0)
                    {
                        hit = def;
                    }
                    if (hit >= 0 && hit != FHit[i])
                    {
                        FHit[i]   = hit;
                        FEvaluate = true;
                    }
                }
            }

            if (!FEvaluate)
            {
                foreach (int id in FHit)
                {
                    if (FPinArr[id].PinIsChanged)
                    {
                        FEvaluate = true;
                        break;
                    }
                }
            }

            if (FEvaluate)
            {
                unsafe
                {
                    double *outVals;
                    FOutput.GetValuePointer(out outVals);
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        double *inVals;
                        int     inCount;
                        FPinArr[FHit[i]].GetValuePointer(out inCount, out inVals);

                        outVals[i] = inVals[i % inCount];
                    }
                }
                FEvaluate = false;
            }
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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)
            {
                jointNames = new List <string>();
                string jointName;
                for (int i = 0; i < FJointNameInput.SliceCount; i++)
                {
                    FJointNameInput.GetString(i, out jointName);
                    jointNames.Add(jointName);
                }
                recalculate = true;
            }

            if (FSkeletonInput.PinIsChanged || recalculate)
            {
                if (FSkeletonInput.IsConnected)
                {
                    object currInterface;
                    FSkeletonInput.GetUpstreamInterface(out currInterface);
                    s = (Skeleton)currInterface;
                    if (inputSkeleton == null || !s.Uid.Equals(inputSkeleton.Uid))
                    {
                        inputSkeleton = (Skeleton)s.DeepCopy();
                    }
                    else
                    {
                        foreach (KeyValuePair <string, IJoint> pair in s.JointTable)
                        {
                            if (!jointNames.Exists(delegate(string name) { return(name == pair.Key); }))
                            {
                                inputSkeleton.JointTable[pair.Key].BaseTransform      = pair.Value.BaseTransform;
                                inputSkeleton.JointTable[pair.Key].AnimationTransform = pair.Value.AnimationTransform;
                            }
                            inputSkeleton.JointTable[pair.Key].Constraints = pair.Value.Constraints;
                        }
                    }
                }
                else
                {
                    inputSkeleton = null;
                }
            }

            if (FSkeletonInput.PinIsChanged || FAnimationTransformInput.PinIsChanged || FBaseTransformInput.PinIsChanged || FParentNameInput.PinIsChanged || FConstraintsInput.PinIsChanged || recalculate)
            {
                if (inputSkeleton != null)
                {
                    IJoint currJoint;
                    for (int i = 0; i < jointNames.Count; i++)
                    {
                        currJoint = inputSkeleton.JointTable[jointNames[i]];
                        Matrix4x4 currAnimationT;
                        Matrix4x4 currBaseT;
                        string    currParentName;
                        if (currJoint != null)
                        {
                            if (FAnimationTransformInput.IsConnected)
                            {
                                FAnimationTransformInput.GetMatrix(i, out currAnimationT);
                                currJoint.AnimationTransform = currAnimationT;
                            }
                            else
                            {
                                currJoint.AnimationTransform = s.JointTable[currJoint.Name].AnimationTransform;
                            }

                            if (FBaseTransformInput.IsConnected)
                            {
                                FBaseTransformInput.GetMatrix(i, out currBaseT);
                                currJoint.BaseTransform = currBaseT;
                            }
                            else
                            {
                                currJoint.BaseTransform = s.JointTable[currJoint.Name].BaseTransform;
                            }

                            /*if (FRotationInput.IsConnected)
                             * {
                             *      currRotation = new Vector3D(0);
                             *      FRotationInput.GetValue3D(i, out currRotation.x, out currRotation.y, out currRotation.z);
                             *      //currJoint.Rotation = currRotation;
                             *
                             * }
                             */

                            /*if (FConstraintsInput.IsConnected)
                             * {
                             *      currConstraints = new List<Vector2D>();
                             *      Vector2D currConstraint;
                             *      for (int j=0; j<3; j++)
                             *      {
                             *              currConstraint = new Vector2D(0);
                             *              FConstraintsInput.GetValue2D(i*3, out currConstraint.x, out currConstraint.y);
                             *              currConstraints.Add(currConstraint);
                             *      }
                             *      currJoint.Constraints = currConstraints;
                             * }
                             */

                            FParentNameInput.GetString(i, out currParentName);
                            if (currParentName != null && (FParentNameInput.SliceCount > 1 || !string.IsNullOrEmpty(currParentName)))
                            {
                                IJoint parent = inputSkeleton.JointTable[currParentName];
                                if (parent != null)
                                {
                                    currJoint.Parent = parent;
                                }
                            }
                        }
                    }
                }

                FSkeletonOutput.MarkPinAsChanged();
            }

            FSkeletonOutput.SetInterface(inputSkeleton);
        }
Exemplo n.º 24
0
        /// <summary>
        /// The Mainloop
        /// </summary>
        public void Evaluate(int SpreadMax)
        {
            try
            {
                FDataOut.SliceCount      = SpreadMax;
                FOnDataOut.SliceCount    = SpreadMax;
                FConnectedOut.SliceCount = SpreadMax;

                for (int i = 0; i < _AvailablePorts.Length; i++)
                {
                    FPortsOut.SetValue(i, Convert.ToDouble(_AvailablePorts[i].Substring(3)));
                }



                string currentSliceData;
                double currentSliceDoSend;
                double currentSliceEnabled;
                double currentSliceKeepLastData;
                double currentSlicePortNumber;
                double currentSliceBaudrate;
                string currentSliceParity;
                string currentSliceDatabits = "";
                string currentSliceStopbits;
                string currentSliceHandShake;
                double currentReadBufferSize;



                //loop for all slices
                for (int i = 0; i < SpreadMax; i++)
                {
                    FDoSendIn.GetValue(i, out currentSliceDoSend);
                    FEnableIn.GetValue(i, out currentSliceEnabled);
                    FKeepLastDataIn.GetValue(i, out currentSliceKeepLastData);
                    FPortNumberIn.GetValue(i, out currentSlicePortNumber);
                    FBaudrateIn.GetValue(i, out currentSliceBaudrate);
                    FParityIn.GetString(i, out currentSliceParity);
                    FDatabitsIn.GetString(i, out currentSliceDatabits);
                    FStopbitsIn.GetString(i, out currentSliceStopbits);
                    FHandShakeIn.GetString(i, out currentSliceHandShake);
                    FReadBufferIn.GetValue(i, out currentReadBufferSize);

                    Port tPort;

                    if (Convert.ToBoolean(currentSliceEnabled))
                    {
                        tPort = this.GetPort((int)currentSlicePortNumber);

                        if (tPort == null)
                        {
                            if ((new List <string>(SerialPort.GetPortNames())).Contains(String.Format("COM{0}", currentSlicePortNumber)))
                            {
                                tPort = new Port((int)currentSlicePortNumber, (int)currentSliceBaudrate,
                                                 currentSliceParity, Convert.ToInt32(currentSliceDatabits.Replace("Bits", "")), currentSliceStopbits.Replace("Bits", ""), (int)currentReadBufferSize);

                                _Ports.Add(tPort);

                                currentReadBufferSize = (double)tPort.BufferSize;
                                FReadBufferOut.SetValue(i, currentReadBufferSize);
                            }
                        }
                        else
                        {
                            //read data from inputs
                            FDataIn.GetString(i, out currentSliceData);
                            FOnDataOut.SetValue(i, Convert.ToDouble(tPort.OnData));
                            FConnectedOut.SetValue(i, Convert.ToDouble(tPort.Connected));

                            // write data to comport
                            if (currentSliceDoSend == 1.0 && !String.IsNullOrEmpty(currentSliceData))
                            {
                                tPort.Write(currentSliceData);
                            }

                            //read data from comport
                            if (tPort.OnData)
                            {
                                FDataOut.SetString(i, tPort.Read());
                            }
                            else
                            {
                                if (Convert.ToBoolean(currentSliceKeepLastData))
                                {
                                    FDataOut.SetString(i, tPort.Data);
                                }
                                else
                                {
                                    FDataOut.SetString(i, "");
                                }
                            }


                            if (FBaudrateIn.PinIsChanged)
                            {
                                tPort.Baudrate = (int)currentSliceBaudrate;
                            }

                            if (FParityIn.PinIsChanged)
                            {
                                tPort.Parity = currentSliceParity;
                            }

                            if (FDatabitsIn.PinIsChanged)
                            {
                                tPort.DataBits = Convert.ToInt32(currentSliceDatabits);
                            }

                            if (FStopbitsIn.PinIsChanged)
                            {
                                tPort.StopBits = currentSliceStopbits;
                            }

                            if (FHandShakeIn.PinIsChanged)
                            {
                                tPort.HandShake = currentSliceHandShake;
                            }
                            if (FReadBufferIn.PinIsChanged)
                            {
                                tPort.Dispose();
                                _Ports.Remove(tPort);
                            }
                        }
                    }
                    else
                    {
                        tPort = this.GetPort((int)currentSlicePortNumber);

                        if (tPort != null)
                        {
                            tPort.Dispose();
                            _Ports.Remove(tPort);
                        }

                        FOnDataOut.SetValue(i, Convert.ToDouble(0));
                        FConnectedOut.SetValue(i, Convert.ToDouble(0));
                        FDataOut.SetString(i, "");
                    }
                }
            }
            catch (Exception ex)
            {
                FHost.Log(TLogType.Error, ex.Message);
            }
        }
Exemplo n.º 25
0
        private void Enable()
        {
            FPinConfigExtension.GetOrd(0, out FExtension);

            double enabled;

            FPinInputEnable.GetValue(0, out enabled);

            String id;

            FPinInputID.GetString(0, out id);

            if (enabled == 1d)
            {
                try
                {
                    // if connected, disconnect first);
                    if (FWorking && FWiimoteID != id)
                    {
                        FRemote.WiimoteChanged          -= OnInvalidatePlugin;
                        FRemote.WiimoteExtensionChanged -= OnChangeReportType;
                        FRemote.Disconnect();
                    }

                    WiimoteCollection wc = new WiimoteCollection();
                    wc.FindAllWiimotes();

                    FPinOutputAvailable.SliceCount = wc.Count;
                    for (int i = 0; i < wc.Count; i++)
                    {
                        FPinOutputAvailable.SetString(i, wc[(int)i].HIDDevicePath);
                    }

                    if (id == "-1" || id == "null")
                    {
                        id = "";                                                 // to keep compatibility with the older nodes.
                    }
                    try {
                        FRemote = null;
                        if (id == "")
                        {
                            FRemote = wc[(int)0];
                        }
                        else
                        {
                            for (int i = 0; i < wc.Count; i++)
                            {
                                if (wc[(int)i].HIDDevicePath == id)
                                {
                                    FRemote = wc[(int)i];
                                }
                            }
                        }
                        if (FRemote == null)
                        {
                            FWorking = false;
                            throw new Exception("No Wiimote with that ID detected. ");
                        }
                    }
                    catch (Exception e) {
                        FWorking = false;
                        throw new Exception("No Wiimote with that ID detected. " + e.ToString());
                    }

                    if (FRemote.WiimoteState.Extension == true)
                    {
                        FRemote.SetReportType(InputReport.IRExtensionAccel, true);
                    }
                    else
                    {
                        FRemote.SetReportType(InputReport.IRAccel, true);
                    }
                    FRemote.Connect();

                    FRemote.SetLEDs(false, false, false, true);                     // light number vvvvour
                    FRemote.WiimoteChanged          += OnInvalidatePlugin;
                    FRemote.WiimoteExtensionChanged += OnChangeReportType;
                    FWorking = true;
                    FMessage = "OK";


                    if (FUseMotionPlus)
                    {
//						FRemote.InitializeMotionPlus();
                    }
                    FRemote.GetStatus();
                }
                catch (WiimoteNotFoundException ex)
                {
                    FMessage = "Wiimote not found error";
                    FWorking = false;
                }
                catch (WiimoteException ex)
                {
                    FMessage = "Wiimote error";
                    FWorking = false;
                }
                catch (Exception ex)
                {
                    FMessage = ex.Message;
                    FWorking = false;
                }
            }
            else
            {
                FWorking = false;
                FMessage = "Disabled";

                try
                {
                    FRemote.SetRumble(false);
                    FRemote.Disconnect();
                }
                catch (Exception x)
                {
                    FMessage = x.Message;
                    FWorking = false;
                }
            }
            FInvalidate = true;
        }