Ejemplo n.º 1
0
        void processSignal(string str)
        {
            char[] delimiters = { ' ', ',' };
            if (str == "")
            {
                return;
            }
            string[] substrings = str.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
            if (substrings.Length == 0)
            {
                return;
            }

            SparrowHawkSignal s = new SparrowHawkSignal(SparrowHawkSignal.ESparrowHawkSigalType.InitType, new float[substrings.Length - 1]);

            for (int i = 1; i < substrings.Length; i++)
            {
                if (substrings[0] != "del:")
                {
                    if (!float.TryParse(substrings[i], out s.data[i - 1]))
                    {
                        return;
                    }
                }
                else
                {
                    s.strData = substrings[1];
                }
            }
            switch (substrings[0])
            {
            case "init:":
                RhinoApp.WriteLine("Calibration point recieved");
                s.type = SparrowHawkSignal.ESparrowHawkSigalType.InitType;
                mSignalQueue.Enqueue(s);
                break;

            case "angle:":
                s.type = SparrowHawkSignal.ESparrowHawkSigalType.EncoderType;
                mSignalQueue.Enqueue(s);
                break;

            case "stroke:":
                s.type = SparrowHawkSignal.ESparrowHawkSigalType.LineType;
                mSignalQueue.Enqueue(s);
                break;

            case "del:":
                s.type = SparrowHawkSignal.ESparrowHawkSigalType.CutType;
                mSignalQueue.Enqueue(s);
                break;
            }
            //mSignalQueue.Enqueue(s);
        }
Ejemplo n.º 2
0
        protected void handleSignals()
        {
            SparrowHawkSignal s = SparrowHawkEventListeners.Instance.getOneSignal();

            if (s == null)
            {
                return;
            }
            switch (s.type)
            {
            case SparrowHawkSignal.ESparrowHawkSigalType.InitType:
                if (s.data.Length >= 3)
                {
                    //To compute VRtoRobot matrix, press V key 8 times.
                    //robotPoint is in mm unit so the calibration result already deal with scale issue
                    Vector3 robotPoint = new Vector3(s.data[0], s.data[1], s.data[2]);
                    robotCallibrationPoints.Add(robotPoint);
                    Rhino.RhinoApp.WriteLine("add robotPoint: " + robotPoint.ToString());
                    if (mIsLefty && mScene.leftControllerIdx < 0 || !mIsLefty && mScene.leftControllerIdx < 0)
                    {
                        break;
                    }
                }
                break;

            case SparrowHawkSignal.ESparrowHawkSigalType.LineType:
                if (s.data.Length >= 4)
                {
                    if (s.data[0] == 0)
                    {
                        OpenTK.Vector3 p1 = new Vector3(s.data[1], s.data[2], s.data[3]);
                        p1 = UtilOld.platformToVRPoint(ref mScene, p1);
                        OpenTK.Vector3 p2 = new Vector3(s.data[4], s.data[5], s.data[6]);
                        p2 = UtilOld.platformToVRPoint(ref mScene, p2);

                        if (((Geometry.RobotPrintStroke)printStroke).mPoints.Count == 0)
                        {
                            printStroke = new Geometry.RobotPrintStroke(ref mScene);
                            ((Geometry.RobotPrintStroke)printStroke).addEdge(p1, p2);
                            printStrokeSN = new SceneNode("PrintStroke", ref printStroke, ref printStroke_m);
                            mScene.tableGeometry.add(ref printStrokeSN);
                        }
                        else
                        {
                            ((Geometry.RobotPrintStroke)printStroke).addEdge(p1, p2);
                            printStrokeSN.geometry = printStroke;
                        }
                    }
                    else
                    {
                        OpenTK.Vector3 p1 = new Vector3(s.data[1], s.data[2], s.data[3]);
                        p1 = UtilOld.platformToVRPoint(ref mScene, p1);
                        //((Geometry.GeometryStroke2)printStroke).addPoint(p1);
                        ((Geometry.RobotPrintStroke)printStroke).addEdge(((Geometry.RobotPrintStroke)printStroke).mPoints[((Geometry.RobotPrintStroke)printStroke).mPoints.Count - 1], p1);
                        printStrokeSN.geometry = printStroke;
                    }
                }
                break;

            case SparrowHawkSignal.ESparrowHawkSigalType.CutType:
                string guidStr = s.strData;
                Guid   delId   = new Guid(guidStr);
                UtilOld.removeRhinoObjectSceneNode(ref mScene, delId);
                //removePrintStroke and show the model again
                ((Geometry.RobotPrintStroke)printStroke).removePoint();
                //mScene.tableGeometry.remove(ref printStrokeSN); //already remove
                Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
                settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep;
                foreach (Rhino.DocObjects.RhinoObject rhObj in mScene.rhinoDoc.Objects.GetObjectList(settings))
                {
                    if (rhObj.Attributes.Name.Contains("aprint"))
                    {
                        SceneNode sn = mScene.BiDictionaryRhinoVR.GetByFirst(rhObj.Id);
                        Material.LambertianMaterial show_m = new Material.LambertianMaterial(((Material.LambertianMaterial)sn.material).mColor.R, ((Material.LambertianMaterial)sn.material).mColor.G, ((Material.LambertianMaterial)sn.material).mColor.B, .3f);
                        sn.material = show_m;
                    }
                }

                mScene.rhinoDoc.Views.Redraw();
                break;

            case SparrowHawkSignal.ESparrowHawkSigalType.EncoderType:

                //for rhino object
                OpenTK.Matrix4 currentRotation = mScene.platformRotation;
                float          theta           = (float)(s.data[0] / 360f * 2 * Math.PI);
                mScene.rhinoTheta = theta;
                Rhino.RhinoApp.WriteLine("Theta = " + theta);
                Matrix4.CreateRotationZ(-theta, out mScene.platformRotation);
                mScene.platformRotation.Transpose();

                //rotate Rhino objects
                OpenTK.Matrix4 rotMRhino = mScene.platformRotation * currentRotation.Inverted();
                mScene.transM = new Transform();
                for (int row = 0; row < 4; row++)
                {
                    for (int col = 0; col < 4; col++)
                    {
                        mScene.transM[row, col] = rotMRhino[row, col];
                    }
                }

                /*
                 * Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
                 * settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep;
                 * foreach (Rhino.DocObjects.RhinoObject rhObj in mScene.rhinoDoc.Objects.GetObjectList(settings))
                 * {
                 *  if (mScene.brepToSceneNodeDic.ContainsKey(rhObj.Id) && !rhObj.Attributes.Name.Contains("planeXY") && !rhObj.Attributes.Name.Contains("planeXZ")
                 *                                                          && !rhObj.Attributes.Name.Contains("planeYZ"))
                 *  {
                 *      //SceneNode sn = mScene.brepToSceneNodeDic[rhObj.Id];
                 *      //mScene.brepToSceneNodeDic.Remove(rhObj.Id);
                 *
                 *      Guid newGuid = mScene.rhinoDoc.Objects.Transform(rhObj.Id, mScene.transM, true);
                 *      Rhino.RhinoApp.WriteLine("transM " + mScene.transM.ToString());
                 *      mScene.rhinoDoc.Views.Redraw();
                 *
                 *      //mScene.brepToSceneNodeDic.Add(newGuid, sn);
                 *      //mScene.SceneNodeToBrepDic[sn.guid] = mScene.rhinoDoc.Objects.Find(newGuid);
                 *  }
                 *
                 * }*/

                //rotate the current interaction curve as well

                /*
                 * foreach(Curve iCurve in mScene.iCurveList)
                 * {
                 *  iCurve.Transform(transM);
                 *
                 * }
                 * if (mScene.peekInteraction().GetType() == typeof(Interaction.EditPoint2))
                 * {
                 *  mScene.peekInteraction().init();
                 * }*/

                break;
            }
        }