Exemple #1
0
        private static IBSplineCurveEntity ByPointsCore(ref DSPoint[] points, DSVector startTangent, DSVector endTangent, bool makePeriodic)
        {
            IPointEntity[] hosts = points.ConvertAll(DSGeometryExtension.ToEntity<DSPoint, IPointEntity>);
            if (hosts == null || hosts.Length < 2)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "points"), "points");
            }
            if (hosts.AreCoincident())
                throw new System.ArgumentException(string.Format(Properties.Resources.PointsCoincident, "points"), "points"); //Can't create BSpline curve with all coincident points.

            IBSplineCurveEntity ent = null;
            if (null != startTangent && null != endTangent)
                ent = HostFactory.Factory.BSplineByPoints(hosts, startTangent.IVector, endTangent.IVector);
            else
                ent = HostFactory.Factory.BSplineByPoints(hosts, makePeriodic);
            if (ent == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSBSplineCurve.ByPoints"));
            points = hosts.ToArray<DSPoint, IPointEntity>(false);
            return ent;
        }
Exemple #2
0
        private static IBSplineCurveEntity ByControlVerticesCore(DSPoint[] controlVertices, ref int degree, bool makePeriodic)
        {
            IPointEntity[] hosts = controlVertices.ConvertAll(DSGeometryExtension.ToEntity<DSPoint, IPointEntity>);
            if (hosts == null)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "controlVertices", "DSBSplineCurve"), "controlVertices");

            if (degree < 1 || degree > 11)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "degree", "one"), "degree");
            }
            if (hosts.AreCoincident())
                throw new System.ArgumentException(string.Format(Properties.Resources.PointsCoincident, "controlVertices"), "controlVertices"); //Can't create BSpline curve with all coincident points.

            // making sure if # of controlVertices > degree by atleast 1
            int udiff = hosts.Length - degree;
            if (udiff < 1)
                degree += udiff - 1; //Fix DID DG-1464903

            var ent = HostFactory.Factory.BSplineByControlVertices(hosts, degree, makePeriodic);
            if (null == ent)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSBSplineCurve.ByControlVertices"));
            return ent;
        }
        /// <summary>
        /// Constructs a subdivision mesh by vertex shading, given an input 
        /// array of vertex points and an input array of faces defined by a set 
        /// of numbers, which are the indices of the vertices in the 'vertices' 
        /// array making up the face. 
        /// </summary>
        /// <param name="vertices">Input array of vertex points</param>
        /// <param name="faceIndices">Input array of faces indices for each 
        /// vertex </param>
        /// <param name="vertexNormals">Input array of vertex normals</param>
        /// <param name="vertexColors">Input array of color assigned to each
        /// vertex </param>
        /// <param name="subDivisionLevel">Initial smoothness level, subDivisionLevel must 
        /// have a value greater than or equal to 0 and less than 5.</param>
        /// <returns>SubDivisionMesh</returns>
        public static DSSubDivisionMesh ByVerticesFaceIndices(DSPoint[] vertices, 
            int[][] faceIndices, DSVector[] vertexNormals, DSColor[] vertexColors, int subDivisionLevel)
        {
            string kMethodName = "DSSubDivisionMesh.ByVerticesFaceIndices";
            if (subDivisionLevel < 0 || subDivisionLevel >= 5)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "subDivisionLevel", kMethodName));

            IPointEntity[] points = vertices.ConvertAll(DSGeometryExtension.ToEntity<DSPoint, IPointEntity>);
            if (points.Length < 3 || points.ArePointsColinear())
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "vertices", kMethodName));

            ISubDMeshEntity entity = HostFactory.Factory.SubDMeshByVerticesFaceIndices(points, faceIndices, subDivisionLevel);
            if (null == entity)
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));

            DSSubDivisionMesh mesh = new DSSubDivisionMesh(entity, true);
            try
            {
                if (null != vertexNormals && vertexNormals.Length > 0)
                {
                    if (vertexNormals.Length != entity.GetNumVertices())
                        throw new System.ArgumentException(string.Format(Properties.Resources.NotEqual, "size of vertexNormals", "number of vertices"), "vertexNormals");

                    if (!entity.UpdateSubDMeshNormals(vertexNormals.ConvertAll((DSVector v)=>v.IVector)))
                        throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
                }

                if (null != vertexColors && vertexColors.Length > 0)
                {
                    if (subDivisionLevel > 0)
                        throw new System.InvalidOperationException(Properties.Resources.VertexColorNotSupported);

                    if (vertexColors.Length != entity.GetNumVertices())
                        throw new System.ArgumentException(string.Format(Properties.Resources.NotEqual, "size of vertexColors", "number of vertices"), "vertexColors");

                    if (!entity.UpdateSubDMeshColors(vertexColors.ConvertAll((DSColor c)=>c.IColor)))
                        throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
                }
            }
            catch (System.Exception ex)
            {
                mesh.Dispose();
                throw ex;
            }

            mesh.SubDivisionLevel = subDivisionLevel;
            return mesh;
        }
        private static ISubDMeshEntity ByVerticesFaceIndicesCore(DSPoint[] vertices, int[][] faceIndices, int subDivisionLevel)
        {
            string kMethodName = "DSSubDivisionMesh.ByVerticesFaceIndices";
            if (subDivisionLevel < 0 || subDivisionLevel >= 5)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "subDivisionLevel", kMethodName));

            IPointEntity[] points = vertices.ConvertAll(DSGeometryExtension.ToEntity<DSPoint, IPointEntity>);
            if (points.Length < 3 || points.ArePointsColinear())
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "vertices", kMethodName));

            ISubDMeshEntity entity = HostFactory.Factory.SubDMeshByVerticesFaceIndices(points, faceIndices, subDivisionLevel);
            if (null == entity)
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            return entity;
        }
Exemple #5
0
        private static IPolygonEntity ByVerticesCore(DSPoint[] vertices)
        {
            IPointEntity[] hosts = vertices.ConvertAll(DSGeometryExtension.ToEntity<DSPoint, IPointEntity>);
            if (hosts.Length <= 2)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of vertices", "3"), "vertices");

            if (hosts.ArePointsColinear())
                throw new System.ArgumentException(string.Format(Properties.Resources.PointsColinear, "vertices"), "vertices");

            IPolygonEntity entity = HostFactory.Factory.PolygonByVertices(hosts);
            if (null == entity)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSPolygon.ByVertices"));
            return entity;
        }