Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/DicomStructureSet.cpp @ 125:44fc253d4876 wasm
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 Nov 2017 16:13:55 +0100 |
parents | e3433dabfb8d |
children | c9e88e7935a4 |
comparison
equal
deleted
inserted
replaced
124:5099aaa53bd0 | 125:44fc253d4876 |
---|---|
150 | 150 |
151 const DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) const | 151 const DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) const |
152 { | 152 { |
153 if (index >= structures_.size()) | 153 if (index >= structures_.size()) |
154 { | 154 { |
155 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 155 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
156 } | |
157 | |
158 return structures_[index]; | |
159 } | |
160 | |
161 | |
162 DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) | |
163 { | |
164 if (index >= structures_.size()) | |
165 { | |
166 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
156 } | 167 } |
157 | 168 |
158 return structures_[index]; | 169 return structures_[index]; |
159 } | 170 } |
160 | 171 |
334 green = s.green_; | 345 green = s.green_; |
335 blue = s.blue_; | 346 blue = s.blue_; |
336 } | 347 } |
337 | 348 |
338 | 349 |
339 void DicomStructureSet::Render(CairoContext& context, | |
340 const CoordinateSystem3D& slice) | |
341 { | |
342 cairo_t* cr = context.GetObject(); | |
343 | |
344 for (Structures::iterator structure = structures_.begin(); | |
345 structure != structures_.end(); ++structure) | |
346 { | |
347 for (Polygons::iterator polygon = structure->polygons_.begin(); | |
348 polygon != structure->polygons_.end(); ++polygon) | |
349 { | |
350 polygon->UpdateReferencedSlice(referencedSlices_); | |
351 | |
352 if (polygon->IsOnSlice(slice)) | |
353 { | |
354 context.SetSourceColor(structure->red_, structure->green_, structure->blue_); | |
355 | |
356 Points::const_iterator p = polygon->GetPoints().begin(); | |
357 | |
358 double x, y; | |
359 slice.ProjectPoint(x, y, *p); | |
360 cairo_move_to(cr, x, y); | |
361 ++p; | |
362 | |
363 while (p != polygon->GetPoints().end()) | |
364 { | |
365 slice.ProjectPoint(x, y, *p); | |
366 cairo_line_to(cr, x, y); | |
367 ++p; | |
368 } | |
369 | |
370 slice.ProjectPoint(x, y, *polygon->GetPoints().begin()); | |
371 cairo_line_to(cr, x, y); | |
372 | |
373 cairo_stroke(cr); | |
374 } | |
375 } | |
376 } | |
377 } | |
378 | |
379 | |
380 void DicomStructureSet::GetReferencedInstances(std::set<std::string>& instances) | 350 void DicomStructureSet::GetReferencedInstances(std::set<std::string>& instances) |
381 { | 351 { |
382 for (Structures::const_iterator structure = structures_.begin(); | 352 for (Structures::const_iterator structure = structures_.begin(); |
383 structure != structures_.end(); ++structure) | 353 structure != structures_.end(); ++structure) |
384 { | 354 { |
530 result->CheckReferencedSlices(); | 500 result->CheckReferencedSlices(); |
531 | 501 |
532 return result.release(); | 502 return result.release(); |
533 } | 503 } |
534 | 504 |
505 | |
506 bool DicomStructureSet::ProjectStructure(std::vector< std::vector<PolygonPoint> >& polygons, | |
507 Structure& structure, | |
508 const CoordinateSystem3D& slice) | |
509 { | |
510 polygons.clear(); | |
511 | |
512 Vector normal = GetNormal(); | |
513 | |
514 bool isOpposite; | |
515 if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetNormal())) | |
516 { | |
517 // This is an axial projection | |
518 | |
519 for (Polygons::iterator polygon = structure.polygons_.begin(); | |
520 polygon != structure.polygons_.end(); ++polygon) | |
521 { | |
522 polygon->UpdateReferencedSlice(referencedSlices_); | |
523 | |
524 if (polygon->IsOnSlice(slice)) | |
525 { | |
526 polygons.push_back(std::vector<PolygonPoint>()); | |
527 | |
528 for (Points::const_iterator p = polygon->GetPoints().begin(); | |
529 p != polygon->GetPoints().end(); ++p) | |
530 { | |
531 double x, y; | |
532 slice.ProjectPoint(x, y, *p); | |
533 polygons.back().push_back(std::make_pair(x, y)); | |
534 } | |
535 } | |
536 } | |
537 | |
538 return true; | |
539 } | |
540 else if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisX()) || | |
541 GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisY())) | |
542 { | |
543 // Sagittal or coronal projections | |
544 | |
545 return false; | |
546 } | |
547 else | |
548 { | |
549 return false; | |
550 } | |
551 } | |
535 } | 552 } |