Ejemplo n.º 1
0
 public BrepLoop(Brep brep, int faceIndex, List <int> trimIndices, BrepLoopType type)
 {
     Brep        = brep;
     FaceIndex   = faceIndex;
     TrimIndices = trimIndices;
     Type        = type;
 }
Ejemplo n.º 2
0
        public static Curve[] _GetEdgesWithDirectionsSameAsTrims(this Surface srf, BrepLoopType loopType, Curve[] loopEdges)
        {
            // duplicate edges coz we want to edit curves (reverse some of them)
            var crvs = loopEdges.Select(o => o.DuplicateCurve()).ToArray();

            // connect them together
            for (var i = 1; i < crvs.Length; i++)
            {
                var iPrev   = i - 1;
                var crv     = crvs[i];
                var crvPrev = crvs[iPrev];

                CurvesConnectionInfo connectionInfo;
                crv._AreConnected(crvPrev, out connectionInfo, 10000);
                if (connectionInfo.Crv1End == connectionInfo.Crv2End)
                {
                    crv.Reverse();
                }
            }

            // Join them into 1 curve
            var jC = Curve.JoinCurves(crvs, 100);// we must tell tollerance to be independed from document tolerance

            // enshure orientation of curves are same as should be for trims: clockwise for Outer loops, and CounterClockwise for Inner loops
            if (jC.Length == 1)
            {
                //Layers.Debug.AddCurve(jC[0], Color.Red, ObjectDecoration.EndArrowhead);
                var loopCentroid = srf._GetCentroid(loopEdges, true);
                var normal       = srf._NormalAt(loopCentroid);
                //Layers.Debug.AddNormal(srf.PointAt(u, v), normal, Color.Red, "_GetEdgesWithDirectionsSameAsTrims - loop centroid normal");
                var orientation     = jC[0].ClosedCurveOrientation(normal);
                var needOrientation = (loopType == BrepLoopType.Outer)
                    ? CurveOrientation.Clockwise
                    : CurveOrientation.CounterClockwise;
                if (orientation != needOrientation)
                {
                    foreach (var crv in crvs)
                    {
                        crv.Reverse();
                    }
                }
            }
            else
            {
                log.wrong("_BrepLoop._GetEdgesWithDirectionsSameAsTrims  failed to join {0} curves", loopEdges.Length);
            }

            return(crvs);
        }