comparison Plugins/Engine/OrthancPlugins.cpp @ 1826:ac5b0b4e2434

refactoring of DicomImageDecoder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Nov 2015 16:00:57 +0100
parents f0f8a94c0858
children 4b6673e828f4
comparison
equal deleted inserted replaced
1825:f0f8a94c0858 1826:ac5b0b4e2434
46 #include "../../OrthancServer/FromDcmtkBridge.h" 46 #include "../../OrthancServer/FromDcmtkBridge.h"
47 #include "../../OrthancServer/OrthancInitialization.h" 47 #include "../../OrthancServer/OrthancInitialization.h"
48 #include "../../OrthancServer/ServerContext.h" 48 #include "../../OrthancServer/ServerContext.h"
49 #include "../../OrthancServer/ServerToolbox.h" 49 #include "../../OrthancServer/ServerToolbox.h"
50 #include "../../OrthancServer/Search/HierarchicalMatcher.h" 50 #include "../../OrthancServer/Search/HierarchicalMatcher.h"
51 #include "../../OrthancServer/Internals/DicomImageDecoder.h"
51 #include "../../Core/Compression/ZlibCompressor.h" 52 #include "../../Core/Compression/ZlibCompressor.h"
52 #include "../../Core/Compression/GzipCompressor.h" 53 #include "../../Core/Compression/GzipCompressor.h"
53 #include "../../Core/Images/Image.h" 54 #include "../../Core/Images/Image.h"
54 #include "../../Core/Images/PngReader.h" 55 #include "../../Core/Images/PngReader.h"
55 #include "../../Core/Images/PngWriter.h" 56 #include "../../Core/Images/PngWriter.h"
284 ServerContext* context_; 285 ServerContext* context_;
285 RestCallbacks restCallbacks_; 286 RestCallbacks restCallbacks_;
286 OnStoredCallbacks onStoredCallbacks_; 287 OnStoredCallbacks onStoredCallbacks_;
287 OnChangeCallbacks onChangeCallbacks_; 288 OnChangeCallbacks onChangeCallbacks_;
288 OrthancPluginWorklistCallback worklistCallback_; 289 OrthancPluginWorklistCallback worklistCallback_;
290 OrthancPluginDecodeImageCallback decodeImageCallback_;
289 std::auto_ptr<StorageAreaFactory> storageArea_; 291 std::auto_ptr<StorageAreaFactory> storageArea_;
290 boost::recursive_mutex restCallbackMutex_; 292 boost::recursive_mutex restCallbackMutex_;
291 boost::recursive_mutex storedCallbackMutex_; 293 boost::recursive_mutex storedCallbackMutex_;
292 boost::recursive_mutex changeCallbackMutex_; 294 boost::recursive_mutex changeCallbackMutex_;
293 boost::mutex worklistCallbackMutex_; 295 boost::mutex worklistCallbackMutex_;
296 boost::mutex decodeImageCallbackMutex_;
294 boost::recursive_mutex invokeServiceMutex_; 297 boost::recursive_mutex invokeServiceMutex_;
295 Properties properties_; 298 Properties properties_;
296 int argc_; 299 int argc_;
297 char** argv_; 300 char** argv_;
298 std::auto_ptr<OrthancPluginDatabase> database_; 301 std::auto_ptr<OrthancPluginDatabase> database_;
299 PluginsErrorDictionary dictionary_; 302 PluginsErrorDictionary dictionary_;
300 303
301 PImpl() : 304 PImpl() :
302 context_(NULL), 305 context_(NULL),
303 worklistCallback_(NULL), 306 worklistCallback_(NULL),
307 decodeImageCallback_(NULL),
304 argc_(1), 308 argc_(1),
305 argv_(NULL) 309 argv_(NULL)
306 { 310 {
307 } 311 }
308 }; 312 };
723 LOG(ERROR) << "Can only register one plugin to handle modality worklists"; 727 LOG(ERROR) << "Can only register one plugin to handle modality worklists";
724 throw OrthancException(ErrorCode_Plugin); 728 throw OrthancException(ErrorCode_Plugin);
725 } 729 }
726 else 730 else
727 { 731 {
728 LOG(INFO) << "Plugin has registered an modality worklist callback"; 732 LOG(INFO) << "Plugin has registered a callback to handle modality worklists";
729 pimpl_->worklistCallback_ = p.callback; 733 pimpl_->worklistCallback_ = p.callback;
734 }
735 }
736
737
738 void OrthancPlugins::RegisterDecodeImageCallback(const void* parameters)
739 {
740 const _OrthancPluginDecodeImageCallback& p =
741 *reinterpret_cast<const _OrthancPluginDecodeImageCallback*>(parameters);
742
743 boost::mutex::scoped_lock lock(pimpl_->decodeImageCallbackMutex_);
744
745 if (pimpl_->decodeImageCallback_ != NULL)
746 {
747 LOG(ERROR) << "Can only register one plugin to handle the decompression of DICOM images";
748 throw OrthancException(ErrorCode_Plugin);
749 }
750 else
751 {
752 LOG(INFO) << "Plugin has registered a callback to decode DICOM images";
753 pimpl_->decodeImageCallback_ = p.callback;
730 } 754 }
731 } 755 }
732 756
733 757
734 758
1542 1566
1543 case _OrthancPluginService_RegisterWorklistCallback: 1567 case _OrthancPluginService_RegisterWorklistCallback:
1544 RegisterWorklistCallback(parameters); 1568 RegisterWorklistCallback(parameters);
1545 return true; 1569 return true;
1546 1570
1571 case _OrthancPluginService_RegisterDecodeImageCallback:
1572 RegisterDecodeImageCallback(parameters);
1573 return true;
1574
1547 case _OrthancPluginService_AnswerBuffer: 1575 case _OrthancPluginService_AnswerBuffer:
1548 AnswerBuffer(parameters); 1576 AnswerBuffer(parameters);
1549 return true; 1577 return true;
1550 1578
1551 case _OrthancPluginService_CompressAndAnswerPngImage: 1579 case _OrthancPluginService_CompressAndAnswerPngImage:
2147 { 2175 {
2148 boost::mutex::scoped_lock lock(pimpl_->worklistCallbackMutex_); 2176 boost::mutex::scoped_lock lock(pimpl_->worklistCallbackMutex_);
2149 return pimpl_->worklistCallback_ != NULL; 2177 return pimpl_->worklistCallback_ != NULL;
2150 } 2178 }
2151 2179
2180
2181 ImageAccessor* OrthancPlugins::Decode(ParsedDicomFile& dicom,
2182 unsigned int frame)
2183 {
2184 {
2185 boost::mutex::scoped_lock lock(pimpl_->decodeImageCallbackMutex_);
2186 if (pimpl_->decodeImageCallback_ != NULL)
2187 {
2188 std::string s;
2189 dicom.SaveToMemoryBuffer(s);
2190
2191 OrthancPluginImage* pluginImage = NULL;
2192 if (pimpl_->decodeImageCallback_(&pluginImage, s.c_str(), s.size(), frame) == OrthancPluginErrorCode_Success &&
2193 pluginImage != NULL)
2194 {
2195 return reinterpret_cast<ImageAccessor*>(pluginImage);
2196 }
2197 else
2198 {
2199 LOG(WARNING) << "The custom image decoder cannot handle an image, trying with the built-in decoder";
2200 }
2201 }
2202 }
2203
2204 DicomImageDecoder defaultDecoder;
2205 return defaultDecoder.Decode(dicom, frame);
2206 }
2152 } 2207 }