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); }
public static intArray frompointer(SWIGTYPE_p_int t) { global::System.IntPtr cPtr = IsarMaincsPINVOKE.intArray_frompointer(SWIGTYPE_p_int.getCPtr(t)); intArray ret = (cPtr == global::System.IntPtr.Zero) ? null : new intArray(cPtr, false); return(ret); }
public static intArray frompointer(SWIGTYPE_p_int t) { global::System.IntPtr cPtr = ompl_basePINVOKE.intArray_frompointer(SWIGTYPE_p_int.getCPtr(t)); intArray ret = (cPtr == global::System.IntPtr.Zero) ? null : new intArray(cPtr, false); if (ompl_basePINVOKE.SWIGPendingException.Pending) { throw ompl_basePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
// 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 } }
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]); } } }
static void Main(string[] args) { #region Variables // ************* Variables *************** // //Create a variable of type int called id. Initialize it to 75. int id = 75; //Create a variable of type string called name. Initialize it to your full name. string name = "Dylan Abeyta"; //Create a variable of type bool called isValid. Initialize it to true. bool isValid = true; //Create a variable of type int called userID. Don't initialize this value. (In C#, ints default to 0) int userID; //Create a variable of type string called state. Don't initialize this value. (In C#, strings default to null) string state; //Create a variable of type bool called hasRan. Don't initialize this value. (In C#, booleans default to false) bool hasRan; //Create a variable of type char called myCharacter. Initialize this value to "a". char myCharacter = 'a'; //Create a variable of type double called myDouble. Initialize this value to 3.14 double myDouble = 3.14; //Create a variable of type float called myFloat. Initialize this value to 3.14 (cannot convert double to float, check 1.0 slides) float myFloat = 3.14f; //Create a variable of type Random called rand. Initialize it to a new Random Object. Random rand = new Random(); #endregion #region Conditionals // ************ Conditionals ************* // //Create a variable of type bool called isValid. Initialize it to true. bool isValid = true; //if isValid is true, then console writeline "isValid is true" if (isValid == true) { Console.WriteLine("isValid is True"); } //else if isValid is not true, then console writeline "isValid is not true" else if (isValid != true) { Console.WriteLine("isValid is not true"); } //Create a variable of type int called x. Initialize it to 75. int x = 75; //Create a variable of type int called y. Initialize it to 100. int y = 100; //If x is greater than y, then console writeline "X is Greater than Y" if (x > y) { Console.WriteLine("x is greater than y"); } //else if x is equal to y, then console writeline "X is equal to Y" else if (x == y) { Console.WriteLine("x is equal to y"); } //else, then console writeline "X is less than Y" else { Cosnole.WriteLine("x is less than y"); } ; //Create a variable of type string called country. Initialize it to "Mexico". string country = "Mexico"; //Create a variable of type int called age. Initialize it to 18. int age = 18; //If country is "Mexico" and age is greater than or equal to 18 then console writeline "You can legally drive" if (country == "Mexico" && age >= 18) { Console.WriteLine("you can legally drive"); } //else if country is not "Mexico" and age is greater than or equal to 16 then console writeline "You can legally drive" else if (country != "Mexico" && age >= 16) { Console.WriteLine("you can legally drive"); } //else console writeline "you cannot legally drive" else { Console.WriteLine("you cannot legally drive"); } #endregion #region Loops // **************** Loops **************** // //for loop starting at i = 0 and continue while i < 10, incrementing by 1. Console writeline the value of i each time. for (int i = 0; i < 10; i++) { Console.WriteLine(i); } //for loop starting at i = 0 and continue while i < 30, incrementing by 2. Console writeline the value of i each time. for (int i = 0; i < 30; i += 2) { Console.WriteLine(i); } //for loop starting at i = 30 and continue while i >= 0, decrementing by 1. Console writeline the value of i each time. for (int i = 30; i >= 0; i--) { Console.WriteLine(i); } //for loop starting at i = 30 and continue while i > 0, decrementing by 3. Console writeline the value of i each time. for (int i = 30; i > 0; i -= 3) { Console.WriteLine(i); } //Create an int variable called index, initialize it to 0. int index = 0; //while index < 10 Console writeline index. while (index < 10) { Console.WriteLine(index); index++; } //reset index variable to 0 int index = 0; //while index < 0 console writeline index while (index < 0) { Console.WriteLine(index); index++; } //Reset index variable to 0 int index = 0; //do-while index < 10 console writeline index. do { Console.WriteLine(index); index++; } while (index < 10); //reset index variable to 0 int index = 0; //do-while index < 0 console writeline index do { Console.WriteLine(index); index++; } while (index < 0); //Create an int variable called input, initialize to 0 int input = 0; //Accept user input with Console.ReadLine and parse it into an integer with int.Parse. Store in input variable. input = int.Parse(Console.ReadLine()); //do-while input does not equal -1, console writeline "Input -1 to end program, input any other number to continue" do { Console.WriteLine("input -1 to end program, input any other nuumber to continue"); } while (input != -1); #endregion #region Arrays // *************** Arrays **************** // //Create an array of type int and of size 10 called intArray. Don't initialize any data. (Remember, ints default to 0 so you now have an array of 10 0's.) int[] intArray = new int[10]; //Create an array of type string and of size 5 called stringArray. Don't initialize any data. string[] stringArray = new string[5]; //For the following, change each index individually. Do not use a loop or assignment on declaration intArray[0] = 0; intArray[1] = 1; intArray[2] = 2; intArray[3] = 3; intArray[4] = 4; intArray[5] = 5; intArray[6] = 6; intArray[7] = 7; intArray[8] = 8; intArray[9] = 9; //Populate intArray with data following the formula: data = index * 3. IE the 3rd element of intArray will equal 9. intArray[0] *= 3; intArray[1] *= 3; intArray[2] *= 3; intArray[3] *= 3; intArray[4] *= 3; intArray[5] *= 3; intArray[6] *= 3; intArray[7] *= 3; intArray[8] *= 3; intArray[9] *= 3; //Populate stringArray with the following data: firstName, lastName, city, state, country stringArray[0] = "firstName"; stringArray[1] = "lastName"; stringArray[2] = "City"; stringArray[3] = "state"; stringArray[4] = "Country"; //for the following use a loop to assign the data into the arrays. //set each index data of intArray using the following formula: data = index * 2 + 1. IE the 3rd element will equal 7 for (int i = 0; i < 10; i++) { intArray[i] = i * 2 + 1; } //set each index data of stringArray to "The current index is i" where i is the actual value of i for (int i = 0; i < 5; i++) { stringArray[i] = ("the current is " + i); } //reset intArray to be a new int array of size 5. In the same line (hint, use { }) set the values to 0,1,2,3,4. int[] intArray = new intArray[5] { 0, 1, 2, 3, 4 }; //reset stringArray to be a new string array of size 3. In the same line (hint, use { }) set the values to "buddy", "guy", "Friend" string[] stringArray = new stringArray[3] { "buddy", "guy", "Friend" }; //for int i = 0, continue for the length of intArray, and increment i + 1, console writeline the value of intArray for (int i = 0; i < intArray.Length; i++) { Console.WriteLine(intArray[i]); } //for int i = 0, continue for the length of stringArray, and increment i + 1, console writeline the value of stringArray for (int i = 0; stringArray.Length; i++) { Console.WriteLine(stringArray[i]); } //iterate over (AKA use a for loop) intArray similarly to what you did above, but do it backwards. Print the last index first, and the 0th index last. for (int i = intArray.Length; i > 0; i--) { Console.WriteLine(intArray[i]); } //iterate over (AKA use a for loop) stringArray similarly to what you did above, but do it backwards. Print the last index first, and the 0th index last. for (int i = stringArray.Length; i > 0; i--) { Console.WriteLine(stringArray[i]); } #endregion }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(intArray obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }