LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
SpatialCell.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 /*
26  * Class to ensure constraints for spatial modeling
27  */
28 
29 #ifndef LSST_AFW_MATH_SPATIALCELL_H
30 #define LSST_AFW_MATH_SPATIALCELL_H
31 
32 #include <limits>
33 #include <vector>
34 #include <string>
35 
36 #include <memory>
37 #include "lsst/base.h"
38 #include "lsst/pex/exceptions.h"
39 #include "lsst/geom.h"
41 
42 namespace lsst {
43 namespace afw {
44 
45 // forward declarations
46 namespace image {
47 template <typename ImagePixelT>
48 class Image;
49 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
50 class MaskedImage;
51 } // namespace image
52 
53 namespace math {
54 
56 class SpatialCellCandidate;
57 
59 public:
61  virtual ~CandidateVisitor() {}
62 
63  virtual void reset() {}
65 };
66 
71 public:
72  enum Status { BAD = 0, GOOD = 1, UNKNOWN = 2 };
73 
74  SpatialCellCandidate(float const xCenter,
75  float const yCenter
76  )
77  : _id(++_CandidateId), _status(UNKNOWN), _xCenter(xCenter), _yCenter(yCenter) {}
78 
81  SpatialCellCandidate& operator=(SpatialCellCandidate const&) = default;
82  SpatialCellCandidate& operator=(SpatialCellCandidate&&) = default;
83 
87  virtual ~SpatialCellCandidate() = default;
88 
90  float getXCenter() const { return _xCenter; }
91 
93  float getYCenter() const { return _yCenter; }
94 
96  virtual bool instantiate() { return true; }
97 
99  virtual double getCandidateRating() const = 0;
101  virtual void setCandidateRating(double) {}
102 
104  int getId() const { return _id; }
106  Status getStatus() const { return _status; }
108  void setStatus(Status status);
110  virtual bool isBad() const { return (_status == BAD); }
111 
112 private:
113  int _id; // Unique ID for object
114  Status _status; // Is this Candidate good?
115  float const _xCenter; // The object's column-centre
116  float const _yCenter; // The object's row-centre
117 
119  static int _CandidateId;
120 };
121 
127 public:
129  SpatialCellImageCandidate(float const xCenter,
130  float const yCenter
131  )
132  : SpatialCellCandidate(xCenter, yCenter), _chi2(std::numeric_limits<double>::max()) {}
135  SpatialCellImageCandidate& operator=(SpatialCellImageCandidate const&) = default;
137  ~SpatialCellImageCandidate() override = default;
138 
140  static void setWidth(int width) { _width = width; }
142  static int getWidth() { return _width; }
143 
145  static void setHeight(int height) { _height = height; }
147  static int getHeight() { return _height; }
148 
150  double getChi2() const { return _chi2; }
152  void setChi2(double chi2) { _chi2 = chi2; }
153 
154 private:
155  static int _width; // the width of images to return; may be ignored by subclasses
156  static int _height; // the height of images to return; may be ignored by subclasses
157  double _chi2; // chi^2 for fit
158 };
159 
164  friend class SpatialCell;
166 
167 public:
168  // ctors are protected
172  void operator++();
176  size_t operator-(SpatialCellCandidateIterator const& rhs) const;
177 
186 
188  bool operator==(SpatialCellCandidateIterator const& rhs) const { return _iterator == rhs._iterator; }
190  bool operator!=(SpatialCellCandidateIterator const& rhs) const { return _iterator != rhs._iterator; }
191 
192 protected:
199  SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end,
200  bool ignoreBad);
207  SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end,
208  bool ignoreBad, bool);
209 
210 private:
211  CandidateList::iterator _iterator;
212  CandidateList::iterator _end;
213  bool _ignoreBad;
214 };
215 
227 class SpatialCell {
228 public:
239  CandidateList const& candidateList = CandidateList());
240 
241  SpatialCell(SpatialCell const&) = default;
242  SpatialCell(SpatialCell&&) = default;
243  SpatialCell& operator=(SpatialCell const&) = default;
244  SpatialCell& operator=(SpatialCell&&) = default;
245 
249  virtual ~SpatialCell() = default;
250 
254  bool empty() const;
258  size_t size() const;
259 
263  void sortCandidates();
268  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), _ignoreBad);
269  }
271  ) {
272  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad);
273  }
278  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), _ignoreBad, true);
279  }
281  ) {
282  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad, true);
283  }
287  void insertCandidate(std::shared_ptr<SpatialCellCandidate> candidate);
288 
295  void removeCandidate(std::shared_ptr<SpatialCellCandidate> candidate);
296 
298  void setIgnoreBad(bool ignoreBad) { _ignoreBad = ignoreBad; }
300  bool getIgnoreBad() const { return _ignoreBad; }
301 
310  std::shared_ptr<SpatialCellCandidate> getCandidateById(int id, bool noThrow = false);
314  std::string const& getLabel() const { return _label; }
318  lsst::geom::Box2I const& getBBox() const { return _bbox; }
319  /*
320  * Visit our candidates
321  */
334  void visitCandidates(CandidateVisitor* visitor, int const nMaxPerCell = -1,
335  bool const ignoreExceptions = false, bool const reset = true);
349  void visitCandidates(CandidateVisitor* visitor, int const nMaxPerCell = -1,
350  bool const ignoreExceptions = false, bool const reset = true) const;
360  void visitAllCandidates(CandidateVisitor* visitor, bool const ignoreExceptions = false,
361  bool const reset = true);
374  void visitAllCandidates(CandidateVisitor* visitor, bool const ignoreExceptions = false,
375  bool const reset = true) const;
376 
377 private:
378  std::string _label; // Name of cell for logging/trace
379  lsst::geom::Box2I _bbox; // Bounding box of cell in overall image
380  CandidateList _candidateList; // List of all candidates in the cell
381  bool _ignoreBad; // Don't include BAD candidates when traversing the list
382 };
383 
388 public:
390 
400  SpatialCellSet(lsst::geom::Box2I const& region, int xSize, int ySize = 0);
401 
402  SpatialCellSet(SpatialCellSet const&) = default;
403  SpatialCellSet(SpatialCellSet&&) = default;
404  SpatialCellSet& operator=(SpatialCellSet const&) = default;
405  SpatialCellSet& operator=(SpatialCellSet&&) = default;
406 
410  virtual ~SpatialCellSet() = default;
411 
415  CellList& getCellList() { return _cellList; }
416 
420  lsst::geom::Box2I getBBox() const { return _region; };
421 
425  void insertCandidate(std::shared_ptr<SpatialCellCandidate> candidate);
426 
428  void sortCandidates();
429 
441  void visitCandidates(CandidateVisitor* visitor, int const nMaxPerCell = -1,
442  bool const ignoreExceptions = false);
452  void visitCandidates(CandidateVisitor* visitor, int const nMaxPerCell = -1,
453  bool const ignoreExceptions = false) const;
462  void visitAllCandidates(CandidateVisitor* visitor, bool const ignoreExceptions = false);
471  void visitAllCandidates(CandidateVisitor* visitor, bool const ignoreExceptions = false) const;
472 
482  std::shared_ptr<SpatialCellCandidate> getCandidateById(int id, bool noThrow = false);
483 
485  void setIgnoreBad(bool ignoreBad);
486 
487 private:
488  lsst::geom::Box2I _region; // Bounding box of overall image
489  CellList _cellList; // List of SpatialCells
490 };
491 } // namespace math
492 } // namespace afw
493 } // namespace lsst
494 
495 #endif
SpatialCellCandidateIterator begin(bool ignoreBad)
Definition: SpatialCell.h:270
static int getWidth()
Return the width of the image that getImage should return.
Definition: SpatialCell.h:142
std::vector< std::shared_ptr< SpatialCellCandidate > > CandidateList
Definition: SpatialCell.h:229
static void setHeight(int height)
Set the height of the image that getImage should return.
Definition: SpatialCell.h:145
SpatialCellCandidateIterator end()
Return an iterator to (one after) the end of the Candidates.
Definition: SpatialCell.h:277
Basic LSST definitions.
std::shared_ptr< Image< PixelT > > operator*(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
Overload operator*()
Definition: ImageSlice.cc:104
float getXCenter() const
Return the object&#39;s column-centre.
Definition: SpatialCell.h:90
virtual bool isBad() const
Is this candidate unacceptable?
Definition: SpatialCell.h:110
STL namespace.
virtual void processCandidate(SpatialCellCandidate *)
Definition: SpatialCell.h:64
int getId() const
Return the candidate&#39;s unique ID.
Definition: SpatialCell.h:104
double getChi2() const
Return the candidate&#39;s chi^2.
Definition: SpatialCell.h:150
bool operator!=(SpatialCellCandidateIterator const &rhs) const
Are two SpatialCellCandidateIterators unequal?
Definition: SpatialCell.h:190
Rotation angle is unknown.
STL class.
bool operator==(SpatialCellCandidateIterator const &rhs) const
Are two SpatialCellCandidateIterators equal?
Definition: SpatialCell.h:188
A collection of SpatialCells covering an entire image.
Definition: SpatialCell.h:387
lsst::geom::Box2I const & getBBox() const
Get SpatialCell&#39;s BBox.
Definition: SpatialCell.h:318
A base class for image defects.
SpatialCellImageCandidate(float const xCenter, float const yCenter)
ctor
Definition: SpatialCell.h:129
Status getStatus() const
Return the candidate&#39;s status.
Definition: SpatialCell.h:106
lsst::geom::Box2I getBBox() const
Return the bounding box of the image.
Definition: SpatialCell.h:420
int max
SpatialCellCandidateIterator iterator
Definition: SpatialCell.h:230
table::Box2IKey bbox
Definition: Detector.cc:169
virtual bool instantiate()
Do anything needed to make this candidate usable.
Definition: SpatialCell.h:96
std::shared_ptr< Image< PixelT > > operator-(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
Overload operator-()
Definition: ImageSlice.cc:89
STL class.
virtual void setCandidateRating(double)
Set the candidate&#39;s rating.
Definition: SpatialCell.h:101
static void setWidth(int width)
Set the width of the image that getImage should return.
Definition: SpatialCell.h:140
Base class for candidate objects in a SpatialCell that are able to return an Image of some sort (e...
Definition: SpatialCell.h:126
float getYCenter() const
Return the object&#39;s row-centre.
Definition: SpatialCell.h:93
std::vector< std::shared_ptr< SpatialCell > > CellList
Definition: SpatialCell.h:389
Class to ensure constraints for spatial modeling.
Definition: SpatialCell.h:227
bool getIgnoreBad() const
Get whether we are omitting BAD candidates from candidate list when traversing.
Definition: SpatialCell.h:300
Base class for candidate objects in a SpatialCell.
Definition: SpatialCell.h:70
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
Definition: SpatialCell.h:298
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
An integer coordinate rectangle.
Definition: Box.h:54
SpatialCellCandidateIterator begin()
Return an iterator to the beginning of the Candidates.
Definition: SpatialCell.h:267
An iterator that only returns usable members of the SpatialCell.
Definition: SpatialCell.h:163
SpatialCellCandidateIterator end(bool ignoreBad)
Definition: SpatialCell.h:280
int end
void setChi2(double chi2)
Set the candidate&#39;s chi^2.
Definition: SpatialCell.h:152
std::string const & getLabel() const
Get SpatialCell&#39;s label.
Definition: SpatialCell.h:314
SpatialCellCandidate(float const xCenter, float const yCenter)
Definition: SpatialCell.h:74
static int getHeight()
Return the height of the image that getImage should return.
Definition: SpatialCell.h:147
CellList & getCellList()
Return our SpatialCells.
Definition: SpatialCell.h:415