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