lsst.afw  15.0-16-g953e39cab
SpanSet.cc
Go to the documentation of this file.
1 
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2016 AURA/LSST.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <https://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #include <algorithm>
25 #include <iterator>
26 #include "lsst/afw/geom/SpanSet.h"
32 
33 namespace lsst {
34 namespace afw {
35 namespace geom {
36 namespace {
37 
38 /* These classes are used in the erode operator to quickly calculate the
39 * contents of the shrunken SpanSet
40 */
41 
42 struct PrimaryRun {
43  int m, y, xmin, xmax;
44 };
45 
46 bool comparePrimaryRun(PrimaryRun const& first, PrimaryRun const& second) {
47  if (first.y != second.y) {
48  return first.y < second.y;
49  } else if (first.m != second.m) {
50  return first.m < second.m;
51  } else {
52  return first.xmin < second.xmin;
53  }
54 }
55 
56 class ComparePrimaryRunY {
57 public:
58  bool operator()(PrimaryRun const& pr, int yval) { return pr.y < yval; }
59  bool operator()(int yval, PrimaryRun const& pr) { return yval < pr.y; }
60 };
61 
62 class ComparePrimaryRunM {
63 public:
64  bool operator()(PrimaryRun const& pr, int mval) { return pr.m < mval; }
65  bool operator()(int mval, PrimaryRun const& pr) { return mval < pr.m; }
66 };
67 
68 /* Determine if two spans overlap
69  *
70  * a First Span in comparison
71  * b Second Span in comparison
72  * compareY a boolean to control if the comparison takes into account the y position of the spans
73  */
74 bool spansOverlap(Span const& a, Span const& b, bool compareY = true) {
75  bool yTruth = true;
76  if (compareY) {
77  yTruth = a.getY() == b.getY();
78  }
79  return (yTruth && ((a.getMaxX() >= b.getMinX() && a.getMinX() <= b.getMinX()) ||
80  (b.getMaxX() >= a.getMinX() && b.getMinX() <= a.getMinX())))
81  ? true
82  : false;
83 }
84 
85 /* Determine if two spans are contiguous, that is they can overlap or the end of one span is
86  * one pixel before the beginning of the next
87  *
88  * a First Span in comparison
89  * b Second Span in comparison
90  * compareY a boolean to control if the comparison takes into account the y position of the spans
91  */
92 bool spansContiguous(Span const& a, Span const& b, bool compareY = true) {
93  bool yTruth(true);
94  if (compareY) {
95  yTruth = a.getY() == b.getY();
96  }
97  return (yTruth && ((a.getMaxX() + 1 >= b.getMinX() && a.getMinX() <= b.getMinX()) ||
98  (b.getMaxX() + 1 >= a.getMinX() && b.getMinX() <= a.getMinX())))
99  ? true
100  : false;
101 }
102 
103 /* Determine the intersection with a mask or its logical inverse
104  *
105  * spanSet - SpanSet object with which to intersect the mask
106  * mask - Mask object to be intersectedNot
107  * bitmask - bitpattern to used when deciding pixel membership in the mask
108  *
109  * Templates:
110  * T - pixel type of the mask
111  * invert - boolean indicating if the intersection is with the mask or the inverse of the mask
112  templated parameter to ensure the check is compiled away if it can be
113 */
114 template <typename T, bool invert>
115 std::shared_ptr<SpanSet> maskIntersect(SpanSet const & spanSet, image::Mask<T> const & mask, T bitmask) {
116  // This vector will store our output spans
117  std::vector<Span> newVec;
118  auto maskBBox = mask.getBBox();
119  for (auto const & spn : spanSet) {
120  // Variable to mark if a new span has been started
121  // Reset the started flag for each different span
122  bool started = false;
123  // Limit the y iteration to be within the mask's bounding box
124  int y = spn.getY();
125  if (y < maskBBox.getMinY() || y > maskBBox.getMaxY()) {
126  continue;
127  }
128  // Reset the min and max variables
129  int minX = 0;
130  int maxX = 0;
131  // Limit the scope of iteration to be within the mask's bounds
132  int startX = std::max(spn.getMinX(), maskBBox.getMinX());
133  int endX = std::min(spn.getMaxX(), maskBBox.getMaxX());
134  for (int x = startX; x <= endX; ++x){
135  // Find if the pixel matches the given bit pattern
136  bool pixelCompare = mask.get0(x, y) & bitmask;
137  // if the templated boolean indicates the compliment of the mask is desired, invert the
138  // pixel comparison
139  if (invert) {
140  pixelCompare = !pixelCompare;
141  }
142  // If the pixel is to be included in the operation, start or append recording values
143  // needed to later construct a Span
144  if (pixelCompare) {
145  if (!started) {
146  started = true;
147  minX = x;
148  maxX = x;
149  } else {
150  maxX = x;
151  }
152  if (x == endX) {
153  // We have reached the end of a row and the pixel evaluates true, should add the
154  // Span
155  newVec.push_back(Span(y, minX, maxX));
156  }
157  } else if(started) {
158  // A span was started but the current pixel is not to be included in the new SpanSet,
159  // the current SpanSet should be close and added to the vector
160  newVec.push_back(Span(y, minX, maxX));
161  started = false;
162  }
163  }
164  }
165  return std::make_shared<SpanSet>(std::move(newVec));
166 }
167 
168 } // namespace
169 
170 // Default constructor, creates a null SpanSet which may be useful for
171 // comparisons
172 SpanSet::SpanSet() : _spanVector(), _bbox(), _area(0) {}
173 
174 // Construct a SpanSet from a Box2I object
175 SpanSet::SpanSet(Box2I const& box) : _bbox(box), _area(box.getArea()) {
176  int beginY = box.getMinY();
177 
178  int beginX = box.getMinX();
179  int maxX = box.getMaxX();
180 
181  for (int i = beginY; i < _bbox.getEndY(); ++i) {
182  _spanVector.push_back(Span(i, beginX, maxX));
183  }
184 }
185 
186 // Construct a SpanSet from a std vector by copying
187 SpanSet::SpanSet(std::vector<Span> const& vec, bool normalize) : _spanVector(vec) {
188  // If the incoming vector is zero, should create an empty spanSet
189  if (_spanVector.empty()) {
190  _bbox = Box2I();
191  _area = 0;
192  } else {
193  if (normalize) {
194  _runNormalize();
195  }
196  _initialize();
197  }
198 }
199 
200 // Construct a SpanSet from a std vector by moving
201 SpanSet::SpanSet(std::vector<Span>&& vec, bool normalize) : _spanVector(std::move(vec)) {
202  // If the incoming vector is zero, should create an empty SpanSet
203  if (_spanVector.size() == 0) {
204  _bbox = Box2I();
205  _area = 0;
206  } else {
207  if (normalize) {
208  _runNormalize();
209  }
210  _initialize();
211  }
212 }
213 
214 void SpanSet::_runNormalize() {
215  // This bit of code is not safe if the _spanVector is empty. However, this function will only be executed
216  // with a non-empty _spanVector as it is called internally by the class constructors, and cannot be
217  // executed from outside the class
218 
219  // Ensure the span set is sorted according to Span < operator
220  std::sort(_spanVector.begin(), _spanVector.end());
221 
222  // Create a new vector to hold the possibly combined Spans
223  std::vector<Span> newSpans;
224  // Reserve the size of the original as it is the maximum possible size
225  newSpans.reserve(_spanVector.size());
226  // push back the first element, as it is certain to be included
227  newSpans.push_back(*_spanVector.begin());
228 
229  // With the sorted span array, spans that are contiguous with the end of the last span in the new vector
230  // should be combined with the last span in the new vector. Only when there is no longer continuity
231  // between spans should a new span be added.
232  // Start iteration from "1" as the 0th element is already in the newSpans vector
233  for (auto iter = ++(_spanVector.begin()); iter != _spanVector.end(); ++iter) {
234  auto & newSpansEnd = newSpans.back();
235  if (spansContiguous(newSpansEnd, *iter)) {
236  newSpansEnd = Span(newSpansEnd.getY(), std::min(newSpansEnd.getMinX(), iter->getMinX()),
237  std::max(newSpansEnd.getMaxX(), iter->getMaxX()));
238  } else {
239  newSpans.push_back(Span(*iter));
240  }
241  }
242 
243  // Set the new normalized vector of spans to the internal span vector container
244  _spanVector = std::move(newSpans);
245 }
246 
247 void SpanSet::_initialize() {
248  /* This function exists to handle common functionality for most of the constructors. It calculates the
249  * bounding box for the SpanSet, and the area covered by the SpanSet
250  */
251 
252  /* Because the array is sorted, the minimum and maximum values for Y will
253  be in the first and last elements, only need to find the min and max X
254  values */
255 
256  // This bit of code will only be executed with a non-empty _spanVector internally
257  // and is not accessable from outside the class
258 
259  int minX = _spanVector[0].getMinX();
260  int maxX = _spanVector[0].getMaxX();
261  _area = 0;
262 
263  for (const auto& span : _spanVector) {
264  if (span.getMinX() < minX) {
265  minX = span.getMinX();
266  }
267  if (span.getMaxX() > maxX) {
268  maxX = span.getMaxX();
269  }
270  // Plus one, because end point is inclusive
271  _area += span.getMaxX() - span.getMinX() + 1;
272  }
273  _bbox = Box2I(Point2I(minX, _spanVector.front().getY()), Point2I(maxX, _spanVector.back().getY()));
274 }
275 
276 // Getter for the area property
277 std::size_t SpanSet::getArea() const { return _area; }
278 
279 // Getter for the bounding box of the SpanSet
280 Box2I SpanSet::getBBox() const { return _bbox; }
281 
282 /* Here is a description of how the _makeLabels and _label function works. In the
283  _makeLabels function, a vector is created with the same number of elements as
284  spans in the SpanSet. This vector will contain the label for each Span in the
285  SpanSet. These labels correspond to which connected region the span falls in.
286  If the whole SpanSet is connected than there will only be one region and every
287  Span will be labeled with a 1. If there are two regions (i.e. there are points
288  in between not contained in the SpanSet) then Some of the Spans will be labeled
289  1, and the rest labeled 2. _makeLabels also sorts each of the Spans in the
290  current span into an unordered map that is indexed by the y position of each
291  span. This allows efficient lookups of corresponding rows.
292 
293  The function loops over all the Spans in the Spanset. If the Span has not been
294  labeled, the _label function is called, with the current span, the vector
295  containing the labels, the label for the current region under consideration,
296  and the indexed map of Spans.
297 
298  The _label function will then loop over all Spans in the SpanSet looking for
299  rows adjacent to the currently being labeled Span which overlap in the x
300  dimension and have not yet been labeled, and mark them with the current label,
301  and recursively call the _label function with the adjacent row as the new Span
302  under consideration. This results in all Spans which overlap each other in x
303  being labeled with the current label.
304 
305  Once _label reaches the end of Spans which meet it's criteria, control falls
306  back to the _makeLabels function and the current label is incremented. The
307  function then moves onto the next Span in the SpanSet which has not been
308  labeled. If all spans were labeled in the recursive call the loop falls to the
309  end, and the label vector and one past the last label number (number of labels +1)
310  are returned to the caller. If instead _makeLabels finds a Span that has not
311  been labeled, the next label is assigned and the process is repeated until
312  all Spans have been labeled.
313  */
314 
315 void SpanSet::_label(
316  Span const& spn, std::vector<std::size_t>& labelVector, std::size_t currentLabel,
318  auto currentIndex = spn.getY();
319  if (currentIndex > 0) {
320  // loop over the prevous row
321  for (auto const& tup : sortMap[currentIndex - 1]) {
322  if (!labelVector[tup.first] && spansOverlap(spn, *(tup.second), false)) {
323  labelVector[tup.first] = currentLabel;
324  _label(*(tup.second), labelVector, currentLabel, sortMap);
325  }
326  }
327  }
328  if (currentIndex <= _spanVector.back().getY() - 1) {
329  // loop over the next row
330  for (auto& tup : sortMap[currentIndex + 1]) {
331  if (!labelVector[tup.first] && spansOverlap(spn, *(tup.second), false)) {
332  labelVector[tup.first] = currentLabel;
333  _label(*(tup.second), labelVector, currentLabel, sortMap);
334  }
335  }
336  }
337 }
338 
339 std::pair<std::vector<std::size_t>, std::size_t> SpanSet::_makeLabels() const {
340  std::vector<std::size_t> labelVector(_spanVector.size(), 0);
341  std::size_t currentLabel = 1;
342  std::size_t index = 0;
343  // Create a sorted array of arrays
345  std::size_t tempIndex = 0;
346  for (auto const& spn : _spanVector) {
347  sortMap[spn.getY()].push_back(std::make_pair(tempIndex, &spn));
348  tempIndex++;
349  }
350  for (auto const& currentSpan : _spanVector) {
351  if (!labelVector[index]) {
352  labelVector[index] = currentLabel;
353  _label(currentSpan, labelVector, currentLabel, sortMap);
354  /* At this point we have recursed enough to reach all of the connected
355  * region, and should increment the label such that any spans not
356  * labeled in the first loop will get a new value. If all of the spans
357  * were connected in the first pass, the rest of this loop will just
358  * fall though.
359  */
360  ++currentLabel;
361  }
362  ++index;
363  }
364  return std::pair<std::vector<std::size_t>, std::size_t>(labelVector, currentLabel);
365 }
366 
367 bool SpanSet::isContiguous() const {
368  auto labeledPair = _makeLabels();
369  // Here we want to check if there is only one label. Since _makeLabels always increments
370  // at the end of each loop, we need to compare against the number 2. I.e. if everything
371  // gets labeled 1, the label counter will increment to 2, and the if statement will always
372  // be false and _makeLabels will fall through to the end and return to here.
373  return labeledPair.second <= 2;
374 }
375 
377  auto labeledPair = _makeLabels();
378  auto labels = labeledPair.first;
379  auto numberOfLabels = labeledPair.second;
381  // As the number of labels is known, the number of SpanSets to be created is also known
382  // make a vector of vectors to hold the Spans which will correspond to each SpanSet
383  std::vector<std::vector<Span>> subSpanLists(numberOfLabels - 1);
384 
385  // if numberOfLabels is 1, that means a null SpanSet is being operated on,
386  // and we should return like
387  if (numberOfLabels == 1) {
388  subRegions.push_back(std::make_shared<SpanSet>());
389  return subRegions;
390  }
391  subRegions.reserve(numberOfLabels - 1);
392 
393  // loop over the current SpanSet's spans sorting each of the spans according to the label
394  // that was assigned
395  for (std::size_t i = 0; i < _spanVector.size(); ++i) {
396  subSpanLists[labels[i] - 1].push_back(_spanVector[i]);
397  }
398  // Transform each of the vectors of Spans into a SpanSet
399  for (std::size_t i = 0; i < numberOfLabels - 1; ++i) {
400  subRegions.push_back(std::make_shared<SpanSet>(subSpanLists[i]));
401  }
402  return subRegions;
403 }
404 
407  setMask(tempMask, static_cast<image::MaskPixel>(1));
408  auto erodedSpanSet = eroded(1, Stencil::CIRCLE);
409  erodedSpanSet->clearMask(tempMask, static_cast<image::MaskPixel>(1));
410  return SpanSet::fromMask(tempMask);
411 }
412 
414  // Function to create a new SpanSet which is a copy of this, shifted by x and y
415  return makeShift(x, y);
416 }
417 
419  // Function to create a new SpanSet which is a copy of this, shifted by an extent object
420  return makeShift(offset.getX(), offset.getY());
421 }
422 
423 std::shared_ptr<SpanSet> SpanSet::makeShift(int x, int y) const {
424  // Implementation method common to all overloads of the shiftedBy method
425  std::vector<Span> tempVec;
426  tempVec.reserve(_spanVector.size());
427  for (auto const& spn : _spanVector) {
428  tempVec.push_back(Span(spn.getY() + y, spn.getMinX() + x, spn.getMaxX() + x));
429  }
430  return std::make_shared<SpanSet>(std::move(tempVec), false);
431 }
432 
434  /* Return a copy of the current SpanSet but only with values which are contained within
435  * the supplied box
436  */
437  std::vector<Span> tempVec;
438  for (auto const& spn : _spanVector) {
439  if (spn.getY() >= box.getMinY() && spn.getY() <= box.getMaxY() &&
440  spansOverlap(spn, Span(spn.getY(), box.getMinX(), box.getMaxX()))) {
441  tempVec.push_back(Span(spn.getY(), std::max(box.getMinX(), spn.getMinX()),
442  std::min(box.getMaxX(), spn.getMaxX())));
443  }
444  }
445  return std::make_shared<SpanSet>(std::move(tempVec), false);
446 }
447 
448 bool SpanSet::overlaps(SpanSet const& other) const {
449  // Function to check if two SpanSets overlap
450  for (auto const& otherSpan : other) {
451  for (auto const& spn : _spanVector) {
452  if (spansOverlap(otherSpan, spn)) {
453  return true;
454  }
455  }
456  }
457  return false;
458 }
459 
460 bool SpanSet::contains(SpanSet const& other) const {
461  // Handle null SpanSet passed as other
462  if (other.empty()) {
463  return false;
464  }
465  // Function to check if a SpanSet is entirely contained within this
466  for (auto const& otherSpn : other) {
467  std::size_t counter = 0;
468  for (auto const& spn : _spanVector) {
469  // Check that the end points of the span from other are contained in the
470  // span from this
471  if (spn.contains(Point2I(otherSpn.getMinX(), otherSpn.getY())) &&
472  spn.contains(Point2I(otherSpn.getMaxX(), otherSpn.getY()))) {
473  ++counter;
474  }
475  }
476  // if counter is equal to zero, then the current span from other is not
477  // contained in any span in this, and the function should return false
478  // short circuiting any other spans from other
479  if (counter == 0) {
480  return false;
481  }
482  }
483  return true;
484 }
485 
486 bool SpanSet::contains(Point2I const& point) const {
487  // Check to see if a given point is found within any spans in this
488  for (auto& spn : _spanVector) {
489  if (spn.contains(point)) {
490  return true;
491  }
492  }
493  return false;
494 }
495 
497  // Find the centroid of the SpanSet
498  std::size_t n = 0;
499  double xc = 0, yc = 0;
500  for (auto const& spn : _spanVector) {
501  int const y = spn.getY();
502  int const x0 = spn.getMinX();
503  int const x1 = spn.getMaxX();
504  int const npix = x1 - x0 + 1;
505 
506  n += npix;
507  xc += npix * 0.5 * (x1 + x0);
508  yc += npix * y;
509  }
510  assert(n == _area);
511 
512  return Point2D(xc / _area, yc / _area);
513 }
514 
516  // Compute the shape of the SpanSet
517  Point2D cen = computeCentroid();
518  double const xc = cen.getX();
519  double const yc = cen.getY();
520 
521  double sumxx = 0, sumxy = 0, sumyy = 0;
522  for (auto const& spn : _spanVector) {
523  int const y = spn.getY();
524  int const x0 = spn.getX0();
525  int const x1 = spn.getX1();
526  int const npix = x1 - x0 + 1;
527 
528  for (int x = x0; x <= x1; ++x) {
529  sumxx += (x - xc) * (x - xc);
530  }
531  sumxy += npix * (0.5 * (x1 + x0) - xc) * (y - yc);
532  sumyy += npix * (y - yc) * (y - yc);
533  }
534 
535  return ellipses::Quadrupole(sumxx / _area, sumyy / _area, sumxy / _area);
536 }
537 
539  // Return a dilated SpanSet made with the given stencil, by creating a SpanSet
540  // from the stencil and forwarding to the appropriate overloaded method
541  std::shared_ptr<SpanSet> stencilToSpanSet = fromShape(r, s);
542  return dilated(*stencilToSpanSet);
543 }
544 
546  // Handle a null SpanSet nothing should be dilated
547  if (other.size() == 0) {
548  return std::make_shared<SpanSet>(_spanVector.begin(), _spanVector.end(), false);
549  }
550 
551  // Return a dilated Spanset by the given SpanSet
552  std::vector<Span> tempVec;
553 
554  for (auto const& spn : _spanVector) {
555  for (auto const& otherSpn : other) {
556  int const xmin = spn.getMinX() + otherSpn.getMinX();
557  int const xmax = spn.getMaxX() + otherSpn.getMaxX();
558  int const yval = spn.getY() + otherSpn.getY();
559  tempVec.push_back(Span(yval, xmin, xmax));
560  }
561  }
562  // Allow constructor to handle merging adjacent and overlapping spans
563  return std::make_shared<SpanSet>(std::move(tempVec));
564 }
565 
567  // Return an eroded SpanSet made with the given stencil, by creating a SpanSet
568  // from the stencil and forwarding to the appropriate overloaded method
569  std::shared_ptr<SpanSet> stencilToSpanSet = fromShape(r, s);
570  return eroded(*stencilToSpanSet);
571 }
572 
574  // Handle a null SpanSet nothing should be eroded
575  if (other.size() == 0 || this->size() == 0) {
576  return std::make_shared<SpanSet>(_spanVector.begin(), _spanVector.end(), false);
577  }
578 
579  // Return a SpanSet eroded by the given SpanSet
580  std::vector<Span> tempVec;
581 
582  // Calculate all possible primary runs.
583  std::vector<PrimaryRun> primaryRuns;
584  for (auto const& spn : _spanVector) {
585  int m = 0;
586  for (auto const& otherSpn : other) {
587  if ((otherSpn.getMaxX() - otherSpn.getMinX()) <= (spn.getMaxX() - spn.getMinX())) {
588  int xmin = spn.getMinX() - otherSpn.getMinX();
589  int xmax = spn.getMaxX() - otherSpn.getMaxX();
590  int y = spn.getY() - otherSpn.getY();
591  primaryRuns.push_back(PrimaryRun({m, y, xmin, xmax}));
592  }
593  ++m;
594  }
595  }
596 
597  // Iterate over the primary runs in such a way that we consider all values of m
598  // for a given y, then all m for y+1 etc.
599  std::sort(primaryRuns.begin(), primaryRuns.end(), comparePrimaryRun);
600 
601  for (int y = primaryRuns.front().y; y <= primaryRuns.back().y; ++y) {
602  auto yRange = std::equal_range(primaryRuns.begin(), primaryRuns.end(), y, ComparePrimaryRunY());
603 
604  /* Discard runs for any value of y for which we find fewer groups than M,
605  * the total Y range of the structuring element. This is step 3.1 of the
606  * Kim et al. algorithm.
607  */
608  // Plus one because end points are inclusive
609  auto otherYRange = other.back().getY() - other.front().getY() + 1;
610  if (std::distance(yRange.first, yRange.second) < otherYRange) {
611  continue;
612  }
613 
614  /* "good" runs are those which are covered by each value of m, ie by each
615  * row in the structuring element. Our algorithm will consider each value
616  * of m in turn, gradually whittling down the list of good runs, then
617  * finally convert the remainder into Spans.
618  */
619  std::list<PrimaryRun> goodRuns;
620 
621  for (int m = 0; m < otherYRange; ++m) {
622  auto mRange = std::equal_range(yRange.first, yRange.second, m, ComparePrimaryRunM());
623  if ((mRange.first == mRange.second)) {
624  // If a particular m is missing, we known that this y contains
625  // no good runs; this is equivalent to Kim et al. step 3.2.
626  goodRuns.clear();
627  } else {
628  // Consolidate all primary runs at this m so that they don't overlap.
629  std::list<PrimaryRun> candidateRuns;
630  int startX = mRange.first->xmin;
631  int endX = mRange.first->xmax;
632  for (auto run = mRange.first + 1; run != mRange.second; ++run) {
633  if (run->xmin > endX) {
634  // Start of a new run
635  candidateRuns.push_back(PrimaryRun{m, y, startX, endX});
636  startX = run->xmin;
637  endX = run->xmax;
638  } else {
639  // Continuation of an existing run
640  endX = run->xmax;
641  }
642  }
643  candidateRuns.push_back(PrimaryRun{m, y, startX, endX});
644 
645  // Otherwise, calculate the intersection of candidate runs at
646  // this m with good runs from all previous m.
647  if (m == 0) {
648  // For m = 0 we have nothing to compare to; all runs are accepted
649  std::swap(goodRuns, candidateRuns);
650  } else {
651  std::list<PrimaryRun> newlist;
652  for (auto& good : goodRuns) {
653  for (auto& cand : candidateRuns) {
654  int start = std::max(good.xmin, cand.xmin);
655  int end = std::min(good.xmax, cand.xmax);
656  if (end >= start) {
657  newlist.push_back(PrimaryRun({m, y, start, end}));
658  }
659  }
660  }
661  std::swap(newlist, goodRuns);
662  }
663  }
664  }
665  for (auto& run : goodRuns) {
666  tempVec.push_back(Span(run.y, run.xmin, run.xmax));
667  }
668  }
669  return std::make_shared<SpanSet>(std::move(tempVec));
670 }
671 
672 bool SpanSet::operator==(SpanSet const& other) const {
673  // Check the equivalence of this SpanSet with another
674  return _spanVector == other._spanVector;
675 }
676 
677 bool SpanSet::operator!=(SpanSet const& other) const {
678  // Check the equivalence of this SpanSet with another
679  return _spanVector != other._spanVector;
680 }
681 
683  // Create a SpanSet from a given Stencil
684  std::vector<Span> tempVec;
685  tempVec.reserve(2 * r + 1);
686  switch (s) {
687  case Stencil::CIRCLE:
688  for (auto dy = -r; dy <= r; ++dy) {
689  int dx = static_cast<int>(sqrt(r * r - dy * dy));
690  tempVec.push_back(Span(dy + offset.getY(), -dx + offset.getX(), dx + offset.getX()));
691  }
692  break;
693  case Stencil::MANHATTAN:
694  for (auto dy = -r; dy <= r; ++dy) {
695  int dx = r - abs(dy);
696  tempVec.push_back(Span(dy + offset.getY(), -dx + offset.getX(), dx + offset.getX()));
697  }
698  break;
699  case Stencil::BOX:
700  for (auto dy = -r; dy <= r; ++dy) {
701  int dx = r;
702  tempVec.push_back(Span(dy + offset.getY(), -dx + offset.getX(), dx + offset.getX()));
703  }
704  break;
705  }
706  return std::make_shared<SpanSet>(std::move(tempVec), false);
707 }
708 
710  ellipses::PixelRegion pr(ellipse);
711  return std::make_shared<SpanSet>(pr.begin(), pr.end());
712 }
713 
715  // Check if the bounding boxes overlap, if not return null SpanSet
716  if (!_bbox.overlaps(other.getBBox())) {
717  return std::make_shared<SpanSet>();
718  }
719  // Handel intersecting a SpanSet with itself
720  if (other == *this) {
721  return std::make_shared<SpanSet>(this->_spanVector);
722  }
723  std::vector<Span> tempVec;
724  auto otherIter = other.begin();
725  for (auto const& spn : _spanVector) {
726  while (otherIter != other.end() && otherIter->getY() <= spn.getY()) {
727  if (spansOverlap(spn, *otherIter)) {
728  auto newMin = std::max(spn.getMinX(), otherIter->getMinX());
729  auto newMax = std::min(spn.getMaxX(), otherIter->getMaxX());
730  auto newSpan = Span(spn.getY(), newMin, newMax);
731  tempVec.push_back(newSpan);
732  }
733  ++otherIter;
734  }
735  }
736  return std::make_shared<SpanSet>(std::move(tempVec));
737 }
738 
740  // Check if the bounding boxes overlap, if not simply return a copy of this
741  if (!getBBox().overlaps(other.getBBox())) {
742  return std::make_shared<SpanSet>(this->begin(), this->end());
743  }
744  // Handle calling a SpanSet's intersectNot with itself as an argument
745  if (other == *this) {
746  return std::make_shared<SpanSet>();
747  }
748  /* This function must find all the areas in this and not in other. These SpanSets
749  * may be overlapping with this less than other a1| b1| a2| b2|,
750  * with this greater than other b1| a1| b2| a2|,
751  * with this containing other a1| b1| b2| a2|,
752  * or with other containing this b1| a1| a2| b2|
753  */
754  std::vector<Span> tempVec;
755  auto otherIter = other.begin();
756  for (auto const& spn : _spanVector) {
757  bool added = false;
758  bool spanStarted = false;
759  int spanBottom = 0;
760  while (otherIter != other.end() && otherIter->getY() <= spn.getY()) {
761  if (spansOverlap(spn, *otherIter)) {
762  added = true;
763  /* To handle one span containing the other, the spans will be added
764  * piecewise, and let the SpanSet constructor normalize spans which
765  * end up contiguous. In the case where this is contained in other,
766  * these statements will all be false, and nothing will be added,
767  * which is the expected behavior.
768  *
769  * Intersection with the logical not of another SpanSet requires that the Intersection
770  * be tested against the condition that multiple Spans may be present in the other
771  * SpanSet at the same Y coordinate. I.E. If one row in *this would contain two
772  * disconnected Spans in other, the result should be three new Spans.
773  */
774  // Check if a span is in the process of being created
775  if (!spanStarted) {
776  // If the minimum value of the Span in *this is less than that of other, add a new Span
777  if (spn.getMinX() < otherIter->getMinX()) {
778  tempVec.push_back(Span(spn.getY(), spn.getMinX(), otherIter->getMinX() - 1));
779  }
780  // Conversely if the maximum value of the Span in *this is greater than that of other,
781  // Start a new span, and record what the minimum value of that span should be. This is
782  // because SpanSets can be disconnected, and the function must check if there are any
783  // additional Spans which fall in the same row
784  if (spn.getMaxX() > otherIter->getMaxX()) {
785  spanStarted = true;
786  spanBottom = otherIter->getMaxX() + 1;
787  }
788  } else {
789  // A span is in the process of being created and should be finished and added
790  tempVec.push_back(Span(spn.getY(), spanBottom,
791  std::min(spn.getMaxX(), otherIter->getMinX() - 1)));
792  spanStarted = false;
793  // Check if the span in *this extends past that of the Span from other, if so
794  // begin a new Span
795  if (spn.getMaxX() > otherIter->getMaxX()){
796  spanStarted = true;
797  spanBottom = otherIter->getMaxX() + 1;
798  }
799  }
800  }
801  if (otherIter->getMaxX() > spn.getMaxX()) {
802  break;
803  }
804  ++otherIter;
805  }
806  // Check if a span has been started but not finished, if that is the case that means there are
807  // no further spans on this row to consider and the span should be closed and added
808  if (spanStarted) {
809  tempVec.push_back(Span(spn.getY(), spanBottom, spn.getMaxX()));
810  }
811  /* If added is still zero, that means it did not overlap any of the spans in other
812  * and should be included in the new span
813  */
814  if (!added) {
815  tempVec.push_back(Span(spn));
816  }
817  }
818  return std::make_shared<SpanSet>(std::move(tempVec));
819 }
820 
822  /* Simply include Spans from both SpanSets in a new vector and let the SpanSet
823  * constructor normalize any of the SpanSets which may be contiguous
824  */
825  std::size_t combineSize = size() + other.size();
826  std::vector<Span> tempVec;
827  tempVec.reserve(combineSize);
828  // Copy this
829  tempVec.insert(tempVec.end(), _spanVector.begin(), _spanVector.end());
830  // Copy other
831  tempVec.insert(tempVec.end(), other.begin(), other.end());
832  return std::make_shared<SpanSet>(std::move(tempVec));
833 }
834 
836  // Transform points in SpanSet by LinearTransform
837  return transformedBy(AffineTransform(t));
838 }
839 
841  // Transform points in SpanSet by AffineTransform
842  return transformedBy(AffineXYTransform(t));
843 }
844 
846  // Transform points in SpanSet by XYTransform
847  // Transform the original bounding box
848  Box2D newBBoxD;
849  newBBoxD.include(t.forwardTransform(Point2D(_bbox.getMinX(), _bbox.getMinY())));
850  newBBoxD.include(t.forwardTransform(Point2D(_bbox.getMinX(), _bbox.getMaxY())));
851  newBBoxD.include(t.forwardTransform(Point2D(_bbox.getMaxX(), _bbox.getMinY())));
852  newBBoxD.include(t.forwardTransform(Point2D(_bbox.getMaxX(), _bbox.getMaxY())));
853 
854  Box2I newBBoxI(newBBoxD);
855 
856  std::vector<Span> tempVec;
857  for (int y = newBBoxI.getBeginY(); y < newBBoxI.getEndY(); ++y) {
858  bool inSpan = false; // Are we in a span?
859  int start = -1; // Start of span
860 
861  for (int x = newBBoxI.getBeginX(); x < newBBoxI.getEndX(); ++x) {
862  Point2D p = t.reverseTransform(Point2D(x, y));
863  int const xSource = std::floor(0.5 + p.getX());
864  int const ySource = std::floor(0.5 + p.getY());
865 
866  if (contains(Point2I(xSource, ySource))) {
867  if (!inSpan) {
868  inSpan = true;
869  start = x;
870  }
871  } else if (inSpan) {
872  inSpan = false;
873  tempVec.push_back(Span(y, start, x - 1));
874  }
875  }
876  if (inSpan) {
877  tempVec.push_back(Span(y, start, newBBoxI.getMaxX()));
878  }
879  }
880  return std::make_shared<SpanSet>(std::move(tempVec));
881 }
882 
884  // Transform points in SpanSet by Transform<Point2Endpoint, Point2Endpoint>
885  // Transform the original bounding box
886  Box2D newBBoxD;
887  std::vector<Point2D> fromCorners;
888  fromCorners.reserve(4);
889  for (auto const & fc: _bbox.getCorners()) {
890  fromCorners.emplace_back(Point2D(fc));
891  }
892  auto toPoints = t.applyForward(fromCorners);
893  for (auto const & tc: toPoints) {
894  newBBoxD.include(tc);
895  }
896 
897  Box2I newBBoxI(newBBoxD);
898 
899  std::vector<Point2D> newBoxPoints;
900  newBoxPoints.reserve(newBBoxI.getWidth());
901  std::vector<Span> tempVec;
902  for (int y = newBBoxI.getBeginY(); y < newBBoxI.getEndY(); ++y) {
903  bool inSpan = false; // Are we in a span?
904  int start = -1; // Start of span
905 
906  // vectorize one row at a time (vectorizing the whole bbox would further improve performance
907  // but could lead to memory issues for very large bounding boxes)
908  newBoxPoints.clear();
909  for (int x = newBBoxI.getBeginX(); x < newBBoxI.getEndX(); ++x) {
910  newBoxPoints.emplace_back(Point2D(x, y));
911  }
912  auto oldBoxPoints = t.applyInverse(newBoxPoints);
913  auto oldBoxPointIter = oldBoxPoints.cbegin();
914  for (int x = newBBoxI.getBeginX(); x < newBBoxI.getEndX(); ++x, ++oldBoxPointIter) {
915  auto p = *oldBoxPointIter;
916  int const xSource = std::floor(0.5 + p.getX());
917  int const ySource = std::floor(0.5 + p.getY());
918 
919  if (contains(Point2I(xSource, ySource))) {
920  if (!inSpan) {
921  inSpan = true;
922  start = x;
923  }
924  } else if (inSpan) {
925  inSpan = false;
926  tempVec.push_back(Span(y, start, x - 1));
927  }
928  }
929  if (inSpan) {
930  tempVec.push_back(Span(y, start, newBBoxI.getMaxX()));
931  }
932  }
933  return std::make_shared<SpanSet>(std::move(tempVec));
934 }
935 
936 template <typename ImageT>
937 void SpanSet::setImage(image::Image<ImageT>& image, ImageT val, Box2I const& region, bool doClip) const {
938  Box2I bbox;
939  if (region.isEmpty()) {
940  bbox = image.getBBox();
941  } else {
942  bbox = region;
943  }
944  auto setterFunc = [](Point2I const& point, ImageT& out, ImageT in) { out = in; };
945  try {
946  if (doClip) {
947  auto tmpSpan = this->clippedTo(bbox);
948  tmpSpan->applyFunctor(setterFunc, image, val);
949  } else {
950  applyFunctor(setterFunc, image, val);
951  }
954  "Footprint Bounds Outside image, set doClip to true");
955  }
956 }
957 
958 template <typename T>
959 void SpanSet::setMask(image::Mask<T>& target, T bitmask) const {
960  // Use a lambda to set bits in a mask at the locations given by SpanSet
961  auto targetArray = target.getArray();
962  auto xy0 = target.getBBox().getMin();
963  auto maskFunctor = [](Point2I const& point, typename details::ImageNdGetter<T, 2, 1>::Reference maskVal,
964  T bitmask) { maskVal |= bitmask; };
965  applyFunctor(maskFunctor, ndarray::ndImage(targetArray, xy0), bitmask);
966 }
967 
968 template <typename T>
969 void SpanSet::clearMask(image::Mask<T>& target, T bitmask) const {
970  // Use a lambda to clear bits in a mask at the locations given by SpanSet
971  auto targetArray = target.getArray();
972  auto xy0 = target.getBBox().getMin();
973  auto clearMaskFunctor = [](Point2I const& point,
975  T bitmask) { maskVal &= ~bitmask; };
976  applyFunctor(clearMaskFunctor, ndarray::ndImage(targetArray, xy0), bitmask);
977 }
978 
979 template <typename T>
981  return maskIntersect<T, false>(*this, other, bitmask);
982 }
983 
984 template <typename T>
986  return maskIntersect<T, true>(*this, other, bitmask);
987 }
988 
989 template <typename T>
991  auto comparator = [bitmask](T pixelValue) { return (pixelValue & bitmask); };
992  auto spanSetFromMask = fromMask(other, comparator);
993  return union_(*spanSetFromMask);
994 }
995 
996 namespace {
997 // Singleton helper class that manages the schema and keys for the persistence of SpanSets
998 class SpanSetPersistenceHelper {
999 public:
1000  table::Schema spanSetSchema;
1001  table::Key<int> spanY;
1002  table::Key<int> spanX0;
1003  table::Key<int> spanX1;
1004 
1005  static SpanSetPersistenceHelper const& get() {
1006  static SpanSetPersistenceHelper instance;
1007  return instance;
1008  }
1009 
1010  // No copying
1011  SpanSetPersistenceHelper(const SpanSetPersistenceHelper&) = delete;
1012  SpanSetPersistenceHelper& operator=(const SpanSetPersistenceHelper&) = delete;
1013 
1014  // No Moving
1015  SpanSetPersistenceHelper(SpanSetPersistenceHelper&&) = delete;
1016  SpanSetPersistenceHelper& operator=(SpanSetPersistenceHelper&&) = delete;
1017 
1018 private:
1019  SpanSetPersistenceHelper()
1020  : spanSetSchema(),
1021  spanY(spanSetSchema.addField<int>("y", "The row of the span", "pixel")),
1022  spanX0(spanSetSchema.addField<int>("x0", "First column of span (inclusive)", "pixel")),
1023  spanX1(spanSetSchema.addField<int>("x1", "Second column of span (inclusive)", "pixel")) {
1024  spanSetSchema.getCitizen().markPersistent();
1025  }
1026 };
1027 
1028 std::string getSpanSetPersistenceName() { return "SpanSet"; }
1029 
1030 class SpanSetFactory : public table::io::PersistableFactory {
1031 public:
1032  virtual std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
1033  CatalogVector const& catalogs) const {
1034  // There should only be one catalog saved
1035  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
1036  // Get the catalog with the spans
1037  auto spansCatalog = catalogs.front();
1038  // Retrieve the keys that will be used to reference the catalog
1039  auto const& keys = SpanSetPersistenceHelper::get();
1040  // Construct a temporary container which will later be turned into the SpanSet
1041  std::vector<Span> tempVec;
1042  tempVec.reserve(spansCatalog.size());
1043  for (auto const& val : spansCatalog) {
1044  tempVec.push_back(Span(val.get(keys.spanY), val.get(keys.spanX0), val.get(keys.spanX1)));
1045  }
1046  return std::make_shared<SpanSet>(std::move(tempVec));
1047  }
1048  explicit SpanSetFactory(std::string const& name) : table::io::PersistableFactory(name) {}
1049 };
1050 
1051 // insert the factory into the registry (instantiating an instance is sufficient, because the code
1052 // that does the work is in the base class ctor)
1053 SpanSetFactory registration(getSpanSetPersistenceName());
1054 
1055 } // end anonymous
1056 
1057 std::string SpanSet::getPersistenceName() const { return getSpanSetPersistenceName(); }
1058 
1059 void SpanSet::write(OutputArchiveHandle& handle) const {
1060  auto const& keys = SpanSetPersistenceHelper::get();
1061  auto spanCat = handle.makeCatalog(keys.spanSetSchema);
1062  spanCat.reserve(size());
1063  for (auto const& val : *this) {
1064  auto record = spanCat.addNew();
1065  record->set(keys.spanY, val.getY());
1066  record->set(keys.spanX0, val.getX0());
1067  record->set(keys.spanX1, val.getX1());
1068  }
1069  handle.saveCatalog(spanCat);
1070 }
1071 
1072 //
1073 // Explicit instantiations
1074 #define INSTANTIATE_IMAGE_TYPE(T) \
1075  template void SpanSet::setImage<T>(image::Image<T> & image, T val, \
1076  geom::Box2I const& region = geom::Box2I(), bool doClip = false) \
1077  const;
1078 
1079 #define INSTANTIATE_MASK_TYPE(T) \
1080  template void SpanSet::setMask<T>(image::Mask<T> & target, T bitmask) const; \
1081  template void SpanSet::clearMask<T>(image::Mask<T> & target, T bitmask) const; \
1082  template std::shared_ptr<SpanSet> SpanSet::intersect<T>(image::Mask<T> const& other, T bitmask) const; \
1083  template std::shared_ptr<SpanSet> SpanSet::intersectNot<T>(image::Mask<T> const& other, T bitmask) \
1084  const; \
1085  template std::shared_ptr<SpanSet> SpanSet::union_<T>(image::Mask<T> const& other, T bitmask) const;
1086 
1090 INSTANTIATE_IMAGE_TYPE(float);
1091 INSTANTIATE_IMAGE_TYPE(double);
1092 
1094 }
1095 }
1096 } // Close lsst::afw::geom
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
std::shared_ptr< SpanSet > union_(SpanSet const &other) const
Create a new SpanSet that contains all points from two SpanSets.
Definition: SpanSet.cc:821
std::shared_ptr< geom::SpanSet > findEdgePixels() const
Select pixels within the SpanSet which touch its edge.
Definition: SpanSet.cc:405
int m
Definition: SpanSet.cc:43
std::vector< std::shared_ptr< geom::SpanSet > > split() const
Split a discontinuous SpanSet into multiple SpanSets which are contiguous.
Definition: SpanSet.cc:376
ToPoint applyForward(FromPoint const &point) const
Transform one point in the forward direction ("from" to "to")
Definition: Transform.cc:77
bool operator!=(SpanSet const &other) const
Definition: SpanSet.cc:677
Stencil
An enumeration class which describes the shapes.
Definition: SpanSet.h:65
std::shared_ptr< SpanSet > intersect(SpanSet const &other) const
Determine the common points between two SpanSets, and create a new SpanSet.
Definition: SpanSet.cc:714
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:163
def keys(self)
T distance(T... args)
int getMinX() const
Definition: Box.h:124
Key< Flag > const & target
bool contains(SpanSet const &other) const
Check if a SpanSet instance entirely contains another SpanSet.
Definition: SpanSet.cc:460
size_type size() const
Definition: SpanSet.h:93
afw::table::Key< afw::table::Array< MaskPixelT > > mask
const_iterator end() const
Definition: SpanSet.h:88
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
Definition: ImageBase.h:448
virtual Point2D reverseTransform(Point2D const &point) const =0
T swap(T... args)
T front(T... args)
virtual Point2D forwardTransform(Point2D const &point) const =0
virtuals for forward and reverse transforms
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, UnaryPredicate comparator=details::AnyBitSetFunctor< T >())
Create a SpanSet from a mask.
Definition: SpanSet.h:646
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
A compact representation of a collection of pixels.
Definition: SpanSet.h:76
A range of pixels within one row of an Image.
Definition: Span.h:55
void applyFunctor(Functor &&func, Args &&... args) const
Apply functor on individual elements from the supplied parameters.
Definition: SpanSet.h:514
std::shared_ptr< SpanSet > shiftedBy(int x, int y) const
Return a new SpanSet shifted by specified amount.
Definition: SpanSet.cc:413
table::Key< int > spanX0
Definition: SpanSet.cc:1002
std::shared_ptr< SpanSet > dilated(int r, Stencil s=Stencil::CIRCLE) const
Perform a set dilation operation, and return a new object.
Definition: SpanSet.cc:538
typename ndarray::Array< T, N, C >::Reference::Reference Reference
STL namespace.
T end(T... args)
const_iterator begin() const
Definition: SpanSet.h:87
std::shared_ptr< SpanSet > intersectNot(SpanSet const &other) const
Determine the common points between a SpanSet and the logical inverse of a second SpanSet and return ...
Definition: SpanSet.cc:739
std::shared_ptr< SpanSet > clippedTo(Box2I const &box) const
Return a new SpanSet which has all pixel values inside specified box.
Definition: SpanSet.cc:433
T floor(T... args)
ItemVariant const * other
Definition: Schema.cc:55
bool isContiguous() const
Defines if the SpanSet is simply contiguous.
Definition: SpanSet.cc:367
ellipses::Quadrupole computeShape() const
Compute the shape parameters for the distribution of points in the SpanSet.
Definition: SpanSet.cc:515
An integer coordinate rectangle.
Definition: Box.h:55
STL class.
T min(T... args)
A 2D linear coordinate transformation.
table::Key< int > spanX1
Definition: SpanSet.cc:1003
int getX0() const
Return the starting x-value.
Definition: Span.h:82
T push_back(T... args)
table::Key< int > spanY
Definition: SpanSet.cc:1001
bool overlaps(Box2I const &other) const
Return true if any points in other are also in this.
Definition: Box.cc:111
A base class for image defects.
FromPoint applyInverse(ToPoint const &point) const
Transform one point in the inverse direction ("to" to "from")
Definition: Transform.cc:93
table::Schema spanSetSchema
Definition: SpanSet.cc:1000
Point< double, 2 > Point2D
Definition: Point.h:304
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:84
An affine coordinate transformation consisting of a linear transformation and an offset.
table::Key< int > b
void setImage(image::Image< ImageT > &image, ImageT val, geom::Box2I const &region=geom::Box2I(), bool doClip=false) const
Set the values of an Image at points defined by the SpanSet.
Definition: SpanSet.cc:937
void include(Point2D const &point)
Expand this to ensure that this->contains(point).
Definition: Box.cc:317
T make_pair(T... args)
bool empty() const
Definition: SpanSet.h:94
double x
const_reference front() const
Definition: SpanSet.h:91
T clear(T... args)
int getWidth() const
Definition: Box.h:154
STL class.
T max(T... args)
def run(suite, exit=True)
int getEndY() const
Definition: Box.h:144
T move(T... args)
int getBeginX() const
Definition: Box.h:139
details::ImageNdGetter< T, inA, inB > ndImage(ndarray::Array< T, inA, inB > const &array, afwGeom::Point2I xy0=afwGeom::Point2I())
Marks a ndarray to be interpreted as an image when applying a functor from a SpanSet.
T insert(T... args)
#define LSST_EXCEPT(type,...)
STL class.
SpanSet()
Default constructor.
Definition: SpanSet.cc:172
static std::shared_ptr< geom::SpanSet > fromShape(int r, Stencil s=Stencil::CIRCLE, Point2I offset=Point2I())
Factory function for creating SpanSets from a Stencil.
Definition: SpanSet.cc:682
size_type getArea() const
Return the number of pixels in the SpanSet.
Definition: SpanSet.cc:277
std::vector< Point2I > getCorners() const
Get the corner points.
Definition: Box.cc:211
void setMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Set a Mask at pixels defined by the SpanSet.
Definition: SpanSet.cc:959
T begin(T... args)
int getMaxX() const
Maximum x-value.
Definition: Span.h:90
Point2D computeCentroid() const
Compute the point about which the SpanSet&#39;s first moment is zero.
Definition: SpanSet.cc:496
int getBeginY() const
Definition: Box.h:140
int getX1() const
Return the ending x-value.
Definition: Span.h:84
int getMaxX() const
Definition: Box.h:128
Virtual base class for 2D transforms.
Definition: XYTransform.h:49
T back(T... args)
const_reference back() const
Definition: SpanSet.h:92
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
table::Box2IKey bbox
void clearMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Unset a Mask at pixels defined by the SpanSet.
Definition: SpanSet.cc:969
int getY() const
Return the y-value.
Definition: Span.h:86
SpanSet & operator=(SpanSet const &)=default
table::Key< int > a
#define INSTANTIATE_MASK_TYPE(T)
Definition: SpanSet.cc:1079
T sort(T... args)
bool overlaps(SpanSet const &other) const
Specifies if this SpanSet overlaps with another SpanSet.
Definition: SpanSet.cc:448
int getMaxY() const
Definition: Box.h:129
std::shared_ptr< SpanSet > transformedBy(LinearTransform const &t) const
Return a new SpanSet who&#39;s pixels are the product of applying the specified transformation.
Definition: SpanSet.cc:835
bool contains(int x) const
Definition: Span.h:96
Point< int, 2 > Point2I
Definition: Point.h:301
A floating-point coordinate rectangle geometry.
Definition: Box.h:266
int getMinX() const
Minimum x-value.
Definition: Span.h:89
#define INSTANTIATE_IMAGE_TYPE(T)
Definition: SpanSet.cc:1074
int xmax
Definition: SpanSet.cc:43
Wrap an AffineTransform.
Definition: XYTransform.h:185
int getMinY() const
Definition: Box.h:125
bool operator==(SpanSet const &other) const
Compute equality between two SpanSets.
Definition: SpanSet.cc:672
int getEndX() const
Definition: Box.h:143
PixelConstReference get0(int x, int y) const
Definition: ImageBase.h:289
int xmin
Definition: SpanSet.cc:43
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:69
int y
Definition: SpanSet.cc:43
T equal_range(T... args)
std::shared_ptr< SpanSet > eroded(int r, Stencil s=Stencil::CIRCLE) const
Perform a set erosion, and return a new object.
Definition: SpanSet.cc:566
Transform LSST spatial data, such as Point2D and SpherePoint, using an AST mapping.
Definition: Transform.h:67
T reserve(T... args)
Box2I getBBox() const
Return a new integer box which is the minimum size to contain the pixels.
Definition: SpanSet.cc:280
T emplace_back(T... args)