Mercurial > hg > orthanc-wsi
comparison Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 82:5b127ab0080b
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Dec 2016 17:01:34 +0100 |
parents | 7a3853d51c45 |
children | 319b8c45c231 |
comparison
equal
deleted
inserted
replaced
81:d101055fc20b | 82:5b127ab0080b |
---|---|
274 Clear(); | 274 Clear(); |
275 Check(OrthancPluginReadFile(context_, &buffer_, path.c_str())); | 275 Check(OrthancPluginReadFile(context_, &buffer_, path.c_str())); |
276 } | 276 } |
277 | 277 |
278 | 278 |
279 OrthancString::OrthancString(OrthancPluginContext* context, | 279 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query) |
280 char* str) : | 280 { |
281 context_(context), | 281 Clear(); |
282 str_(str) | 282 Check(OrthancPluginWorklistGetDicomQuery(context_, &buffer_, query)); |
283 { | 283 } |
284 | |
285 | |
286 void OrthancString::Assign(char* str) | |
287 { | |
288 if (str == NULL) | |
289 { | |
290 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError); | |
291 } | |
292 else | |
293 { | |
294 Clear(); | |
295 str_ = str; | |
296 } | |
284 } | 297 } |
285 | 298 |
286 | 299 |
287 void OrthancString::Clear() | 300 void OrthancString::Clear() |
288 { | 301 { |
320 { | 333 { |
321 OrthancPluginLogError(context_, "Cannot convert some memory buffer to JSON"); | 334 OrthancPluginLogError(context_, "Cannot convert some memory buffer to JSON"); |
322 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat); | 335 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat); |
323 } | 336 } |
324 } | 337 } |
338 | |
339 | |
340 void MemoryBuffer::DicomToJson(Json::Value& target, | |
341 OrthancPluginDicomToJsonFormat format, | |
342 OrthancPluginDicomToJsonFlags flags, | |
343 uint32_t maxStringLength) | |
344 { | |
345 OrthancString str(context_); | |
346 str.Assign(OrthancPluginDicomBufferToJson(context_, GetData(), GetSize(), format, flags, maxStringLength)); | |
347 str.ToJson(target); | |
348 } | |
349 | |
325 | 350 |
326 | 351 |
327 OrthancConfiguration::OrthancConfiguration(OrthancPluginContext* context) : | 352 OrthancConfiguration::OrthancConfiguration(OrthancPluginContext* context) : |
328 context_(context) | 353 context_(context) |
329 { | 354 { |
330 OrthancString str(context, OrthancPluginGetConfiguration(context)); | 355 OrthancString str(context); |
356 str.Assign(OrthancPluginGetConfiguration(context)); | |
331 | 357 |
332 if (str.GetContent() == NULL) | 358 if (str.GetContent() == NULL) |
333 { | 359 { |
334 OrthancPluginLogError(context, "Cannot access the Orthanc configuration"); | 360 OrthancPluginLogError(context, "Cannot access the Orthanc configuration"); |
335 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError); | 361 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError); |
807 OrthancPluginCompressAndAnswerJpegImage(context_, output, GetPixelFormat(), | 833 OrthancPluginCompressAndAnswerJpegImage(context_, output, GetPixelFormat(), |
808 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); | 834 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); |
809 } | 835 } |
810 | 836 |
811 | 837 |
838 | |
839 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 | |
840 FindMatcher::FindMatcher(OrthancPluginContext* context, | |
841 const OrthancPluginWorklistQuery* worklist) : | |
842 context_(context), | |
843 matcher_(NULL), | |
844 worklist_(worklist) | |
845 { | |
846 if (worklist_ == NULL) | |
847 { | |
848 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange); | |
849 } | |
850 } | |
851 | |
852 | |
853 void FindMatcher::SetupDicom(OrthancPluginContext* context, | |
854 const void* query, | |
855 uint32_t size) | |
856 { | |
857 context_ = context; | |
858 worklist_ = NULL; | |
859 | |
860 matcher_ = OrthancPluginCreateFindMatcher(context_, query, size); | |
861 if (matcher_ == NULL) | |
862 { | |
863 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError); | |
864 } | |
865 } | |
866 | |
867 | |
868 FindMatcher::~FindMatcher() | |
869 { | |
870 // The "worklist_" field | |
871 | |
872 if (matcher_ != NULL) | |
873 { | |
874 OrthancPluginFreeFindMatcher(context_, matcher_); | |
875 } | |
876 } | |
877 | |
878 | |
879 | |
880 bool FindMatcher::IsMatch(const void* dicom, | |
881 uint32_t size) const | |
882 { | |
883 int32_t result; | |
884 | |
885 if (matcher_ != NULL) | |
886 { | |
887 result = OrthancPluginFindMatcherIsMatch(context_, matcher_, dicom, size); | |
888 } | |
889 else if (worklist_ != NULL) | |
890 { | |
891 result = OrthancPluginWorklistIsMatch(context_, worklist_, dicom, size); | |
892 } | |
893 else | |
894 { | |
895 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError); | |
896 } | |
897 | |
898 if (result == 0) | |
899 { | |
900 return false; | |
901 } | |
902 else if (result == 1) | |
903 { | |
904 return true; | |
905 } | |
906 else | |
907 { | |
908 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError); | |
909 } | |
910 } | |
911 | |
912 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ | |
913 | |
914 | |
812 bool RestApiGet(Json::Value& result, | 915 bool RestApiGet(Json::Value& result, |
813 OrthancPluginContext* context, | 916 OrthancPluginContext* context, |
814 const std::string& uri, | 917 const std::string& uri, |
815 bool applyPlugins) | 918 bool applyPlugins) |
816 { | 919 { |