コード例 #1
0
        /// <summary>
        /// Calculates the area of an object
        /// </summary>
        public static double GetArea(IRhinoObject obj, double tol)
        {
            if (null != obj)
            {
                IOnCurve crv = OnCurve.ConstCast(obj.Geometry());
                if (null != crv)
                {
                    return(GetCurveArea(crv, tol));
                }

                IOnSurface srf = OnSurface.ConstCast(obj.Geometry());
                if (null != srf)
                {
                    return(GetSurfaceArea(srf));
                }

                IOnBrep brep = OnBrep.ConstCast(obj.Geometry());
                if (null != brep)
                {
                    return(GetBrepArea(brep));
                }

                IOnMesh mesh = OnMesh.ConstCast(obj.Geometry());
                if (null != mesh)
                {
                    return(GetMeshArea(mesh));
                }
            }
            return(0.0);
        }
コード例 #2
0
        /// <summary>
        /// Calculates the length of an object
        /// </summary>
        public static double GetLength(IRhinoObject obj)
        {
            double length = 0.0;

            if (null != obj)
            {
                IOnCurve crv = OnCurve.ConstCast(obj.Geometry());
                if (null != crv)
                {
                    crv.GetLength(ref length);
                }
            }
            return(length);
        }
コード例 #3
0
        public override bool CustomGeometryFilter(IRhinoObject obj, IOnGeometry geo, OnCOMPONENT_INDEX ci)
        {
            if (geo != null)
            {
                IOnCurve crv = OnCurve.ConstCast(geo);
                if (crv != null)
                {
                    if (crv.IsClosed() && crv.IsPlanar())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                IOnBrep brep = OnBrep.ConstCast(geo);
                if (brep != null)
                {
                    if (brep.m_F.Count() == 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                IOnSurface srf = OnSurface.ConstCast(geo);
                if (srf != null)
                {
                    return(true);
                }

                IOnMesh mesh = OnMesh.ConstCast(geo);
                if (mesh != null)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
        private static double GetCurveArea(IOnCurve crv, double tol)
        {
            double area = 0.0;

            if (null != crv && crv.IsClosed())
            {
                OnPlane plane = new OnPlane();
                if (crv.IsPlanar(plane, tol))
                {
                    OnBoundingBox    bbox  = crv.BoundingBox();
                    On3dPoint        point = plane.ClosestPointTo(bbox.Center());
                    OnMassProperties mp    = new OnMassProperties();
                    if (crv.AreaMassProperties(point, plane.Normal(), ref mp))
                    {
                        area = Math.Abs(mp.Area());
                    }
                }
            }
            return(area);
        }
コード例 #5
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select curve");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnCurve curve = go.Object(0).Curve();

            if (null == curve)
            {
                return(IRhinoCommand.result.failure);
            }

            // Several types of OnCurve objects can have the form of a polyline,
            // including OnLineCurve, a degree 1 OnNurbsCurve, ON_PolylineCurve,
            // and ON_PolyCurve (whose segments form a polyline). OnCurve.IsPolyline
            // tests a curve to see if it can be represented as a polyline.
            ArrayOn3dPoint points      = new ArrayOn3dPoint(64);
            int            point_count = curve.IsPolyline(points);

            if (point_count > 0)
            {
                string point_str = string.Empty;
                for (int i = 0; i < point_count; i++)
                {
                    point_str = string.Empty;
                    RhUtil.RhinoFormatPoint(points[i], ref point_str);
                    RhUtil.RhinoApp().Print(string.Format("Point {0} = {1}\n", i, point_str));
                }
            }

            return(IRhinoCommand.result.success);
        }
コード例 #6
0
        /// <summary>
        /// This gets called when when the user runs this command.
        /// </summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select objects to animate
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to animate");
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Select path curve
            MRhinoGetObject gc = new MRhinoGetObject();

            gc.SetCommandPrompt("Select path curve");
            gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve);
            gc.EnableDeselectAllBeforePostSelect(false);
            gc.GetObjects(1, 1);
            if (gc.CommandResult() != IRhinoCommand.result.success)
            {
                return(gc.CommandResult());
            }

            // Get the curve
            IOnCurve crv = gc.Object(0).Curve();

            if (null == crv)
            {
                return(IRhinoCommand.result.failure);
            }

            // Create an array of normalized curve parameters
            List <double> slist = new List <double>(m_max_steps);

            for (int i = 0; i < m_max_steps; i++)
            {
                double s = (double)i / ((double)m_max_steps - 1);
                slist.Add(s);
            }

            // Get the real parameters along the curve
            double[] tlist = new double[m_max_steps];
            if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist))
            {
                return(IRhinoCommand.result.failure);
            }

            // Create the display conduit
            SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit();

            // Get points along curve
            On3dPoint        start = new On3dPoint(crv.PointAtStart());
            List <On3dPoint> plist = new List <On3dPoint>(tlist.Length);

            for (int i = 0; i < m_max_steps; i++)
            {
                On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i]));
                plist.Add(pt);
            }

            // Hide objects and add them to conduit's object array
            for (int i = 0; i < go.ObjectCount(); i++)
            {
                MRhinoObjRef objref = go.Object(i);
                context.m_doc.HideObject(objref);
                conduit.m_objects.Add(objref.Object());
            }

            // Do animation...
            conduit.Enable();

            for (int i = 0; i < m_max_steps; i++)
            {
                On3dVector v = plist[i] - start;
                conduit.m_xform.Translation(v);
                context.m_doc.Redraw();
                Thread.Sleep(100);
            }

            for (int i = m_max_steps - 1; i >= 0; i--)
            {
                On3dVector v = plist[i] - start;
                conduit.m_xform.Translation(v);
                if (0 != i)
                {
                    context.m_doc.Redraw();
                    Thread.Sleep(100);
                }
            }

            conduit.Disable();

            // Show hidden objects
            for (int i = 0; i < go.ObjectCount(); i++)
            {
                MRhinoObjRef objref = go.Object(i);
                context.m_doc.ShowObject(objref);
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
コード例 #7
0
 private static double GetCurveArea(IOnCurve crv, double tol)
 {
     double area = 0.0;
       if (null != crv && crv.IsClosed())
       {
     OnPlane plane = new OnPlane();
     if (crv.IsPlanar(plane, tol))
     {
       OnBoundingBox bbox = crv.BoundingBox();
       On3dPoint point = plane.ClosestPointTo(bbox.Center());
       OnMassProperties mp = new OnMassProperties();
       if (crv.AreaMassProperties(point, plane.Normal(), ref mp))
     area = Math.Abs(mp.Area());
     }
       }
       return area;
 }