Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp @ 2097:a9e23ef9ee09 dicom-sr
preparing to extract dicom-sr annotations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 Nov 2023 16:31:49 +0100 |
parents | 79e984a89a38 |
children | 4288d635d77e |
comparison
equal
deleted
inserted
replaced
2096:79e984a89a38 | 2097:a9e23ef9ee09 |
---|---|
118 | 118 |
119 namespace OrthancStone | 119 namespace OrthancStone |
120 { | 120 { |
121 void DicomStructuredReport::ReferencedInstance::AddFrame(unsigned int frame) | 121 void DicomStructuredReport::ReferencedInstance::AddFrame(unsigned int frame) |
122 { | 122 { |
123 if (frame == 0) | 123 frames_.insert(frame); |
124 { | |
125 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
126 } | |
127 else | |
128 { | |
129 frames_.insert(frame - 1); | |
130 } | |
131 } | 124 } |
132 | 125 |
133 | 126 |
134 class DicomStructuredReport::Structure : public boost::noncopyable | 127 class DicomStructuredReport::Structure : public boost::noncopyable |
135 { | 128 { |
138 bool hasFrameNumber_; | 131 bool hasFrameNumber_; |
139 unsigned int frameNumber_; | 132 unsigned int frameNumber_; |
140 bool hasProbabilityOfCancer_; | 133 bool hasProbabilityOfCancer_; |
141 float probabilityOfCancer_; | 134 float probabilityOfCancer_; |
142 | 135 |
136 protected: | |
137 void Copy(const Structure& other) | |
138 { | |
139 if (other.HasFrameNumber()) | |
140 { | |
141 SetFrameNumber(other.GetFrameNumber()); | |
142 } | |
143 | |
144 if (other.HasProbabilityOfCancer()) | |
145 { | |
146 SetProbabilityOfCancer(other.GetProbabilityOfCancer()); | |
147 } | |
148 } | |
149 | |
143 public: | 150 public: |
144 Structure(const std::string& sopInstanceUid) : | 151 Structure(const std::string& sopInstanceUid) : |
145 sopInstanceUid_(sopInstanceUid), | 152 sopInstanceUid_(sopInstanceUid), |
146 hasFrameNumber_(false), | 153 hasFrameNumber_(false), |
147 hasProbabilityOfCancer_(false) | 154 hasProbabilityOfCancer_(false) |
150 | 157 |
151 virtual ~Structure() | 158 virtual ~Structure() |
152 { | 159 { |
153 } | 160 } |
154 | 161 |
162 virtual Structure* Clone() const = 0; | |
163 | |
164 const std::string& GetSopInstanceUid() const | |
165 { | |
166 return sopInstanceUid_; | |
167 } | |
168 | |
155 void SetFrameNumber(unsigned int frame) | 169 void SetFrameNumber(unsigned int frame) |
156 { | 170 { |
157 if (frame <= 0) | 171 hasFrameNumber_ = true; |
158 { | 172 frameNumber_ = frame; |
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
160 } | |
161 else | |
162 { | |
163 hasFrameNumber_ = true; | |
164 frameNumber_ = frame - 1; | |
165 } | |
166 } | 173 } |
167 | 174 |
168 void SetProbabilityOfCancer(float probability) | 175 void SetProbabilityOfCancer(float probability) |
169 { | 176 { |
170 if (probability < 0 || | 177 if (probability < 0 || |
227 Structure(sopInstanceUid), | 234 Structure(sopInstanceUid), |
228 point_(x, y) | 235 point_(x, y) |
229 { | 236 { |
230 } | 237 } |
231 | 238 |
239 virtual Structure* Clone() const | |
240 { | |
241 std::unique_ptr<Point> cloned(new Point(GetSopInstanceUid(), point_.GetX(), point_.GetY())); | |
242 cloned->Copy(*this); | |
243 return cloned.release(); | |
244 } | |
245 | |
232 const ScenePoint2D& GetPoint() const | 246 const ScenePoint2D& GetPoint() const |
233 { | 247 { |
234 return point_; | 248 return point_; |
235 } | 249 } |
236 }; | 250 }; |
256 | 270 |
257 for (unsigned long i = 0; i < pointsCount; i += 2) | 271 for (unsigned long i = 0; i < pointsCount; i += 2) |
258 { | 272 { |
259 points_.push_back(ScenePoint2D(points[i], points[i + 1])); | 273 points_.push_back(ScenePoint2D(points[i], points[i + 1])); |
260 } | 274 } |
275 } | |
276 | |
277 Polyline(const std::string& sopInstanceUid, | |
278 const std::vector<ScenePoint2D>& points) : | |
279 Structure(sopInstanceUid), | |
280 points_(points) | |
281 { | |
282 } | |
283 | |
284 virtual Structure* Clone() const | |
285 { | |
286 std::unique_ptr<Polyline> cloned(new Polyline(GetSopInstanceUid(), points_)); | |
287 cloned->Copy(*this); | |
288 return cloned.release(); | |
261 } | 289 } |
262 | 290 |
263 size_t GetSize() const | 291 size_t GetSize() const |
264 { | 292 { |
265 return points_.size(); | 293 return points_.size(); |
502 Orthanc::Toolbox::SplitString(tokens, frames, '\\'); | 530 Orthanc::Toolbox::SplitString(tokens, frames, '\\'); |
503 | 531 |
504 for (size_t m = 0; m < tokens.size(); m++) | 532 for (size_t m = 0; m < tokens.size(); m++) |
505 { | 533 { |
506 uint32_t frame; | 534 uint32_t frame; |
507 if (!Orthanc::SerializationToolbox::ParseUnsignedInteger32(frame, tokens[m])) | 535 if (!Orthanc::SerializationToolbox::ParseUnsignedInteger32(frame, tokens[m]) || |
536 frame <= 0) | |
508 { | 537 { |
509 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 538 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
510 } | 539 } |
511 else | 540 else |
512 { | 541 { |
513 AddStructure(sopInstanceUid, group, true, frame, hasProbabilityOfCancer, probabilityOfCancer); | 542 AddStructure(sopInstanceUid, group, true, frame - 1, hasProbabilityOfCancer, probabilityOfCancer); |
514 instanceInformation->second->AddFrame(frame); | 543 instanceInformation->second->AddFrame(frame - 1); |
515 } | 544 } |
516 } | 545 } |
517 } | 546 } |
518 else | 547 else |
519 { | 548 { |
520 AddStructure(sopInstanceUid, group, false, 0, hasProbabilityOfCancer, probabilityOfCancer); | 549 AddStructure(sopInstanceUid, group, false, 0, hasProbabilityOfCancer, probabilityOfCancer); |
521 instanceInformation->second->AddFrame(1); | 550 instanceInformation->second->AddFrame(0); |
522 } | 551 } |
523 } | 552 } |
524 } | 553 } |
525 } | 554 } |
526 } | 555 } |
529 } | 558 } |
530 } | 559 } |
531 } | 560 } |
532 | 561 |
533 | 562 |
563 DicomStructuredReport::DicomStructuredReport(const DicomStructuredReport& other) : | |
564 studyInstanceUid_(other.studyInstanceUid_), | |
565 seriesInstanceUid_(other.seriesInstanceUid_), | |
566 sopInstanceUid_(other.sopInstanceUid_), | |
567 orderedInstances_(other.orderedInstances_) | |
568 { | |
569 for (std::map<std::string, ReferencedInstance*>::const_iterator | |
570 it = other.instancesInformation_.begin(); it != other.instancesInformation_.end(); ++it) | |
571 { | |
572 assert(it->second != NULL); | |
573 instancesInformation_[it->first] = new ReferencedInstance(*it->second); | |
574 } | |
575 | |
576 for (std::list<Structure*>::const_iterator it = other.structures_.begin(); it != other.structures_.end(); ++it) | |
577 { | |
578 assert(*it != NULL); | |
579 structures_.push_back((*it)->Clone()); | |
580 } | |
581 } | |
582 | |
583 | |
534 DicomStructuredReport::~DicomStructuredReport() | 584 DicomStructuredReport::~DicomStructuredReport() |
535 { | 585 { |
536 for (std::list<Structure*>::iterator it = structures_.begin(); it != structures_.end(); ++it) | 586 for (std::list<Structure*>::iterator it = structures_.begin(); it != structures_.end(); ++it) |
537 { | 587 { |
538 assert(*it != NULL); | 588 assert(*it != NULL); |