Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Loaders/DicomStructureSetLoader.cpp @ 1640:52b8b96cb55f
cleaning namespaces
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Nov 2020 16:55:22 +0100 |
parents | 8563ea5d8ae4 |
children | 9ac2a65d4172 |
comparison
equal
deleted
inserted
replaced
1639:5cdc5b98f14d | 1640:52b8b96cb55f |
---|---|
90 State(that), | 90 State(that), |
91 instanceId_(instanceId) | 91 instanceId_(instanceId) |
92 { | 92 { |
93 } | 93 } |
94 | 94 |
95 virtual void Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message) ORTHANC_OVERRIDE | 95 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) ORTHANC_OVERRIDE |
96 { | 96 { |
97 Json::Value tags; | 97 Json::Value tags; |
98 message.ParseJsonBody(tags); | 98 message.ParseJsonBody(tags); |
99 | 99 |
100 Orthanc::DicomMap dicom; | 100 Orthanc::DicomMap dicom; |
119 State(that), | 119 State(that), |
120 sopInstanceUid_(sopInstanceUid) | 120 sopInstanceUid_(sopInstanceUid) |
121 { | 121 { |
122 } | 122 } |
123 | 123 |
124 virtual void Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message) ORTHANC_OVERRIDE | 124 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) ORTHANC_OVERRIDE |
125 { | 125 { |
126 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); | 126 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); |
127 | 127 |
128 Json::Value lookup; | 128 Json::Value lookup; |
129 message.ParseJsonBody(lookup); | 129 message.ParseJsonBody(lookup); |
136 lookup[0]["ID"].type() != Json::stringValue || | 136 lookup[0]["ID"].type() != Json::stringValue || |
137 lookup[0]["Type"].asString() != "Instance") | 137 lookup[0]["Type"].asString() != "Instance") |
138 { | 138 { |
139 std::stringstream msg; | 139 std::stringstream msg; |
140 msg << "Unknown resource! message.GetAnswer() = " << message.GetAnswer() << " message.GetAnswerHeaders() = "; | 140 msg << "Unknown resource! message.GetAnswer() = " << message.GetAnswer() << " message.GetAnswerHeaders() = "; |
141 for (OrthancStone::OrthancRestApiCommand::HttpHeaders::const_iterator it = message.GetAnswerHeaders().begin(); | 141 for (OrthancRestApiCommand::HttpHeaders::const_iterator it = message.GetAnswerHeaders().begin(); |
142 it != message.GetAnswerHeaders().end(); ++it) | 142 it != message.GetAnswerHeaders().end(); ++it) |
143 { | 143 { |
144 msg << "\nkey: \"" << it->first << "\" value: \"" << it->second << "\"\n"; | 144 msg << "\nkey: \"" << it->first << "\" value: \"" << it->second << "\"\n"; |
145 } | 145 } |
146 const std::string msgStr = msg.str(); | 146 const std::string msgStr = msg.str(); |
149 } | 149 } |
150 | 150 |
151 const std::string instanceId = lookup[0]["ID"].asString(); | 151 const std::string instanceId = lookup[0]["ID"].asString(); |
152 | 152 |
153 { | 153 { |
154 std::unique_ptr<OrthancStone::OrthancRestApiCommand> command(new OrthancStone::OrthancRestApiCommand); | 154 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
155 command->SetHttpHeader("Accept-Encoding", "gzip"); | 155 command->SetHttpHeader("Accept-Encoding", "gzip"); |
156 std::string uri = "/instances/" + instanceId + "/tags"; | 156 std::string uri = "/instances/" + instanceId + "/tags"; |
157 command->SetUri(uri); | 157 command->SetUri(uri); |
158 command->AcquirePayload(new AddReferencedInstance(loader, instanceId)); | 158 command->AcquirePayload(new AddReferencedInstance(loader, instanceId)); |
159 Schedule(command.release()); | 159 Schedule(command.release()); |
166 { | 166 { |
167 for (std::set<std::string>::const_iterator it = nonEmptyInstances.begin(); | 167 for (std::set<std::string>::const_iterator it = nonEmptyInstances.begin(); |
168 it != nonEmptyInstances.end(); | 168 it != nonEmptyInstances.end(); |
169 ++it) | 169 ++it) |
170 { | 170 { |
171 std::unique_ptr<OrthancStone::OrthancRestApiCommand> command(new OrthancStone::OrthancRestApiCommand); | 171 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
172 command->SetUri("/tools/lookup"); | 172 command->SetUri("/tools/lookup"); |
173 command->SetMethod(Orthanc::HttpMethod_Post); | 173 command->SetMethod(Orthanc::HttpMethod_Post); |
174 command->SetBody(*it); | 174 command->SetBody(*it); |
175 command->AcquirePayload(new LookupInstance(loader_, *it)); | 175 command->AcquirePayload(new LookupInstance(loader_, *it)); |
176 Schedule(command.release()); | 176 Schedule(command.release()); |
183 explicit LoadStructure(DicomStructureSetLoader& that) : | 183 explicit LoadStructure(DicomStructureSetLoader& that) : |
184 State(that) | 184 State(that) |
185 { | 185 { |
186 } | 186 } |
187 | 187 |
188 virtual void Handle(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message) ORTHANC_OVERRIDE | 188 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) ORTHANC_OVERRIDE |
189 { | 189 { |
190 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); | 190 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); |
191 | 191 |
192 // Set the actual structure set content | 192 // Set the actual structure set content |
193 { | 193 { |
194 FullOrthancDataset dicom(message.GetAnswer()); | 194 FullOrthancDataset dicom(message.GetAnswer()); |
195 | 195 |
196 loader.content_.reset(new OrthancStone::DicomStructureSet(dicom)); | 196 loader.content_.reset(new DicomStructureSet(dicom)); |
197 } | 197 } |
198 | 198 |
199 // initialize visibility flags | 199 // initialize visibility flags |
200 SetDefaultStructureVisibility(); | 200 SetDefaultStructureVisibility(); |
201 | 201 |
271 | 271 |
272 | 272 |
273 class DicomStructureSetLoader::Slice : public IExtractedSlice | 273 class DicomStructureSetLoader::Slice : public IExtractedSlice |
274 { | 274 { |
275 private: | 275 private: |
276 const OrthancStone::DicomStructureSet& content_; | 276 const DicomStructureSet& content_; |
277 uint64_t revision_; | 277 uint64_t revision_; |
278 bool isValid_; | 278 bool isValid_; |
279 std::vector<bool> visibility_; | 279 std::vector<bool> visibility_; |
280 | 280 |
281 public: | 281 public: |
287 structure set. | 287 structure set. |
288 In the first case (empty vector), all the structures are displayed. | 288 In the first case (empty vector), all the structures are displayed. |
289 In the second case, the visibility of each structure is defined by the | 289 In the second case, the visibility of each structure is defined by the |
290 content of the vector at the corresponding index. | 290 content of the vector at the corresponding index. |
291 */ | 291 */ |
292 Slice(const OrthancStone::DicomStructureSet& content, | 292 Slice(const DicomStructureSet& content, |
293 uint64_t revision, | 293 uint64_t revision, |
294 const OrthancStone::CoordinateSystem3D& cuttingPlane, | 294 const CoordinateSystem3D& cuttingPlane, |
295 const std::vector<bool>& visibility) : | 295 const std::vector<bool>& visibility) : |
296 content_(content), | 296 content_(content), |
297 revision_(revision), | 297 revision_(revision), |
298 visibility_(visibility) | 298 visibility_(visibility) |
299 { | 299 { |
300 ORTHANC_ASSERT((visibility_.size() == content_.GetStructuresCount()) | 300 ORTHANC_ASSERT((visibility_.size() == content_.GetStructuresCount()) |
301 || (visibility_.size() == 0u)); | 301 || (visibility_.size() == 0u)); |
302 | 302 |
303 bool opposite; | 303 bool opposite; |
304 | 304 |
305 const OrthancStone::Vector normal = content.GetNormal(); | 305 const Vector normal = content.GetNormal(); |
306 isValid_ = ( | 306 isValid_ = ( |
307 OrthancStone::GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetNormal()) || | 307 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetNormal()) || |
308 OrthancStone::GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisX()) || | 308 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisX()) || |
309 OrthancStone::GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisY())); | 309 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisY())); |
310 } | 310 } |
311 | 311 |
312 virtual bool IsValid() ORTHANC_OVERRIDE | 312 virtual bool IsValid() ORTHANC_OVERRIDE |
313 { | 313 { |
314 return isValid_; | 314 return isValid_; |
317 virtual uint64_t GetRevision() ORTHANC_OVERRIDE | 317 virtual uint64_t GetRevision() ORTHANC_OVERRIDE |
318 { | 318 { |
319 return revision_; | 319 return revision_; |
320 } | 320 } |
321 | 321 |
322 virtual OrthancStone::ISceneLayer* CreateSceneLayer( | 322 virtual ISceneLayer* CreateSceneLayer( |
323 const OrthancStone::ILayerStyleConfigurator* configurator, | 323 const ILayerStyleConfigurator* configurator, |
324 const OrthancStone::CoordinateSystem3D& cuttingPlane) ORTHANC_OVERRIDE | 324 const CoordinateSystem3D& cuttingPlane) ORTHANC_OVERRIDE |
325 { | 325 { |
326 assert(isValid_); | 326 assert(isValid_); |
327 | 327 |
328 std::unique_ptr<OrthancStone::PolylineSceneLayer> layer(new OrthancStone::PolylineSceneLayer); | 328 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer); |
329 layer->SetThickness(2); | 329 layer->SetThickness(2); |
330 | 330 |
331 for (size_t i = 0; i < content_.GetStructuresCount(); i++) | 331 for (size_t i = 0; i < content_.GetStructuresCount(); i++) |
332 { | 332 { |
333 if ((visibility_.size() == 0) || visibility_.at(i)) | 333 if ((visibility_.size() == 0) || visibility_.at(i)) |
334 { | 334 { |
335 const OrthancStone::Color& color = content_.GetStructureColor(i); | 335 const Color& color = content_.GetStructureColor(i); |
336 | 336 |
337 #ifdef USE_BOOST_UNION_FOR_POLYGONS | 337 #ifdef USE_BOOST_UNION_FOR_POLYGONS |
338 std::vector< std::vector<OrthancStone::Point2D> > polygons; | 338 std::vector< std::vector<Point2D> > polygons; |
339 | 339 |
340 if (content_.ProjectStructure(polygons, i, cuttingPlane)) | 340 if (content_.ProjectStructure(polygons, i, cuttingPlane)) |
341 { | 341 { |
342 for (size_t j = 0; j < polygons.size(); j++) | 342 for (size_t j = 0; j < polygons.size(); j++) |
343 { | 343 { |
351 | 351 |
352 layer->AddChain(chain, true /* closed */, color); | 352 layer->AddChain(chain, true /* closed */, color); |
353 } | 353 } |
354 } | 354 } |
355 #else | 355 #else |
356 std::vector< std::pair<OrthancStone::Point2D, OrthancStone::Point2D> > segments; | 356 std::vector< std::pair<Point2D, Point2D> > segments; |
357 | 357 |
358 if (content_.ProjectStructure(segments, i, cuttingPlane)) | 358 if (content_.ProjectStructure(segments, i, cuttingPlane)) |
359 { | 359 { |
360 for (size_t j = 0; j < segments.size(); j++) | 360 for (size_t j = 0; j < segments.size(); j++) |
361 { | 361 { |
362 OrthancStone::PolylineSceneLayer::Chain chain; | 362 PolylineSceneLayer::Chain chain; |
363 chain.resize(2); | 363 chain.resize(2); |
364 | 364 |
365 chain[0] = OrthancStone::ScenePoint2D(segments[j].first.x, segments[j].first.y); | 365 chain[0] = ScenePoint2D(segments[j].first.x, segments[j].first.y); |
366 chain[1] = OrthancStone::ScenePoint2D(segments[j].second.x, segments[j].second.y); | 366 chain[1] = ScenePoint2D(segments[j].second.x, segments[j].second.y); |
367 | 367 |
368 layer->AddChain(chain, false /* NOT closed */, color); | 368 layer->AddChain(chain, false /* NOT closed */, color); |
369 } | 369 } |
370 } | 370 } |
371 #endif | 371 #endif |
376 } | 376 } |
377 }; | 377 }; |
378 | 378 |
379 | 379 |
380 DicomStructureSetLoader::DicomStructureSetLoader( | 380 DicomStructureSetLoader::DicomStructureSetLoader( |
381 OrthancStone::ILoadersContext& loadersContext) | 381 ILoadersContext& loadersContext) |
382 : LoaderStateMachine(loadersContext) | 382 : LoaderStateMachine(loadersContext) |
383 , loadersContext_(loadersContext) | 383 , loadersContext_(loadersContext) |
384 , revision_(0) | 384 , revision_(0) |
385 , countProcessedInstances_(0) | 385 , countProcessedInstances_(0) |
386 , countReferencedInstances_(0) | 386 , countReferencedInstances_(0) |
388 { | 388 { |
389 // the default handler to retrieve slice geometry is RestInstanceLookupHandler | 389 // the default handler to retrieve slice geometry is RestInstanceLookupHandler |
390 instanceLookupHandler_ = RestInstanceLookupHandler::Create(*this); | 390 instanceLookupHandler_ = RestInstanceLookupHandler::Create(*this); |
391 } | 391 } |
392 | 392 |
393 boost::shared_ptr<OrthancStone::DicomStructureSetLoader> DicomStructureSetLoader::Create(OrthancStone::ILoadersContext& loadersContext) | 393 boost::shared_ptr<DicomStructureSetLoader> DicomStructureSetLoader::Create(ILoadersContext& loadersContext) |
394 { | 394 { |
395 boost::shared_ptr<DicomStructureSetLoader> obj( | 395 boost::shared_ptr<DicomStructureSetLoader> obj( |
396 new DicomStructureSetLoader( | 396 new DicomStructureSetLoader( |
397 loadersContext)); | 397 loadersContext)); |
398 obj->LoaderStateMachine::PostConstructor(); | 398 obj->LoaderStateMachine::PostConstructor(); |
443 | 443 |
444 instanceId_ = instanceId; | 444 instanceId_ = instanceId; |
445 initiallyVisibleStructures_ = initiallyVisibleStructures; | 445 initiallyVisibleStructures_ = initiallyVisibleStructures; |
446 | 446 |
447 { | 447 { |
448 std::unique_ptr<OrthancStone::OrthancRestApiCommand> command(new OrthancStone::OrthancRestApiCommand); | 448 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
449 command->SetHttpHeader("Accept-Encoding", "gzip"); | 449 command->SetHttpHeader("Accept-Encoding", "gzip"); |
450 | 450 |
451 std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3006-0050"; | 451 std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3006-0050"; |
452 | 452 |
453 command->SetUri(uri); | 453 command->SetUri(uri); |
461 std::vector<std::string> initiallyVisibleStructures; | 461 std::vector<std::string> initiallyVisibleStructures; |
462 initiallyVisibleStructures.push_back("*"); // wildcard to make all structure sets visible | 462 initiallyVisibleStructures.push_back("*"); // wildcard to make all structure sets visible |
463 LoadInstance(instanceId, initiallyVisibleStructures); | 463 LoadInstance(instanceId, initiallyVisibleStructures); |
464 } | 464 } |
465 | 465 |
466 OrthancStone::IVolumeSlicer::IExtractedSlice* DicomStructureSetLoader::ExtractSlice(const OrthancStone::CoordinateSystem3D& cuttingPlane) | 466 IVolumeSlicer::IExtractedSlice* DicomStructureSetLoader::ExtractSlice(const CoordinateSystem3D& cuttingPlane) |
467 { | 467 { |
468 if (content_.get() == NULL) | 468 if (content_.get() == NULL) |
469 { | 469 { |
470 // Geometry is not available yet | 470 // Geometry is not available yet |
471 return new OrthancStone::IVolumeSlicer::InvalidSlice; | 471 return new IVolumeSlicer::InvalidSlice; |
472 } | 472 } |
473 else | 473 else |
474 { | 474 { |
475 return new Slice(*content_, revision_, cuttingPlane, structureVisibility_); | 475 return new Slice(*content_, revision_, cuttingPlane, structureVisibility_); |
476 } | 476 } |