comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3916:0e3849268a55 transcoding

new plugin SDK primitives related to OrthancPluginDicomInstance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 11 May 2020 21:07:36 +0200
parents 7e33516965f8
children 6f11b3233a06
comparison
equal deleted inserted replaced
3915:7e33516965f8 3916:0e3849268a55
38 #include <boost/thread.hpp> 38 #include <boost/thread.hpp>
39 #include <json/reader.h> 39 #include <json/reader.h>
40 #include <json/writer.h> 40 #include <json/writer.h>
41 41
42 42
43 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0)
44 static const OrthancPluginErrorCode OrthancPluginErrorCode_NullPointer = OrthancPluginErrorCode_Plugin;
45 #endif
46
47
43 namespace OrthancPlugins 48 namespace OrthancPlugins
44 { 49 {
45 static OrthancPluginContext* globalContext_ = NULL; 50 static OrthancPluginContext* globalContext_ = NULL;
46 51
47 52
3183 { 3188 {
3184 assert(rawHandler != NULL); 3189 assert(rawHandler != NULL);
3185 delete reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler); 3190 delete reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler);
3186 } 3191 }
3187 #endif 3192 #endif
3193
3194
3195 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
3196 DicomInstance::DicomInstance(const OrthancPluginDicomInstance* instance) :
3197 toFree_(false),
3198 instance_(instance)
3199 {
3200 }
3201 #else
3202 DicomInstance::DicomInstance(OrthancPluginDicomInstance* instance) :
3203 toFree_(false),
3204 instance_(instance)
3205 {
3206 }
3207 #endif
3208
3209
3210 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
3211 DicomInstance::DicomInstance(const void* buffer,
3212 size_t size) :
3213 toFree_(true),
3214 instance_(OrthancPluginCreateDicomInstance(GetGlobalContext(), buffer, size))
3215 {
3216 if (instance_ == NULL)
3217 {
3218 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer);
3219 }
3220 }
3221 #endif
3222
3223
3224 DicomInstance::~DicomInstance()
3225 {
3226 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
3227 if (toFree_ &&
3228 instance_ != NULL)
3229 {
3230 OrthancPluginFreeDicomInstance(
3231 GetGlobalContext(), const_cast<OrthancPluginDicomInstance*>(instance_));
3232 }
3233 #endif
3234 }
3235
3236
3237 std::string DicomInstance::GetRemoteAet() const
3238 {
3239 const char* s = OrthancPluginGetInstanceRemoteAet(GetGlobalContext(), instance_);
3240 if (s == NULL)
3241 {
3242 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
3243 }
3244 else
3245 {
3246 return std::string(s);
3247 }
3248 }
3249
3250
3251 void DicomInstance::GetJson(Json::Value& target) const
3252 {
3253 OrthancString s;
3254 s.Assign(OrthancPluginGetInstanceJson(GetGlobalContext(), instance_));
3255 s.ToJson(target);
3256 }
3257
3258
3259 void DicomInstance::GetSimplifiedJson(Json::Value& target) const
3260 {
3261 OrthancString s;
3262 s.Assign(OrthancPluginGetInstanceSimplifiedJson(GetGlobalContext(), instance_));
3263 s.ToJson(target);
3264 }
3265
3266
3267 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
3268 std::string DicomInstance::GetTransferSyntaxUid() const
3269 {
3270 OrthancString s;
3271 s.Assign(OrthancPluginGetInstanceTransferSyntaxUid(GetGlobalContext(), instance_));
3272
3273 std::string result;
3274 s.ToString(result);
3275 return result;
3276 }
3277 #endif
3278
3279
3280 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
3281 bool DicomInstance::HasPixelData() const
3282 {
3283 int32_t result = OrthancPluginHasInstancePixelData(GetGlobalContext(), instance_);
3284 if (result < 0)
3285 {
3286 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
3287 }
3288 else
3289 {
3290 return (result != 0);
3291 }
3292 }
3293 #endif
3294
3295
3296 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
3297 void DicomInstance::GetRawFrame(std::string& target,
3298 unsigned int frameIndex) const
3299 {
3300 OrthancPluginMemoryBuffer buffer;
3301 OrthancPluginErrorCode code = OrthancPluginGetInstanceRawFrame(
3302 GetGlobalContext(), &buffer, instance_, frameIndex);
3303
3304 if (code != OrthancPluginErrorCode_Success)
3305 {
3306 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
3307 }
3308 }
3309 #endif
3310
3311
3312
3313 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
3314 OrthancImage* DicomInstance::GetDecodedFrame(unsigned int frameIndex) const
3315 {
3316 OrthancPluginImage* image = OrthancPluginGetInstanceDecodedFrame(
3317 GetGlobalContext(), instance_, frameIndex);
3318
3319 if (image == NULL)
3320 {
3321 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
3322 }
3323 else
3324 {
3325 return new OrthancImage(image);
3326 }
3327 }
3328 #endif
3188 } 3329 }