- Timestamp:
- Mar 10, 2009 9:30:01 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/data/flowvis_dx_files/convpro/main.cpp
r1305 r1308 4 4 5 5 struct Vector2 { 6 6 float x, y; 7 7 }; 8 8 9 9 void storeInOpenDX(const char* filename, Vector2* vector, int width, int height, int depth) 10 10 { 11 11 FILE* file = fopen(filename, "wb"); 12 12 13 int ori_width = width; 14 int ori_height = height; 15 if (ori_width > 512) width = 512; 16 if (ori_height > 512) height = 512; 13 int ori_width = width; 14 int ori_height = height; 17 15 18 int count = width * height; 19 int total_count = width * height * depth; 20 fprintf(file, "object 1 class gridpositions counts %d %d %d\n", width, height, depth); 21 fprintf(file, "origin 0 0 0\n"); 22 fprintf(file, "delta 50 0 0\n"); 23 fprintf(file, "delta 0 50 0\n"); 24 fprintf(file, "delta 0 0 50\n"); 25 fprintf(file, "object 2 class gridconnections counts %d %d %d\n", width, height, depth); 26 fprintf(file, "object 3 class array type double shape 3 rank 1 items %d data follows\n", total_count); 27 16 if (ori_width > 512) { 17 width = 512; 18 } 19 if (ori_height > 512) { 20 height = 512; 21 } 28 22 29 if (ori_width <= 512 && ori_height <= 512) 30 { 31 int dataindex = 0; 32 Vector2* ptr; 33 for (int z = 0; z < depth; ++z) 34 { 35 for (int y = 0; y < height; ++y) 36 { 37 for (int x = 0; x < width; ++x) 38 { 39 ptr = vector + (y * ori_width + x); 40 fprintf(file, "%f %f 0.0\n", ptr->x, ptr->y); 41 } 42 } 43 } 44 } 45 else 46 { 47 int offsetx = 0, offsety = 0; 48 if (ori_width > 512) { width = 512; offsetx = (ori_width - width) / 2;} 49 if (ori_height > 512) { height = 512; offsety = (ori_height - height) / 2;} 50 51 int dataindex = 0; 52 Vector2* ptr; 53 for (int z = 0; z < depth; ++z) 54 { 55 for (int y = 0; y < height; ++y) 56 { 57 for (int x = 0; x < width; ++x) 58 { 59 ptr = vector + ((y + offsety) * ori_width + x + offsetx); 60 fprintf(file, "%f %f 0.0\n", ptr->x, ptr->y); 61 } 62 } 63 } 64 } 23 int total_count = width * height * depth; 24 fprintf(file, "object 1 class gridpositions counts %d %d %d\n", width, height, depth); 25 fprintf(file, "origin 0 0 0\n"); 26 fprintf(file, "delta 50 0 0\n"); 27 fprintf(file, "delta 0 50 0\n"); 28 fprintf(file, "delta 0 0 50\n"); 29 fprintf(file, "object 2 class gridconnections counts %d %d %d\n", width, height, depth); 30 fprintf(file, "object 3 class array type double shape 3 rank 1 items %d data follows\n", total_count); 65 31 66 32 67 fclose(file); 33 if (ori_width <= 512 && ori_height <= 512) { 34 Vector2* ptr; 35 for (int z = 0; z < depth; ++z) { 36 for (int y = 0; y < height; ++y) { 37 for (int x = 0; x < width; ++x) { 38 ptr = vector + (y * ori_width + x); 39 fprintf(file, "%f %f 0.0\n", ptr->x, ptr->y); 40 } 41 } 42 } 43 } else { 44 int offsetx = 0, offsety = 0; 45 if (ori_width > 512) { 46 width = 512; 47 offsetx = (ori_width - width) / 2; 48 } 49 if (ori_height > 512) { 50 height = 512; 51 offsety = (ori_height - height) / 2; 52 } 53 54 Vector2* ptr; 55 for (int z = 0; z < depth; ++z) { 56 for (int y = 0; y < height; ++y) { 57 for (int x = 0; x < width; ++x) { 58 ptr = vector + ((y + offsety) * ori_width + x + offsetx); 59 fprintf(file, "%f %f 0.0\n", ptr->x, ptr->y); 60 } 61 } 62 } 63 } 64 65 fprintf(file, "attribute \"dep\" string \"positions\"\n"); 66 fprintf(file, "object \"regular positions regular connections\" class field\n"); 67 fprintf(file, "component \"positions\" value 1\n"); 68 fprintf(file, "component \"connections\" value 2\n"); 69 fprintf(file, "component \"data\" value 3\n"); 70 71 fclose(file); 68 72 } 69 73 70 74 int main(int argc, char* argv[]) 71 75 { 72 #if 0 73 if (argc < 6) 74 { 75 printf("usage: mat2dx <Ix ascii filename> <Iy ascii filename> <width> <height> <depth>\n"); 76 } 77 FILE* xComp = fopen(argv[1], "rb"); 78 FILE* yComp = fopen(argv[2], "rb"); 79 int width = 610, height = 218; 80 width = atoi(argv[3]); 81 height = atoi(argv[4]); 82 depth = atoi(argv[5]); 83 #else 84 //int width =218, height = 610;(?) 85 int width =610, height = 218; 86 int depth = 50; 87 FILE* xComp = fopen("Ix_data.txt", "rb"); 88 FILE* yComp = fopen("Iy_data.txt", "rb"); 89 #endif 90 Vector2* data = new Vector2[width * height]; 76 // int width = 218; 77 int width = 610; 91 78 92 int index = 0; 93 char buff[256]; 94 for (int y = 0; y < height; ++y) 95 { 96 for (int x = 0; x < width; ++x) 97 { 98 fscanf(xComp, "%s", buff); 99 if (strcmp(buff, "NaN") == 0) 100 { 101 data[index].x = 0; 102 } 103 else 104 { 105 data[index].x = atof(buff); 106 } 79 // int height = 610; 80 int height = 218; 81 82 int depth = 1; 83 // int depth = 50; 84 85 FILE* xComp = fopen("Ix_data.txt", "rb"); 86 FILE* yComp = fopen("Iy_data.txt", "rb"); 87 Vector2* data = new Vector2[width * height]; 88 89 int index = 0; 90 char buff[256]; 91 for (int y = 0; y < height; ++y) { 92 for (int x = 0; x < width; ++x) { 93 fscanf(xComp, "%s", buff); 94 if (strcmp(buff, "NaN") == 0) { 95 data[index].x = 0; 96 } else { 97 data[index].x = atof(buff); 98 } 107 99 108 100 109 fscanf(xComp, "%s", buff); 110 if (strcmp(buff, "NaN") == 0) 111 { 112 data[index].y = 0; 113 } 114 else 115 { 116 data[index].y = atof(buff); 117 } 101 fscanf(xComp, "%s", buff); 102 if (strcmp(buff, "NaN") == 0) { 103 data[index].y = 0; 104 } else { 105 data[index].y = atof(buff); 106 } 118 107 119 120 108 ++index; 109 } 121 110 122 111 } 123 112 124 125 113 fclose(xComp); 114 fclose(yComp); 126 115 127 116 storeInOpenDX("flow2d.dx", data, width, height, depth); 128 117 }
Note: See TracChangeset
for help on using the changeset viewer.