Changeset 3605 for trunk/packages/vizservers/nanovis/FlowCmd.cpp
- Timestamp:
- Apr 2, 2013, 1:31:30 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/FlowCmd.cpp
r3598 r3605 25 25 #include "nvconf.h" 26 26 27 #include "nanovisServer.h" 27 28 #include "nanovis.h" 28 29 #include "CmdProc.h" 29 30 #include "Command.h" 31 #include "PPMWriter.h" 30 32 #include "FlowCmd.h" 31 33 #include "FlowTypes.h" … … 41 43 #include "Trace.h" 42 44 45 using namespace nv; 43 46 using namespace vrmath; 44 47 … … 231 234 return TCL_ERROR; 232 235 } 233 Rappture::Buffer buf ;236 Rappture::Buffer buf(nBytes); 234 237 TRACE("Flow data loading bytes: %d components: %d", nBytes, nComponents); 235 238 if (GetDataStream(interp, buf, nBytes) != TCL_OK) { 236 239 return TCL_ERROR; 237 240 } 241 char *bytes = (char *)buf.bytes(); 242 size_t length = buf.size(); 243 238 244 Rappture::Unirect3d *dataPtr; 239 245 dataPtr = new Rappture::Unirect3d(nComponents); 240 246 241 247 Flow *flow = (Flow *)clientData; 242 size_t length = buf.size();243 char *bytes = (char *)buf.bytes();244 248 if ((length > 4) && (strncmp(bytes, "<DX>", 4) == 0)) { 245 249 if (!dataPtr->importDx(result, nComponents, length - 4, bytes + 4)) { … … 292 296 { 293 297 char info[1024]; 294 ssize_t nWritten; 295 size_t length; 296 297 length = sprintf(info, "nv>data tag %s min %g max %g\n", 298 flow->name(), dataPtr->magMin(), dataPtr->magMax()); 299 nWritten = write(1, info, length); 300 assert(nWritten == (ssize_t)strlen(info)); 298 int length = 299 sprintf(info, "nv>data tag %s min %g max %g\n", 300 flow->name(), dataPtr->magMin(), dataPtr->magMax()); 301 #ifdef USE_THREADS 302 queueResponse(info, (size_t)length, Response::VOLATILE); 303 #else 304 if (SocketWrite(info, (size_t)length) < 0) { 305 return TCL_ERROR; 306 } 307 #endif 301 308 } 302 309 NanoVis::eventuallyRedraw(NanoVis::MAP_FLOWS); … … 1064 1071 1065 1072 static int 1066 ppmWriteToFile(Tcl_Interp *interp, const char *path, FlowVideoSwitches *switchesPtr)1067 {1068 int f;1069 1070 /* Open the named file for writing. */1071 f = creat(path, 0600);1072 if (f < 0) {1073 Tcl_AppendResult(interp, "can't open temporary image file \"", path,1074 "\": ", Tcl_PosixError(interp), (char *)NULL);1075 return TCL_ERROR;1076 }1077 // Generate the PPM binary file header1078 char header[200];1079 #define PPM_MAXVAL 2551080 sprintf(header, "P6 %d %d %d\n", switchesPtr->width, switchesPtr->height,1081 PPM_MAXVAL);1082 1083 size_t header_length = strlen(header);1084 size_t wordsPerRow = (switchesPtr->width * 24 + 31) / 32;1085 size_t bytesPerRow = wordsPerRow * 4;1086 size_t rowLength = switchesPtr->width * 3;1087 size_t numRecords = switchesPtr->height + 1;1088 1089 struct iovec *iov;1090 iov = (struct iovec *)malloc(sizeof(struct iovec) * numRecords);1091 1092 // Add the PPM image header.1093 iov[0].iov_base = header;1094 iov[0].iov_len = header_length;1095 1096 // Now add the image data, reversing the order of the rows.1097 int y;1098 unsigned char *srcRowPtr = NanoVis::screenBuffer;1099 /* Reversing the pointers for the image rows. PPM is top-to-bottom. */1100 for (y = switchesPtr->height; y >= 1; y--) {1101 iov[y].iov_base = srcRowPtr;1102 iov[y].iov_len = rowLength;1103 srcRowPtr += bytesPerRow;1104 }1105 if (writev(f, iov, numRecords) < 0) {1106 Tcl_AppendResult(interp, "writing image to \"", path, "\" failed: ",1107 Tcl_PosixError(interp), (char *)NULL);1108 free(iov);1109 close(f);1110 return TCL_ERROR;1111 }1112 close(f);1113 free(iov);1114 return TCL_OK;1115 }1116 1117 static int1118 1073 MakeImageFiles(Tcl_Interp *interp, char *tmpFileName, 1119 1074 FlowVideoSwitches *switchesPtr, bool *cancelPtr) 1120 1075 { 1121 1076 struct pollfd pollResults; 1122 pollResults.fd = fileno( NanoVis::stdin);1077 pollResults.fd = fileno(nv::g_fIn); 1123 1078 pollResults.events = POLLIN; 1124 1079 #define PENDING_TIMEOUT 10 /* milliseconds. */ … … 1160 1115 1161 1116 sprintf(tmpFileName + length, "/image%d.ppm", i); 1162 result = ppmWriteToFile(interp, tmpFileName, switchesPtr); 1117 result = nv::writePPMFile(tmpFileName, NanoVis::screenBuffer, 1118 switchesPtr->width, switchesPtr->height); 1163 1119 if (result != TCL_OK) { 1164 1120 break; … … 1230 1186 sprintf(cmd,"nv>image -type movie -token \"%s\" -bytes %lu\n", 1231 1187 token, (unsigned long)data.size()); 1232 NanoVis::sendDataToClient(cmd, data.bytes(), data.size());1188 nv::sendDataToClient(cmd, data.bytes(), data.size()); 1233 1189 return TCL_OK; 1234 1190 } … … 1292 1248 sprintf(tmpFileName + length, "/image%d.ppm", i); 1293 1249 unlink(tmpFileName); 1294 } 1250 } 1295 1251 tmpFileName[length] = '\0'; 1296 1252 rmdir(tmpFileName); … … 1343 1299 * associative array. 1344 1300 */ 1345 int 1346 FlowCmdInitProc(Tcl_Interp *interp) 1347 { 1348 Tcl_CreateObjCommand(interp, "flow", FlowCmdProc, NULL, NULL); 1349 return TCL_OK; 1350 } 1301 void 1302 FlowCmdInitProc(Tcl_Interp *interp, ClientData clientData) 1303 { 1304 Tcl_CreateObjCommand(interp, "flow", FlowCmdProc, clientData, NULL); 1305 }
Note: See TracChangeset
for help on using the changeset viewer.