/// <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); }
/// <summary> /// TwistedCubeTrimmingCurve /// </summary> static OnCurve TwistedCubeTrimmingCurve( IOnSurface s, int side // 0 = SW to SE // 1 = SE to NE // 2 = NE to NW // 3 = NW to SW ) { // A trimming curve is a 2d curve whose image lies in the surface's domain. // The "active" portion of the surface is to the left of the trimming curve. // An outer trimming loop consists of a simple closed curve running // counter-clockwise around the region it trims. On2dPoint from = new On2dPoint(); On2dPoint to = new On2dPoint(); double u0 = 0.0, u1 = 0.0, v0 = 0.0, v1 = 0.0; s.GetDomain(0, ref u0, ref u1); s.GetDomain(1, ref v0, ref v1); switch (side) { case 0: // SW to SE from.x = u0; from.y = v0; to.x = u1; to.y = v0; break; case 1: // SE to NE from.x = u1; from.y = v0; to.x = u1; to.y = v1; break; case 2: // NE to NW from.x = u1; from.y = v1; to.x = u0; to.y = v1; break; case 3: // NW to SW from.x = u0; from.y = v1; to.x = u0; to.y = v0; break; default: return(null); } OnLineCurve c2d = new OnLineCurve(from, to); c2d.SetDomain(0.0, 1.0); return(c2d); }
private static double GetSurfaceVolume(IOnSurface srf) { double volume = 0.0; if (null != srf) { OnMassProperties mp = new OnMassProperties(); if (srf.VolumeMassProperties(ref mp, true)) { volume = Math.Abs(mp.Volume()); } } return(volume); }
private static double GetSurfaceArea(IOnSurface srf) { double area = 0.0; if (null != srf) { OnMassProperties mp = new OnMassProperties(); if (srf.AreaMassProperties(ref mp, true)) { area = Math.Abs(mp.Area()); } } return(area); }
///<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 surface"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object); go.EnableSubObjectSelect(false); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IOnSurface srf = go.Object(0).Surface(); if (null == srf) { return(IRhinoCommand.result.failure); } IOnNurbsSurface ns = srf.NurbsSurface(); if (null == ns) { RhUtil.RhinoApp().Print("Not a NURBS surface.\n"); return(IRhinoCommand.result.nothing); } On3dPoint cv = new On3dPoint(); string str = string.Empty; for (int u = 0; u < ns.CVCount(0); u++) { for (int v = 0; v < ns.CVCount(1); v++) { if (ns.GetCV(u, v, ref cv)) { str = string.Empty; RhUtil.RhinoFormatPoint(cv, ref str); RhUtil.RhinoApp().Print(string.Format("CV({0},{1}) = {2}\n", u, v, str)); } } } return(IRhinoCommand.result.success); }
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); }
/// <summary> /// Calculates the volume of an object /// </summary> public static double GetVolume(IRhinoObject obj) { if (null != obj && obj.IsSolid()) { IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) { return(GetSurfaceVolume(srf)); } IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) { return(GetBrepVolume(brep)); } IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) { return(GetMeshVolume(mesh)); } } return(0.0); }
/// <summary> /// TwistedCubeTrimmingCurve /// </summary> static OnCurve TwistedCubeTrimmingCurve( IOnSurface s, int side // 0 = SW to SE // 1 = SE to NE // 2 = NE to NW // 3 = NW to SW ) { // A trimming curve is a 2d curve whose image lies in the surface's domain. // The "active" portion of the surface is to the left of the trimming curve. // An outer trimming loop consists of a simple closed curve running // counter-clockwise around the region it trims. On2dPoint from = new On2dPoint(); On2dPoint to = new On2dPoint(); double u0 = 0.0, u1 = 0.0, v0 = 0.0, v1 = 0.0; s.GetDomain(0, ref u0, ref u1); s.GetDomain(1, ref v0, ref v1); switch (side) { case 0: // SW to SE from.x = u0; from.y = v0; to.x = u1; to.y = v0; break; case 1: // SE to NE from.x = u1; from.y = v0; to.x = u1; to.y = v1; break; case 2: // NE to NW from.x = u1; from.y = v1; to.x = u0; to.y = v1; break; case 3: // NW to SW from.x = u0; from.y = v1; to.x = u0; to.y = v0; break; default: return null; } OnLineCurve c2d = new OnLineCurve(from, to); c2d.SetDomain(0.0, 1.0); return c2d; }
/// <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); }
private static double GetSurfaceVolume(IOnSurface srf) { double volume = 0.0; if (null != srf) { OnMassProperties mp = new OnMassProperties(); if (srf.VolumeMassProperties(ref mp, true)) volume = Math.Abs(mp.Volume()); } return volume; }
private static double GetSurfaceArea(IOnSurface srf) { double area = 0.0; if (null != srf) { OnMassProperties mp = new OnMassProperties(); if (srf.AreaMassProperties(ref mp, true)) area = Math.Abs(mp.Area()); } return area; }