Example #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = ControlPointList.Cast <Vector4>().GetHashCode(v => v.GetHashCode());
         hashCode = (hashCode * 397) ^ KnotsU.GetHashCode(v => v.GetHashCode());
         hashCode = (hashCode * 397) ^ KnotsV.GetHashCode(v => v.GetHashCode());
         hashCode = (hashCode * 397) ^ OrderU;
         hashCode = (hashCode * 397) ^ OrderV;
         return(hashCode);
     }
 }
Example #2
0
        /// <summary>
        /// Returns an untrimmed solidworks surface.
        /// </summary>
        /// <param name="swBSplineSurfaceParams"></param>
        /// <returns></returns>
        public ISurface ToSurface()
        {
            var vOrder = BitConverter.GetBytes(OrderV);
            var uOrder = BitConverter.GetBytes(OrderU);

            var swControlPointList = ControlPointList
                                     .EnumerateColumnWise()
                                     .SelectMany(v => new[] { v.X / v.W, v.Y / v.W, v.Z / v.W, v.W }.Take(SurfaceDimension))
                                     .ToArray();

            var uLength = ControlPointList.GetLength(0);
            var vLength = ControlPointList.GetLength(1);

            var numUCtrPts = BitConverter.GetBytes(uLength);
            var numVCtrPts = BitConverter.GetBytes(vLength);

            var uPeriodicity = BitConverter.GetBytes(UIsPeriodic ? 1 : 0);
            var vPeriodicity = BitConverter.GetBytes(VIsPeriodic ? 1 : 0);

            var dimControlPoints = BitConverter.GetBytes(SurfaceDimension);
            var unusedParameter  = BitConverter.GetBytes(0);

            var props = new[]
            {
                BitConverter.ToDouble(uOrder.Concat(vOrder).ToArray(), 0),
                BitConverter.ToDouble(numVCtrPts.Concat(numUCtrPts).ToArray(), 0),
                BitConverter.ToDouble(uPeriodicity.Concat(vPeriodicity).ToArray(), 0),
                BitConverter.ToDouble(dimControlPoints.Concat(unusedParameter).ToArray(), 0)
            };

            var bsplineSurface = (Surface)SwAddinBase.Active.Modeler
                                 .CreateBsplineSurface
                                     (props
                                     , KnotsU
                                     , KnotsV
                                     , swControlPointList
                                     );

            Debug.Assert(bsplineSurface != null);

#if DEBUG
            var p = bsplineSurface.Parameterization2();
            Debug.Assert(Math.Abs(p.UMax - KnotsU.Last()) < 1e-9);
            Debug.Assert(Math.Abs(p.UMin - KnotsU.First()) < 1e-9);
            Debug.Assert(Math.Abs(p.VMax - KnotsV.Last()) < 1e-9);
            Debug.Assert(Math.Abs(p.VMin - KnotsV.First()) < 1e-9);
#endif

            return(bsplineSurface);
        }
Example #3
0
        /// <summary>
        /// Internal constructor used to validate the NURBS surface.
        /// </summary>
        /// <param name="degreeU">The degree in the U direction.</param>
        /// <param name="degreeV">The degree in the V direction.</param>
        /// <param name="knotsU">The knotVector in the U direction.</param>
        /// <param name="knotsV">The knotVector in the V direction.</param>
        /// <param name="controlPts">Two dimensional array of points.</param>
        internal NurbsSurface(int degreeU, int degreeV, KnotVector knotsU, KnotVector knotsV, List <List <Point4> > controlPts)
        {
            if (controlPts == null)
            {
                throw new ArgumentNullException("Control points array connot be null!");
            }
            if (degreeU < 1)
            {
                throw new ArgumentException("DegreeU must be greater than 1!");
            }
            if (degreeV < 1)
            {
                throw new ArgumentException("DegreeV must be greater than 1!");
            }
            if (knotsU == null)
            {
                throw new ArgumentNullException("KnotU cannot be null!");
            }
            if (knotsV == null)
            {
                throw new ArgumentNullException("KnotV cannot be null!");
            }
            if (knotsU.Count != controlPts.Count() + degreeU + 1)
            {
                throw new ArgumentException("Points count + degreeU + 1 must equal knotsU count!");
            }
            if (knotsV.Count != controlPts.First().Count() + degreeV + 1)
            {
                throw new ArgumentException("Points count + degreeV + 1 must equal knotsV count!");
            }
            if (!knotsU.IsValid(degreeU, controlPts.Count()))
            {
                throw new ArgumentException("Invalid knotsU!");
            }
            if (!knotsV.IsValid(degreeV, controlPts.First().Count()))
            {
                throw new ArgumentException("Invalid knotsV!");
            }

            DegreeU = degreeU;
            DegreeV = degreeV;
            KnotsU  = (Math.Abs(knotsU.GetDomain(degreeU).Length - 1.0) > GSharkMath.Epsilon) ? knotsU.Normalize() : knotsU;
            KnotsV  = (Math.Abs(knotsV.GetDomain(degreeV).Length - 1.0) > GSharkMath.Epsilon) ? knotsV.Normalize() : knotsV;
            Weights = Point4.GetWeights2d(controlPts);
            ControlPointLocations = Point4.PointDehomogenizer2d(controlPts);
            ControlPoints         = controlPts;
            DomainU = new Interval(KnotsU.First(), KnotsU.Last());
            DomainV = new Interval(KnotsV.First(), KnotsV.Last());
        }
Example #4
0
        public bool Equals(BSplineSurface other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            return(ControlPointList.Cast <Vector4>().SequenceEqual(other.ControlPointList.Cast <Vector4>()) &&
                   KnotsU.SequenceEqual(other.KnotsU) &&
                   KnotsV.SequenceEqual(other.KnotsV)

                   && OrderU == other.OrderU &&
                   OrderV == other.OrderV);
        }
Example #5
0
        /// <summary>
        /// Check that all values in other are within epsilon of the values in this
        /// </summary>
        /// <param name="other"></param>
        /// <param name="epsilon"></param>
        /// <returns></returns>
        public bool EpsilonEquals(NurbsSurface other, double epsilon)
        {
            if (null == other)
            {
                throw new ArgumentNullException("other");
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if ((Degree(0) != other.Degree(0)) || (Degree(1) != other.Degree(1)))
            {
                return(false);
            }

            if (IsRational != other.IsRational)
            {
                return(false);
            }

            if (Points.CountU != other.Points.CountU || Points.CountV != other.Points.CountV)
            {
                return(false);
            }

            if (!KnotsU.EpsilonEquals(other.KnotsU, epsilon))
            {
                return(false);
            }

            if (!KnotsV.EpsilonEquals(other.KnotsV, epsilon))
            {
                return(false);
            }

            return(true);
        }