Changeset 4028
- Timestamp:
- Nov 4, 2013, 2:11:09 AM (11 years ago)
- Location:
- trunk/packages/vizservers/geovis
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/geovis/Makefile.in
r4023 r4028 4 4 USE_OFFSCREEN_RENDERING = #yes 5 5 USE_THREADS = yes 6 USE_READ_THREAD = #yes 6 7 7 8 bindir = @bindir@ … … 50 51 OSGEARTH_LIB_SPEC = -L${OSG_LIB_DIR} \ 51 52 -losgEarthFeatures \ 53 -losgEarthAnnotation \ 52 54 -losgEarthSymbology \ 53 55 -losgEarthUtil \ 54 56 -losgEarth 55 57 56 LD_RUN_PATH = $( libdir)58 LD_RUN_PATH = $(OSG_LIB_DIR):$(libdir) 57 59 58 60 LIBS = \ … … 90 92 DEFINES += -DUSE_THREADS 91 93 endif 94 ifdef USE_READ_THREAD 95 DEFINES += -DUSE_READ_THREAD 96 endif 92 97 93 98 CXX_SWITCHES = $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(DEFINES) $(INCLUDES) … … 105 110 106 111 ifdef USE_THREADS 107 SERVER_SRCS+=ResponseQueue.cpp 112 SERVER_SRCS+= \ 113 ResponseQueue.cpp 114 ifdef USE_READ_THREAD 115 SERVER_SRCS+= \ 116 CommandQueue.cpp 117 endif 108 118 endif 109 119 … … 142 152 143 153 CmdProc.o: CmdProc.h 154 CommandQueue.o: CommandQueue.h Trace.h 144 155 md5.o: md5.h 145 156 PPMWriter.o: PPMWriter.h ResponseQueue.h Trace.h -
trunk/packages/vizservers/geovis/RenderServer.cpp
r4025 r4028 33 33 #include <pthread.h> 34 34 #include "ResponseQueue.h" 35 #ifdef USE_READ_THREAD 36 #include "CommandQueue.h" 37 #endif 35 38 #endif 36 39 #include <md5.h> … … 47 50 Renderer *GeoVis::g_renderer = NULL; ///< Main render worker 48 51 ReadBuffer *GeoVis::g_inBufPtr = NULL; ///< Socket read buffer 49 ResponseQueue *GeoVis::g_queue = NULL; 52 #ifdef USE_THREADS 53 ResponseQueue *GeoVis::g_outQueue = NULL; 54 #ifdef USE_READER_THREAD 55 CommandQueue *GeoVis::g_inQueue = NULL; 56 #endif 57 #endif 50 58 51 59 #ifdef USE_THREADS … … 66 74 g_renderer->getWindowWidth(), 67 75 g_renderer->getWindowHeight(), 68 TARGA_BYTES_PER_PIXEL); 76 TARGA_BYTES_PER_PIXEL, 77 true); 69 78 #endif /*RENDER_TARGA*/ 70 79 … … 83 92 g_renderer->getWindowHeight()); 84 93 #endif /*RENDER_TARGA*/ 85 #endif /*DEBUG */94 #endif /*DEBUG_WRITE_FRAME_FILE*/ 86 95 } 87 96 … … 91 100 writeFrame(int fd, const unsigned char *imgData) 92 101 { 93 #ifdef DEBUG 94 if (g_renderer->getCameraMode() == Renderer::IMAGE) { 95 double xywh[4]; 96 g_renderer->getScreenWorldCoords(xywh); 97 TRACE("Image bbox: %g %g %g %g", 98 xywh[0], 99 (xywh[1] + xywh[3]), 100 (xywh[0] + xywh[2]), 101 xywh[1]); 102 } 102 #ifdef DEBUG_WRITE_FRAME_FILE 103 103 104 104 #ifdef RENDER_TARGA … … 118 118 119 119 #else 120 if (g_renderer->getCameraMode() == Renderer::IMAGE) {121 double xywh[4];122 g_renderer->getCameraZoomRegion(xywh);123 std::ostringstream oss;124 oss.precision(12);125 // Send upper left and lower right corners as bbox126 oss << "nv>image -type image -bbox {"127 << std::scientific128 << xywh[0] << " "129 << xywh[1] << " "130 << xywh[2] << " "131 << xywh[3] << "} -bytes";132 120 133 121 #ifdef RENDER_TARGA 134 writeTGA(fd, oss.str().c_str(),135 136 137 138 139 #else 140 writePPM(fd, oss.str().c_str(),141 imgData->GetPointer(0),142 143 122 writeTGA(fd, "nv>image -type image -bytes", 123 imgData, 124 g_renderer->getWindowWidth(), 125 g_renderer->getWindowHeight(), 126 TARGA_BYTES_PER_PIXEL); 127 #else 128 writePPM(fd, "nv>image -type image -bytes", 129 imgData, 130 g_renderer->getWindowWidth(), 131 g_renderer->getWindowHeight()); 144 132 #endif /*RENDER_TARGA*/ 145 } else { 146 #ifdef RENDER_TARGA 147 writeTGA(fd, "nv>image -type image -bytes", 148 imgData, 149 g_renderer->getWindowWidth(), 150 g_renderer->getWindowHeight(), 151 TARGA_BYTES_PER_PIXEL); 152 #else 153 writePPM(fd, "nv>image -type image -bytes", 154 imgData, 155 g_renderer->getWindowWidth(), 156 g_renderer->getWindowHeight()); 157 #endif /*RENDER_TARGA*/ 158 } 159 #endif /*DEBUG*/ 133 #endif /*DEBUG_WRITE_FRAME_FILE*/ 160 134 } 161 135 #endif /*USE_THREADS*/ … … 419 393 #ifdef USE_THREADS 420 394 395 #ifdef USE_READ_THREAD 396 static void * 397 readerThread(void *clientData) 398 { 399 Tcl_Interp *interp = (Tcl_Interp *)clientData; 400 401 TRACE("Starting reader thread"); 402 403 queueCommands(interp, NULL, g_inBufPtr); 404 405 return NULL; 406 } 407 #endif 408 421 409 static void * 422 410 writerThread(void *clientData) … … 471 459 472 460 #ifdef USE_THREADS 473 g_ queue = new ResponseQueue();461 g_outQueue = new ResponseQueue(); 474 462 475 463 pthread_t writerThreadId; 476 if (pthread_create(&writerThreadId, NULL, &writerThread, g_ queue) < 0) {464 if (pthread_create(&writerThreadId, NULL, &writerThread, g_outQueue) < 0) { 477 465 ERROR("Can't create writer thread: %s", strerror(errno)); 478 466 } … … 485 473 for (;;) { 486 474 long timeout = g_renderer->getTimeout(); 487 if (processCommands(interp, NULL, g_inBufPtr, g_fdOut, timeout) < 0) 475 int cmdStatus = processCommands(interp, NULL, g_inBufPtr, g_fdOut, timeout); 476 if (cmdStatus < 0) 488 477 break; 489 478 … … 496 485 TRACE("Image: %d x %d", imgData->s(), imgData->t()); 497 486 } 498 #ifdef USE_THREADS 499 queueFrame(g_queue, imgData->data()); 500 #else 501 writeFrame(g_fdOut, imgData->data()); 502 #endif 487 if (imgData->s() == g_renderer->getWindowWidth() && 488 imgData->t() == g_renderer->getWindowHeight()) { 489 #ifdef USE_THREADS 490 queueFrame(g_outQueue, imgData->data()); 491 #else 492 writeFrame(g_fdOut, imgData->data()); 493 #endif 494 } 503 495 g_stats.nFrames++; 504 g_stats.nFrameBytes += 0; // FIXME496 g_stats.nFrameBytes += imgData->s() * imgData->t() * 3; 505 497 } else { 506 TRACE("No render required"); 507 sendAck(); 498 //TRACE("No render required"); 499 if (cmdStatus > 1) { 500 sendAck(); 501 } 508 502 } 509 503 … … 533 527 534 528 TRACE("Deleting ResponseQueue"); 535 delete g_ queue;536 g_ queue = NULL;529 delete g_outQueue; 530 g_outQueue = NULL; 537 531 #endif 538 532 -
trunk/packages/vizservers/geovis/RenderServer.h
r3998 r4028 16 16 class Renderer; 17 17 class ReadBuffer; 18 class CommandQueue; 18 19 class ResponseQueue; 19 20 … … 49 50 extern Renderer *g_renderer; 50 51 extern ReadBuffer *g_inBufPtr; 51 extern ResponseQueue *g_queue; 52 #ifdef USE_THREADS 53 #ifdef USE_READ_THREAD 54 extern CommandQueue *g_inQueue; 55 #endif 56 extern ResponseQueue *g_outQueue; 57 #endif 52 58 extern int g_statsFile; 53 59 extern int writeToStatsFile(int f, const char *s, size_t length); -
trunk/packages/vizservers/geovis/Renderer.cpp
r4027 r4028 16 16 #include <sys/time.h> 17 17 #endif 18 19 #include <osgGA/StateSetManipulator> 18 20 19 21 #include <osgEarth/Version> … … 52 54 _captureCallback = new ScreenCaptureCallback(); 53 55 _viewer->getCamera()->setPostDrawCallback(_captureCallback.get()); 54 _sceneRoot = new osg::Node; 56 osgEarth::MapOptions mapOpts; 57 mapOpts.coordSysType() = osgEarth::MapOptions::CSTYPE_PROJECTED; 58 mapOpts.profile() = osgEarth::ProfileOptions("global-geodetic"); 59 osgEarth::Map *map = new osgEarth::Map(mapOpts); 60 _map = map; 61 osgEarth::MapNodeOptions mapNodeOpts; 62 mapNodeOpts.enableLighting() = false; 63 osgEarth::MapNode *mapNode = new osgEarth::MapNode(map, mapNodeOpts); 64 _mapNode = mapNode; 65 _sceneRoot = mapNode; 55 66 _viewer->setSceneData(_sceneRoot.get()); 56 67 _manipulator = new osgEarth::Util::EarthManipulator; 57 _viewer->setCameraManipulator(_manipulator); 68 _viewer->setCameraManipulator(_manipulator.get()); 69 _viewer->addEventHandler(new osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet())); 58 70 _coordsCallback = new MouseCoordsCallback(); 71 _mouseCoordsTool = new osgEarth::Util::MouseCoordsTool(mapNode); 72 _mouseCoordsTool->addCallback(_coordsCallback); 73 _viewer->addEventHandler(_mouseCoordsTool); 59 74 _viewer->getCamera()->setNearFarRatio(0.00002); 60 75 _viewer->getCamera()->setSmallFeatureCullingPixelSize(-1.0f); 61 76 _viewer->setUpViewInWindow(0, 0, _windowWidth, _windowHeight); 62 77 _viewer->realize(); 78 #ifdef DEBUG 63 79 if (_viewer->getViewerStats() != NULL) { 64 80 TRACE("Enabling stats"); 65 81 _viewer->getViewerStats()->collectStats("scene", true); 66 82 } 83 #endif 84 #if 0 85 osgViewer::ViewerBase::Windows windows; 86 _viewer->getWindows(windows); 87 if (windows.size() == 1) { 88 windows[0]->setSyncToVBlank(false); 89 } else { 90 ERROR("Num windows: %lu", windows.size()); 91 } 92 #endif 93 } 94 95 osgGA::EventQueue *Renderer::getEventQueue() 96 { 97 osgViewer::ViewerBase::Windows windows; 98 _viewer->getWindows(windows); 99 return windows[0]->getEventQueue(); 67 100 } 68 101 … … 77 110 { 78 111 TRACE("Loading %s", path); 79 _sceneRoot = osgDB::readNodeFile(path); 80 osgEarth::MapNode *mapNode = osgEarth::MapNode::findMapNode(_sceneRoot.get()); 112 osg::Node *node = osgDB::readNodeFile(path); 113 if (node == NULL) { 114 ERROR("Couldn't load %s", path); 115 return; 116 } 117 osgEarth::MapNode *mapNode = osgEarth::MapNode::findMapNode(node); 81 118 if (mapNode == NULL) { 82 119 ERROR("Couldn't find MapNode"); 120 return; 83 121 } else { 122 _sceneRoot = node; 84 123 _map = mapNode->getMap(); 85 124 } 125 _mapNode = mapNode; 86 126 if (_mouseCoordsTool.valid()) 87 _viewer->removeEventHandler(_mouseCoordsTool );127 _viewer->removeEventHandler(_mouseCoordsTool.get()); 88 128 _mouseCoordsTool = new osgEarth::Util::MouseCoordsTool(mapNode); 89 _mouseCoordsTool->addCallback(_coordsCallback );90 _viewer->addEventHandler(_mouseCoordsTool );129 _mouseCoordsTool->addCallback(_coordsCallback.get()); 130 _viewer->addEventHandler(_mouseCoordsTool.get()); 91 131 _viewer->setSceneData(_sceneRoot.get()); 132 _manipulator = new osgEarth::Util::EarthManipulator; 133 _viewer->setCameraManipulator(_manipulator.get()); 92 134 _manipulator->setNode(NULL); 93 135 _manipulator->setNode(_sceneRoot.get()); … … 97 139 } 98 140 141 void Renderer::resetMap(osgEarth::MapOptions::CoordinateSystemType type, const char *profile) 142 { 143 TRACE("Restting map with type %d, profile %s", type, profile); 144 145 osgEarth::MapOptions mapOpts; 146 mapOpts.coordSysType() = type; 147 if (profile != NULL) { 148 mapOpts.profile() = osgEarth::ProfileOptions(profile); 149 } else if (type == osgEarth::MapOptions::CSTYPE_PROJECTED) { 150 mapOpts.profile() = osgEarth::ProfileOptions("global-geodetic"); 151 } 152 osgEarth::Map *map = new osgEarth::Map(mapOpts); 153 _map = map; 154 osgEarth::MapNodeOptions mapNodeOpts; 155 mapNodeOpts.enableLighting() = false; 156 osgEarth::MapNode *mapNode = new osgEarth::MapNode(map, mapNodeOpts); 157 _mapNode = mapNode; 158 _sceneRoot = mapNode; 159 if (_mouseCoordsTool.valid()) 160 _viewer->removeEventHandler(_mouseCoordsTool.get()); 161 _mouseCoordsTool = new osgEarth::Util::MouseCoordsTool(mapNode); 162 _mouseCoordsTool->addCallback(_coordsCallback.get()); 163 _viewer->addEventHandler(_mouseCoordsTool.get()); 164 _viewer->setSceneData(_sceneRoot.get()); 165 _manipulator = new osgEarth::Util::EarthManipulator; 166 _viewer->setCameraManipulator(_manipulator.get()); 167 _manipulator->setNode(NULL); 168 _manipulator->setNode(_sceneRoot.get()); 169 _manipulator->computeHomePosition(); 170 _viewer->home(); 171 _needsRedraw = true; 172 } 173 174 bool Renderer::mapMouseCoords(float mouseX, float mouseY, osgEarth::GeoPoint& map) 175 { 176 osg::Vec3d world; 177 if (_mapNode->getTerrain()->getWorldCoordsUnderMouse(_viewer.get(), mouseX, mouseY, world)) { 178 map.fromWorld(_mapNode->getMapSRS(), world); 179 return true; 180 } 181 return false; 182 } 183 99 184 void Renderer::addImageLayer(const char *name, const osgEarth::TileSourceOptions& opts) 100 185 { … … 155 240 void Renderer::removeModelLayer(const char *name) 156 241 { 157 #if 1158 242 osgEarth::ModelLayer *layer = _map->getModelLayerByName(name); 159 243 _map->removeModelLayer(layer); 160 #endif161 244 } 162 245 163 246 void Renderer::moveModelLayer(const char *name, unsigned int pos) 164 247 { 165 #if 1166 248 osgEarth::ModelLayer *layer = _map->getModelLayerByName(name); 167 249 _map->moveModelLayer(layer, pos); 168 #endif169 250 } 170 251 … … 267 348 } 268 349 350 void Renderer::setThrowingEnabled(bool state) 351 { 352 _manipulator->getSettings()->setThrowingEnabled(state); 353 } 354 269 355 void Renderer::mouseDoubleClick(int button, double x, double y) 270 356 { 271 _viewer->getEventQueue()->mouseDoubleButtonPress((float)x, (float)y, button);357 getEventQueue()->mouseDoubleButtonPress((float)x, (float)y, button); 272 358 _needsRedraw = true; 273 359 } … … 275 361 void Renderer::mouseClick(int button, double x, double y) 276 362 { 277 _viewer->getEventQueue()->mouseButtonPress((float)x, (float)y, button);363 getEventQueue()->mouseButtonPress((float)x, (float)y, button); 278 364 _needsRedraw = true; 279 365 } … … 281 367 void Renderer::mouseDrag(int button, double x, double y) 282 368 { 283 _viewer->getEventQueue()->mouseMotion((float)x, (float)y);369 getEventQueue()->mouseMotion((float)x, (float)y); 284 370 _needsRedraw = true; 285 371 } … … 287 373 void Renderer::mouseRelease(int button, double x, double y) 288 374 { 289 _viewer->getEventQueue()->mouseButtonRelease((float)x, (float)y, button);375 getEventQueue()->mouseButtonRelease((float)x, (float)y, button); 290 376 _needsRedraw = true; 291 377 } … … 293 379 void Renderer::mouseMotion(double x, double y) 294 380 { 295 _viewer->getEventQueue()->mouseMotion((float)x, (float)y); 296 _needsRedraw = true; 381 //getEventQueue()->mouseMotion((float)x, (float)y); 382 return; 383 osgEarth::GeoPoint map; 384 if (mapMouseCoords(x, y, map)) { 385 _coordsCallback->set(map, _viewer.get(), _mapNode); 386 } else { 387 _coordsCallback->reset(_viewer.get(), _mapNode); 388 } 297 389 } 298 390 299 391 void Renderer::mouseScroll(int direction) 300 392 { 301 _viewer->getEventQueue()->mouseScroll((direction > 0 ? osgGA::GUIEventAdapter::SCROLL_UP : osgGA::GUIEventAdapter::SCROLL_DOWN));393 getEventQueue()->mouseScroll((direction > 0 ? osgGA::GUIEventAdapter::SCROLL_UP : osgGA::GUIEventAdapter::SCROLL_DOWN)); 302 394 _needsRedraw = true; 303 395 } … … 336 428 bool Renderer::isPagerIdle() 337 429 { 338 return (!_viewer->getDatabasePager()->requiresUpdateSceneGraph() && 339 !_viewer->getDatabasePager()->getRequestsInProgress()); 430 //return (!_viewer->getDatabasePager()->requiresUpdateSceneGraph() && 431 // !_viewer->getDatabasePager()->getRequestsInProgress()); 432 return !_viewer->getDatabasePager()->requiresUpdateSceneGraph(); 340 433 } 341 434 … … 348 441 bool Renderer::render() 349 442 { 350 TRACE("Enter needsRedraw=%d", _needsRedraw ? 1 : 0); 351 352 if (_needsRedraw || !isPagerIdle()) { 443 if (_needsRedraw || 444 //!isPagerIdle() 445 _viewer->checkNeedToDoFrame() 446 ) { 447 TRACE("Enter needsRedraw=%d", _needsRedraw ? 1 : 0); 448 353 449 osg::Timer_t startFrameTick = osg::Timer::instance()->tick(); 354 450 TRACE("Before frame()"); … … 364 460 } 365 461 #endif 462 #ifdef WANT_TRACE 366 463 if (_viewer->getViewerStats() != NULL) { 367 464 _viewer->getViewerStats()->report(std::cerr, _viewer->getViewerStats()->getLatestFrameNumber()); 368 465 } 466 #endif 369 467 _needsRedraw = false; 370 468 return true; -
trunk/packages/vizservers/geovis/Renderer.h
r4025 r4028 33 33 34 34 // Controls if TGA format is sent to client 35 #define RENDER_TARGA35 //#define RENDER_TARGA 36 36 #define TARGA_BYTES_PER_PIXEL 3 37 37 … … 49 49 virtual void operator()(osg::RenderInfo &renderInfo) const 50 50 { 51 TRACE("Enter ");51 TRACE("Enter ScreenCaptureCallback"); 52 52 int width, height; 53 53 if (renderInfo.getCurrentCamera() == NULL) { … … 88 88 {} 89 89 90 void set(const osgEarth::GeoPoint& p, osg::View* view, osgEarth::MapNode* mapNode) 91 { 92 // p.y(), p.x() 90 void set(const osgEarth::GeoPoint& p, osg::View *view, osgEarth::MapNode *mapNode) 91 { 93 92 _pt = p; 94 93 _havePoint = true; 95 94 } 96 95 97 void reset(osg::View * view, osgEarth::MapNode*mapNode)96 void reset(osg::View *view, osgEarth::MapNode *mapNode) 98 97 { 99 98 // Out of range click 100 //_havePoint = false;99 _havePoint = false; 101 100 } 102 101 … … 131 130 void loadEarthFile(const char *path); 132 131 132 void resetMap(osgEarth::MapOptions::CoordinateSystemType type, const char *profile = NULL); 133 134 // Map options 135 136 void setLighting(bool state); 137 133 138 // Image raster layers 134 139 … … 185 190 // Mouse events 186 191 192 void setThrowingEnabled(bool state); 193 187 194 void mouseClick(int button, double x, double y); 188 195 … … 206 213 207 214 osg::Image *getRenderedFrame(); 215 216 bool mapMouseCoords(float mouseX, float mouseY, osgEarth::GeoPoint &pt); 208 217 209 218 bool getMousePoint(double *x, double *y, double *z) … … 218 227 private: 219 228 void initCamera(); 229 230 osgGA::EventQueue *getEventQueue(); 220 231 221 232 bool _needsRedraw; -
trunk/packages/vizservers/geovis/RendererCmd.cpp
r4025 r4028 19 19 #include <tcl.h> 20 20 21 #include <osgEarthDrivers/gdal/GDALOptions> 22 21 23 #include "Trace.h" 22 24 #include "CmdProc.h" … … 28 30 #include "PPMWriter.h" 29 31 #include "TGAWriter.h" 30 #ifdef USE_THREADS31 32 #include "ResponseQueue.h" 33 #ifdef USE_READ_THREAD 34 #include "CommandQueue.h" 32 35 #endif 33 36 … … 36 39 static int lastCmdStatus; 37 40 38 ssize_t 39 GeoVis::queueResponse(const void *bytes, size_t len, 40 Response::AllocationType allocType, 41 Response::ResponseType type) 42 { 43 #ifdef USE_THREADS 44 Response *response = new Response(type); 45 response->setMessage((unsigned char *)bytes, len, allocType); 46 g_queue->enqueue(response); 47 return (ssize_t)len; 48 #else 49 return SocketWrite(bytes, len); 50 #endif 51 } 52 41 #ifndef USE_THREADS 53 42 static ssize_t 54 43 SocketWrite(const void *bytes, size_t len) … … 66 55 return bytesWritten; 67 56 } 57 #endif 68 58 69 59 static bool … … 74 64 TRACE("followingData status: %d", status); 75 65 return (status == ReadBuffer::OK); 66 } 67 68 ssize_t 69 GeoVis::queueResponse(const void *bytes, size_t len, 70 Response::AllocationType allocType, 71 Response::ResponseType type) 72 { 73 #ifdef USE_THREADS 74 Response *response = new Response(type); 75 response->setMessage((unsigned char *)bytes, len, allocType); 76 g_outQueue->enqueue(response); 77 return (ssize_t)len; 78 #else 79 return SocketWrite(bytes, len); 80 #endif 76 81 } 77 82 … … 192 197 193 198 static int 199 CameraThrowOp(ClientData clientData, Tcl_Interp *interp, int objc, 200 Tcl_Obj *const *objv) 201 { 202 bool state; 203 204 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 205 return TCL_ERROR; 206 } 207 208 g_renderer->setThrowingEnabled(state); 209 return TCL_OK; 210 } 211 212 static int 194 213 CameraZoomOp(ClientData clientData, Tcl_Interp *interp, int objc, 195 214 Tcl_Obj *const *objv) … … 210 229 {"reset", 2, CameraResetOp, 2, 3, "?all?"}, 211 230 {"rotate", 2, CameraRotateOp, 4, 4, "azimuth elevation"}, 231 {"throw", 1, CameraThrowOp, 3, 3, "bool"}, 212 232 {"zoom", 1, CameraZoomOp, 3, 3, "zoomAmount"} 213 233 }; … … 312 332 313 333 static int 334 MapLayerAddOp(ClientData clientData, Tcl_Interp *interp, int objc, 335 Tcl_Obj *const *objv) 336 { 337 osgEarth::Drivers::GDALOptions opts; 338 char *url = Tcl_GetString(objv[3]); 339 char *name = Tcl_GetString(objv[4]); 340 341 opts.url() = url; 342 343 g_renderer->addImageLayer(name, opts); 344 345 return TCL_OK; 346 } 347 348 static int 349 MapLayerDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 350 Tcl_Obj *const *objv) 351 { 352 if (objc > 3) { 353 char *name = Tcl_GetString(objv[3]); 354 g_renderer->removeImageLayer(name); 355 } else { 356 g_renderer->removeImageLayer("all"); 357 } 358 359 return TCL_OK; 360 } 361 362 static int 363 MapLayerMoveOp(ClientData clientData, Tcl_Interp *interp, int objc, 364 Tcl_Obj *const *objv) 365 { 366 int pos; 367 if (Tcl_GetIntFromObj(interp, objv[3], &pos) != TCL_OK) { 368 return TCL_ERROR; 369 } 370 char *name = Tcl_GetString(objv[4]); 371 if (pos < 0) { 372 Tcl_AppendResult(interp, "bad layer pos ", pos, 373 ": must be positive", (char*)NULL); 374 return TCL_ERROR; 375 } 376 g_renderer->moveImageLayer(name, (unsigned int)pos); 377 378 return TCL_OK; 379 } 380 381 static int 382 MapLayerOpacityOp(ClientData clientData, Tcl_Interp *interp, int objc, 383 Tcl_Obj *const *objv) 384 { 385 double opacity; 386 if (Tcl_GetDoubleFromObj(interp, objv[3], &opacity) != TCL_OK) { 387 return TCL_ERROR; 388 } 389 char *name = Tcl_GetString(objv[4]); 390 if (opacity < 0.0 || opacity > 1.0) { 391 Tcl_AppendResult(interp, "bad layer opacity ", opacity, 392 ": must be [0,1]", (char*)NULL); 393 return TCL_ERROR; 394 } 395 g_renderer->setImageLayerOpacity(name, opacity); 396 397 return TCL_OK; 398 } 399 400 static int 401 MapLayerVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 402 Tcl_Obj *const *objv) 403 { 404 bool visible; 405 if (GetBooleanFromObj(interp, objv[3], &visible) != TCL_OK) { 406 return TCL_ERROR; 407 } 408 char *name = Tcl_GetString(objv[4]); 409 410 g_renderer->setImageLayerVisibility(name, visible); 411 412 return TCL_OK; 413 } 414 415 static Rappture::CmdSpec mapLayerOps[] = { 416 {"add", 1, MapLayerAddOp, 5, 5, "type url name"}, 417 {"delete", 1, MapLayerDeleteOp, 3, 4, "?name?"}, 418 {"move", 1, MapLayerMoveOp, 5, 5, "pos name"}, 419 {"opacity", 1, MapLayerOpacityOp, 5, 5, "opacity ?name?"}, 420 {"visible", 1, MapLayerVisibleOp, 5, 5, "bool ?name?"}, 421 }; 422 static int nMapLayerOps = NumCmdSpecs(mapLayerOps); 423 424 static int 425 MapLayerOp(ClientData clientData, Tcl_Interp *interp, int objc, 426 Tcl_Obj *const *objv) 427 { 428 Tcl_ObjCmdProc *proc; 429 430 proc = Rappture::GetOpFromObj(interp, nMapLayerOps, mapLayerOps, 431 Rappture::CMDSPEC_ARG2, objc, objv, 0); 432 if (proc == NULL) { 433 return TCL_ERROR; 434 } 435 return (*proc) (clientData, interp, objc, objv); 436 } 437 438 static int 439 MapLoadOp(ClientData clientData, Tcl_Interp *interp, int objc, 440 Tcl_Obj *const *objv) 441 { 442 char *opt = Tcl_GetString(objv[2]); 443 if (opt[0] == 'f' && strcmp(opt, "file") == 0) { 444 g_renderer->loadEarthFile(Tcl_GetString(objv[3])); 445 } else if (opt[0] == 'u' && strcmp(opt, "url") == 0) { 446 std::ostringstream path; 447 path << "server:" << Tcl_GetString(objv[3]); 448 g_renderer->loadEarthFile(path.str().c_str()); 449 } else if (opt[0] == 'd' && strcmp(opt, "data") == 0) { 450 opt = Tcl_GetString(objv[3]); 451 if (opt[0] != 'f' || strcmp(opt, "follows") != 0) { 452 return TCL_ERROR; 453 } 454 int len; 455 if (Tcl_GetIntFromObj(interp, objv[4], &len) != TCL_OK) { 456 return TCL_ERROR; 457 } 458 // Read Earth file from socket 459 char *buf = (char *)malloc((size_t)len); 460 SocketRead(buf, (size_t)len); 461 std::ostringstream path; 462 path << "/tmp/tmp" << getpid() << ".earth"; 463 FILE *tmpFile = fopen(path.str().c_str(), "w"); 464 fwrite(buf, len, 1, tmpFile); 465 fclose(tmpFile); 466 g_renderer->loadEarthFile(path.str().c_str()); 467 unlink(path.str().c_str()); 468 free(buf); 469 } else { 470 return TCL_ERROR; 471 } 472 return TCL_OK; 473 } 474 475 static int 476 MapResetOp(ClientData clientData, Tcl_Interp *interp, int objc, 477 Tcl_Obj *const *objv) 478 { 479 char *typeStr = Tcl_GetString(objv[2]); 480 osgEarth::MapOptions::CoordinateSystemType type; 481 if (typeStr[0] == 'g' && strcmp(typeStr, "geocentric") == 0) { 482 type = osgEarth::MapOptions::CSTYPE_GEOCENTRIC; 483 } else if (typeStr[0] == 'g' && strcmp(typeStr, "geocentric_cube") == 0) { 484 type = osgEarth::MapOptions::CSTYPE_GEOCENTRIC_CUBE; 485 } else if (typeStr[0] == 'p' && strcmp(typeStr, "projected") == 0) { 486 type = osgEarth::MapOptions::CSTYPE_PROJECTED; 487 } else { 488 Tcl_AppendResult(interp, "bad map type \"", typeStr, 489 "\": must be geocentric, geocentric_cube or projected", (char*)NULL); 490 return TCL_ERROR; 491 } 492 493 char *profile = NULL; 494 if (objc > 3) { 495 profile = Tcl_GetString(objv[3]); 496 } 497 498 g_renderer->resetMap(type, profile); 499 500 return TCL_OK; 501 } 502 503 static Rappture::CmdSpec mapOps[] = { 504 {"layer", 2, MapLayerOp, 3, 5, "op ?params...?"}, 505 {"load", 2, MapLoadOp, 4, 5, "options"}, 506 {"reset", 1, MapResetOp, 3, 4, "type ?profile?"}, 507 }; 508 static int nMapOps = NumCmdSpecs(mapOps); 509 510 static int 511 MapCmd(ClientData clientData, Tcl_Interp *interp, int objc, 512 Tcl_Obj *const *objv) 513 { 514 Tcl_ObjCmdProc *proc; 515 516 proc = Rappture::GetOpFromObj(interp, nMapOps, mapOps, 517 Rappture::CMDSPEC_ARG1, objc, objv, 0); 518 if (proc == NULL) { 519 return TCL_ERROR; 520 } 521 return (*proc) (clientData, interp, objc, objv); 522 } 523 524 static int 314 525 MouseClickOp(ClientData clientData, Tcl_Interp *interp, int objc, 315 526 Tcl_Obj *const *objv) … … 441 652 442 653 static int 443 RendererLoadOp(ClientData clientData, Tcl_Interp *interp, int objc,444 Tcl_Obj *const *objv)445 {446 g_renderer->loadEarthFile(Tcl_GetString(objv[2]));447 return TCL_OK;448 }449 450 static int451 654 RendererRenderOp(ClientData clientData, Tcl_Interp *interp, int objc, 452 655 Tcl_Obj *const *objv) … … 457 660 458 661 static Rappture::CmdSpec rendererOps[] = { 459 {"load", 1, RendererLoadOp, 3, 3, "path"},460 662 {"render", 1, RendererRenderOp, 2, 2, ""}, 461 663 }; … … 526 728 return (*proc) (clientData, interp, objc, objv); 527 729 } 730 731 #ifdef USE_READ_THREAD 732 int 733 GeoVis::queueCommands(Tcl_Interp *interp, 734 ClientData clientData, 735 ReadBuffer *inBufPtr) 736 { 737 Tcl_DString commandString; 738 Tcl_DStringInit(&commandString); 739 fd_set readFds; 740 741 FD_ZERO(&readFds); 742 FD_SET(inBufPtr->file(), &readFds); 743 while (inBufPtr->isLineAvailable() || 744 (select(1, &readFds, NULL, NULL, NULL) > 0)) { 745 size_t numBytes; 746 unsigned char *buffer; 747 748 /* A short read is treated as an error here because we assume that we 749 * will always get commands line by line. */ 750 if (inBufPtr->getLine(&numBytes, &buffer) != ReadBuffer::OK) { 751 /* Terminate the server if we can't communicate with the client 752 * anymore. */ 753 if (inBufPtr->status() == ReadBuffer::ENDFILE) { 754 TRACE("Exiting server on EOF from client"); 755 return -1; 756 } else { 757 ERROR("Exiting server, failed to read from client: %s", 758 strerror(errno)); 759 return -1; 760 } 761 } 762 Tcl_DStringAppend(&commandString, (char *)buffer, numBytes); 763 if (Tcl_CommandComplete(Tcl_DStringValue(&commandString))) { 764 // Add to queue 765 Command *command = new Command(Command::COMMAND); 766 command->setMessage((unsigned char *)Tcl_DStringValue(&commandString), 767 Tcl_DStringLength(&commandString), Command::VOLATILE); 768 g_inQueue->enqueue(command); 769 Tcl_DStringSetLength(&commandString, 0); 770 } 771 FD_SET(inBufPtr->file(), &readFds); 772 } 773 774 return 1; 775 } 776 #endif 528 777 529 778 /** … … 592 841 g_stats.nCommands++; 593 842 if (status == TCL_BREAK) { 594 return 1; /* This was caused by a "imgflush"843 return 2; /* This was caused by a "imgflush" 595 844 * command. Break out of the read loop 596 845 * and allow a new image to be … … 602 851 } 603 852 } 853 if (status == TCL_OK) { 854 ret = 3; 855 } 604 856 } 605 857 … … 671 923 Tcl_CreateObjCommand(interp, "clientinfo", ClientInfoCmd, clientData, NULL); 672 924 Tcl_CreateObjCommand(interp, "imgflush", ImageFlushCmd, clientData, NULL); 925 Tcl_CreateObjCommand(interp, "map", MapCmd, clientData, NULL); 673 926 Tcl_CreateObjCommand(interp, "mouse", MouseCmd, clientData, NULL); 674 927 Tcl_CreateObjCommand(interp, "renderer", RendererCmd, clientData, NULL); … … 684 937 Tcl_DeleteCommand(interp, "clientinfo"); 685 938 Tcl_DeleteCommand(interp, "imgflush"); 939 Tcl_DeleteCommand(interp, "map"); 686 940 Tcl_DeleteCommand(interp, "mouse"); 687 941 Tcl_DeleteCommand(interp, "renderer"); -
trunk/packages/vizservers/geovis/RendererCmd.h
r4025 r4028 13 13 14 14 #include "ReadBuffer.h" 15 #ifdef USE_THREADS16 15 #include "ResponseQueue.h" 17 #endif18 16 19 17 namespace GeoVis { 20 18 21 #ifdef USE_THREADS22 19 extern ssize_t queueResponse(const void *bytes, size_t len, 23 20 Response::AllocationType allocType, 24 21 Response::ResponseType type = Response::DATA); 22 23 #ifdef USE_READ_THREAD 24 extern int queueCommands(Tcl_Interp *interp, 25 ClientData clientData, 26 ReadBuffer *inBufPtr); 25 27 #endif 26 28 -
trunk/packages/vizservers/geovis/TGAWriter.cpp
r3998 r4028 138 138 iov[1].iov_len = headerLength; 139 139 // Image data **must be BGR(A)!** 140 iov[2].iov_base = data;140 iov[2].iov_base = const_cast<unsigned char *>(data); 141 141 iov[2].iov_len = dataLength; 142 142
Note: See TracChangeset
for help on using the changeset viewer.