示例#1
0
    static public void Main()
    {
        //create points with the swig doubleArray proxy
        //http://www.swig.org/Doc3.0/SWIGDocumentation.html#Library_carrays
        doubleArray p = new doubleArray(12); //column major

        p.setitem(0, 0.0); p.setitem(3, 0.5); p.setitem(6, 0.5); p.setitem(9, 0.0);
        p.setitem(1, 0.0); p.setitem(4, 0.0); p.setitem(7, 1.0); p.setitem(10, 1.0);
        p.setitem(2, 0.0); p.setitem(5, 1.0); p.setitem(8, 0.0); p.setitem(11, 1.0);
        System.Console.WriteLine("Input points:");
        printArray(p, 4);
        SWIGTYPE_p_ShapeOpSolver s = shapeopCSharp.shapeop_create();

        shapeopCSharp.shapeop_setPoints(s, p.cast(), 4);
        double weight = 1.0;
        //add a plane constraint to all the vertices.
        intArray ids = new intArray(4);

        ids.setitem(0, 0); ids.setitem(1, 1); ids.setitem(2, 2); ids.setitem(3, 3);
        shapeopCSharp.shapeop_addPlaneConstraint(s, ids.cast(), 4, weight);
        //add a closeness constraint to the 1st vertex.
        shapeopCSharp.shapeop_addClosenessConstraint(s, 0, weight);
        //add a closeness constraint to the 4th vertex.
        shapeopCSharp.shapeop_addClosenessConstraint(s, 3, weight);
        shapeopCSharp.shapeop_init(s);
        shapeopCSharp.shapeop_solve(s, 10);
        shapeopCSharp.shapeop_getPoints(s, p.cast(), 4);
        shapeopCSharp.shapeop_delete(s);
        System.Console.WriteLine("Output points:");
        printArray(p, 4);
    }
示例#2
0
    // Test Driver
    public static void Main(string[] args)
    {
        // Call initialize function to set up any necessary state
        System.Console.WriteLine("Calling initialize");
        timestwocs.timestwo_initialize();

        // 2-by-3 input
        int m = 2;
        int n = 3;

        using (intArray dims = new intArray(2))                                                   // Size vector
            using (doubleArray data = new doubleArray(6))                                         // Data
                using (emxArray_real_T x = timestwocs.emxCreateWrapper_real_T(data.cast(), m, n)) // Input
                    using (emxArray_real_T y = timestwocs.emxCreate_real_T(0, 0)) {               // Output
                        // 2-by-3 input
                        dims.setitem(0, m);
                        dims.setitem(1, n);

                        // Data
                        int numel = m * n;
                        for (int i = 0; i < numel; i++)
                        {
                            data.setitem(i, i);
                        }
                        System.Console.WriteLine("Initial data");
                        timestwoMain.printArray(data, numel);
                        // Call entry-point
                        timestwocs.timestwo(x, y);

                        // Gather returned data
                        doubleArray output      = doubleArray.frompointer(y.data);
                        int         outputND    = y.numDimensions;
                        intArray    outputSize  = intArray.frompointer(y.size);
                        int         outputNumel = 1;
                        for (int dim = 0; dim < outputND; dim++)
                        {
                            outputNumel *= outputSize.getitem(dim);
                        }
                        timestwoMain.printArray(output, outputNumel);

                        // Call terminate function to perform any necessary clean up
                        System.Console.WriteLine("Calling terminate");
                        timestwocs.timestwo_terminate();

                        // No need to clean up emxArray variables as destructors are
                        // automatically called and have the call to emxDestroy_real_T
                        // injected in them
                    }
    }
示例#3
0
        private void InternalCallback(uint number, uint inputCount, uint outputCount, global::System.IntPtr inputs, global::System.IntPtr outputs)
        {
            int[] callbackInput  = new int[inputCount];
            int[] callbackOutput = new int[outputCount];

            Callback(number, inputCount, outputCount, callbackInput, callbackOutput);

            using (intArray inputArray = new intArray(inputs, false))
                using (intArray outputArray = new intArray(outputs, false))
                {
                    for (int i = 0; i < inputCount; i++)
                    {
                        inputArray.setitem(i, callbackInput[i]);
                    }
                    for (int i = 0; i < outputCount; i++)
                    {
                        outputArray.setitem(i, callbackOutput[i]);
                    }
                }
        }