Example #1
0
 //Deprecated in favor of ray
 //public static Curve curve;
 public tLine(double X1, double Y1, double Z1, double X2, double Y2, double Z2)
 {
     // Find the static fixed positions
     startPoint = new tPoint(X1,Y1,Z1);
     endPoint = new tPoint(X2,Y2,Z2);
     lineFormed = false;
     rayFormed = false;
     vectorFormed = false;
 }
Example #2
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            pluginObj = ((nishanchiPlugin)this.PlugIn);
            RhinoView viewObj = doc.Views.ActiveView;
            RhinoViewport viewPortObj = viewObj.ActiveViewport;
            Vector3d originalCameraVector = viewPortObj.CameraDirection;
            Point3d originalCameraLocation = viewPortObj.CameraLocation;
            Mesh meshObj;

            Boolean logging = false;
            StreamWriter logWriter = null;

            String reportString;
            String logString;
            String printCommandStr;

            if (((nishanchiPlugin)this.PlugIn).logEnabled())
            {
                logWriter = new StreamWriter(((nishanchiPlugin)this.PlugIn).getNewLogFile());
                logWriter.WriteLine("Printing...");
                logging = true;
            }

            if (!pluginObj.trackerConnected)
            {
                RhinoApp.WriteLine("Tracker disconnected");
                return Rhino.Commands.Result.Failure;
            }

            connectKbEvt();

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select the mesh to print");
            go.Get();
            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                disconnectKbEvt();
                return rc;
            }

            meshObj = new Mesh();
            if (go.ObjectCount == 1){
                ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId);
                meshObj = tmpRef.Mesh();
                if (meshObj == null){
                    disconnectKbEvt();
                    return rc;
                }
            }

            createNozzles(doc);
            cameraPoint = new tPoint(Nozzle.XOffset + 100.0, Nozzle.YOffset, Nozzle.ZOffset + (Nozzle.ZMultiplier * ((numNozzles-1)/2)));

            fastrak trackerObj = pluginObj.trackerObj;
            int numPoints = 0;

            Boolean retval;

            RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker."));
            pluginObj.trackerObj.setContinuous();
            RhinoApp.WriteLine(string.Format("Printing mode enabled now."));

            running = true;
            while (running)
            {
                retval = trackerObj.readFrame();
                if (retval)
                {
                    //q0,q1,q2,q3 Quaternion begin
                    //Compute the rotation matrix
                    reportString = String.Format("{0},{1},{2}", trackerObj.x, trackerObj.y, trackerObj.z);
                    logString = String.Format("p,{0},{1},{2},{3},{4},{5},{6},{7}", numPoints, trackerObj.x, trackerObj.y, trackerObj.z, trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);

                    RhinoApp.WriteLine(reportString);
                    if (logging)
                    {
                        logWriter.WriteLine(logString);
                    }

                    rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z);
                    orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);
                    orientationQuat.GetRotation(out angle, out axis);
                    rotMat = Transform.Rotation(angle, axis, origin);

                    // Compute the new positions for the nozzlePoints and also compute the new lines
                    for (int i = 0; i < numNozzles; i++)
                    {
                        nozzles[i].computeTxTx(rotMat, rxTxTx);
                    }

                    //And, I move the view around
                    if ((numPoints % 100) == 0)
                    {
                        cameraPoint.computeTxTx(rotMat, rxTxTx);
                        viewPortObj.SetCameraLocation(cameraPoint.txTx(), true);
                        viewPortObj.SetCameraDirection(nozzles[4].vector(), true);
                        viewPortObj.Rotate(Math.PI / 2, nozzles[4].vector(), cameraPoint.txTx());
                        cameraUpTx = rotMat * cameraUpRx;
                        viewPortObj.CameraUp = cameraUpTx;

                        removeNozzleLinesFromDocument(doc);
                        addNozzleLinesToDocument(doc);
                        doc.Views.ActiveView.Redraw();
                        RhinoApp.Wait();
                    }

                    //Compute ray intersections
                    if ((numPoints % 4) == 0)
                    {
                        //RhinoApp.WriteLine("Calculating intersections..");
                        for (int i = 0; i < numNozzles; i++)
                        {
                            nozzles[i].rayIntersectionDistance = Intersection.MeshRay(meshObj,nozzles[i].ray());
                        }

                        printCommandStr = printCommand();
                        //RhinoApp.WriteLine(printCommandStr);

                        if (logging)
                        {
                            logString = String.Format("c,{0},{1}", numPoints, printCommandStr);
                            logWriter.WriteLine(logString);
                        }
                    }
                    numPoints++;
                }
            }

            running = false;

            //clean up
            removeNozzleLinesFromDocument(doc);
            doc.Views.ActiveView.Redraw();
            RhinoApp.WriteLine("Removing printHead objects!!");

            if (logging)
            {
                logWriter.Close();
                ((nishanchiPlugin)this.PlugIn).closeLogFile();
            }

            //stop the tracker
            RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker."));
            pluginObj.trackerObj.stopContinuous();
            disconnectKbEvt();
            RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!"));

            //setup the viewport as it was
            viewPortObj.SetCameraLocation(originalCameraLocation, true);
            viewPortObj.SetCameraDirection(originalCameraVector, true);

            return Rhino.Commands.Result.Success;
        }