comparison ViewerPlugin/Plugin.cpp @ 156:dafbb7ebc00f

fix for compatibility with simplified OrthancPluginCppWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Dec 2018 09:33:49 +0100
parents 1304498491e4
children 6b8ccfc02051
comparison
equal deleted inserted replaced
155:1304498491e4 156:dafbb7ebc00f
35 35
36 #include <EmbeddedResources.h> 36 #include <EmbeddedResources.h>
37 37
38 #include <cassert> 38 #include <cassert>
39 39
40 OrthancPluginContext* context_ = NULL;
41
42 std::auto_ptr<OrthancPlugins::OrthancPluginConnection> orthanc_; 40 std::auto_ptr<OrthancPlugins::OrthancPluginConnection> orthanc_;
43 std::auto_ptr<OrthancWSI::DicomPyramidCache> cache_; 41 std::auto_ptr<OrthancWSI::DicomPyramidCache> cache_;
44 std::auto_ptr<Orthanc::Semaphore> transcoderSemaphore_; 42 std::auto_ptr<Orthanc::Semaphore> transcoderSemaphore_;
45 43
46 44
55 uint8_t green = 0; 53 uint8_t green = 0;
56 uint8_t blue = 0; 54 uint8_t blue = 0;
57 Orthanc::ImageProcessing::Set(tile, red, green, blue, 255); 55 Orthanc::ImageProcessing::Set(tile, red, green, blue, 255);
58 56
59 // TODO Cache the tile 57 // TODO Cache the tile
60 OrthancPluginCompressAndAnswerPngImage(context_, output, OrthancPluginPixelFormat_RGB24, 58 OrthancPluginCompressAndAnswerPngImage(OrthancPlugins::GetGlobalContext(),
59 output, OrthancPluginPixelFormat_RGB24,
61 tile.GetWidth(), tile.GetHeight(), 60 tile.GetWidth(), tile.GetHeight(),
62 tile.GetPitch(), tile.GetBuffer()); 61 tile.GetPitch(), tile.GetBuffer());
63 } 62 }
64 63
65 64
66 static bool DisplayPerformanceWarning() 65 static bool DisplayPerformanceWarning()
67 { 66 {
68 (void) DisplayPerformanceWarning; // Disable warning about unused function 67 (void) DisplayPerformanceWarning; // Disable warning about unused function
69 OrthancPluginLogWarning(context_, "Performance warning in whole-slide imaging: " 68 OrthancPluginLogWarning(OrthancPlugins::GetGlobalContext(), "Performance warning in whole-slide imaging: "
70 "Non-release build, runtime debug assertions are turned on"); 69 "Non-release build, runtime debug assertions are turned on");
71 return true; 70 return true;
72 } 71 }
73 72
74 73
78 { 77 {
79 std::string seriesId(request->groups[0]); 78 std::string seriesId(request->groups[0]);
80 79
81 char tmp[1024]; 80 char tmp[1024];
82 sprintf(tmp, "Accessing whole-slide pyramid of series %s", seriesId.c_str()); 81 sprintf(tmp, "Accessing whole-slide pyramid of series %s", seriesId.c_str());
83 OrthancPluginLogInfo(context_, tmp); 82 OrthancPluginLogInfo(OrthancPlugins::GetGlobalContext(), tmp);
84 83
85 84
86 OrthancWSI::DicomPyramidCache::Locker locker(*cache_, seriesId); 85 OrthancWSI::DicomPyramidCache::Locker locker(*cache_, seriesId);
87 86
88 unsigned int tileWidth = locker.GetPyramid().GetTileWidth(); 87 unsigned int tileWidth = locker.GetPyramid().GetTileWidth();
120 result["TilesCount"] = tilesCount; 119 result["TilesCount"] = tilesCount;
121 result["TotalHeight"] = totalHeight; 120 result["TotalHeight"] = totalHeight;
122 result["TotalWidth"] = totalWidth; 121 result["TotalWidth"] = totalWidth;
123 122
124 std::string s = result.toStyledString(); 123 std::string s = result.toStyledString();
125 OrthancPluginAnswerBuffer(context_, output, s.c_str(), s.size(), "application/json"); 124 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json");
126 } 125 }
127 126
128 127
129 void ServeTile(OrthancPluginRestOutput* output, 128 void ServeTile(OrthancPluginRestOutput* output,
130 const char* url, 129 const char* url,
135 int tileY = boost::lexical_cast<int>(request->groups[3]); 134 int tileY = boost::lexical_cast<int>(request->groups[3]);
136 int tileX = boost::lexical_cast<int>(request->groups[2]); 135 int tileX = boost::lexical_cast<int>(request->groups[2]);
137 136
138 char tmp[1024]; 137 char tmp[1024];
139 sprintf(tmp, "Accessing tile in series %s: (%d,%d) at level %d", seriesId.c_str(), tileX, tileY, level); 138 sprintf(tmp, "Accessing tile in series %s: (%d,%d) at level %d", seriesId.c_str(), tileX, tileY, level);
140 OrthancPluginLogInfo(context_, tmp); 139 OrthancPluginLogInfo(OrthancPlugins::GetGlobalContext(), tmp);
141 140
142 if (level < 0 || 141 if (level < 0 ||
143 tileX < 0 || 142 tileX < 0 ||
144 tileY < 0) 143 tileY < 0)
145 { 144 {
174 // Test whether the tile is a JPEG image. In such a case, we can 173 // Test whether the tile is a JPEG image. In such a case, we can
175 // serve it as such, because any Web browser can handle JPEG 174 // serve it as such, because any Web browser can handle JPEG
176 175
177 if (compression == OrthancWSI::ImageCompression_Jpeg) 176 if (compression == OrthancWSI::ImageCompression_Jpeg)
178 { 177 {
179 OrthancPluginAnswerBuffer(context_, output, tile.c_str(), tile.size(), "image/jpeg"); 178 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, tile.c_str(), tile.size(), "image/jpeg");
180 return; // We're done 179 return; // We're done
181 } 180 }
182 181
183 182
184 // The tile does not come from a DICOM-JPEG instance, we need to 183 // The tile does not come from a DICOM-JPEG instance, we need to
218 217
219 std::string png; 218 std::string png;
220 Orthanc::PngWriter writer; 219 Orthanc::PngWriter writer;
221 writer.WriteToMemory(png, *decoded); 220 writer.WriteToMemory(png, *decoded);
222 221
223 OrthancPluginAnswerBuffer(context_, output, png.c_str(), png.size(), "image/png"); 222 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, png.c_str(), png.size(), "image/png");
224 } 223 }
225 224
226 225
227 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, 226 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
228 OrthancPluginResourceType resourceType, 227 OrthancPluginResourceType resourceType,
231 if (resourceType == OrthancPluginResourceType_Series && 230 if (resourceType == OrthancPluginResourceType_Series &&
232 changeType == OrthancPluginChangeType_NewChildInstance) 231 changeType == OrthancPluginChangeType_NewChildInstance)
233 { 232 {
234 char tmp[1024]; 233 char tmp[1024];
235 sprintf(tmp, "New instance has been added to series %s, invalidating it", resourceId); 234 sprintf(tmp, "New instance has been added to series %s, invalidating it", resourceId);
236 OrthancPluginLogInfo(context_, tmp); 235 OrthancPluginLogInfo(OrthancPlugins::GetGlobalContext(), tmp);
237 236
238 cache_->Invalidate(resourceId); 237 cache_->Invalidate(resourceId);
239 } 238 }
240 239
241 return OrthancPluginErrorCode_Success; 240 return OrthancPluginErrorCode_Success;
278 } 277 }
279 278
280 std::string content; 279 std::string content;
281 Orthanc::EmbeddedResources::GetFileResource(content, resource); 280 Orthanc::EmbeddedResources::GetFileResource(content, resource);
282 281
283 OrthancPluginAnswerBuffer(context_, output, content.c_str(), content.size(), mime.c_str()); 282 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, content.c_str(), content.size(), mime.c_str());
284 } 283 }
285 284
286 285
287 286
288 extern "C" 287 extern "C"
289 { 288 {
290 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) 289 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
291 { 290 {
292 context_ = context; 291 OrthancPlugins::SetGlobalContext(context);
293 assert(DisplayPerformanceWarning()); 292 assert(DisplayPerformanceWarning());
294 293
295 /* Check the version of the Orthanc core */ 294 /* Check the version of the Orthanc core */
296 if (OrthancPluginCheckVersion(context_) == 0) 295 if (OrthancPluginCheckVersion(OrthancPlugins::GetGlobalContext()) == 0)
297 { 296 {
298 char info[1024]; 297 char info[1024];
299 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", 298 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
300 context_->orthancVersion, 299 OrthancPlugins::GetGlobalContext()->orthancVersion,
301 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, 300 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
302 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, 301 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
303 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); 302 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
304 OrthancPluginLogError(context_, info); 303 OrthancPluginLogError(OrthancPlugins::GetGlobalContext(), info);
305 return -1; 304 return -1;
306 } 305 }
307 306
308 if (!OrthancPlugins::CheckMinimalOrthancVersion(context_, 1, 1, 0)) 307 if (!OrthancPlugins::CheckMinimalOrthancVersion(1, 1, 0))
309 { 308 {
310 // We need the "/instances/.../frames/.../raw" URI that was introduced in Orthanc 1.1.0 309 // We need the "/instances/.../frames/.../raw" URI that was introduced in Orthanc 1.1.0
311 return -1; 310 return -1;
312 } 311 }
313 312
319 unsigned int threads = Orthanc::SystemToolbox::GetHardwareConcurrency(); 318 unsigned int threads = Orthanc::SystemToolbox::GetHardwareConcurrency();
320 transcoderSemaphore_.reset(new Orthanc::Semaphore(threads)); 319 transcoderSemaphore_.reset(new Orthanc::Semaphore(threads));
321 320
322 char info[1024]; 321 char info[1024];
323 sprintf(info, "The whole-slide imaging plugin will use at most %u threads to transcode the tiles", threads); 322 sprintf(info, "The whole-slide imaging plugin will use at most %u threads to transcode the tiles", threads);
324 OrthancPluginLogWarning(context_, info); 323 OrthancPluginLogWarning(OrthancPlugins::GetGlobalContext(), info);
325 324
326 OrthancPluginSetDescription(context, "Provides a Web viewer of whole-slide microscopic images within Orthanc."); 325 OrthancPluginSetDescription(context, "Provides a Web viewer of whole-slide microscopic images within Orthanc.");
327 326
328 orthanc_.reset(new OrthancPlugins::OrthancPluginConnection(context)); 327 orthanc_.reset(new OrthancPlugins::OrthancPluginConnection);
329 cache_.reset(new OrthancWSI::DicomPyramidCache(*orthanc_, 10 /* Number of pyramids to be cached - TODO parameter */)); 328 cache_.reset(new OrthancWSI::DicomPyramidCache(*orthanc_, 10 /* Number of pyramids to be cached - TODO parameter */));
330 329
331 OrthancPluginRegisterOnChangeCallback(context_, OnChangeCallback); 330 OrthancPluginRegisterOnChangeCallback(OrthancPlugins::GetGlobalContext(), OnChangeCallback);
332 331
333 OrthancPlugins::RegisterRestCallback<ServeFile>(context, "/wsi/app/(ol.css)", true); 332 OrthancPlugins::RegisterRestCallback<ServeFile>("/wsi/app/(ol.css)", true);
334 OrthancPlugins::RegisterRestCallback<ServeFile>(context, "/wsi/app/(ol.js)", true); 333 OrthancPlugins::RegisterRestCallback<ServeFile>("/wsi/app/(ol.js)", true);
335 OrthancPlugins::RegisterRestCallback<ServeFile>(context, "/wsi/app/(viewer.html)", true); 334 OrthancPlugins::RegisterRestCallback<ServeFile>("/wsi/app/(viewer.html)", true);
336 OrthancPlugins::RegisterRestCallback<ServeFile>(context, "/wsi/app/(viewer.js)", true); 335 OrthancPlugins::RegisterRestCallback<ServeFile>("/wsi/app/(viewer.js)", true);
337 OrthancPlugins::RegisterRestCallback<ServePyramid>(context, "/wsi/pyramids/([0-9a-f-]+)", true); 336 OrthancPlugins::RegisterRestCallback<ServePyramid>("/wsi/pyramids/([0-9a-f-]+)", true);
338 OrthancPlugins::RegisterRestCallback<ServeTile>(context, "/wsi/tiles/([0-9a-f-]+)/([0-9-]+)/([0-9-]+)/([0-9-]+)", true); 337 OrthancPlugins::RegisterRestCallback<ServeTile>("/wsi/tiles/([0-9a-f-]+)/([0-9-]+)/([0-9-]+)/([0-9-]+)", true);
339 338
340 // Extend the default Orthanc Explorer with custom JavaScript for WSI 339 // Extend the default Orthanc Explorer with custom JavaScript for WSI
341 std::string explorer; 340 std::string explorer;
342 Orthanc::EmbeddedResources::GetFileResource(explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER); 341 Orthanc::EmbeddedResources::GetFileResource(explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER);
343 OrthancPluginExtendOrthancExplorer(context_, explorer.c_str()); 342 OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str());
344 343
345 return 0; 344 return 0;
346 } 345 }
347 346
348 347