comparison OrthancCppClient/Series.cpp @ 504:50d9660f960c laaw

laaw exception
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Jul 2013 10:12:20 +0200
parents ee33c7d0cda0
children ffedcc8f0938
comparison
equal deleted inserted replaced
502:ee33c7d0cda0 504:50d9660f960c
31 31
32 32
33 #include "Series.h" 33 #include "Series.h"
34 34
35 #include "OrthancConnection.h" 35 #include "OrthancConnection.h"
36 #include "../Core/OrthancException.h"
37 36
38 #include <set> 37 #include <set>
39 #include <boost/lexical_cast.hpp> 38 #include <boost/lexical_cast.hpp>
40 39
41 namespace OrthancClient 40 namespace OrthancClient
59 std::vector<float> cosines; 58 std::vector<float> cosines;
60 someSlice.SplitVectorOfFloats(cosines, "ImageOrientationPatient"); 59 someSlice.SplitVectorOfFloats(cosines, "ImageOrientationPatient");
61 60
62 if (cosines.size() != 6) 61 if (cosines.size() != 6)
63 { 62 {
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 63 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
65 } 64 }
66 65
67 normal_[0] = cosines[1] * cosines[5] - cosines[2] * cosines[4]; 66 normal_[0] = cosines[1] * cosines[5] - cosines[2] * cosines[4];
68 normal_[1] = cosines[2] * cosines[3] - cosines[0] * cosines[5]; 67 normal_[1] = cosines[2] * cosines[3] - cosines[0] * cosines[5];
69 normal_[2] = cosines[0] * cosines[4] - cosines[1] * cosines[3]; 68 normal_[2] = cosines[0] * cosines[4] - cosines[1] * cosines[3];
77 { 76 {
78 std::vector<float> ipp; 77 std::vector<float> ipp;
79 instance.SplitVectorOfFloats(ipp, "ImagePositionPatient"); 78 instance.SplitVectorOfFloats(ipp, "ImagePositionPatient");
80 if (ipp.size() != 3) 79 if (ipp.size() != 3)
81 { 80 {
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 81 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
83 } 82 }
84 83
85 float dist = 0; 84 float dist = 0;
86 85
87 for (int i = 0; i < 3; i++) 86 for (int i = 0; i < 3; i++)
142 p[2] = *s; 141 p[2] = *s;
143 } 142 }
144 } 143 }
145 else 144 else
146 { 145 {
147 throw OrthancException(ErrorCode_NotImplemented); 146 throw OrthancClientException(ErrorCode_NotImplemented);
148 } 147 }
149 } 148 }
150 149
151 // Do not keep the image in memory, as we are loading 3D images 150 // Do not keep the image in memory, as we are loading 3D images
152 instance_.DiscardImage(); 151 instance_.DiscardImage();
159 158
160 void Series::Check3DImage() 159 void Series::Check3DImage()
161 { 160 {
162 if (!Is3DImage()) 161 if (!Is3DImage())
163 { 162 {
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 163 throw OrthancClientException(Orthanc::ErrorCode_NotImplemented);
165 } 164 }
166 } 165 }
167 166
168 bool Series::Is3DImageInternal() 167 bool Series::Is3DImageInternal()
169 { 168 {
197 l.insert(locator.ComputeSliceLocation(GetInstance(i))); 196 l.insert(locator.ComputeSliceLocation(GetInstance(i)));
198 } 197 }
199 198
200 return l.size() == GetInstanceCount(); 199 return l.size() == GetInstanceCount();
201 } 200 }
202 catch (Orthanc::OrthancException) 201 catch (OrthancClientException)
203 { 202 {
204 return false; 203 return false;
205 } 204 }
206 } 205 }
207 206
211 210
212 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/series/" + id_); 211 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/series/" + id_);
213 Json::Value v; 212 Json::Value v;
214 if (!client.Apply(series_)) 213 if (!client.Apply(series_))
215 { 214 {
216 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); 215 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol);
217 } 216 }
218 } 217 }
219 218
220 Orthanc::IDynamicObject* Series::GetFillerItem(size_t index) 219 Orthanc::IDynamicObject* Series::GetFillerItem(size_t index)
221 { 220 {
309 voxelSizeY_ = boost::lexical_cast<float>(sy); 308 voxelSizeY_ = boost::lexical_cast<float>(sy);
310 voxelSizeZ_ = GetInstance(0).GetTagAsFloat("SliceThickness"); 309 voxelSizeZ_ = GetInstance(0).GetTagAsFloat("SliceThickness");
311 } 310 }
312 catch (boost::bad_lexical_cast) 311 catch (boost::bad_lexical_cast)
313 { 312 {
314 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 313 throw OrthancClientException(Orthanc::ErrorCode_NotImplemented);
315 } 314 }
316 } 315 }
317 316
318 isVoxelSizeRead_ = true; 317 isVoxelSizeRead_ = true;
319 } 318 }
369 mode = ImageExtractionMode_UInt16; 368 mode = ImageExtractionMode_UInt16;
370 format = PixelFormat_Grayscale16; 369 format = PixelFormat_Grayscale16;
371 break; 370 break;
372 371
373 default: 372 default:
374 throw OrthancException(ErrorCode_NotImplemented); 373 throw OrthancClientException(ErrorCode_NotImplemented);
375 } 374 }
376 375
377 376
378 // Check that the target image is properly sized 377 // Check that the target image is properly sized
379 unsigned int sx = GetWidth(); 378 unsigned int sx = GetWidth();
380 unsigned int sy = GetHeight(); 379 unsigned int sy = GetHeight();
381 380
382 if (lineStride < sx * bytesPerPixel || 381 if (lineStride < sx * bytesPerPixel ||
383 stackStride < sx * sy * bytesPerPixel) 382 stackStride < sx * sy * bytesPerPixel)
384 { 383 {
385 throw OrthancException(ErrorCode_BadRequest); 384 throw OrthancClientException(ErrorCode_BadRequest);
386 } 385 }
387 386
388 if (sx == 0 || sy == 0 || GetInstanceCount() == 0) 387 if (sx == 0 || sy == 0 || GetInstanceCount() == 0)
389 { 388 {
390 // Empty image, nothing to do 389 // Empty image, nothing to do
410 } 409 }
411 410
412 if (instances.size() != GetInstanceCount()) 411 if (instances.size() != GetInstanceCount())
413 { 412 {
414 // Several instances have the same Z coordinate 413 // Several instances have the same Z coordinate
415 throw OrthancException(ErrorCode_NotImplemented); 414 throw OrthancClientException(ErrorCode_NotImplemented);
416 } 415 }
417 416
418 417
419 // Submit the download of each stack as a set of commands 418 // Submit the download of each stack as a set of commands
420 ThreadedCommandProcessor processor(connection_.GetThreadCount()); 419 ThreadedCommandProcessor processor(connection_.GetThreadCount());
433 432
434 433
435 // Wait for all the stacks to be downloaded 434 // Wait for all the stacks to be downloaded
436 if (!processor.Join()) 435 if (!processor.Join())
437 { 436 {
438 throw OrthancException(ErrorCode_NetworkProtocol); 437 throw OrthancClientException(ErrorCode_NetworkProtocol);
439 } 438 }
440 } 439 }
441 440
442 float Series::GetVoxelSizeX() 441 float Series::GetVoxelSizeX()
443 { 442 {