Changeset 800 for trunk/vizservers/nanovis
- Timestamp:
- Aug 27, 2007 8:18:14 AM (17 years ago)
- Location:
- trunk/vizservers/nanovis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/NvZincBlendeReconstructor.cpp
r777 r800 1 #include <stdio.h> 2 #include <string.h> 1 3 #include "NvZincBlendeReconstructor.h" 2 4 #include "ZincBlendeVolume.h" … … 29 31 void* data = NULL; 30 32 31 ifstream stream;32 stream.open(fileName, ios::binary);33 std::ifstream stream; 34 stream.open(fileName, std::ios::binary); 33 35 34 36 ZincBlendeVolume* volume = loadFromStream(stream); … … 41 43 ZincBlendeVolume* NvZincBlendeReconstructor::loadFromStream(std::istream& stream) 42 44 { 45 ZincBlendeVolume* volume = 0; 43 46 Vector3 origin, delta; 44 47 double temp; 45 48 int width = 0, height = 0, depth = 0; 46 49 void* data = NULL; 50 int version = 1; 47 51 48 52 char str[5][20]; 49 53 do { 50 54 getLine(stream); 51 } while(strstr(buff, "object") == 0); 52 53 54 sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4],&width, &height, &depth); 55 getLine(stream); 56 sscanf(buff, "%s%f%f%f", str[0], &(origin.x), &(origin.y), &(origin.z)); 57 getLine(stream); 58 sscanf(buff, "%s%f%f%f", str[0], &(delta.x), &temp, &temp); 59 getLine(stream); 60 sscanf(buff, "%s%f%f%f", str[0], &temp, &(delta.y), &temp); 61 getLine(stream); 62 sscanf(buff, "%s%f%f%f", str[0], &temp, &temp, &(delta.z)); 63 64 do { 65 getLine(stream); 66 } while(strcmp(buff, "<\\HDR>") != 0); 67 68 69 width = width / 4; 70 height = height / 4; 71 depth = depth / 4; 72 data = new double[width * height * depth * 8 * 4]; // 8 atom per cell, 4 double (x, y, z, and probability) per atom 73 74 try { 55 if (buff[0] == '#') 56 { 57 continue; 58 } 59 else if (strstr((const char*) buff, "object") != 0) 60 { 61 version = 1; 62 break; 63 } 64 else if (strstr(buff, "record format") != 0) 65 { 66 version = 2; 67 break; 68 } 69 } while(1); 70 71 72 if (version == 1) 73 { 74 sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4],&width, &height, &depth); 75 getLine(stream); 76 sscanf(buff, "%s%f%f%f", str[0], &(origin.x), &(origin.y), &(origin.z)); 77 getLine(stream); 78 sscanf(buff, "%s%f%f%f", str[0], &(delta.x), &temp, &temp); 79 getLine(stream); 80 sscanf(buff, "%s%f%f%f", str[0], &temp, &(delta.y), &temp); 81 getLine(stream); 82 sscanf(buff, "%s%f%f%f", str[0], &temp, &temp, &(delta.z)); 83 do { 84 getLine(stream); 85 } while(strcmp(buff, "<\\HDR>") != 0); 86 87 width = width / 4; 88 height = height / 4; 89 depth = depth / 4; 90 //data = new double[width * height * depth * 8 * 4]; 91 data = malloc(width * height * depth * 8 * 4 * sizeof(double)); 92 // 8 atom per cell, 4 double (x, y, z, and probability) per atom 93 try { 94 stream.read((char*) data, width * height * depth * 8 * 4 * sizeof(double)); 95 } 96 catch (...) 97 { 98 printf("ERROR\n"); 99 } 100 101 volume = buildUp(origin, delta, width, height, depth, data); 102 103 free(data); 104 } 105 else if (version == 2) 106 { 107 const char* pt; 108 int datacount; 109 double emptyvalue; 110 do { 111 getLine(stream); 112 if ((pt = strstr(buff, "delta")) != 0) 113 { 114 sscanf(pt, "%s%f%f%f", str[0], &(delta.x), &(delta.y), &(delta.z)); 115 } 116 else if ((pt = strstr(buff, "datacount")) != 0) 117 { 118 sscanf(pt, "%s%d", str[0], &datacount); 119 } 120 else if ((pt = strstr(buff, "datatype")) != 0) 121 { 122 sscanf(pt, "%s%s", str[0], str[1]); 123 if (strcmp(str[1], "double64")) 124 { 125 } 126 } 127 else if ((pt = strstr(buff, "count")) != 0) 128 { 129 sscanf(pt, "%s%d%d%d", str[0], &width, &height, &depth); 130 } 131 else if ((pt = strstr(buff, "emptymark")) != 0) 132 { 133 sscanf(pt, "%s%lf", str[0], &emptyvalue); 134 } 135 else if ((pt = strstr(buff, "emprymark")) != 0) 136 { 137 sscanf(pt, "%s%lf", str[0], &emptyvalue); 138 } 139 } while(strcmp(buff, "<\\HDR>") != 0); 140 141 data = malloc(width * height * depth * 8 * 4 * sizeof(double)); 75 142 stream.read((char*) data, width * height * depth * 8 * 4 * sizeof(double)); 76 } 77 catch (...) 78 { 79 printf("ERROR\n"); 80 } 81 82 return buildUp(origin, delta, width, height, depth, data); 143 144 volume = buildUp(origin, delta, width, height, depth, datacount, emptyvalue, data); 145 free(data); 146 } 147 return volume; 83 148 } 84 149 … … 193 258 } 194 259 260 ZincBlendeVolume* NvZincBlendeReconstructor::buildUp(const Vector3& origin, const Vector3& delta, int width, int height, int depth, int datacount, double emptyvalue, void* data) 261 { 262 ZincBlendeVolume* zincBlendeVolume = NULL; 263 float *fourAnionVolume, *fourCationVolume; 264 int size = width * height * depth * 4; 265 fourAnionVolume = new float[size]; 266 fourCationVolume = new float[size]; 267 268 memset(fourAnionVolume, 0, size * sizeof(float)); 269 memset(fourCationVolume, 0, size * sizeof(float)); 270 271 _NvAtomInfo* srcPtr = (_NvAtomInfo*) data; 272 273 float* component4A, *component4B; 274 float vmin, vmax, nzero_min; 275 int index; 276 nzero_min = 1e23f; 277 vmin = vmax = srcPtr->atom; 278 int i; 279 for (i = 0; i < datacount; ++i) 280 { 281 282 index = srcPtr->getIndex(width, height); 283 component4A = fourAnionVolume + index; 284 component4B = fourCationVolume + index; 285 286 component4A[0] = (srcPtr->atom != emptyvalue)? (float) srcPtr->atom : 0.0f; srcPtr++; 287 component4A[1] = (srcPtr->atom != emptyvalue)? (float) srcPtr->atom : 0.0f; srcPtr++; 288 component4A[2] = (srcPtr->atom != emptyvalue)? (float) srcPtr->atom : 0.0f; srcPtr++; 289 component4A[3] = (srcPtr->atom != emptyvalue)? (float) srcPtr->atom : 0.0f; srcPtr++; 290 291 component4B[0] = (srcPtr->atom != emptyvalue)? (float) srcPtr->atom : 0.0f; srcPtr++; 292 component4B[1] = (srcPtr->atom != emptyvalue)? (float) srcPtr->atom : 0.0f; srcPtr++; 293 component4B[2] = (srcPtr->atom != emptyvalue)? (float) srcPtr->atom : 0.0f; srcPtr++; 294 component4B[3] = (srcPtr->atom != emptyvalue)? (float) srcPtr->atom : 0.0f; srcPtr++; 295 296 vmax = _NvMax3(_NvMax4(component4A), _NvMax4(component4B), vmax); 297 vmin = _NvMin3(_NvMin4(component4A), _NvMin4(component4B), vmin); 298 299 if (vmin != 0.0 && vmin < nzero_min) 300 { 301 nzero_min = vmin; 302 } 303 304 } 305 306 double dv = vmax - vmin; 307 if (vmax != 0.0f) 308 { 309 for (i=0; i < datacount; ++i) 310 { 311 fourAnionVolume[i] = (fourAnionVolume[i] - vmin)/ dv; 312 fourCationVolume[i] = (fourCationVolume[i] - vmin) / dv; 313 } 314 } 315 316 Vector3 cellSize; 317 cellSize.x = 0.25 / width; 318 cellSize.y = 0.25 / height; 319 cellSize.z = 0.25 / depth; 320 321 zincBlendeVolume = new ZincBlendeVolume(origin.x, origin.y, origin.z, 322 width, height, depth, 1, 4, 323 fourAnionVolume, fourCationVolume, 324 vmin, vmax, nzero_min, cellSize); 325 326 return zincBlendeVolume; 327 } 328 195 329 void NvZincBlendeReconstructor::getLine(std::istream& sin) 196 330 { -
trunk/vizservers/nanovis/NvZincBlendeReconstructor.h
r617 r800 80 80 */ 81 81 ZincBlendeVolume* buildUp(const Vector3& origin, const Vector3& delta, int width, int height, int depth, void* data); 82 ZincBlendeVolume* buildUp(const Vector3& origin, const Vector3& delta, int width, int height, int depth, int datacount, double emptyvalue, void* data); 82 83 }; 83 84
Note: See TracChangeset
for help on using the changeset viewer.