Exemple #1
0
        public static Extrusion OgrPolygonToExtrusion(OSGeo.OGR.Geometry polygon, Transform transform, double height, double min_height, bool underground)
        {
            List <Curve> pList = new List <Curve>();

            OSGeo.OGR.Geometry sub_geom;
            int direction = 1;

            if (underground)
            {
                direction = -1;
            }

            //pList = OgrMultiLinestringToCurves(polygon, transform);

            for (int i = 0; i < polygon.GetGeometryCount(); i++)
            {
                sub_geom = polygon.GetGeometryRef(i);
                Curve crv = Heron.Convert.OgrRingToCurve(sub_geom, transform);
                if (crv.ClosedCurveOrientation(Plane.WorldXY.ZAxis) == CurveOrientation.Clockwise)
                {
                    crv.Reverse();
                }
                pList.Add(crv);
                sub_geom.Dispose();
            }

            pList[0].TryGetPlane(out var profilePlane);
            Transform profileTransform = Transform.PlaneToPlane(profilePlane, Plane.WorldXY);

            Extrusion extrusion = Extrusion.Create(pList[0], (height - min_height) * direction, true);

            if (extrusion == null)
            {
                return(null);
            }

            if (pList.Count > 1)
            {
                pList.RemoveAt(0);
                foreach (Curve innerCurve in pList)
                {
                    Curve crv = innerCurve.DuplicateCurve();
                    crv.Transform(profileTransform);
                    extrusion.AddInnerProfile(crv);
                }
            }

            Vector3d moveDir = new Vector3d(0, 0, min_height);

            extrusion.Translate(moveDir);

            return(extrusion);
        }
        protected Extrusion CreateExtrusion(Curve outerProfile, Curve[] innerProfiles, double height)
        {
            if (null == outerProfile || height <= RhinoMath.ZeroTolerance)
            {
                return(null);
            }

            Plane plane;

            if (!outerProfile.TryGetPlane(out plane))
            {
                return(null);
            }

            var path = new Line
            {
                From = plane.PointAt(0.0, 0.0, 0.0),
                To   = plane.PointAt(0.0, 0.0, height)
            };

            if (!path.IsValid || !(path.Length > RhinoMath.ZeroTolerance))
            {
                return(null);
            }

            var up      = plane.YAxis;
            var tangent = path.To - path.From;

            tangent.Unitize();
            if (!up.IsValid || !up.IsUnitVector || Math.Abs(up * tangent) > RhinoMath.SqrtEpsilon)
            {
                return(null);
            }

            var xform = Transform.ChangeBasis(Plane.WorldXY, plane);

            var curve = outerProfile.DuplicateCurve();

            curve.Transform(xform);
            curve.ChangeDimension(2);

            var extrusion = new Extrusion();

            extrusion.SetOuterProfile(curve, true);

            foreach (var profile in innerProfiles)
            {
                Plane curve_plane;
                if (profile.TryGetPlane(out curve_plane))
                {
                    if (plane.IsCoplanar(curve_plane, RhinoMath.ZeroTolerance))
                    {
                        curve = profile.DuplicateCurve();
                        curve.Transform(xform);
                        curve.ChangeDimension(2);
                        extrusion.AddInnerProfile(curve);
                    }
                }
            }

            extrusion.SetPathAndUp(path.From, path.To, up);

            return(extrusion.IsValid ? extrusion : null);
        }