Changeset 1515 for trunk/packages
- Timestamp:
- Jun 13, 2009, 1:02:51 PM (15 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/FlowCmd.cpp
r1510 r1515 4 4 #include <stddef.h> 5 5 #include <limits.h> 6 #include <poll.h> 6 7 #include <tcl.h> 7 8 #include "Switch.h" … … 1351 1352 } 1352 1353 1354 /* 1355 *--------------------------------------------------------------------------- 1356 * 1357 * VideoFormatSwitchProc -- 1358 * 1359 * Convert a Tcl_Obj representing the video format into its 1360 * integer id. 1361 * 1362 * Results: 1363 * The return value is a standard Tcl result. 1364 * 1365 *--------------------------------------------------------------------------- 1366 */ 1367 /*ARGSUSED*/ 1368 static int 1369 VideoFormatSwitchProc( 1370 ClientData clientData, /* Not used. */ 1371 Tcl_Interp *interp, /* Interpreter to send results back to */ 1372 const char *switchName, /* Not used. */ 1373 Tcl_Obj *objPtr, /* String representation */ 1374 char *record, /* Structure record */ 1375 int offset, /* Not used. */ 1376 int flags) /* Not used. */ 1377 { 1378 Rappture::AVTranslate::VideoFormats *formatPtr = 1379 (Rappture::AVTranslate::VideoFormats *)(record + offset); 1380 const char *string; 1381 char c; 1382 1383 string = Tcl_GetString(objPtr); 1384 c = string[0]; 1385 if ((c == 'm') && (strcmp(string, "mpeg") == 0)) { 1386 *formatPtr = Rappture::AVTranslate::MPEG1; 1387 } else if ((c == 't') && (strcmp(string, "theora") == 0)) { 1388 *formatPtr = Rappture::AVTranslate::THEORA; 1389 } else if ((c == 'm') && (strcmp(string, "mov") == 0)) { 1390 *formatPtr = Rappture::AVTranslate::QUICKTIME; 1391 } else { 1392 Tcl_AppendResult(interp, "bad video format \"", string, 1393 "\": should be mpeg, theora, or mov", (char*)NULL); 1394 } 1395 return TCL_ERROR; 1396 } 1397 1353 1398 static int 1354 1399 FlowConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc, … … 1874 1919 } 1875 1920 1921 struct FlowVideoValues { 1922 float frameRate; /* Frame rate */ 1923 int bitRate; /* Video bitrate */ 1924 int width, height; /* Dimensions of video frame. */ 1925 int nFrames; 1926 Rappture::AVTranslate::VideoFormats format; 1927 }; 1928 1929 static Rappture::SwitchParseProc VideoFormatSwitchProc; 1930 static Rappture::SwitchCustom videoFormatSwitch = { 1931 VideoFormatSwitchProc, NULL, 0, 1932 }; 1933 1934 Rappture::SwitchSpec FlowCmd::videoSwitches[] = { 1935 {Rappture::SWITCH_FLOAT, "-bitrate", "value", 1936 offsetof(FlowVideoValues, bitRate), 0}, 1937 {Rappture::SWITCH_CUSTOM, "-format", "string", 1938 offsetof(FlowVideoValues, format), 0, 0, &videoFormatSwitch}, 1939 {Rappture::SWITCH_FLOAT, "-framerate", "value", 1940 offsetof(FlowVideoValues, frameRate), 0}, 1941 {Rappture::SWITCH_INT, "-height", "integer", 1942 offsetof(FlowVideoValues, height), 0}, 1943 {Rappture::SWITCH_INT, "-numframes", "count", 1944 offsetof(FlowVideoValues, nFrames), 0}, 1945 {Rappture::SWITCH_INT, "-width", "integer", 1946 offsetof(FlowVideoValues, width), 0}, 1947 {Rappture::SWITCH_END} 1948 }; 1949 1876 1950 static int 1877 1951 FlowVideoOp(ClientData clientData, Tcl_Interp *interp, int objc, 1878 1952 Tcl_Obj *const *objv) 1879 1953 { 1880 int width, height; // Resolution of video. 1881 int numFrames; // Total number of frames. 1882 float frameRate; // Frame rate of the video. 1883 float bitRate; // Bit rate of the vide. 1884 1885 if ((Tcl_GetIntFromObj(interp, objv[2], &width) != TCL_OK) || 1886 (Tcl_GetIntFromObj(interp, objv[3], &height) != TCL_OK) || 1887 (Tcl_GetIntFromObj(interp, objv[4], &numFrames) != TCL_OK) || 1888 (GetFloatFromObj(interp, objv[5], &frameRate) != TCL_OK) || 1889 (GetFloatFromObj(interp, objv[6], &bitRate) != TCL_OK)) { 1890 return TCL_ERROR; 1891 } 1892 if ((width<0) || (width>SHRT_MAX) || (height<0) || (height>SHRT_MAX)) { 1954 struct pollfd pollResults; 1955 int timeout; 1956 1957 pollResults.fd = fileno(NanoVis::stdin); 1958 pollResults.events = POLLIN; 1959 1960 #define PENDING_TIMEOUT 10 /* milliseconds. */ 1961 timeout = PENDING_TIMEOUT; 1962 1963 FlowVideoValues values; 1964 const char *token; 1965 1966 token = Tcl_GetString(objv[2]); 1967 values.frameRate = 25.0f; // Default frame rate 25 fps 1968 values.bitRate = 6.0e+6f; // Default video bit rate. 1969 values.width = NanoVis::win_width; 1970 values.height = NanoVis::win_height; 1971 values.nFrames = 100; 1972 values.format = Rappture::AVTranslate::MPEG1; 1973 if (Rappture::ParseSwitches(interp, FlowCmd::videoSwitches, 1974 objc - 2, objv + 2, &values, SWITCH_DEFAULTS) < 0) { 1975 return TCL_ERROR; 1976 } 1977 if ((values.width < 0) || (values.width > SHRT_MAX) || 1978 (values.height < 0) || (values.height > SHRT_MAX)) { 1893 1979 Tcl_AppendResult(interp, "bad dimensions for video", (char *)NULL); 1894 1980 return TCL_ERROR; 1895 1981 } 1896 if ((frameRate < 0.0f) || (frameRate > 30.0f)) { 1897 Tcl_AppendResult(interp, "bad frame rate \"", Tcl_GetString(objv[5]), 1898 "\"", (char *)NULL); 1899 return TCL_ERROR; 1900 } 1901 if ((bitRate < 0.0f) || (frameRate > 30.0f)) { 1902 Tcl_AppendResult(interp, "bad bit rate \"", Tcl_GetString(objv[6]), 1903 "\"", (char *)NULL); 1982 if ((values.frameRate < 0.0f) || (values.frameRate > 30.0f)) { 1983 Tcl_AppendResult(interp, "bad frame rate.", (char *)NULL); 1984 return TCL_ERROR; 1985 } 1986 if (values.bitRate < 0.0f) { 1987 Tcl_AppendResult(interp, "bad bit rate.", (char *)NULL); 1904 1988 return TCL_ERROR; 1905 1989 } 1906 1990 if (NanoVis::licRenderer == NULL) { 1907 1991 Tcl_AppendResult(interp, "no lic renderer.", (char *)NULL); 1908 return TCL_ERROR;1909 }1910 if (NanoVis::flowVisRenderer == NULL) {1911 Tcl_AppendResult(interp, "no flow renderer.", (char *)NULL);1912 1992 return TCL_ERROR; 1913 1993 } … … 1917 1997 oldHeight = NanoVis::win_height; 1918 1998 1919 char fileName[200];1920 sprintf(fileName,"/tmp/flow%d.mpeg", getpid());1921 1922 1999 Trace("FLOW started\n"); 1923 2000 1924 2001 Rappture::Outcome context; 1925 2002 1926 Rappture::AVTranslate movie(width, height, bitRate, frameRate); 1927 if (!movie.init(context, fileName)) { 1928 Tcl_AppendResult(interp, "can't initialized movie \"", fileName, 1929 "\": ", context.remark(), (char *)NULL); 1930 return TCL_ERROR; 1931 } 1932 if ((width != oldWidth) || (height != oldHeight)) { 2003 Rappture::AVTranslate movie(values.width, values.height, values.bitRate, 2004 values.frameRate); 2005 char tmpFileName[200]; 2006 sprintf(tmpFileName,"/tmp/flow%d.mpeg", getpid()); 2007 if (!movie.init(context, tmpFileName)) { 2008 Tcl_AppendResult(interp, "can't initialized movie \"", tmpFileName, 2009 "\": ", context.remark(), (char *)NULL); 2010 return TCL_ERROR; 2011 } 2012 if ((values.width != oldWidth) || (values.height != oldHeight)) { 1933 2013 // Resize to the requested size. 1934 NanoVis::resize_offscreen_buffer( width,height);2014 NanoVis::resize_offscreen_buffer(values.width, values.height); 1935 2015 } 1936 2016 // Now compute the line padding for the offscreen buffer. 1937 2017 int pad = 0; 1938 if (( 3*NanoVis::win_width) % 4 > 0) {1939 pad = 4 - ((3* NanoVis::win_width) % 4);2018 if (( 3 * values.width) % 4 > 0) { 2019 pad = 4 - ((3* values.width) % 4); 1940 2020 } 1941 2021 NanoVis::ResetFlows(); 1942 for (int i = 0; i < numFrames; i++) { 1943 // Generate the latest frame and send it back to the client 2022 bool canceled = false; 2023 for (int i = 0; i < values.nFrames; i++) { 2024 if (poll(&pollResults, 1, 0 /* No Timeout */) > 0) { 2025 /* If there's another command on stdin, that means the client is 2026 * trying to cancel this operation. */ 2027 canceled = true; 2028 break; 2029 } 1944 2030 NanoVis::licRenderer->convolve(); 1945 2031 NanoVis::AdvectFlows(); … … 1947 2033 NanoVis::offscreen_buffer_capture(); //enable offscreen render 1948 2034 NanoVis::display(); 1949 1950 2035 NanoVis::read_screen(); 1951 2036 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1952 1953 // This is done before bmp_write_to_file because bmp_write_to_file1954 // turns rgb data to bgr1955 2037 movie.append(context, NanoVis::screen_buffer, pad); 1956 // NanoVis::bmp_write_to_file(frame_count, fileName); 1957 } 1958 2038 } 1959 2039 movie.done(context); 1960 2040 Trace("FLOW end\n"); 1961 1962 // FIXME: find a way to get the data from the movie object as a void* 1963 Rappture::Buffer data; 1964 if (!data.load(context, fileName)) {1965 Tcl_AppendResult(interp, "can't load data from temporary moviefile \"",1966 fileName, "\": ", context.remark(), (char *)NULL);1967 return TCL_ERROR;1968 1969 1970 1971 1972 1973 1974 1975 1976 if (( width != oldWidth) || (height != oldHeight)) {2041 if (!canceled) { 2042 Rappture::Buffer data; 2043 // FIXME: find a way to get the data from the movie object as a void* 2044 if (!data.load(context, tmpFileName)) { 2045 Tcl_AppendResult(interp, "can't load data from temporary file \"", 2046 tmpFileName, "\": ", context.remark(), (char *)NULL); 2047 return TCL_ERROR; 2048 } 2049 2050 // Build the command string for the client. 2051 char command[200]; 2052 sprintf(command,"nv>image -bytes %lu -type movie -token \"%s\"\n", 2053 (unsigned long)data.size(), Tcl_GetString(objv[7])); 2054 NanoVis::sendDataToClient(command, data.bytes(), data.size()); 2055 } 2056 if ((values.width != oldWidth) || (values.height != oldHeight)) { 1977 2057 // Restore to the old size. 1978 2058 NanoVis::resize_offscreen_buffer(oldWidth, oldHeight); … … 1980 2060 NanoVis::ResetFlows(); 1981 2061 NanoVis::licRenderer->make_patterns(); 1982 if (unlink( fileName) != 0) {2062 if (unlink(tmpFileName) != 0) { 1983 2063 Tcl_AppendResult(interp, "can't unlink temporary movie file \"", 1984 fileName, "\": ", Tcl_PosixError(interp), (char *)NULL);2064 tmpFileName, "\": ", Tcl_PosixError(interp), (char *)NULL); 1985 2065 return TCL_ERROR; 1986 2066 } -
trunk/packages/vizservers/nanovis/FlowCmd.h
r1510 r1515 187 187 void RenderBoxes(void); 188 188 public: 189 static Rappture::SwitchSpec videoSwitches[]; 189 190 enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z }; 190 191 FlowCmd(Tcl_Interp *interp, const char *name, Tcl_HashEntry *hPtr); -
trunk/packages/vizservers/nanovis/Lic.cpp
r1510 r1515 23 23 24 24 Lic::Lic(int _size, int _width, int _height, float _offset, 25 CGcontext _context, GLuint _vector _field,25 CGcontext _context, GLuint _vectorField, 26 26 float scalex, float scaley, float scalez): 27 27 Renderable(Vector3(0.,0.,0.)), … … 96 96 m_plane_normal_param_render_vel = cgGetNamedParameter(m_render_vel_fprog, 97 97 "plane_normal"); 98 cgGLSetTextureParameter(m_vel_tex_param_render_vel, _vector _field);98 cgGLSetTextureParameter(m_vel_tex_param_render_vel, _vectorField); 99 99 100 100 get_slice(); -
trunk/packages/vizservers/nanovis/Lic.h
r1510 r1515 61 61 GLuint fbo, vel_fbo, slice_vector_tex; //for projecting 3d vector to 2d vector on a plane 62 62 63 Volume* vector_field;63 Volume* _vectorField; 64 64 65 65 public: … … 67 67 //the inherited Vector3 location is its center 68 68 Lic(int _size, int _width, int _height, float _offset, 69 CGcontext _context, GLuint _vector _field,69 CGcontext _context, GLuint _vectorField, 70 70 float scalex, float scaley, float scalez); 71 71 ~Lic(); -
trunk/packages/vizservers/nanovis/NvLIC.cpp
r1510 r1515 41 41 max(1.0f), 42 42 m_g_context(_context), 43 vectorFieldID(0),43 _vectorFieldId(0), 44 44 _activate(false) 45 45 { … … 248 248 249 249 glEnable(GL_TEXTURE_3D); 250 glBindTexture(GL_TEXTURE_3D, vectorFieldID);250 glBindTexture(GL_TEXTURE_3D, _vectorFieldId); 251 251 cgGLBindProgram(m_render_vel_fprog); 252 252 253 cgGLSetTextureParameter(m_vel_tex_param_render_vel, vectorFieldID);253 cgGLSetTextureParameter(m_vel_tex_param_render_vel, _vectorFieldId); 254 254 cgGLEnableTextureParameter(m_vel_tex_param_render_vel); 255 255 cgGLSetParameter4f(m_plane_normal_param_render_vel, 1., 1., 0., 0); … … 310 310 NvLIC::convolve() 311 311 { 312 if ( vectorFieldID== 0) {312 if (_vectorFieldId == 0) { 313 313 return; 314 314 } … … 419 419 NvLIC::display() 420 420 { 421 if ( vectorFieldID== 0) {421 if (_vectorFieldId == 0) { 422 422 return; 423 423 } … … 506 506 { 507 507 Trace("NvLIC: vector field is assigned [%d]\n", texID); 508 vectorFieldID= texID;508 _vectorFieldId = texID; 509 509 origin = ori; 510 510 scale = Vector3(scaleX, scaleY, scaleZ); -
trunk/packages/vizservers/nanovis/NvLIC.h
r1510 r1515 38 38 39 39 private: 40 unsignedint disListID;40 GLuint disListID; 41 41 42 42 int width, height; … … 71 71 GLuint fbo, vel_fbo, slice_vector_tex; // For projecting 3d vector to 2d 72 72 // vector on a plane. 73 GLuint vectorFieldID;73 GLuint _vectorFieldId; 74 74 75 Volume* vector_field;75 Volume* _vectorField; 76 76 /** 77 77 * flag for rendering … … 82 82 Vector3 normal; //the normal vector of the NvLIC plane, 83 83 //the inherited Vector3 location is its center 84 NvLIC(int _size, int _width, int _height, int axis, const Vector3& _offset, CGcontext _context); 84 NvLIC(int _size, int _width, int _height, int axis, 85 const Vector3& _offset, CGcontext _context); 85 86 ~NvLIC(); 86 87 -
trunk/packages/vizservers/nanovis/NvVectorField.cpp
r1431 r1515 4 4 5 5 NvVectorField::NvVectorField() : 6 _vectorFieldI D(0),6 _vectorFieldId(0), 7 7 _activated(true), 8 8 _scaleX(1), … … 36 36 _scaleZ = scaleZ; 37 37 _max = max; 38 _vectorFieldI D= volPtr->id;38 _vectorFieldId = volPtr->id; 39 39 _physicalMin = volPtr->getPhysicalBBoxMin(); 40 40 printf("_pysicalMin %f %f %f\n", _physicalMin.x, _physicalMin.y, _physicalMin.z); … … 107 107 } 108 108 109 renderer->setVectorField(_vectorFieldI D, _origin, _scaleX, _scaleY, _scaleZ, _max);109 renderer->setVectorField(_vectorFieldId, _origin, _scaleX, _scaleY, _scaleZ, _max); 110 110 if (renderer) { 111 111 renderer->initialize(); -
trunk/packages/vizservers/nanovis/NvVectorField.h
r1431 r1515 22 22 23 23 class NvVectorField { 24 unsigned int _vectorFieldID;24 GLuint _vectorFieldId; 25 25 Volume* _volPtr; 26 26 std::map<std::string, NvParticleRenderer*> _particleRendererMap; -
trunk/packages/vizservers/nanovis/RpAVTranslate.h
r1351 r1515 33 33 class AVTranslate { 34 34 public: 35 enum VideoFormats { MPEG1, MPEG4, THEORA, QUICKTIME }; 35 36 AVTranslate(size_t width, size_t height); 36 37 -
trunk/packages/vizservers/nanovis/nanovis.h
r1510 r1515 1 1 2 /* 2 3 * ----------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.