Beispiel #1
0
        protected override void OnDynamicDraw(GetPointDrawEventArgs e)
        {
            base.OnDynamicDraw(e);

            Point3d  Origin       = new_brep.UserDictionary.GetPoint3d("CurrentPosition");
            Vector3d OriginVector = new_brep.UserDictionary.GetVector3d("CurrentDirection");

            Point3d currentpoint = e.CurrentPoint;

            Vector3d normal_on_mesh = base_mesh.NormalAt(base_mesh.ClosestMeshPoint(currentpoint, 0));

            Brep moved_brep = new_brep.DuplicateBrep();

            if (OriginVector.IsParallelTo(normal_on_mesh) == 0)
            {
                double   RotationAngle = Vector3d.VectorAngle(OriginVector, normal_on_mesh);
                Vector3d RoationAxis   = Vector3d.CrossProduct(OriginVector, normal_on_mesh);
                moved_brep.Rotate(RotationAngle, RoationAxis, Origin);
            }

            moved_brep.Translate(currentpoint - Origin);
            e.Display.DrawBrepWires(moved_brep, System.Drawing.Color.Red);
            Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(System.Drawing.Color.Red);
            e.Display.DrawBrepShaded(moved_brep, material);
            moved_brep.Dispose();
        }
Beispiel #2
0
        //Methods
        private void GeomSurfGenerator(Autodesk.AutoCAD.DatabaseServices.Surface Surf)
        {
            Brep Br = new Brep(Surf);

            foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc in Br.Faces)
            {
                ExternalBoundedSurface[] ebSurfs = fc.GetSurfaceAsTrimmedNurbs();
                m_geomSurf = ebSurfs[0];
            }
            Br.Dispose();
        }
Beispiel #3
0
 public void Dispose()
 {
     environment.Dispose();
 }
Beispiel #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            Stopwatch watch = new Stopwatch();

            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gbrep.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);

            GetObjectPosition gp = new GetObjectPosition(brep, my_mesh);

            gp.SetCommandPrompt("Get the object position on mesh: ");
            gp.Constrain(my_mesh, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Brep     moved_brep     = brep.DuplicateBrep();
            Point3d  Origin         = brep.UserDictionary.GetPoint3d("CurrentPosition");
            Vector3d OriginVector   = brep.UserDictionary.GetVector3d("CurrentDirection");
            Point3d  new_position   = gp.Point();
            Vector3d normal_on_mesh = my_mesh.NormalAt(my_mesh.ClosestMeshPoint(new_position, 0));

            if (OriginVector.IsParallelTo(normal_on_mesh) == 0)
            {
                double   RotationAngle = Vector3d.VectorAngle(OriginVector, normal_on_mesh);
                Vector3d RoationAxis   = Vector3d.CrossProduct(OriginVector, normal_on_mesh);
                moved_brep.Rotate(RotationAngle, RoationAxis, Origin);
            }

            moved_brep.Translate(new_position - Origin);
            moved_brep.UserDictionary.Set("CurrentPosition", new_position);
            moved_brep.UserDictionary.Set("CurrentDirection", normal_on_mesh);

            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor = Color.FromName(moved_brep.UserDictionary.GetString("Color"));
            my_attributes.ColorSource = ObjectColorSource.ColorFromObject;

            watch.Start();
            //delete all old paths
            IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve);

            foreach (RhinoObject path in path_objref)
            {
                doc.Objects.Delete(path, true);
            }
            watch.Stop();
            RhinoApp.WriteLine("time 1: {0}", watch.Elapsed);

            ObjectAttributes path_attributes = new ObjectAttributes();

            path_attributes.ObjectColor      = Color.Yellow;
            path_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            path_attributes.PlotWeight       = 2.0;


            Guid      pin_1_id          = moved_brep.UserDictionary.GetGuid("PinID");
            MeshPoint current_meshpoint = my_mesh.ClosestMeshPoint(new_position, 0.0);

            watch.Restart();
            List <NurbsCurve> new_path_list = p.graph.DijkstraPath_Change(pin_1_id, current_meshpoint);

            watch.Stop();
            RhinoApp.WriteLine("time 2: {0}", watch.Elapsed);
            watch.Restart();
            for (int i = 0; i < new_path_list.Count; i++)
            {
                doc.Objects.Add(new_path_list[i], path_attributes);
            }

            doc.Objects.Delete(my_objref, true);
            brep.Dispose();
            doc.Objects.AddBrep(moved_brep, my_attributes);
            doc.Views.Redraw();
            watch.Stop();
            RhinoApp.WriteLine("time 3: {0}", watch.Elapsed);

            return(Result.Success);
        }
Beispiel #5
0
        /// <summary>
        /// Scan the solid from bottom, identify points and create
        /// a surface
        /// </summary>
        /// <param name="solidId">Solid to scan</param>
        /// <param name="tinSurfaceToCutId">Referecen surface</param>
        /// <param name="solidSurfaceName">Name of the new
        /// surface that will be created</param>
        /// <param name="densityOfPoints">Number of points per
        /// AutoCAD unit used on scan</param>
        /// <param name="simplifySurface">Whether o not simplify
        /// the surface at the end (using Civil 3D
        /// built-in operation)</param>
        private static void GenerateSurfaceByScan(
            ObjectId solidId,
            ObjectId tinSurfaceToCutId,
            string solidSurfaceName,
            int densityOfPoints,
            bool simplifySurface)
        {
            _db = Application.DocumentManager.MdiActiveDocument.Database;
            using (_trans = _db.TransactionManager.StartTransaction())
            {
                try
                {
                    // open entities
                    _solid = _trans.GetObject(solidId, OpenMode.ForRead)
                             as Solid3d;
                    if (!tinSurfaceToCutId.IsNull)
                    {
                        _surface =
                            _trans.GetObject(tinSurfaceToCutId, OpenMode.ForRead)
                            as TinSurface;
                    }

                    // extract the Brep of the solid
                    _brepSolid = new Brep(_solid);
                    _newPoints = new Point3dCollection();

                    // get the extend of the solid
                    Extents3d extends = _solid.GeometricExtents;
                    // and expand by 20% to increase accuracy
                    // on the solid edges/borders
                    extends.TransformBy(Matrix3d.Scaling(1.2,
                                                         _solid.MassProperties.Centroid));

                    // geometric line at the bottom (virtual datum)
                    // this line is the scan line
                    //
                    //  x--------------------------x
                    //  |  pt2        ^            pt3
                    //  |             direction
                    //  |             of scan progress
                    //  |
                    //  | <-scan line
                    //  |
                    //  x  pt1
                    //
                    Point3d scanLinePt1 = extends.MinPoint;
                    Point3d scanLinePt2 = new Point3d(
                        scanLinePt1.X, extends.MaxPoint.Y, scanLinePt1.Z);
                    LineSegment3d scanLine = new LineSegment3d(
                        scanLinePt1, scanLinePt2);
                    Point3d scanLinePt3 = new Point3d(
                        extends.MaxPoint.X, extends.MaxPoint.Y, scanLinePt1.Z);
                    _upperLimit = extends.MaxPoint.Z; // scan upper limit

                    int numberOfScanLines = ((int)
                                             Math.Round(scanLinePt2.DistanceTo(scanLinePt3),
                                                        MidpointRounding.ToEven)) * densityOfPoints;

                    ProgressMeter progressBar = new ProgressMeter();
                    progressBar.SetLimit(numberOfScanLines);
                    progressBar.Start("Scanning solid...");

                    for (int i = 0; i < numberOfScanLines; i++)
                    {
                        ProcessScanLine(scanLine, densityOfPoints, true);

                        // move the scan line over the scane direction
                        // get direction vector
                        Vector3d scanLineDisplacementDirection =
                            scanLinePt2.GetVectorTo(scanLinePt3);
                        // make unit vector
                        scanLineDisplacementDirection /=
                            scanLineDisplacementDirection.Length;
                        // adjust size
                        scanLineDisplacementDirection *=
                            (1.0 / densityOfPoints);
                        scanLine.TransformBy(Matrix3d.Displacement(
                                                 scanLineDisplacementDirection));

                        progressBar.MeterProgress();
                        Util.AvoidNotResponding();
                    }
                    progressBar.Stop();
                    scanLine.Dispose();

                    #region For testing only
#if DEBUG
                    BlockTableRecord mSpace = _trans.GetObject(_db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                    foreach (Point3d pt in _newPoints)
                    {
                        DBPoint p = new DBPoint(pt);
                        mSpace.AppendEntity(p);
                        _trans.AddNewlyCreatedDBObject(p, true);
                    }
#endif
                    #endregion

                    CreateSolidSurface(solidSurfaceName, simplifySurface);

                    _trans.Commit();
                }
                catch (System.Exception ex)
                {
                    Application.DocumentManager.MdiActiveDocument.
                    Editor.WriteMessage("Error: Operation aborted ({0})",
                                        ex.Message);
                    _trans.Abort();
                }
                finally
                {
                    // final cleanup
                    if (!_brepSolid.IsDisposed)
                    {
                        _brepSolid.Dispose();
                    }
                    if (!_newPoints.IsDisposed)
                    {
                        _newPoints.Dispose();
                    }
                    _solid     = null;
                    _surface   = null;
                    _brepSolid = null;
                    _newPoints = null;
                }
            }
        }