Example #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);
        }
Example #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);
        }
        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);
        }
Example #4
0
        /// <summary>
        /// MakeTwistedCubeTrimmingLoop
        /// </summary>
        static int MakeTwistedCubeTrimmingLoop(
            ref OnBrep brep,                        // returns index of loop
            ref OnBrepFace face,                    // face loop is on
            int vSWi, int vSEi, int vNEi, int vNWi, // Indices of corner vertices listed in SW, SE, NW, NE order
            int eSi,                                // index of edge on south side of surface
            int eS_dir,                             // orientation of edge with respect to surface trim
            int eEi,                                // index of edge on south side of surface
            int eE_dir,                             // orientation of edge with respect to surface trim
            int eNi,                                // index of edge on south side of surface
            int eN_dir,                             // orientation of edge with respect to surface trim
            int eWi,                                // index of edge on south side of surface
            int eW_dir                              // orientation of edge with respect to surface trim
            )
        {
            IOnSurface srf = brep.m_S[face.m_si];

            OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face);

            // Create trimming curves running counter clockwise around the surface's domain.
            // Start at the south side
            int  c2i = 0, ei = 0;
            bool bRev3d = false;

            IOnSurface.ISO iso = IOnSurface.ISO.not_iso;

            for (int side = 0; side < 4; side++)
            {
                // side: 0=south, 1=east, 2=north, 3=west
                OnCurve c2 = TwistedCubeTrimmingCurve(srf, side);
                c2i = brep.m_C2.Count();
                brep.m_C2.Append(c2);

                switch (side)
                {
                case 0: // south
                    ei     = eSi;
                    bRev3d = (eS_dir == -1);
                    iso    = IOnSurface.ISO.S_iso;
                    break;

                case 1: // east
                    ei     = eEi;
                    bRev3d = (eE_dir == -1);
                    iso    = IOnSurface.ISO.E_iso;
                    break;

                case 2: // north
                    ei     = eNi;
                    bRev3d = (eN_dir == -1);
                    iso    = IOnSurface.ISO.N_iso;
                    break;

                case 3: // west
                    ei     = eWi;
                    bRev3d = (eW_dir == -1);
                    iso    = IOnSurface.ISO.W_iso;
                    break;
                }

                OnBrepEdge edge = brep.m_E[ei];
                OnBrepTrim trim = brep.NewTrim(ref edge, bRev3d, ref loop, c2i);
                trim.m_iso  = iso;
                trim.m_type = IOnBrepTrim.TYPE.mated; // This b-rep is closed, so all trims have mates.
                trim.set_m_tolerance(0, 0.0);         // This simple example is exact - for models with
                trim.set_m_tolerance(1, 0.0);         // non-exact data, set tolerance as explained in
                                                      // definition of OnBrepTrim.
            }

            return(loop.m_loop_index);
        }