comparison Plugins/Engine/OrthancPlugins.cpp @ 1625:c17b1142caab

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Sep 2015 12:58:51 +0200
parents 0a2ad4a6858f
children da7854deb662
comparison
equal deleted inserted replaced
1624:0a2ad4a6858f 1625:c17b1142caab
28 * You should have received a copy of the GNU General Public License 28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. 29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 **/ 30 **/
31 31
32 32
33 #include "../../Core/PrecompiledHeaders.h" 33 #include "../../OrthancServer/PrecompiledHeadersServer.h"
34 #include "OrthancPlugins.h" 34 #include "OrthancPlugins.h"
35 35
36 #include "../../Core/ChunkedBuffer.h" 36 #include "../../Core/ChunkedBuffer.h"
37 #include "../../Core/HttpServer/HttpToolbox.h" 37 #include "../../Core/HttpServer/HttpToolbox.h"
38 #include "../../Core/Logging.h" 38 #include "../../Core/Logging.h"
47 #include "../../Core/Images/PngReader.h" 47 #include "../../Core/Images/PngReader.h"
48 #include "../../Core/Images/PngWriter.h" 48 #include "../../Core/Images/PngWriter.h"
49 #include "../../Core/Images/JpegReader.h" 49 #include "../../Core/Images/JpegReader.h"
50 #include "../../Core/Images/JpegWriter.h" 50 #include "../../Core/Images/JpegWriter.h"
51 #include "../../Core/Images/ImageProcessing.h" 51 #include "../../Core/Images/ImageProcessing.h"
52 #include "PluginsEnumerations.h"
52 53
53 #include <boost/regex.hpp> 54 #include <boost/regex.hpp>
54 55
55 namespace Orthanc 56 namespace Orthanc
56 { 57 {
57 static OrthancPluginResourceType Convert(ResourceType type)
58 {
59 switch (type)
60 {
61 case ResourceType_Patient:
62 return OrthancPluginResourceType_Patient;
63
64 case ResourceType_Study:
65 return OrthancPluginResourceType_Study;
66
67 case ResourceType_Series:
68 return OrthancPluginResourceType_Series;
69
70 case ResourceType_Instance:
71 return OrthancPluginResourceType_Instance;
72
73 default:
74 throw OrthancException(ErrorCode_ParameterOutOfRange);
75 }
76 }
77
78
79 static OrthancPluginChangeType Convert(ChangeType type)
80 {
81 switch (type)
82 {
83 case ChangeType_CompletedSeries:
84 return OrthancPluginChangeType_CompletedSeries;
85
86 case ChangeType_Deleted:
87 return OrthancPluginChangeType_Deleted;
88
89 case ChangeType_NewChildInstance:
90 return OrthancPluginChangeType_NewChildInstance;
91
92 case ChangeType_NewInstance:
93 return OrthancPluginChangeType_NewInstance;
94
95 case ChangeType_NewPatient:
96 return OrthancPluginChangeType_NewPatient;
97
98 case ChangeType_NewSeries:
99 return OrthancPluginChangeType_NewSeries;
100
101 case ChangeType_NewStudy:
102 return OrthancPluginChangeType_NewStudy;
103
104 case ChangeType_StablePatient:
105 return OrthancPluginChangeType_StablePatient;
106
107 case ChangeType_StableSeries:
108 return OrthancPluginChangeType_StableSeries;
109
110 case ChangeType_StableStudy:
111 return OrthancPluginChangeType_StableStudy;
112
113 default:
114 throw OrthancException(ErrorCode_ParameterOutOfRange);
115 }
116 }
117
118
119 static OrthancPluginPixelFormat Convert(PixelFormat format)
120 {
121 switch (format)
122 {
123 case PixelFormat_Grayscale16:
124 return OrthancPluginPixelFormat_Grayscale16;
125
126 case PixelFormat_Grayscale8:
127 return OrthancPluginPixelFormat_Grayscale8;
128
129 case PixelFormat_RGB24:
130 return OrthancPluginPixelFormat_RGB24;
131
132 case PixelFormat_RGBA32:
133 return OrthancPluginPixelFormat_RGBA32;
134
135 case PixelFormat_SignedGrayscale16:
136 return OrthancPluginPixelFormat_SignedGrayscale16;
137
138 default:
139 throw OrthancException(ErrorCode_ParameterOutOfRange);
140 }
141 }
142
143
144 static PixelFormat Convert(OrthancPluginPixelFormat format)
145 {
146 switch (format)
147 {
148 case OrthancPluginPixelFormat_Grayscale16:
149 return PixelFormat_Grayscale16;
150
151 case OrthancPluginPixelFormat_Grayscale8:
152 return PixelFormat_Grayscale8;
153
154 case OrthancPluginPixelFormat_RGB24:
155 return PixelFormat_RGB24;
156
157 case OrthancPluginPixelFormat_RGBA32:
158 return PixelFormat_RGBA32;
159
160 case OrthancPluginPixelFormat_SignedGrayscale16:
161 return PixelFormat_SignedGrayscale16;
162
163 default:
164 throw OrthancException(ErrorCode_ParameterOutOfRange);
165 }
166 }
167
168
169 static OrthancPluginContentType Convert(FileContentType type)
170 {
171 switch (type)
172 {
173 case FileContentType_Dicom:
174 return OrthancPluginContentType_Dicom;
175
176 case FileContentType_DicomAsJson:
177 return OrthancPluginContentType_DicomAsJson;
178
179 default:
180 return OrthancPluginContentType_Unknown;
181 }
182 }
183
184
185 static FileContentType Convert(OrthancPluginContentType type)
186 {
187 switch (type)
188 {
189 case OrthancPluginContentType_Dicom:
190 return FileContentType_Dicom;
191
192 case OrthancPluginContentType_DicomAsJson:
193 return FileContentType_DicomAsJson;
194
195 default:
196 return FileContentType_Unknown;
197 }
198 }
199
200
201 struct OrthancPlugins::PImpl 58 struct OrthancPlugins::PImpl
202 { 59 {
203 class RestCallback : public boost::noncopyable 60 class RestCallback : public boost::noncopyable
204 { 61 {
205 private: 62 private:
528 385
529 for (std::list<OrthancPluginOnChangeCallback>::const_iterator 386 for (std::list<OrthancPluginOnChangeCallback>::const_iterator
530 callback = pimpl_->onChangeCallbacks_.begin(); 387 callback = pimpl_->onChangeCallbacks_.begin();
531 callback != pimpl_->onChangeCallbacks_.end(); ++callback) 388 callback != pimpl_->onChangeCallbacks_.end(); ++callback)
532 { 389 {
533 (*callback) (Convert(change.GetChangeType()), 390 (*callback) (Plugins::Convert(change.GetChangeType()),
534 Convert(change.GetResourceType()), 391 Plugins::Convert(change.GetResourceType()),
535 change.GetPublicId().c_str()); 392 change.GetPublicId().c_str());
536 } 393 }
537 } 394 }
538 catch (OrthancException&) 395 catch (OrthancException&)
539 { 396 {
737 *reinterpret_cast<const _OrthancPluginCompressAndAnswerImage*>(parameters); 594 *reinterpret_cast<const _OrthancPluginCompressAndAnswerImage*>(parameters);
738 595
739 HttpOutput* translatedOutput = reinterpret_cast<HttpOutput*>(p.output); 596 HttpOutput* translatedOutput = reinterpret_cast<HttpOutput*>(p.output);
740 597
741 ImageAccessor accessor; 598 ImageAccessor accessor;
742 accessor.AssignReadOnly(Convert(p.pixelFormat), p.width, p.height, p.pitch, p.buffer); 599 accessor.AssignReadOnly(Plugins::Convert(p.pixelFormat), p.width, p.height, p.pitch, p.buffer);
743 600
744 std::string compressed; 601 std::string compressed;
745 602
746 switch (p.imageFormat) 603 switch (p.imageFormat)
747 { 604 {
1133 switch (p.imageFormat) 990 switch (p.imageFormat)
1134 { 991 {
1135 case OrthancPluginImageFormat_Png: 992 case OrthancPluginImageFormat_Png:
1136 { 993 {
1137 PngWriter writer; 994 PngWriter writer;
1138 writer.WriteToMemory(compressed, p.width, p.height, p.pitch, Convert(p.pixelFormat), p.buffer); 995 writer.WriteToMemory(compressed, p.width, p.height, p.pitch, Plugins::Convert(p.pixelFormat), p.buffer);
1139 break; 996 break;
1140 } 997 }
1141 998
1142 case OrthancPluginImageFormat_Jpeg: 999 case OrthancPluginImageFormat_Jpeg:
1143 { 1000 {
1144 JpegWriter writer; 1001 JpegWriter writer;
1145 writer.SetQuality(p.quality); 1002 writer.SetQuality(p.quality);
1146 writer.WriteToMemory(compressed, p.width, p.height, p.pitch, Convert(p.pixelFormat), p.buffer); 1003 writer.WriteToMemory(compressed, p.width, p.height, p.pitch, Plugins::Convert(p.pixelFormat), p.buffer);
1147 break; 1004 break;
1148 } 1005 }
1149 1006
1150 default: 1007 default:
1151 throw OrthancException(ErrorCode_ParameterOutOfRange); 1008 throw OrthancException(ErrorCode_ParameterOutOfRange);
1205 void OrthancPlugins::ConvertPixelFormat(const void* parameters) 1062 void OrthancPlugins::ConvertPixelFormat(const void* parameters)
1206 { 1063 {
1207 const _OrthancPluginConvertPixelFormat& p = *reinterpret_cast<const _OrthancPluginConvertPixelFormat*>(parameters); 1064 const _OrthancPluginConvertPixelFormat& p = *reinterpret_cast<const _OrthancPluginConvertPixelFormat*>(parameters);
1208 const ImageAccessor& source = *reinterpret_cast<const ImageAccessor*>(p.source); 1065 const ImageAccessor& source = *reinterpret_cast<const ImageAccessor*>(p.source);
1209 1066
1210 std::auto_ptr<ImageAccessor> target(new Image(Convert(p.targetFormat), source.GetWidth(), source.GetHeight())); 1067 std::auto_ptr<ImageAccessor> target(new Image(Plugins::Convert(p.targetFormat), source.GetWidth(), source.GetHeight()));
1211 ImageProcessing::Convert(*target, source); 1068 ImageProcessing::Convert(*target, source);
1212 1069
1213 *(p.target) = reinterpret_cast<OrthancPluginImage*>(target.release()); 1070 *(p.target) = reinterpret_cast<OrthancPluginImage*>(target.release());
1214 } 1071 }
1215 1072
1570 } 1427 }
1571 1428
1572 case _OrthancPluginService_GetImagePixelFormat: 1429 case _OrthancPluginService_GetImagePixelFormat:
1573 { 1430 {
1574 const _OrthancPluginGetImageInfo& p = *reinterpret_cast<const _OrthancPluginGetImageInfo*>(parameters); 1431 const _OrthancPluginGetImageInfo& p = *reinterpret_cast<const _OrthancPluginGetImageInfo*>(parameters);
1575 *(p.resultPixelFormat) = Convert(reinterpret_cast<const ImageAccessor*>(p.image)->GetFormat()); 1432 *(p.resultPixelFormat) = Plugins::Convert(reinterpret_cast<const ImageAccessor*>(p.image)->GetFormat());
1576 return true; 1433 return true;
1577 } 1434 }
1578 1435
1579 case _OrthancPluginService_GetImageWidth: 1436 case _OrthancPluginService_GetImageWidth:
1580 { 1437 {
1653 case _OrthancPluginService_StorageAreaCreate: 1510 case _OrthancPluginService_StorageAreaCreate:
1654 { 1511 {
1655 const _OrthancPluginStorageAreaCreate& p = 1512 const _OrthancPluginStorageAreaCreate& p =
1656 *reinterpret_cast<const _OrthancPluginStorageAreaCreate*>(parameters); 1513 *reinterpret_cast<const _OrthancPluginStorageAreaCreate*>(parameters);
1657 IStorageArea& storage = *reinterpret_cast<IStorageArea*>(p.storageArea); 1514 IStorageArea& storage = *reinterpret_cast<IStorageArea*>(p.storageArea);
1658 storage.Create(p.uuid, p.content, p.size, Convert(p.type)); 1515 storage.Create(p.uuid, p.content, p.size, Plugins::Convert(p.type));
1659 return true; 1516 return true;
1660 } 1517 }
1661 1518
1662 case _OrthancPluginService_StorageAreaRead: 1519 case _OrthancPluginService_StorageAreaRead:
1663 { 1520 {
1664 const _OrthancPluginStorageAreaRead& p = 1521 const _OrthancPluginStorageAreaRead& p =
1665 *reinterpret_cast<const _OrthancPluginStorageAreaRead*>(parameters); 1522 *reinterpret_cast<const _OrthancPluginStorageAreaRead*>(parameters);
1666 IStorageArea& storage = *reinterpret_cast<IStorageArea*>(p.storageArea); 1523 IStorageArea& storage = *reinterpret_cast<IStorageArea*>(p.storageArea);
1667 std::string content; 1524 std::string content;
1668 storage.Read(content, p.uuid, Convert(p.type)); 1525 storage.Read(content, p.uuid, Plugins::Convert(p.type));
1669 CopyToMemoryBuffer(*p.target, content); 1526 CopyToMemoryBuffer(*p.target, content);
1670 return true; 1527 return true;
1671 } 1528 }
1672 1529
1673 case _OrthancPluginService_StorageAreaRemove: 1530 case _OrthancPluginService_StorageAreaRemove:
1674 { 1531 {
1675 const _OrthancPluginStorageAreaRemove& p = 1532 const _OrthancPluginStorageAreaRemove& p =
1676 *reinterpret_cast<const _OrthancPluginStorageAreaRemove*>(parameters); 1533 *reinterpret_cast<const _OrthancPluginStorageAreaRemove*>(parameters);
1677 IStorageArea& storage = *reinterpret_cast<IStorageArea*>(p.storageArea); 1534 IStorageArea& storage = *reinterpret_cast<IStorageArea*>(p.storageArea);
1678 storage.Remove(p.uuid, Convert(p.type)); 1535 storage.Remove(p.uuid, Plugins::Convert(p.type));
1679 return true; 1536 return true;
1680 } 1537 }
1681 1538
1682 default: 1539 default:
1683 { 1540 {
1723 virtual void Create(const std::string& uuid, 1580 virtual void Create(const std::string& uuid,
1724 const void* content, 1581 const void* content,
1725 size_t size, 1582 size_t size,
1726 FileContentType type) 1583 FileContentType type)
1727 { 1584 {
1728 if (params_.create(uuid.c_str(), content, size, Convert(type)) != 0) 1585 if (params_.create(uuid.c_str(), content, size, Plugins::Convert(type)) != 0)
1729 { 1586 {
1730 throw OrthancException(ErrorCode_Plugin); 1587 throw OrthancException(ErrorCode_Plugin);
1731 } 1588 }
1732 } 1589 }
1733 1590
1736 FileContentType type) 1593 FileContentType type)
1737 { 1594 {
1738 void* buffer = NULL; 1595 void* buffer = NULL;
1739 int64_t size = 0; 1596 int64_t size = 0;
1740 1597
1741 if (params_.read(&buffer, &size, uuid.c_str(), Convert(type)) != 0) 1598 if (params_.read(&buffer, &size, uuid.c_str(), Plugins::Convert(type)) != 0)
1742 { 1599 {
1743 throw OrthancException(ErrorCode_Plugin); 1600 throw OrthancException(ErrorCode_Plugin);
1744 } 1601 }
1745 1602
1746 try 1603 try
1762 } 1619 }
1763 1620
1764 virtual void Remove(const std::string& uuid, 1621 virtual void Remove(const std::string& uuid,
1765 FileContentType type) 1622 FileContentType type)
1766 { 1623 {
1767 if (params_.remove(uuid.c_str(), Convert(type)) != 0) 1624 if (params_.remove(uuid.c_str(), Plugins::Convert(type)) != 0)
1768 { 1625 {
1769 throw OrthancException(ErrorCode_Plugin); 1626 throw OrthancException(ErrorCode_Plugin);
1770 } 1627 }
1771 } 1628 }
1772 }; 1629 };