1 / 35

2311: Algorithmic Architecture Basics of Algorithms Data IO

2311: Algorithmic Architecture Basics of Algorithms Data IO. Data input/output. Email I received. Is there a way to "drive" mel algorithms with data coming from outside Maya like GIS data or else?. int r = red (c); int g = green (c); int b = blue (c); int a = alpha (c);.

Download Presentation

2311: Algorithmic Architecture Basics of Algorithms Data IO

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2311: Algorithmic Architecture Basics of Algorithms Data IO

  2. Data input/output

  3. Email I received Is there a way to "drive" mel algorithms with data coming from outside Maya like GIS data or else?

  4. int r = red(c); int g = green(c); int b = blue(c); int a = alpha(c); Alpha Red GreenBlue 00000000 000000000000000000000000 4Bit Byte (ASCII) ( A Byte (Color) ( A int (Color) ( A

  5. Open the JPG file For every pixel{ get RGB values gray[]= (R + G + B)/3 } Make a plane the size of the pixels For every cv cv.z = gray[]

  6. Open the JPG file Open a text file For every pixel{ get RGB values write R, G, B (as text) } Close files Open text file For every line{ gray[]= (R + G + B)/3 } Make a plane the size of the pixels For every cv cv.z = gray[] Open the JPG file For every pixel{ get RGB values gray[]= (R + G + B)/3 } Make a plane the size of the pixels For every cv cv.z = gray[]

  7. fopen This command creates/opens a file for write/read and returns a file identifier. "w" open file for writing (destroys prior contents of file). "a" append for writing (appends to end of file). "r" open for reading.

  8. fopen This command creates/opens a file for write/read and returns a file identifier. "w" open file for writing (destroys prior contents of file). "a" append for writing (appends to end of file). "r" open for reading. Example $fileId =`fopen "filex.txt" "w" `; fclose $fileId;

  9. fopen This command creates/opens a file for write/read and returns a file identifier. "w" open file for writing (destroys prior contents of file). "a" append for writing (appends to end of file). "r" open for reading. Example $fileId =`fopen "filex.txt" "w" `; //also $fileId = eval("fopen \"filex.txt\“ \”w\”"); fclose $fileId;

  10. fopen This command creates/opens a file for write/read and returns a file identifier. "w" open file for writing (destroys prior contents of file). "a" append for writing (appends to end of file). "r" open for reading. Example $fileId =`fopen "filex.txt" "w" `; //also $fileId = eval("fopen \"filex.txt\“ \”w\”"); fclose $fileId; chdir "C:/Data"; $filename = "MyData.txt"; $fileId =`fopen $filename ”r”`;//or $fileId = eval("fopen " + $filename + “\”r\””); fclose $fileId;

  11. fwrite Writes the next set of bytes as binary data

  12. fwrite Writes the next set of bytes as binary data fread Reads the next set of bytes as binary data up to the first occurrence of a NULL character or until EOF.

  13. fwrite Writes the next set of bytes as binary data fread Reads the next set of bytes as binary data up to the first occurrence of a NULL character or until EOF. fgetword Returns the next word (string of characters separated by white space characters) or nothing at end of file.

  14. Open a file to write chdir"C:/Data"; $fileId =`fopen"hello.txt" "w"`; fwrite $fileId"Hello there\n"; fclose $fileId;

  15. Open a file to write chdir"C:/Data"; $fileId =`fopen"hello.txt" "w"`; fwrite $fileId"Hello there\n"; fclose $fileId;

  16. Open a file to write chdir"C:/Data"; $fileId =`fopen"hello.txt" “w"`; fwrite $fileId"Hello there\n"; fclose $fileId; Open a file to read from chdir"C:/Data"; $fileId=`fopen"hello.txt" "r"`; string $s; $s=`fread $fileId $s`; print $s; fclose $fileId; Hello there

  17. Write and retrieve data chdir "C:/Data"; $fileId=`fopen "data.txt" "w"`; $num = 10; fprint $fileId ($num + " "); for($i=0; $i<$num; $i++) fprint $fileId (rand(10) + " "); fclose $fileId; 10 8.759808672 5.315568646 9.202609419 5.154311513 8.104294535 1.884202504 8.863144439 5.706140193 0.7677456488 8.152738823

  18. Write and retrieve data chdir "C:/Data"; $fileId=`fopen "data.txt" "w"`; $num = 10; fprint $fileId ($num + " "); for($i=0; $i<$num; $i++) fprint $fileId (rand(10) + " "); fclose $fileId; chdir "C:/Data"; string $filename = "data.txt"; $fileId = `fopen $filename "r"`; string $s=`fgetword $fileId`; int $num = (int)$s; print($num + "\n"); for($i=0; $i<$num; $i++) { string $d=`fgetword $fileId`; print( $d + "\n"); } fclose $fileId; 10 8.759808672 5.315568646 9.202609419 5.154311513 8.104294535 1.884202504 8.863144439 5.706140193 0.7677456488 8.152738823 10 8.759808672 5.315568646 9.202609419 5.154311513 8.104294535 1.884202504 8.863144439 5.706140193 0.7677456488 8.152738823

  19. 5 7 87 87 87 81 81 81 92 92 92 65 65 65 60 60 60 55 55 55 17 17 17 82 82 82 66 66 66 81 81 81 82 82 82 121 121 121 164 164 164 159 159 159 92 92 92 68 68 68 88 88 88 104 104 104 155 155 155 208 208 208 201 201 201 86 86 86 75 75 75 122 122 122 145 145 145 172 172 172 198 198 198 168 168 168 67 67 67 77 77 77 158 158 158 190 190 190 195 195 195 211 211 211 188 188 188

  20. 5 7 87 87 87 81 81 81 92 92 92 65 65 65 60 60 60 55 55 55 17 17 17 82 82 82 66 66 66 81 81 81 82 82 82 121 121 121 164 164 164 159 159 159 92 92 92 68 68 68 88 88 88 104 104 104 155 155 155 208 208 208 201 201 201 86 86 86 75 75 75 122 122 122 145 145 145 172 172 172 198 198 198 168 168 168 67 67 67 77 77 77 158 158 158 190 190 190 195 195 195 211 211 211 188 188 188

  21. chdir "C:/Data"; int $fileId = `fopen "out.txt" "r"`; Open the file out.txt 5 7 87 87 87 81 81 81 92 92 92 65 65 65 60 60 60 55 55 55 17 17 17 82 82 82 66 66 66 81 81 81 82 82 82 121 121 121 164 164 164 159 159 159 92 92 92 68 68 68 88 88 88 104 104 104 155 155 155 208 208 208 201 201 201 86 86 86 75 75 75 122 122 122 145 145 145 172 172 172 198 198 198 168 168 168 67 67 67 77 77 77 158 158 158 190 190 190 195 195 195 211 211 211 188 188 188

  22. chdir "C:/Data"; int $fileId = `fopen "out.txt" "r"`; string $s=`fgetword $fileId`; //read the width int $width = (int)$s; // convert to an integer $s=`fgetword $fileId`; //read the height int $height = (int)$s; // convert to an integer int $size = $width * $height; int $dataSet[]; // declare an array to hold the values to be read Open the file Read the xm and ym values out.txt 5 7 87 87 87 81 81 81 92 92 92 65 65 65 60 60 60 55 55 55 17 17 17 82 82 82 66 66 66 81 81 81 82 82 82 121 121 121 164 164 164 159 159 159 92 92 92 68 68 68 88 88 88 104 104 104 155 155 155 208 208 208 201 201 201 86 86 86 75 75 75 122 122 122 145 145 145 172 172 172 198 198 198 168 168 168 67 67 67 77 77 77 158 158 158 190 190 190 195 195 195 211 211 211 188 188 188

  23. chdir "C:/Data"; int $fileId = `fopen "out.txt" "r"`; string $s=`fgetword $fileId`; //read the width int $width = (int)$s; // convert to an integer $s=`fgetword $fileId`; //read the height int $height = (int)$s; // convert to an integer int $size = $width * $height; int $dataSet[]; // declare an array to hold the values to be read for($i=0; $i<$size; $i++) { string $red = `fgetword $fileId`; // read Red string $green = `fgetword $fileId`; // read Green string $blue = `fgetword $fileId`; // read Blue float $av = ((float)$red + (float)$green + (float)$blue)/3.; $dataSet[$i] = (int)$av; // save the average } fclose $fileId; // close the file Open the file Read the xm and ym values Loop in and Retrieve the RGB values. Average and put in an array data[][] Close the file out.txt 5 7 87 87 87 81 81 81 92 92 92 65 65 65 60 60 60 55 55 55 17 17 17 82 82 82 66 66 66 81 81 81 82 82 82 121 121 121 164 164 164 159 159 159 92 92 92 68 68 68 88 88 88 104 104 104 155 155 155 208 208 208 201 201 201 86 86 86 75 75 75 122 122 122 145 145 145 172 172 172 198 198 198 168 168 168 67 67 67 77 77 77 158 158 158 190 190 190 195 195 195 211 211 211 188 188 188

  24. chdir "C:/Data"; int $fileId = `fopen "out.txt" "r"`; string $s=`fgetword $fileId`; //read the width int $width = (int)$s; // convert to an integer $s=`fgetword $fileId`; //read the height int $height = (int)$s; // convert to an integer int $size = $width * $height; int $dataSet[]; // declare an array to hold the values to be read for($i=0; $i<$size; $i++) { string $red = `fgetword $fileId`; // read Red string $green = `fgetword $fileId`; // read Green string $blue = `fgetword $fileId`; // read Blue float $av = ((float)$red + (float)$green + (float)$blue)/3.; $dataSet[$i] = (int)$av; // save the average } fclose $fileId; // close the file //create a plane the size of the data eval("nurbsPlane -d 1 -ax 0 0 1 -w 10 -u "+$width+" -v "+$height); Open the file Read the xm and ym values Loop in and Retrieve the RGB values. Average and put in an array data[][] Close the file Make a plane xm by ym out.txt 5 7 87 87 87 81 81 81 92 92 92 65 65 65 60 60 60 55 55 55 17 17 17 82 82 82 66 66 66 81 81 81 82 82 82 121 121 121 164 164 164 159 159 159 92 92 92 68 68 68 88 88 88 104 104 104 155 155 155 208 208 208 201 201 201 86 86 86 75 75 75 122 122 122 145 145 145 172 172 172 198 198 198 168 168 168 67 67 67 77 77 77 158 158 158 190 190 190 195 195 195 211 211 211 188 188 188

  25. chdir "C:/Data"; int $fileId = `fopen "out.txt" "r"`; string $s=`fgetword $fileId`; //read the width int $width = (int)$s; // convert to an integer $s=`fgetword $fileId`; //read the height int $height = (int)$s; // convert to an integer int $size = $width * $height; int $dataSet[]; // declare an array to hold the values to be read for($i=0; $i<$size; $i++) { string $red = `fgetword $fileId`; // read Red string $green = `fgetword $fileId`; // read Green string $blue = `fgetword $fileId`; // read Blue float $av = ((float)$red + (float)$green + (float)$blue)/3.; $dataSet[$i] = (int)$av; // save the average } fclose $fileId; // close the file //create a plane the size of the data eval("nurbsPlane -d 1 -ax 0 0 1 -w 10 -u "+$width+" -v "+$height); int $k=0; // use a counter to read from the array for($x=0; $x<$width; $x++) for($y=0; $y<$height; $y++){ select -r nurbsPlane1.cv[$x][$y] ; //select a cv sequentially int $val = $dataSet[$k]; // get the data (average) float $z = (float)$val/100; // assign it as height move -r 0 0 $z ; $k++; // increase the array counter }; Open the file Read the xm and ym values Loop in and Retrieve the RGB values. Average and put in an array data[][] Close the file Make a plane xm by ym Make the height of every cv equal to the array value data[][] out.txt 5 7 87 87 87 81 81 81 92 92 92 65 65 65 60 60 60 55 55 55 17 17 17 82 82 82 66 66 66 81 81 81 82 82 82 121 121 121 164 164 164 159 159 159 92 92 92 68 68 68 88 88 88 104 104 104 155 155 155 208 208 208 201 201 201 86 86 86 75 75 75 122 122 122 145 145 145 172 172 172 198 198 198 168 168 168 67 67 67 77 77 77 158 158 158 190 190 190 195 195 195 211 211 211 188 188 188

  26. Processing Code to Read JPG/GIF and create a text file with RGB values //Open the image file PImage myImage = loadImage("c:/data/test.jpg"); image(myImage, 0, 0); //display the image (also loads it in memory) Open the image and

  27. Processing Code to Read JPG/GIF and create a text file with RGB values //Open the image file PImage myImage = loadImage("c:/data/test.jpg"); image(myImage, 0, 0); //display the image (also loads it in memory) Open the image and

  28. Processing Code to Read JPG/GIF and create a text file with RGB values //Open the image file PImage myImage = loadImage("c:/data/test.jpg"); image(myImage, 0, 0); //display the image (also loads it in memory) int size = myImage.height*myImage.width; //get the number of pixels String list[] = newString[size+2]; //allocate memory for all pixels list[0] = myImage.width+""; list[1] = myImage.height+""; Open the image and get the width and height

  29. Processing Code to Read JPG/GIF and create a text file with RGB values //Open the image file PImage myImage = loadImage("c:/data/test.jpg"); image(myImage, 0, 0); //display the image (also loads it in memory) int size = myImage.height*myImage.width; //get the number of pixels String list[] = newString[size+2]; //allocate memory for all pixels list[0] = myImage.width+""; list[1] = myImage.height+""; int i=2; //initialize the counter for(int x=0; x<myImage.height; x++) for(int y=0; y<myImage.width; y++){ color c = get(x,y); //get the color of a pixel list[i] = (red(c) + " " + green(c) + " " + blue(c)); //store the color as a string i++; //increment the counter } Open the image and get the width and height Write the RGB values

  30. Processing Code to Read JPG/GIF and create a text file with RGB values //Open the image file PImage myImage = loadImage("c:/data/test.jpg"); image(myImage, 0, 0); //display the image (also loads it in memory) int size = myImage.height*myImage.width; //get the number of pixels String list[] = newString[size+2]; //allocate memory for all pixels list[0] = myImage.width+""; list[1] = myImage.height+""; int i=2; //initialize the counter for(int x=0; x<myImage.height; x++) for(int y=0; y<myImage.width; y++){ color c = get(x,y); //get the color of a pixel list[i] = (red(c) + " " + green(c) + " " + blue(c)); //store the color as a string i++; //increment the counter } // now write the strings to a file, each on a separate line saveStrings("c:/data/image.txt", list); Open the image and get the width and height Write the RGB values

More Related