comparison OrthancStone/Sources/Toolbox/UnionOfRectangles.cpp @ 1876:b1f510e601d2

more unit tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Jan 2022 21:26:47 +0100
parents b896f20d24ca
children c9ccd13c6a3c
comparison
equal deleted inserted replaced
1875:b896f20d24ca 1876:b1f510e601d2
82 82
83 83
84 class UnionOfRectangles::Factory : public SegmentTree::IPayloadFactory 84 class UnionOfRectangles::Factory : public SegmentTree::IPayloadFactory
85 { 85 {
86 public: 86 public:
87 virtual Orthanc::IDynamicObject* Create() 87 virtual Orthanc::IDynamicObject* Create() ORTHANC_OVERRIDE
88 { 88 {
89 return new Payload; 89 return new Payload;
90 } 90 }
91 }; 91 };
92 92
101 operation_(operation) 101 operation_(operation)
102 { 102 {
103 } 103 }
104 104
105 virtual void Visit(const SegmentTree& node, 105 virtual void Visit(const SegmentTree& node,
106 bool fullyInside) 106 bool fullyInside) ORTHANC_OVERRIDE
107 { 107 {
108 Payload& payload = node.GetTypedPayload<Payload>(); 108 Payload& payload = node.GetTypedPayload<Payload>();
109 109
110 if (fullyInside) 110 if (fullyInside)
111 { 111 {
382 382
383 383
384 void UnionOfRectangles::Apply(std::list< std::vector<ScenePoint2D> >& contours, 384 void UnionOfRectangles::Apply(std::list< std::vector<ScenePoint2D> >& contours,
385 const std::list<Extent2D>& rectangles) 385 const std::list<Extent2D>& rectangles)
386 { 386 {
387 contours.clear();
388
387 /** 389 /**
388 * STEP 1 390 * STEP 1
389 **/ 391 **/
390 Internals::RectanglesIntegerProjection horizontalProjection(rectangles, true); 392 Internals::RectanglesIntegerProjection horizontalProjection(rectangles, true);
391 Internals::RectanglesIntegerProjection verticalProjection(rectangles, false); 393 Internals::RectanglesIntegerProjection verticalProjection(rectangles, false);
392 394
393 assert(horizontalProjection.GetProjectedRectanglesCount() == verticalProjection.GetProjectedRectanglesCount()); 395 assert(horizontalProjection.GetProjectedRectanglesCount() == verticalProjection.GetProjectedRectanglesCount());
394 396
395
396 /** 397 /**
397 * STEP 2 398 * STEP 2
398 **/ 399 **/
400 if (verticalProjection.GetEndpointsCount() == 0)
401 {
402 return;
403 }
404
399 Factory factory; 405 Factory factory;
400 SegmentTree tree(0, verticalProjection.GetEndpointsCount() - 1, factory); 406 SegmentTree tree(0, verticalProjection.GetEndpointsCount() - 1, factory);
401 407
402 408
403 /** 409 /**
526 assert(allEdges.size() == horizontalEdges.size() + verticalEdges.size()); 532 assert(allEdges.size() == horizontalEdges.size() + verticalEdges.size());
527 533
528 std::list<Internals::OrientedIntegerLine2D::Chain> chains; 534 std::list<Internals::OrientedIntegerLine2D::Chain> chains;
529 Internals::OrientedIntegerLine2D::ExtractChains(chains, allEdges); 535 Internals::OrientedIntegerLine2D::ExtractChains(chains, allEdges);
530 536
531 contours.clear();
532
533 for (std::list<Internals::OrientedIntegerLine2D::Chain>::const_iterator 537 for (std::list<Internals::OrientedIntegerLine2D::Chain>::const_iterator
534 it = chains.begin(); it != chains.end(); ++it) 538 it = chains.begin(); it != chains.end(); ++it)
535 { 539 {
536 assert(!it->empty()); 540 assert(!it->empty());
537 541