- Timestamp:
- Aug 27, 2014, 1:08:53 PM (10 years ago)
- Location:
- geovis/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
geovis/trunk/Makefile.in
r4376 r4628 5 5 USE_THREADS = yes 6 6 USE_READ_THREAD = #yes 7 USE_CACHE = yes 8 USE_OSGEARTH_TRUNK = #yes 9 USE_THROTTLING_SLEEP = #yes 10 SLEEP_AFTER_QUEUE_FRAME = yes 7 11 8 12 bindir = @bindir@ … … 95 99 DEFINES += -DUSE_READ_THREAD 96 100 endif 101 ifdef USE_CACHE 102 DEFINES += -DUSE_CACHE 103 endif 104 ifdef USE_OSGEARTH_TRUNK 105 DEFINES += -DUSE_OSGEARTH_TRUNK 106 endif 107 ifdef USE_THROTTLING_SLEEP 108 DEFINES += -DUSE_THROTTLING_SLEEP 109 endif 110 ifdef SLEEP_AFTER_QUEUE_FRAME 111 DEFINES += -DSLEEP_AFTER_QUEUE_FRAME 112 endif 97 113 98 114 CXX_SWITCHES = $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(DEFINES) $(INCLUDES) -
geovis/trunk/RenderServer.cpp
r4424 r4628 367 367 for (;;) { 368 368 long timeout = g_renderer->getTimeout(); 369 #ifdef SLEEP_AFTER_QUEUE_FRAME 370 g_renderer->markFrameStart(); 371 #endif 369 372 int cmdStatus = processCommands(interp, NULL, g_inBufPtr, g_fdOut, timeout); 370 373 if (cmdStatus < 0) … … 391 394 g_stats.nFrameBytes += imgData->s() * imgData->t() * 3; 392 395 } 396 #ifdef SLEEP_AFTER_QUEUE_FRAME 397 g_renderer->markFrameEnd(); 398 #endif 393 399 } else { 394 400 //TRACE("No render required"); -
geovis/trunk/Renderer.cpp
r4575 r4628 20 20 #include <sys/time.h> 21 21 #endif 22 23 //#define USE_OSGEARTH_TRUNK24 #define USE_CACHE25 22 26 23 #include <osgDB/FileUtils> … … 89 86 _bgColor[1] = 0; 90 87 _bgColor[2] = 0; 91 _minFrameTime = 1.0/30.0; 88 //setMaximumFrameRateInHertz(15.0); 89 // 100MBit 90 setMaximumBitrate(1.0e8); 92 91 _lastFrameTime = _minFrameTime; 92 TRACE("Bandwidth target: %.2f MBit", (float)(getMaximumBitrate()/1.0e6)); 93 TRACE("Frame rate target: %.2f Hz", (float)getMaximumFrameRateInHertz()); 93 94 94 95 char *base = getenv("MAP_BASE_URI"); … … 1026 1027 } 1027 1028 1028 voidRenderer::addImageLayer(const char *name,1029 bool Renderer::addImageLayer(const char *name, 1029 1030 osgEarth::TileSourceOptions& opts, 1030 1031 bool makeShared, … … 1033 1034 if (!_map.valid()) { 1034 1035 ERROR("No map"); 1035 return ;1036 return false; 1036 1037 } 1037 1038 TRACE("layer: %s", name); … … 1046 1047 layerOpts.visible() = false; 1047 1048 } 1048 _map->addImageLayer(new osgEarth::ImageLayer(layerOpts)); 1049 osg::ref_ptr<osgEarth::ImageLayer> layer = new osgEarth::ImageLayer(layerOpts); 1050 _map->addImageLayer(layer.get()); 1051 if (layer->getTileSource() == NULL || !layer->getTileSource()->isOK()) { 1052 ERROR("Failed to add image layer: %s", name); 1053 _map->removeImageLayer(layer.get()); 1054 return false; 1055 } 1049 1056 _needsRedraw = true; 1057 return true; 1050 1058 } 1051 1059 … … 1307 1315 TRACE("Setting window size to %dx%d", width, height); 1308 1316 1317 double origBitrate = getMaximumBitrate(); 1318 1309 1319 _windowWidth = width; 1310 1320 _windowHeight = height; 1321 1322 setMaximumBitrate(origBitrate); 1323 TRACE("Bandwidth target: %.2f MBit", (float)(getMaximumBitrate()/1.0e6)); 1324 TRACE("Frame rate target: %.2f Hz", (float)getMaximumFrameRateInHertz()); 1325 1311 1326 if (_viewer.valid()) { 1312 1327 #ifdef USE_OFFSCREEN_RENDERING … … 1647 1662 } 1648 1663 1664 void Renderer::markFrameStart() 1665 { 1666 _startFrameTime = osg::Timer::instance()->tick(); 1667 } 1668 1669 void Renderer::markFrameEnd() 1670 { 1671 osg::Timer_t endFrameTick = osg::Timer::instance()->tick(); 1672 _lastFrameTime = osg::Timer::instance()->delta_s(_startFrameTime, endFrameTick); 1673 TRACE("Frame time: %g sec", _lastFrameTime); 1674 #ifdef USE_THROTTLING_SLEEP 1675 if (_lastFrameTime < _minFrameTime) { 1676 TRACE("Sleeping for %g secs", _minFrameTime - _lastFrameTime); 1677 OpenThreads::Thread::microSleep(static_cast<unsigned int>(1000000.0*(_minFrameTime - _lastFrameTime))); 1678 } 1679 #endif 1680 } 1681 1649 1682 /** 1650 1683 * \brief Cause the rendering to render a new image if needed … … 1657 1690 if (_viewer.valid() && checkNeedToDoFrame()) { 1658 1691 TRACE("Enter needsRedraw=%d", _needsRedraw ? 1 : 0); 1692 #ifndef SLEEP_AFTER_QUEUE_FRAME 1659 1693 osg::Timer_t startFrameTick = osg::Timer::instance()->tick(); 1694 #endif 1660 1695 TRACE("Before frame()"); 1661 1696 _viewer->frame(); 1662 1697 TRACE("After frame()"); 1698 #ifndef SLEEP_AFTER_QUEUE_FRAME 1663 1699 osg::Timer_t endFrameTick = osg::Timer::instance()->tick(); 1664 1700 _lastFrameTime = osg::Timer::instance()->delta_s(startFrameTick, endFrameTick); 1665 1701 TRACE("Frame time: %g sec", _lastFrameTime); 1666 #if 0 1667 if (frameTime < minFrameTime) { 1668 TRACE("Sleeping for %g secs", minFrameTime-frameTime); 1669 OpenThreads::Thread::microSleep(static_cast<unsigned int>(1000000.0*(minFrameTime-frameTime))); 1670 } 1702 #ifdef USE_THROTTLING_SLEEP 1703 if (_lastFrameTime < _minFrameTime) { 1704 TRACE("Sleeping for %g secs", _minFrameTime - _lastFrameTime); 1705 OpenThreads::Thread::microSleep(static_cast<unsigned int>(1000000.0*(_minFrameTime - _lastFrameTime))); 1706 } 1707 #endif 1671 1708 #endif 1672 1709 #ifdef WANT_TRACE -
geovis/trunk/Renderer.h
r4575 r4628 191 191 } 192 192 193 voidaddImageLayer(const char *name, osgEarth::TileSourceOptions& opts,193 bool addImageLayer(const char *name, osgEarth::TileSourceOptions& opts, 194 194 bool makeShared = false, bool visible = true); 195 195 … … 358 358 bool invertY = true); 359 359 360 void setMaximumFrameRateInHertz(double rate) 361 { 362 if (rate > 60.0) 363 rate = 60.0; 364 if (rate < 0.25) 365 rate = 0.25; 366 _minFrameTime = 1.0/rate; 367 } 368 369 void setMaximumBitrate(double bitsPerSecond) 370 { 371 unsigned long bitsPerFrame = (_windowWidth * _windowHeight * 3 + 16) * 8; 372 double fps = bitsPerSecond / ((double)bitsPerFrame); 373 setMaximumFrameRateInHertz(fps); 374 } 375 376 double getMaximumFrameRateInHertz() 377 { 378 return (1.0/_minFrameTime); 379 } 380 381 double getMaximumBitrate() 382 { 383 unsigned long bitsPerFrame = (_windowWidth * _windowHeight * 3 + 16) * 8; 384 return ((double)bitsPerFrame * getMaximumFrameRateInHertz()); 385 } 386 387 void markFrameStart(); 388 389 void markFrameEnd(); 390 360 391 long getTimeout(); 361 392 … … 399 430 double _minFrameTime; 400 431 double _lastFrameTime; 432 osg::Timer_t _startFrameTime; 401 433 402 434 ColorMapHashmap _colorMaps; -
geovis/trunk/RendererCmd.cpp
r4575 r4628 666 666 667 667 static int 668 FilePutOp(ClientData clientData, Tcl_Interp *interp, int objc, 669 Tcl_Obj *const *objv) 670 { 671 long size; 672 const char *path = Tcl_GetString(objv[2]); 673 if (Tcl_GetLongFromObj(interp, objv[4], &size) != TCL_OK || 674 size < 1) { 675 return TCL_ERROR; 676 } 677 char *data = (char *)malloc((size_t)size); 678 if (!SocketRead(data, size)) { 679 free(data); 680 return TCL_ERROR; 681 } 682 std::ostringstream fullPath; 683 //fullPath << "/tmp/" << path; 684 fullPath << path; 685 FILE *fp = fopen(fullPath.str().c_str(), "wb"); 686 if (fp == NULL) { 687 free(data); 688 return TCL_ERROR; 689 } 690 int bytesWritten = fwrite(data, 1, (size_t)size, fp); 691 fclose(fp); 692 free(data); 693 return (bytesWritten == size) ? TCL_OK : TCL_ERROR; 694 } 695 696 static CmdSpec fileOps[] = { 697 {"put", 1, FilePutOp, 5, 5, "name type size"} 698 }; 699 static int nFileOps = NumCmdSpecs(fileOps); 700 701 static int 702 FileCmd(ClientData clientData, Tcl_Interp *interp, int objc, 703 Tcl_Obj *const *objv) 704 { 705 Tcl_ObjCmdProc *proc; 706 707 proc = GetOpFromObj(interp, nFileOps, fileOps, 708 CMDSPEC_ARG1, objc, objv, 0); 709 if (proc == NULL) { 710 return TCL_ERROR; 711 } 712 return (*proc) (clientData, interp, objc, objv); 713 } 714 715 static int 668 716 ImageFlushCmd(ClientData clientData, Tcl_Interp *interp, int objc, 669 717 Tcl_Obj *const *objv) … … 804 852 char *type = Tcl_GetString(objv[3]); 805 853 if (type[0] == 'i' && strcmp(type, "image") == 0) { 854 bool ret; 855 char *name; 806 856 char *driver = Tcl_GetString(objv[4]); 807 857 std::string url; … … 817 867 if (driver[0] == 'd' && strcmp(driver, "debug") == 0) { 818 868 osgEarth::Drivers::DebugOptions opts; 819 char *name = Tcl_GetString(objv[5]);820 g_renderer->addImageLayer(name, opts);869 name = Tcl_GetString(objv[5]); 870 ret = g_renderer->addImageLayer(name, opts); 821 871 } else if (driver[0] == 'g' && strcmp(driver, "gdal") == 0) { 822 872 osgEarth::Drivers::GDALOptions opts; 823 873 opts.url() = url; 824 char *name = Tcl_GetString(objv[6]);825 g_renderer->addImageLayer(name, opts);874 name = Tcl_GetString(objv[6]); 875 ret = g_renderer->addImageLayer(name, opts); 826 876 } else if (driver[0] == 't' && strcmp(driver, "tms") == 0) { 827 877 osgEarth::Drivers::TMSOptions opts; … … 831 881 //opts.tmsType() = tmsType; 832 882 //opts.format() = format; 833 char *name = Tcl_GetString(objv[6]);834 g_renderer->addImageLayer(name, opts);883 name = Tcl_GetString(objv[6]); 884 ret = g_renderer->addImageLayer(name, opts); 835 885 } else if (driver[0] == 'w' && strcmp(driver, "wms") == 0) { 836 886 osgEarth::Drivers::WMSOptions opts; … … 846 896 opts.transparent() = transparent; 847 897 848 char *name = Tcl_GetString(objv[9]);849 g_renderer->addImageLayer(name, opts);898 name = Tcl_GetString(objv[9]); 899 ret = g_renderer->addImageLayer(name, opts); 850 900 } else if (driver[0] == 'x' && strcmp(driver, "xyz") == 0) { 851 901 osgEarth::Drivers::XYZOptions opts; … … 855 905 //opts.invertY() = invertY; 856 906 //opts.format() = Tcl_GetString(objv[6]); 857 char *name = Tcl_GetString(objv[6]);858 g_renderer->addImageLayer(name, opts);907 name = Tcl_GetString(objv[6]); 908 ret = g_renderer->addImageLayer(name, opts); 859 909 } else { 860 910 Tcl_AppendResult(interp, "unknown image driver \"", driver, 861 911 "\": should be 'debug', 'gdal', 'tms', 'wms' or 'xyz'", (char*)NULL); 912 return TCL_ERROR; 913 } 914 if (!ret) { 915 Tcl_AppendResult(interp, "Failed to add image layer \"", name, "\"", (char*)NULL); 862 916 return TCL_ERROR; 863 917 } … … 1981 2035 Tcl_CreateObjCommand(interp, "clientinfo", ClientInfoCmd, clientData, NULL); 1982 2036 Tcl_CreateObjCommand(interp, "colormap", ColorMapCmd, clientData, NULL); 2037 Tcl_CreateObjCommand(interp, "file", FileCmd, clientData, NULL); 1983 2038 Tcl_CreateObjCommand(interp, "imgflush", ImageFlushCmd, clientData, NULL); 1984 2039 Tcl_CreateObjCommand(interp, "key", KeyCmd, clientData, NULL); … … 1997 2052 Tcl_DeleteCommand(interp, "clientinfo"); 1998 2053 Tcl_DeleteCommand(interp, "colormap"); 2054 Tcl_DeleteCommand(interp, "file"); 1999 2055 Tcl_DeleteCommand(interp, "imgflush"); 2000 2056 Tcl_DeleteCommand(interp, "key");
Note: See TracChangeset
for help on using the changeset viewer.