protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select two curves for planar curve containment test");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
            go.SubObjectSelect         = false;
            go.GetMultiple(2, 2);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Curve curveA = go.Object(0).Curve();
            Rhino.Geometry.Curve curveB = go.Object(1).Curve();
            if (null == curveA || null == curveB)
            {
                return(Result.Failure);
            }

            Plane planeA, planeB;

            if (!curveA.IsPlanar() || !curveA.TryGetPlane(out planeA))
            {
                RhinoApp.WriteLine("Curve A is not planar.");
                return(Result.Success);
            }

            if (!curveB.IsPlanar() || !curveB.TryGetPlane(out planeB))
            {
                RhinoApp.WriteLine("Curve B is not planar.");
                return(Result.Success);
            }

            double            tol = Rhino.RhinoMath.ZeroTolerance;
            RegionContainment rc  = Curve.PlanarClosedCurveRelationship(curveA, curveB, planeA, tol);

            switch (rc)
            {
            case RegionContainment.Disjoint:
                RhinoApp.WriteLine("There is no common area between the two regions.");
                break;

            case RegionContainment.MutualIntersection:
                RhinoApp.WriteLine("The two curves intersect. No full containment relationship exists.");
                break;

            case RegionContainment.AInsideB:
                RhinoApp.WriteLine("Region bounded by curveA (first curve) is inside of curveB (second curve).");
                break;

            case RegionContainment.BInsideA:
                RhinoApp.WriteLine("Region bounded by curveB (second curve) is inside of curveA (first curve).");
                break;
            }

            return(Result.Success);
        }
Exemple #2
0
        /***************************************************/

        public static RHG.Brep ToRhino(this BHG.PlanarSurface planarSurface)
        {
            if (planarSurface == null || planarSurface.ExternalBoundary == null)
            {
                return(null);
            }

            RHG.Curve externalCurve = planarSurface.ExternalBoundary.IToRhino();
            if (externalCurve == null || !externalCurve.IsPlanar(BHG.Tolerance.Distance))
            {
                return(null);
            }

            List <RHG.Curve> rhCurves = new List <RHG.Curve>();

            if (planarSurface.InternalBoundaries != null)
            {
                rhCurves.AddRange(planarSurface.InternalBoundaries.Select(c => c.IToRhino()).Where(c => c.IsPlanar(BHG.Tolerance.Distance)).ToList());
                if (rhCurves.Count < planarSurface.InternalBoundaries.Count)
                {
                    int skipped = planarSurface.InternalBoundaries.Count - rhCurves.Count;
                    Reflection.Compute.RecordWarning($"{skipped} internal boundaries skipped due to a failed planarity test.");
                }
            }
            rhCurves.Add(externalCurve);

            RHG.Brep[] rhSurfaces = RHG.Brep.CreatePlanarBreps(rhCurves);
            if (rhSurfaces == null)
            {
                return(null);
            }

            if (rhSurfaces.Length > 1)
            {
                //If more than one surface is extracted, try boolean difference of the curves to generate the geometry
                List <RHG.Curve> inner = new List <RHG.Curve>(rhCurves);
                inner.RemoveAt(inner.Count - 1);

                RHG.Curve[] difference = RHG.Curve.CreateBooleanDifference(externalCurve, inner);
                //Internal and external edges fully overlap -> 0 edges -> empty Brep
                if (difference == null || difference.Length == 0)
                {
                    return(null);
                }

                RHG.Brep[] rhSurfacesFromDifference = RHG.Brep.CreatePlanarBreps(difference);
                if (rhSurfacesFromDifference == null)
                {
                    return(null);
                }

                if (rhSurfacesFromDifference.Length > 1)
                {
                    Reflection.Compute.RecordWarning("Surface edges are not coplanar or their intersection is not empty." +
                                                     "The conversion to Rhino results into multiple Breps and only the first brep will be returned.");
                }
                else if (rhSurfacesFromDifference.Length == 1)
                {
                    Reflection.Compute.RecordWarning("The internal edges overlap with the external." +
                                                     "Boolean intersection has been used to try to get out the correct geometry." +
                                                     "Topology might have changed for the surface obejct");
                    return(rhSurfacesFromDifference.FirstOrDefault());
                }
            }
            return(rhSurfaces.FirstOrDefault());
        }