comparison Framework/Toolbox/MessagingToolbox.cpp @ 118:a4d0b6c82b29 wasm

using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Oct 2017 14:31:26 +0200
parents 2eca030792aa
children ba83e38cf3ff
comparison
equal deleted inserted replaced
117:42c05a3baee3 118:a4d0b6c82b29
30 #include <Core/Logging.h> 30 #include <Core/Logging.h>
31 31
32 #include <boost/lexical_cast.hpp> 32 #include <boost/lexical_cast.hpp>
33 #include <json/reader.h> 33 #include <json/reader.h>
34 34
35 #if defined(__native_client__)
36 # include <boost/math/special_functions/round.hpp>
37 #else
38 # include <boost/date_time/posix_time/posix_time.hpp>
39 # include <boost/date_time/microsec_time_clock.hpp>
40 #endif
41
42 namespace OrthancStone 35 namespace OrthancStone
43 { 36 {
44 namespace MessagingToolbox 37 namespace MessagingToolbox
45 { 38 {
46 #if defined(__native_client__)
47 static pp::Core* core_ = NULL;
48
49 void Timestamp::Initialize(pp::Core* core)
50 {
51 if (core == NULL)
52 {
53 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
54 }
55
56 core_ = core;
57 }
58
59 Timestamp::Timestamp()
60 {
61 if (core_ == NULL)
62 {
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
64 }
65
66 time_ = core_->GetTimeTicks();
67 }
68
69 int Timestamp::GetMillisecondsSince(const Timestamp& other)
70 {
71 double difference = time_ - other.time_;
72 return static_cast<int>(boost::math::iround(difference * 1000.0));
73 }
74 #else
75 Timestamp::Timestamp()
76 {
77 time_ = boost::posix_time::microsec_clock::local_time();
78 }
79
80 int Timestamp::GetMillisecondsSince(const Timestamp& other)
81 {
82 boost::posix_time::time_duration difference = time_ - other.time_;
83 return static_cast<int>(difference.total_milliseconds());
84 }
85 #endif
86
87 static bool ParseVersion(std::string& version, 39 static bool ParseVersion(std::string& version,
88 unsigned int& major, 40 unsigned int& major,
89 unsigned int& minor, 41 unsigned int& minor,
90 unsigned int& patch, 42 unsigned int& patch,
91 const Json::Value& info) 43 const Json::Value& info)
444 std::cout << stretchLow << "->" << stretchHigh << " = " << a << "->" << b << std::endl; 396 std::cout << stretchLow << "->" << stretchHigh << " = " << a << "->" << b << std::endl;
445 #endif 397 #endif
446 398
447 return image.release(); 399 return image.release();
448 } 400 }
401
402
403 static void AddTag(Orthanc::DicomMap& target,
404 const OrthancPlugins::IDicomDataset& source,
405 const Orthanc::DicomTag& tag)
406 {
407 OrthancPlugins::DicomTag key(tag.GetGroup(), tag.GetElement());
408
409 std::string value;
410 if (source.GetStringValue(value, key))
411 {
412 target.SetValue(tag, value, false);
413 }
414 }
415
416
417 void ConvertDataset(Orthanc::DicomMap& target,
418 const OrthancPlugins::IDicomDataset& source)
419 {
420 target.Clear();
421
422 AddTag(target, source, Orthanc::DICOM_TAG_BITS_ALLOCATED);
423 AddTag(target, source, Orthanc::DICOM_TAG_BITS_STORED);
424 AddTag(target, source, Orthanc::DICOM_TAG_COLUMNS);
425 AddTag(target, source, Orthanc::DICOM_TAG_FRAME_INCREMENT_POINTER);
426 AddTag(target, source, Orthanc::DICOM_TAG_GRID_FRAME_OFFSET_VECTOR);
427 AddTag(target, source, Orthanc::DICOM_TAG_HIGH_BIT);
428 AddTag(target, source, Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT);
429 AddTag(target, source, Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT);
430 AddTag(target, source, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES);
431 AddTag(target, source, Orthanc::DICOM_TAG_PHOTOMETRIC_INTERPRETATION);
432 AddTag(target, source, Orthanc::DICOM_TAG_PIXEL_REPRESENTATION);
433 AddTag(target, source, Orthanc::DICOM_TAG_PIXEL_SPACING);
434 AddTag(target, source, Orthanc::DICOM_TAG_PLANAR_CONFIGURATION);
435 AddTag(target, source, Orthanc::DICOM_TAG_RESCALE_INTERCEPT);
436 AddTag(target, source, Orthanc::DICOM_TAG_RESCALE_SLOPE);
437 AddTag(target, source, Orthanc::DICOM_TAG_ROWS);
438 AddTag(target, source, Orthanc::DICOM_TAG_SAMPLES_PER_PIXEL);
439 AddTag(target, source, Orthanc::DICOM_TAG_SLICE_THICKNESS);
440 AddTag(target, source, Orthanc::DICOM_TAG_SOP_CLASS_UID);
441 AddTag(target, source, Orthanc::DICOM_TAG_WINDOW_CENTER);
442 AddTag(target, source, Orthanc::DICOM_TAG_WINDOW_WIDTH);
443 }
449 } 444 }
450 } 445 }