- Timestamp:
- Sep 8, 2011 8:03:53 PM (13 years ago)
- Location:
- branches/vtkvis_threaded
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/vtkvis_threaded/CmdProc.cpp
r2123 r2495 10 10 11 11 #include "CmdProc.h" 12 13 using namespace Rappture; 12 14 13 15 /** … … 22 24 */ 23 25 static int 24 BinaryOpSearch( Rappture::CmdSpec *specs,26 BinaryOpSearch(CmdSpec *specs, 25 27 int nSpecs, 26 28 char *string) /* Name of minor operation to search for */ … … 35 37 length = strlen(string); 36 38 while (low <= high) { 37 Rappture::CmdSpec *specPtr;39 CmdSpec *specPtr; 38 40 int compare; 39 41 int median; … … 76 78 */ 77 79 static int 78 LinearOpSearch( Rappture::CmdSpec *specs,80 LinearOpSearch(CmdSpec *specs, 79 81 int nSpecs, 80 82 char *string) /* Name of minor operation to search for */ 81 83 { 82 Rappture::CmdSpec *specPtr;84 CmdSpec *specPtr; 83 85 char c; 84 86 size_t length; … … 120 122 */ 121 123 Tcl_ObjCmdProc * 122 Rappture::GetOpFromObj(Tcl_Interp *interp, 123 int nSpecs, 124 Rappture::CmdSpec *specs,/* Op specification array */125 int operPos, 126 127 int objc, 128 129 130 Tcl_Obj *const *objv, 124 Rappture::GetOpFromObj(Tcl_Interp *interp, /* Interpreter to report errors to */ 125 int nSpecs, /* Number of specifications in array */ 126 CmdSpec *specs, /* Op specification array */ 127 int operPos, /* Position of operation in argument 128 * list. */ 129 int objc, /* Number of arguments in the argument 130 * vector. This includes any prefixed 131 * arguments */ 132 Tcl_Obj *const *objv, /* Argument vector */ 131 133 int flags) 132 134 { -
branches/vtkvis_threaded/CmdProc.h
r2123 r2495 19 19 * for a function pointer associated with the operation name. 20 20 */ 21 typedef struct{21 struct CmdSpec { 22 22 const char *name; /**< Name of operation */ 23 23 int minChars; /**< Minimum # characters to disambiguate */ … … 26 26 int maxArgs; /**< Maximum # args required */ 27 27 const char *usage; /**< Usage message */ 28 } CmdSpec;28 }; 29 29 30 typedef enum{30 enum CmdSpecIndex { 31 31 CMDSPEC_ARG0, /**< Op is the first argument. */ 32 32 CMDSPEC_ARG1, /**< Op is the second argument. */ … … 34 34 CMDSPEC_ARG3, /**< Op is the fourth argument. */ 35 35 CMDSPEC_ARG4 /**< Op is the fifth argument. */ 36 } CmdSpecIndex;36 }; 37 37 38 38 #define CMDSPEC_LINEAR_SEARCH 1 -
branches/vtkvis_threaded/Makefile.in
r2488 r2495 80 80 ColorMap.cpp \ 81 81 PPMWriter.cpp \ 82 ResponseQueue.cpp \83 82 RpContour2D.cpp \ 84 83 RpContour3D.cpp \ … … 100 99 ifdef USE_CUSTOM_AXES 101 100 SERVER_SRCS+=vtkRpCubeAxesActor2D.cpp 101 endif 102 ifdef USE_THREADS 103 SERVER_SRCS+=ResponseQueue.cpp 102 104 endif 103 105 … … 134 136 CmdProc.o: CmdProc.h 135 137 ColorMap.o: ColorMap.h RpMolecule.h Trace.h 136 PPMWriter.o: PPMWriter.h Trace.h 138 PPMWriter.o: PPMWriter.h ResponseQueue.h Trace.h 139 ResponseQueue.o: ResponseQueue.h Trace.h 137 140 RpContour2D.o: RpContour2D.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h 138 141 RpContour3D.o: RpContour3D.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h … … 147 150 RpVtkDataSet.o: RpVtkDataSet.h Trace.h 148 151 RpVtkRenderer.o: RpVtkRenderer.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h Trace.h 149 RpVtkRendererCmd.o: RpVtkRenderer.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h150 RpVtkRenderServer.o: RpVtkRenderServer.h RpVtkRendererCmd.h RpVtkRenderer.h Trace.h PPMWriter.h TGAWriter.h152 RpVtkRendererCmd.o: RpVtkRenderer.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h ResponseQueue.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h 153 RpVtkRenderServer.o: RpVtkRenderServer.h RpVtkRendererCmd.h RpVtkRenderer.h ResponseQueue.h Trace.h PPMWriter.h TGAWriter.h 151 154 Trace.o: Trace.h 152 TGAWriter.o: TGAWriter.h Trace.h155 TGAWriter.o: TGAWriter.h ResponseQueue.h Trace.h 153 156 vtkRpCubeAxesActor2D.o: vtkRpCubeAxesActor2D.h -
branches/vtkvis_threaded/PPMWriter.cpp
r2488 r2495 10 10 #include <cstring> 11 11 #include <cerrno> 12 #include <stdlib.h>13 12 #include <sys/uio.h> 14 13 … … 17 16 #ifdef USE_THREADS 18 17 #include "ResponseQueue.h" 19 #endif /*USE_THREADS*/18 #endif 20 19 21 20 using namespace Rappture::VtkVis; 21 22 #ifdef USE_THREADS 22 23 23 24 /** … … 36 37 * to bottom scanlines. 37 38 * 38 * \param[in] fd File descriptor that will be writtento39 * \param[in] queue Pointer to ResponseQueue to write to 39 40 * \param[in] cmdName Command name to send (byte length will be appended) 40 41 * \param[in] data Image data … … 42 43 * \param[in] height Height of image in pixels 43 44 */ 44 45 #ifdef USE_THREADS46 45 void 47 Rappture::VtkVis:: QueuePPM(ResponseQueue *queuePtr, const char *cmdName,46 Rappture::VtkVis::queuePPM(ResponseQueue *queue, const char *cmdName, 48 47 const unsigned char *data, int width, int height) 49 48 { … … 54 53 // Generate the PPM binary file header 55 54 snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height, 56 PPM_MAXVAL);55 PPM_MAXVAL); 57 56 58 57 size_t headerLength = strlen(header); … … 88 87 } 89 88 90 Response *response Ptr;89 Response *response; 91 90 if (strncmp(cmdName, "nv>legend", 9) == 0) { 92 response Ptr= new Response(Response::LEGEND);91 response = new Response(Response::LEGEND); 93 92 } else { 94 response Ptr= new Response(Response::IMAGE);93 response = new Response(Response::IMAGE); 95 94 } 96 response Ptr->SetMessage(mesg, length, Response::DYNAMIC);97 queue Ptr->Enqueue(responsePtr);95 response->setMessage(mesg, length, Response::DYNAMIC); 96 queue->enqueue(response); 98 97 TRACE("Leaving (%dx%d)\n", width, height); 99 98 } 100 99 #else 101 100 101 /** 102 * \brief Writes image data as PPM binary data to the client. 103 * 104 * The PPM binary format is very simple. 105 * 106 * P6 w h 255\n 107 * 3-byte RGB pixel data. 108 * 109 * The client (using the TkImg library) will do less work to unpack this 110 * format, as opposed to BMP or PNG. 111 * 112 * Note that currently the image data has bottom to top scanlines. This 113 * routine could be made even simpler (faster) if the image data had top 114 * to bottom scanlines. 115 * 116 * \param[in] fd File descriptor that will be written to 117 * \param[in] cmdName Command name to send (byte length will be appended) 118 * \param[in] data Image data 119 * \param[in] width Width of image in pixels 120 * \param[in] height Height of image in pixels 121 */ 102 122 void 103 123 Rappture::VtkVis::writePPM(int fd, const char *cmdName, … … 109 129 TRACE("Entering (%dx%d)\n", width, height); 110 130 // Generate the PPM binary file header 111 snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height, PPM_MAXVAL); 131 snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height, 132 PPM_MAXVAL); 112 133 113 134 size_t headerLength = strlen(header); … … 141 162 } 142 163 if (writev(fd, iov, nRecs) < 0) { 143 164 ERROR("write failed: %s\n", strerror(errno)); 144 165 } 145 166 free(iov); -
branches/vtkvis_threaded/PPMWriter.h
r2488 r2495 11 11 #ifdef USE_THREADS 12 12 #include "ResponseQueue.h" 13 #endif /*USE_THREADS*/13 #endif 14 14 15 15 namespace Rappture { 16 16 namespace VtkVis { 17 17 #ifdef USE_THREADS 18 extern void QueuePPM(ResponseQueue *queuePtr, const char *cmdName, 19 const unsigned char *data, int width, int height); 18 extern 19 void queuePPM(ResponseQueue *queue, const char *cmdName, 20 const unsigned char *data, int width, int height); 20 21 #else 21 extern void writePPM(int fd, const char *cmdName, 22 const unsigned char *data, int width, int height); 23 #endif /*USE_THREADS*/ 24 } 22 extern 23 void writePPM(int fd, const char *cmdName, 24 const unsigned char *data, int width, int height); 25 #endif 26 } 25 27 } 26 28 #endif -
branches/vtkvis_threaded/ResponseQueue.cpp
r2488 r2495 1 2 #ifdef USE_THREADS 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (C) 2011, Purdue Research Foundation 4 * 5 * Author: George A. Howlett <gah@purdue.edu> 6 */ 3 7 4 8 #include <pthread.h> 5 9 #include <semaphore.h> 6 #include <errno.h> 7 #include <list> 8 #include <stdlib.h> 9 #include <errno.h> 10 #include <cerrno> 10 11 #include <cstring> 11 12 #include <cstdlib> 13 #include <list> 14 12 15 #include "Trace.h" 13 16 #include "ResponseQueue.h" 14 17 15 ResponseQueue::ResponseQueue(void *clientData) 18 using namespace Rappture::VtkVis; 19 20 ResponseQueue::ResponseQueue(void *clientData) : 21 _clientData(clientData) 16 22 { 17 23 pthread_mutex_init(&_idle, NULL); 18 24 if (sem_init(&_ready, 0, 0) < 0) { 19 25 ERROR("can't initialize semaphore: %s", strerror(errno)); 20 26 } 21 _clientData = clientData;22 27 } 23 28 24 ResponseQueue::~ResponseQueue( void)29 ResponseQueue::~ResponseQueue() 25 30 { 26 31 pthread_mutex_destroy(&_idle); 27 32 if (sem_destroy(&_ready) < 0) { 28 33 ERROR("can't destroy semaphore: %s", strerror(errno)); 29 34 } 30 35 } 31 36 32 37 void 33 ResponseQueue:: Enqueue(Response *responsePtr)38 ResponseQueue::enqueue(Response *response) 34 39 { 35 40 if (pthread_mutex_lock(&_idle) != 0) { 36 41 ERROR("can't lock mutex: %s", strerror(errno)); 37 42 } 38 43 /* Examine the list and remove any queued responses of the same type. */ 39 44 INFO("before # of elements is %d\n", _list.size()); 40 std::list<Response *>::iterator iter;41 for (iter = _list.begin(); iter != _list.end(); iter++) {42 43 44 if ((*iter)->Type() == responsePtr->Type()) {45 _list.erase(iter);46 45 for (std::list<Response *>::iterator itr = _list.begin(); 46 itr != _list.end(); ++itr) { 47 /* Remove any responses of the same type. There should be no more than 48 * one. */ 49 if ((*itr)->type() == response->type()) { 50 _list.erase(itr); 51 } 47 52 } 48 53 /* Add the new response to the end of the list. */ 49 _list.push_back(response Ptr);54 _list.push_back(response); 50 55 if (sem_post(&_ready) < 0) { 51 56 ERROR("can't post semaphore: %s", strerror(errno)); 52 57 } 53 58 if (pthread_mutex_unlock(&_idle) != 0) { 54 59 ERROR("can't unlock mutex: %s", strerror(errno)); 55 60 } 56 61 } 57 62 58 63 Response * 59 ResponseQueue:: Dequeue(void)64 ResponseQueue::dequeue() 60 65 { 61 Response *response Ptr;66 Response *response; 62 67 63 68 if (sem_wait(&_ready) < 0) { 64 69 ERROR("can't wait on semaphore: %s", strerror(errno)); 65 70 } 66 71 if (pthread_mutex_lock(&_idle) != 0) { 67 72 ERROR("can't lock mutex: %s", strerror(errno)); 68 73 } 69 response Ptr= _list.front();74 response = _list.front(); 70 75 _list.pop_front(); 71 76 if (pthread_mutex_unlock(&_idle) != 0) { 72 77 ERROR("can't unlock mutex: %s", strerror(errno)); 73 78 } 74 return response Ptr;79 return response; 75 80 } 76 77 #endif /*USE_THREADS*/ -
branches/vtkvis_threaded/ResponseQueue.h
r2488 r2495 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (C) 2011, Purdue Research Foundation 4 * 5 * Author: George A. Howlett <gah@purdue.edu> 6 */ 1 7 2 8 #include <pthread.h> 3 9 #include <semaphore.h> 10 #include <cstdlib> 4 11 #include <list> 5 #include <stdlib.h>6 #include <cstdlib>7 12 8 13 #ifndef _RESPONSE_QUEUE_H 9 14 #define _RESPONSE_QUEUE_H 10 15 16 namespace Rappture { 17 namespace VtkVis { 11 18 12 class Response { 19 class Response 20 { 13 21 public: 14 typedef enum AllocTypes { 15 STATIC, DYNAMIC, VOLATILE 16 } AllocationType; 17 typedef enum ResponseTypes { 18 IMAGE, /* Image to be displayed. */ 19 LEGEND, /* Legend to be displayed. */ 20 DATA /* Any other type of message. */ 21 } ResponseType; 22 Response(ResponseType type) { 23 _length = 0; 24 _type = type; 25 _mesg = NULL; 22 enum AllocationType { 23 STATIC, 24 DYNAMIC, 25 VOLATILE 26 }; 27 enum ResponseType { 28 IMAGE, /**< Image to be displayed. */ 29 LEGEND, /**< Legend to be displayed. */ 30 DATA /**< Any other type of message. */ 31 }; 32 33 Response(ResponseType type) : 34 _mesg(NULL), 35 _length(0), 36 _type(type) 37 { 26 38 } 27 ResponseType Type(void) { 28 return _type; 29 } 30 unsigned char *Message(void) { 31 return _mesg; 32 } 33 size_t Length(void) { 34 return _length; 35 } 36 ~Response(void) { 39 40 virtual ~Response() 41 { 37 42 if (_length > 0) { 38 43 if (_allocType == DYNAMIC) { … … 41 46 } 42 47 } 43 void SetMessage(unsigned char *mesg, size_t length, AllocationType type) { 48 49 ResponseType type() 50 { 51 return _type; 52 } 53 54 unsigned char *message() 55 { 56 return _mesg; 57 } 58 59 size_t length() 60 { 61 return _length; 62 } 63 64 void setMessage(unsigned char *mesg, size_t length, AllocationType type) 65 { 44 66 if (type == VOLATILE) { 45 67 _length = length; … … 53 75 } 54 76 } 77 55 78 private: 56 unsigned char *_mesg; /* (Malloc-ed by caller, freed by57 * destructor) Contains the 58 * message/bytes to be sent to the 59 * client. */ 60 size_t _length; /*# of bytes in the above message. */79 /** 80 * (Malloc-ed by caller, freed by destructor) 81 * Contains the message/bytes to be sent to the client. */ 82 unsigned char *_mesg; 83 size_t _length; /**< # of bytes in the above message. */ 61 84 ResponseType _type; 62 85 AllocationType _allocType; 63 86 }; 64 87 65 class ResponseQueue { 88 class ResponseQueue 89 { 90 public: 91 ResponseQueue(void *clientData); 92 93 virtual ~ResponseQueue(); 94 95 void *clientData() 96 { 97 return _clientData; 98 } 99 100 void enqueue(Response *response); 101 102 Response *dequeue(); 103 104 private: 66 105 pthread_mutex_t _idle; 67 sem_t _ready; /* Semaphore indicating that a 68 * response has been queued. */ 106 sem_t _ready; /**< Semaphore indicating that a response has been queued. */ 69 107 std::list<Response *> _list; 70 108 void *_clientData; 71 72 public:73 ResponseQueue(void *clientData);74 ~ResponseQueue(void);75 void *ClientData(void) {76 return _clientData;77 }78 void Enqueue(Response *responsePtr);79 Response *Dequeue();80 109 }; 81 110 111 } 112 } 113 82 114 #endif -
branches/vtkvis_threaded/RpVtkRenderServer.cpp
r2488 r2495 10 10 #include <cstring> 11 11 #include <cstdlib> 12 #include <string> 13 #include <sstream> 12 #include <cerrno> 14 13 #include <unistd.h> 15 14 #include <signal.h> 16 #include <errno.h>17 15 18 16 #ifdef WANT_TRACE 19 17 #include <sys/time.h> 20 18 #endif 19 20 #include <string> 21 #include <sstream> 21 22 22 23 #include "Trace.h" … … 29 30 #include <pthread.h> 30 31 #include "ResponseQueue.h" 31 #endif /*USE_THREADS*/32 #endif 32 33 33 34 using namespace Rappture::VtkVis; … … 46 47 #ifdef USE_THREADS 47 48 static void 48 QueueFrame(ResponseQueue *queuePtr, vtkUnsignedCharArray *imgData)49 queueFrame(ResponseQueue *queue, vtkUnsignedCharArray *imgData) 49 50 { 50 51 #ifdef DEBUG … … 89 90 90 91 #ifdef RENDER_TARGA 91 QueueTGA(queuePtr, oss.str().c_str(),92 imgData->GetPointer(0), 93 g_renderer->getWindowWidth(), 94 g_renderer->getWindowHeight(), 95 TARGA_BYTES_PER_PIXEL); 96 #else 97 QueuePPM(queuePtr, oss.str().c_str(),92 queueTGA(queue, oss.str().c_str(), 93 imgData->GetPointer(0), 94 g_renderer->getWindowWidth(), 95 g_renderer->getWindowHeight(), 96 TARGA_BYTES_PER_PIXEL); 97 #else 98 queuePPM(queue, oss.str().c_str(), 98 99 imgData->GetPointer(0), 99 100 g_renderer->getWindowWidth(), … … 102 103 } else { 103 104 #ifdef RENDER_TARGA 104 QueueTGA(queuePtr, "nv>image -type image -bytes",105 imgData->GetPointer(0), 106 g_renderer->getWindowWidth(), 107 g_renderer->getWindowHeight(), 108 TARGA_BYTES_PER_PIXEL); 109 #else 110 QueuePPM(queuePtr, "nv>image -type image -bytes",105 queueTGA(queue, "nv>image -type image -bytes", 106 imgData->GetPointer(0), 107 g_renderer->getWindowWidth(), 108 g_renderer->getWindowHeight(), 109 TARGA_BYTES_PER_PIXEL); 110 #else 111 queuePPM(queue, "nv>image -type image -bytes", 111 112 imgData->GetPointer(0), 112 113 g_renderer->getWindowWidth(), … … 237 238 #ifdef USE_THREADS 238 239 static void * 239 ReaderThread(void *clientData)240 { 241 ResponseQueue *queue Ptr= (ResponseQueue *)clientData;240 readerThread(void *clientData) 241 { 242 ResponseQueue *queue = (ResponseQueue *)clientData; 242 243 Tcl_Interp *interp; 243 244 244 245 INFO("starting reader thread"); 245 interp = (Tcl_Interp *)queue Ptr->ClientData();246 interp = (Tcl_Interp *)queue->clientData(); 246 247 vtkSmartPointer<vtkUnsignedCharArray> imgData = 247 248 vtkSmartPointer<vtkUnsignedCharArray>::New(); … … 255 256 TRACE("Rendering new frame"); 256 257 g_renderer->getRenderedFrame(imgData); 257 QueueFrame(queuePtr, imgData);258 queueFrame(queue, imgData); 258 259 } else { 259 260 TRACE("No render required"); … … 266 267 267 268 static void * 268 WriterThread(void *clientData)269 { 270 ResponseQueue *queue Ptr= (ResponseQueue *)clientData;269 writerThread(void *clientData) 270 { 271 ResponseQueue *queue = (ResponseQueue *)clientData; 271 272 272 273 INFO("starting writer thread"); 273 274 for (;;) { 274 Response *response Ptr;275 276 response Ptr = queuePtr->Dequeue();277 if (fwrite(response Ptr->Message(), sizeof(char), responsePtr->Length(),278 g_fOut) != response Ptr->Length()) {275 Response *response; 276 277 response = queue->dequeue(); 278 if (fwrite(response->message(), sizeof(char), response->length(), 279 g_fOut) != response->length()) { 279 280 ERROR("short write while trying to write %ld bytes", 280 response Ptr->Length());281 response->length()); 281 282 } 282 283 fflush(g_fOut); 283 delete response Ptr;284 delete response; 284 285 if (feof(g_fOut)) 285 286 break; … … 296 297 signal(SIGPIPE, SIG_IGN); 297 298 initService(); 298 InitLog();299 initLog(); 299 300 300 301 TRACE("Starting VTKVis Server"); … … 321 322 322 323 pthread_t readerThreadId, writerThreadId; 323 if (pthread_create(&readerThreadId, NULL, & ReaderThread, &queue) < 0) {324 if (pthread_create(&readerThreadId, NULL, &readerThread, &queue) < 0) { 324 325 ERROR("can't create reader thread: %s", strerror(errno)); 325 326 } 326 if (pthread_create(&writerThreadId, NULL, & WriterThread, &queue) < 0) {327 if (pthread_create(&writerThreadId, NULL, &writerThread, &queue) < 0) { 327 328 ERROR("can't create writer thread: %s", strerror(errno)); 328 329 } … … 365 366 TRACE("Exiting VTKVis Server"); 366 367 367 CloseLog();368 closeLog(); 368 369 exitService(); 369 370 -
branches/vtkvis_threaded/RpVtkRendererCmd.cpp
r2488 r2495 25 25 #ifdef USE_THREADS 26 26 #include "ResponseQueue.h" 27 #endif /*USE_THREADS*/27 #endif 28 28 29 29 using namespace Rappture::VtkVis; … … 34 34 static void 35 35 QueueResponse(ClientData clientData, const void *bytes, size_t len, 36 Response::AllocationType allocType)37 { 38 ResponseQueue *queue Ptr= (ResponseQueue *)clientData;39 40 Response *response Ptr;41 42 response Ptr= new Response(Response::DATA);43 response Ptr->SetMessage((unsigned char *)bytes, len, allocType);44 queue Ptr->Enqueue(responsePtr);36 Response::AllocationType allocType) 37 { 38 ResponseQueue *queue = (ResponseQueue *)clientData; 39 40 Response *response; 41 42 response = new Response(Response::DATA); 43 response->setMessage((unsigned char *)bytes, len, allocType); 44 queue->enqueue(response); 45 45 } 46 46 #else … … 2688 2688 #else 2689 2689 #ifdef USE_THREADS 2690 ResponseQueue *queue Ptr= (ResponseQueue *)clientData;2691 QueuePPM(queuePtr, cmd, imgData->GetPointer(0), width, height);2690 ResponseQueue *queue = (ResponseQueue *)clientData; 2691 queuePPM(queue, cmd, imgData->GetPointer(0), width, height); 2692 2692 #else 2693 2693 writePPM(g_fdOut, cmd, imgData->GetPointer(0), width, height); -
branches/vtkvis_threaded/RpVtkRendererCmd.h
r2482 r2495 13 13 14 14 namespace Rappture { 15 namespace VtkVis { 16 extern int processCommands(Tcl_Interp *interp, FILE *fin, FILE *fout); 17 extern void initTcl(Tcl_Interp *interp, ClientData clientData); 18 extern void exitTcl(Tcl_Interp *interp); 19 } 15 namespace VtkVis { 16 17 extern int processCommands(Tcl_Interp *interp, FILE *fin, FILE *fout); 18 extern void initTcl(Tcl_Interp *interp, ClientData clientData); 19 extern void exitTcl(Tcl_Interp *interp); 20 21 } 20 22 } 21 23 -
branches/vtkvis_threaded/TGAWriter.cpp
r2488 r2495 19 19 #ifdef USE_THREADS 20 20 #include "ResponseQueue.h" 21 #endif /*USE_THREADS*/ 21 #endif 22 23 #ifdef USE_THREADS 22 24 23 25 /** … … 27 29 * top scanline ordering. 28 30 * 29 * \param[in] fd File descriptor that will be writtento31 * \param[in] queue Pointer to ResponseQueue to write to 30 32 * \param[in] cmdName Command name to send (byte length will be appended) 31 33 * \param[in] data Image data … … 34 36 * \param[in] bytesPerPixel Should be 3 or 4, depending on alpha 35 37 */ 36 #ifdef USE_THREADS37 38 void 38 Rappture::VtkVis:: QueueTGA(ResponseQueue *queuePtr, const char *cmdName,39 Rappture::VtkVis::queueTGA(ResponseQueue *queue, const char *cmdName, 39 40 const unsigned char *data, 40 41 int width, int height, … … 59 60 char command[200]; 60 61 cmdLength = snprintf(command, sizeof(command), "%s %lu\n", cmdName, 61 (unsigned long)headerLength + dataLength);62 (unsigned long)headerLength + dataLength); 62 63 63 64 size_t length; 64 unsigned char *mesg ;65 unsigned char *mesg = NULL; 65 66 66 67 length = headerLength + dataLength + cmdLength; … … 72 73 memcpy(mesg, command, cmdLength); 73 74 memcpy(mesg + cmdLength, header, headerLength); 74 75 size_t bytesPerRow = width * 3; 76 unsigned char *destRowPtr = mesg + cmdLength + headerLength; 77 int y; 78 unsigned char *srcRowPtr = const_cast<unsigned char *>(data); 79 for (y = 0; y < height; y++) { 80 memcpy(destRowPtr, srcRowPtr, bytesPerRow); 81 srcRowPtr += bytesPerRow; 82 destRowPtr += bytesPerRow; 83 } 84 85 Response *responsePtr; 75 memcpy(mesg + cmdLength + headerLength, 76 const_cast<unsigned char *>(data), dataLength); 77 78 Response *response = NULL; 86 79 if (strncmp(cmdName, "nv>legend", 9) == 0) { 87 response Ptr= new Response(Response::LEGEND);80 response = new Response(Response::LEGEND); 88 81 } else { 89 response Ptr= new Response(Response::IMAGE);90 } 91 response Ptr->SetMessage(mesg, length, Response::DYNAMIC);92 queue Ptr->Enqueue(responsePtr);82 response = new Response(Response::IMAGE); 83 } 84 response->setMessage(mesg, length, Response::DYNAMIC); 85 queue->enqueue(response); 93 86 TRACE("Leaving (%dx%d)\n", width, height); 94 87 } 95 88 #else 96 89 90 /** 91 * \brief Writes image command + data to supplied file descriptor. 92 * 93 * The image data must be supplied in BGR(A) order with bottom to 94 * top scanline ordering. 95 * 96 * \param[in] fd File descriptor that will be written to 97 * \param[in] cmdName Command name to send (byte length will be appended) 98 * \param[in] data Image data 99 * \param[in] width Width of image in pixels 100 * \param[in] height Height of image in pixels 101 * \param[in] bytesPerPixel Should be 3 or 4, depending on alpha 102 */ 97 103 void 98 104 Rappture::VtkVis::writeTGA(int fd, const char *cmdName, -
branches/vtkvis_threaded/TGAWriter.h
r2488 r2495 11 11 #ifdef USE_THREADS 12 12 #include "ResponseQueue.h" 13 #endif /*USE_THREADS*/13 #endif 14 14 15 15 namespace Rappture { 16 16 namespace VtkVis { 17 17 #ifdef USE_THREADS 18 extern void QueueTGA(ResponseQueue *queuePtr, const char *cmdName, 19 const unsigned char *data, int width, int height, 20 int bytesPerPixel); 18 extern 19 void queueTGA(ResponseQueue *queue, const char *cmdName, 20 const unsigned char *data, int width, int height, 21 int bytesPerPixel); 21 22 #else 22 extern void writeTGA(int fd, const char *cmdName, 23 const unsigned char *data, int width, int height, 24 int bytesPerPixel); 25 #endif /*USE_THREADS*/ 26 extern void writeTGAFile(const char *filename, 27 const unsigned char *data, int width, int height, 28 int bytesPerPixel, bool srcIsRGB = false); 29 } 23 extern 24 void writeTGA(int fd, const char *cmdName, 25 const unsigned char *data, int width, int height, 26 int bytesPerPixel); 27 #endif 28 extern 29 void writeTGAFile(const char *filename, 30 const unsigned char *data, int width, int height, 31 int bytesPerPixel, bool srcIsRGB = false); 32 } 30 33 } 31 34 32 #endif /*__RAPPTURE_VTKVIS_TGA_WRITER_H__*/35 #endif -
branches/vtkvis_threaded/Trace.cpp
r2100 r2495 21 21 */ 22 22 void 23 Rappture::VtkVis:: InitLog()23 Rappture::VtkVis::initLog() 24 24 { 25 25 openlog("vtkvis", LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER); … … 30 30 */ 31 31 void 32 Rappture::VtkVis:: CloseLog()32 Rappture::VtkVis::closeLog() 33 33 { 34 34 closelog(); … … 39 39 */ 40 40 void 41 Rappture::VtkVis:: LogMessage(int priority, const char *funcname,41 Rappture::VtkVis::logMessage(int priority, const char *funcname, 42 42 const char *path, int lineNum, const char* fmt, ...) 43 43 { -
branches/vtkvis_threaded/Trace.h
r2482 r2495 14 14 namespace VtkVis { 15 15 16 extern void InitLog();16 extern void initLog(); 17 17 18 extern void CloseLog();18 extern void closeLog(); 19 19 20 extern void LogMessage(int priority, const char *funcname, const char *fileName,20 extern void logMessage(int priority, const char *funcname, const char *fileName, 21 21 int lineNum, const char* format, ...); 22 22 23 #define ERROR(...) Rappture::VtkVis:: LogMessage(LOG_ERR, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)23 #define ERROR(...) Rappture::VtkVis::logMessage(LOG_ERR, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) 24 24 #ifdef WANT_TRACE 25 #define TRACE(...) Rappture::VtkVis:: LogMessage(LOG_DEBUG, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)25 #define TRACE(...) Rappture::VtkVis::logMessage(LOG_DEBUG, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) 26 26 #else 27 27 #define TRACE(...) 28 28 #endif /*WANT_TRACE*/ 29 #define WARN(...) Rappture::VtkVis:: LogMessage(LOG_WARNING, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)30 #define INFO(...) Rappture::VtkVis:: LogMessage(LOG_INFO, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)29 #define WARN(...) Rappture::VtkVis::logMessage(LOG_WARNING, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) 30 #define INFO(...) Rappture::VtkVis::logMessage(LOG_INFO, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) 31 31 32 32 }
Note: See TracChangeset
for help on using the changeset viewer.