Beispiel #1
0
        internal static Snap.NX.Spline CreateSplineThroughPoints(Snap.Position[] qpts, Vector startTangent, Vector endTangent)
        {
            Tag tag;
            int length = qpts.Length;

            int[]    numArray  = new int[length];
            int[]    numArray2 = new int[length];
            double[] numArray3 = new double[3 * length];
            double[] numArray4 = new double[3 * length];
            for (int i = 0; i < length; i++)
            {
                numArray[i]      = -1;
                numArray2[i]     = -1;
                numArray3[i]     = 0.0;
                numArray3[i + 1] = 0.0;
                numArray3[i + 2] = 0.0;
                numArray4[i]     = 0.0;
                numArray4[i + 1] = 0.0;
                numArray4[i + 2] = 0.0;
            }
            numArray3[0] = startTangent.X;
            numArray3[(3 * length) - 3] = endTangent.X;
            numArray3[1] = startTangent.Y;
            numArray3[(3 * length) - 2] = endTangent.Y;
            numArray3[2] = startTangent.Z;
            numArray3[(3 * length) - 1] = endTangent.Z;
            numArray[0]          = 1;
            numArray[length - 1] = 1;
            UFCurve.PtSlopeCrvatr[] crvatrArray = new UFCurve.PtSlopeCrvatr[length];
            for (int j = 0; j < length; j++)
            {
                crvatrArray[j]             = new UFCurve.PtSlopeCrvatr();
                crvatrArray[j].point       = new double[] { qpts[j].X, qpts[j].Y, qpts[j].Z };
                crvatrArray[j].slope_type  = numArray[j];
                crvatrArray[j].slope       = new double[] { numArray3[3 * j], numArray3[(3 * j) + 1], numArray3[(3 * j) + 2] };
                crvatrArray[j].crvatr_type = numArray2[j];
                crvatrArray[j].crvatr      = new double[] { numArray4[3 * j], numArray4[(3 * j) + 1], numArray4[(3 * j) + 2] };
            }
            int num4 = 1;

            double[]  parameters  = null;
            int       periodicity = 0;
            UFSession uFSession   = Globals.UFSession;

            uFSession.Curve.CreateSplineThruPts(3, periodicity, length, crvatrArray, parameters, num4, out tag);
            uFSession.So.SetVisibilityOption(tag, UFSo.VisibilityOption.Visible);
            return(new Snap.NX.Spline(tag));
        }
        public const int UF_CURVE_CRVATR_VEC      = 2;  /* UF_CURVE_CREATE_SPLINE_THRU_PTS */

        public int Execute()
        {
            Tag    UFPart;
            string part_name = "EX_Curve_CreateSplineThruPts";
            int    units     = 2;
            string name;


            theUfSession.Part.New(part_name, units, out UFPart);
            theUfSession.Part.AskPartName(UFPart, out name);
            w.WriteLine("Loaded: " + name);

            /* B-spline parameters  */
            int degree      = 3;
            int periodicity = 0;
            int num_points  = NUMBER_POINTS;

            /* Point/slope UFCurve attribute array */
            UFCurve.PtSlopeCrvatr[] point_data = new UFCurve.PtSlopeCrvatr[NUMBER_POINTS];

            /* Arrays of user's defining point data */
            double[] parameters = { 0.00, 0.17, 0.32, 0.45, 1.29 };
            double[] points     = { 1.1000, 0.5320, 2.0000,
                                    1.5240,     0.6789, 2.3000,
                                    2.0000,     0.9000, 3.5956,
                                    2.3456,     1.3456, 3.7890,
                                    3.1000,     2.4567, 3.3214 };
            int[]    slopeTypes = { UF_CURVE_SLOPE_DIR,
                                    UF_CURVE_SLOPE_AUTO,
                                    UF_CURVE_SLOPE_NONE,
                                    UF_CURVE_SLOPE_DIR,
                                    UF_CURVE_SLOPE_VEC };
            double[] slopeVecs = { 1.2300,  5.0506, 4.0360,
                                   0.0000,  0.0000, 0.0000,
                                   0.0000,  0.0000, 0.0000,
                                   0.5000,  1.0000, 0.5000,
                                   1.0000, -2.0000, 1.0000 };
            int[]    crvatrTypes = { UF_CURVE_CRVATR_NONE,
                                     UF_CURVE_CRVATR_AUTO_DIR,
                                     UF_CURVE_CRVATR_NONE,
                                     UF_CURVE_CRVATR_VEC,
                                     UF_CURVE_CRVATR_VEC };
            double[] crvatrVecs = { 0.0000,   0.0000, 0.0000,
                                    1.0000,   2.5780, 5.6700,
                                    0.0000,   0.0000, 0.0000,
                                    1.0000,  -1.0000, 1.0000,
                                    -1.0000, -1.0000, -1.0000 };
            int      i, save_def_data = 1;

            Tag spline_tag;

            for (i = 0; i < NUMBER_POINTS; i++)
            {
                point_data[i].point       = new double[3];
                point_data[i].point[0]    = points[3 * i];
                point_data[i].point[1]    = points[3 * i + 1];
                point_data[i].point[2]    = points[3 * i + 2];
                point_data[i].slope_type  = slopeTypes[i];
                point_data[i].slope       = new double[3];
                point_data[i].slope[0]    = slopeVecs[3 * i];
                point_data[i].slope[1]    = slopeVecs[3 * i + 1];
                point_data[i].slope[2]    = slopeVecs[3 * i + 2];
                point_data[i].crvatr_type = crvatrTypes[i];
                point_data[i].crvatr      = new double[3];
                point_data[i].crvatr[0]   = crvatrVecs[3 * i];
                point_data[i].crvatr[1]   = crvatrVecs[3 * i + 1];
                point_data[i].crvatr[2]   = crvatrVecs[3 * i + 2];
            }
            /* Create B-spline UFCurve */
            theUfSession.Curve.CreateSplineThruPts(degree,
                                                   periodicity,
                                                   num_points,
                                                   point_data,
                                                   parameters,
                                                   save_def_data,
                                                   out spline_tag);
            theUfSession.Part.Save();
            return(0);
        }