LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
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 
33 #ifndef LSST_AFW_MATH_SPATIALCELL_H
34 #define LSST_AFW_MATH_SPATIALCELL_H
35 
36 #include <limits>
37 #include <vector>
38 #include <string>
39 
40 #include <memory>
41 #include "lsst/base.h"
42 #include "lsst/pex/exceptions.h"
43 #include "lsst/afw/geom.h"
45 
46 namespace lsst {
47 namespace afw {
48 
49 // forward declarations
50 namespace image {
51  template<typename ImagePixelT> class Image;
52  template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT> class MaskedImage;
53 }
54 
55 namespace math {
56 
57  /********************************************************************************************************/
59  class SpatialCellCandidate;
60 
62  public:
64  virtual ~CandidateVisitor() {}
65 
66  virtual void reset() {}
68  };
69 
70  /************************************************************************************************************/
75  public:
76  typedef std::shared_ptr<SpatialCellCandidate> Ptr;
77  typedef std::shared_ptr<const SpatialCellCandidate> ConstPtr;
78 
79  enum Status {BAD = 0, GOOD = 1, UNKNOWN = 2};
80 
81  SpatialCellCandidate(float const xCenter,
82  float const yCenter
83  ) :
84  _id(++_CandidateId),
86  _xCenter(xCenter), _yCenter(yCenter) {
87  }
88 
92  virtual ~SpatialCellCandidate() {}
93 
95  float getXCenter() const { return _xCenter; }
96 
98  float getYCenter() const { return _yCenter; }
99 
101  virtual bool instantiate() { return true; }
102 
104  virtual double getCandidateRating() const = 0;
106  virtual void setCandidateRating(double) {}
107 
109  int getId() const { return _id; }
111  Status getStatus() const { return _status; }
112  void setStatus(Status status);
114  virtual bool isBad() const {
115  return (_status == BAD);
116  }
117  private:
118  int _id; // Unique ID for object
119  Status _status; // Is this Candidate good?
120  float const _xCenter; // The object's column-centre
121  float const _yCenter; // The object's row-centre
122 
123  static int _CandidateId; // Unique identifier for candidates; useful for preserving current candidate
124  // following insertion
125  };
126 
127  /************************************************************************************************************/
133  public:
134  typedef std::shared_ptr<SpatialCellImageCandidate> Ptr;
135  typedef std::shared_ptr<const SpatialCellImageCandidate> ConstPtr;
136 
138  SpatialCellImageCandidate(float const xCenter,
139  float const yCenter
140  ) : SpatialCellCandidate(xCenter, yCenter),
141  _chi2(std::numeric_limits<double>::max()) {
142  }
144 
146  static void setWidth(int width) {
147  _width = width;
148  }
150  static int getWidth() { return _width; }
151 
153  static void setHeight(int height) { _height = height; }
155  static int getHeight() { return _height; }
156 
158  double getChi2() const { return _chi2; }
160  void setChi2(double chi2) { _chi2 = chi2; }
161 
162  private:
163  static int _width; // the width of images to return; may be ignored by subclasses
164  static int _height; // the height of images to return; may be ignored by subclasses
165  double _chi2; // chi^2 for fit
166  };
167 
168 
169  /************************************************************************************************************/
174  friend class SpatialCell;
175  typedef std::vector<PTR(SpatialCellCandidate)> CandidateList;
176 
177  public:
178  // ctors are protected
179  void operator++();
180  size_t operator-(SpatialCellCandidateIterator const& rhs) const;
181 
182  CONST_PTR(SpatialCellCandidate) operator*() const;
183  PTR(SpatialCellCandidate) operator*();
184 
186  bool operator==(SpatialCellCandidateIterator const& rhs) const {
187  return _iterator == rhs._iterator;
188  }
190  bool operator!=(SpatialCellCandidateIterator const& rhs) const {
191  return _iterator != rhs._iterator;
192  }
193 
194  protected:
195  SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end, bool ignoreBad);
196  SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end, bool ignoreBad, bool);
197 
198  private:
199  CandidateList::iterator _iterator;
200  CandidateList::iterator _end;
202  };
203 
204  /************************************************************************************************************/
216  class SpatialCell {
217  public:
218  typedef std::shared_ptr<SpatialCell> Ptr;
219  typedef std::shared_ptr<const SpatialCell> ConstPtr;
220  typedef std::vector<PTR(SpatialCellCandidate)> CandidateList;
225  SpatialCell(std::string const& label,
227  CandidateList const& candidateList=CandidateList());
228 
232  virtual ~SpatialCell() {;};
233 
234  bool empty() const;
235  size_t size() const;
236 
237  void sortCandidates();
243  }
245  ) {
246  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad);
247  }
253  }
255  ) {
256  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad, true);
257  }
258  //
259  void insertCandidate(PTR(SpatialCellCandidate) candidate);
260 
266  void removeCandidate(PTR(SpatialCellCandidate) candidate);
267 
269  void setIgnoreBad(bool ignoreBad) { _ignoreBad = ignoreBad; }
271  bool getIgnoreBad() const { return _ignoreBad; }
272 
273  PTR(SpatialCellCandidate) getCandidateById(int id, bool noThrow=false);
277  std::string const& getLabel() const { return _label; }
281  lsst::afw::geom::Box2I const& getBBox() const { return _bbox; }
282  /*
283  * Visit our candidates
284  */
285  void visitCandidates(CandidateVisitor * visitor, int const nMaxPerCell=-1,
286  bool const ignoreExceptions=false, bool const reset=true);
287  void visitCandidates(CandidateVisitor * visitor, int const nMaxPerCell=-1,
288  bool const ignoreExceptions=false, bool const reset=true) const;
289  void visitAllCandidates(CandidateVisitor * visitor,
290  bool const ignoreExceptions=false, bool const reset=true);
291  void visitAllCandidates(CandidateVisitor * visitor,
292  bool const ignoreExceptions=false, bool const reset=true) const;
293 
294  private:
295  std::string _label; // Name of cell for logging/trace
296  lsst::afw::geom::Box2I _bbox; // Bounding box of cell in overall image
297  CandidateList _candidateList; // List of all candidates in the cell
298  bool _ignoreBad; // Don't include BAD candidates when traversing the list
299  };
300 
305  public:
306  typedef std::shared_ptr<SpatialCellSet> Ptr;
307  typedef std::shared_ptr<const SpatialCellSet> ConstPtr;
308 
309  typedef std::vector<PTR(SpatialCell)> CellList;
310 
311  SpatialCellSet(lsst::afw::geom::Box2I const& region, int xSize, int ySize=0);
312 
316  virtual ~SpatialCellSet() {;};
317 
322 
327 
328  void insertCandidate(PTR(SpatialCellCandidate) candidate);
329 
330  void sortCandidates();
331 
332  void visitCandidates(CandidateVisitor * visitor, int const nMaxPerCell=-1,
333  bool const ignoreExceptions=false);
334  void visitCandidates(CandidateVisitor * visitor, int const nMaxPerCell=-1,
335  bool const ignoreExceptions=false) const;
336  void visitAllCandidates(CandidateVisitor * visitor, bool const ignoreExceptions=false);
337  void visitAllCandidates(CandidateVisitor * visitor, bool const ignoreExceptions=false) const;
338 
339  PTR(SpatialCellCandidate) getCandidateById(int id, bool noThrow=false);
340 
341  void setIgnoreBad(bool ignoreBad);
342 
343  private:
344  lsst::afw::geom::Box2I _region; // Bounding box of overall image
345  CellList _cellList; // List of SpatialCells
346  };
347 }}}
348 
349 #endif
std::shared_ptr< SpatialCellImageCandidate > Ptr
Definition: SpatialCell.h:134
SpatialCellCandidateIterator begin(bool ignoreBad)
Definition: SpatialCell.h:244
void setStatus(Status status)
Set the candidate&#39;s status.
Definition: SpatialCell.cc:61
An include file to include the header files for lsst::afw::geom.
static int getWidth()
Return the width of the image that getImage should return.
Definition: SpatialCell.h:150
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false, bool const reset=true)
Call the visitor&#39;s processCandidate method for every Candidate in the SpatialCell.
Definition: SpatialCell.cc:264
void insertCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
Insert a candidate into the correct cell.
Definition: SpatialCell.cc:481
virtual ~SpatialCellCandidate()
(virtual) destructor – this is a base class you know
Definition: SpatialCell.h:92
static void setHeight(int height)
Set the height of the image that getImage should return.
Definition: SpatialCell.h:153
bool empty() const
Determine if cell has no usable candidates.
Definition: SpatialCell.cc:131
SpatialCellCandidateIterator end()
Return an iterator to (one after) the end of the Candidates.
Definition: SpatialCell.h:251
SpatialCellSet(lsst::afw::geom::Box2I const &region, int xSize, int ySize=0)
Constructor.
Definition: SpatialCell.cc:416
std::shared_ptr< const SpatialCellCandidate > ConstPtr
Definition: SpatialCell.h:77
Include files required for standard LSST Exception handling.
std::vector< boost::shared_ptr< SpatialCell > > CellList
Definition: SpatialCell.h:309
size_t operator-(SpatialCellCandidateIterator const &rhs) const
Return the number of candidate between this and rhs.
Definition: SpatialCell.cc:376
static int _CandidateId
Unique identifier for candidates; useful for preserving current candidate following insertion...
Definition: SpatialCell.h:123
float getYCenter() const
Return the object&#39;s row-centre.
Definition: SpatialCell.h:98
std::string const & getLabel() const
Get SpatialCell&#39;s label.
Definition: SpatialCell.h:277
std::shared_ptr< SpatialCellCandidate > Ptr
Definition: SpatialCell.h:76
std::shared_ptr< const SpatialCellImageCandidate > ConstPtr
Definition: SpatialCell.h:135
void sortCandidates()
Rearrange the candidates to reflect their current ratings.
Definition: SpatialCell.cc:102
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
Definition: SpatialCell.cc:604
SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end, bool ignoreBad)
ctor; designed to be used to pass begin to SpatialCellCandidateIterator
Definition: SpatialCell.cc:327
virtual void processCandidate(SpatialCellCandidate *)
Definition: SpatialCell.h:67
virtual double getCandidateRating() const =0
Return candidate&#39;s rating.
std::shared_ptr< const SpatialCellSet > ConstPtr
Definition: SpatialCell.h:307
double getChi2() const
Return the candidate&#39;s chi^2.
Definition: SpatialCell.h:158
virtual ~SpatialCell()
Destructor.
Definition: SpatialCell.h:232
lsst::afw::geom::Box2I _region
Definition: SpatialCell.h:344
An integer coordinate rectangle.
Definition: Box.h:53
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
boost::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
Definition: SpatialCell.cc:162
void operator++()
Advance the iterator, maybe skipping over candidates labelled BAD.
Definition: SpatialCell.cc:359
Status getStatus() const
Return the candidate&#39;s status.
Definition: SpatialCell.h:111
boost::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
Definition: SpatialCell.cc:584
A collection of SpatialCells covering an entire image.
Definition: SpatialCell.h:304
std::vector< boost::shared_ptr< SpatialCellCandidate > > CandidateList
Definition: SpatialCell.h:220
std::vector< boost::shared_ptr< SpatialCellCandidate > > CandidateList
Definition: SpatialCell.h:175
std::shared_ptr< SpatialCellSet > Ptr
Definition: SpatialCell.h:306
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void removeCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
Remove a candidate from the list.
Definition: SpatialCell.cc:117
SpatialCellImageCandidate(float const xCenter, float const yCenter)
ctor
Definition: SpatialCell.h:138
int getId() const
Return the candidate&#39;s unique ID.
Definition: SpatialCell.h:109
SpatialCell(std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Constructor.
Definition: SpatialCell.cc:84
virtual ~SpatialCellSet()
Destructor.
Definition: SpatialCell.h:316
virtual bool isBad() const
Is this candidate unacceptable?
Definition: SpatialCell.h:114
std::shared_ptr< const SpatialCell > ConstPtr
Definition: SpatialCell.h:219
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false, bool const reset=true)
Call the visitor&#39;s processCandidate method for each Candidate in the SpatialCell. ...
Definition: SpatialCell.cc:186
bool getIgnoreBad() const
Get whether we are omitting BAD candidates from candidate list when traversing.
Definition: SpatialCell.h:271
SpatialCellCandidateIterator iterator
Definition: SpatialCell.h:221
float getXCenter() const
Return the object&#39;s column-centre.
Definition: SpatialCell.h:95
lsst::afw::geom::Box2I getBBox() const
Return the bounding box of the image.
Definition: SpatialCell.h:326
size_t size() const
Return number of usable candidates in Cell.
Definition: SpatialCell.cc:148
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
virtual bool instantiate()
Do anything needed to make this candidate usable.
Definition: SpatialCell.h:101
void sortCandidates()
Rearrange the Candidates in all SpatialCells to reflect their current ratings.
Definition: SpatialCell.cc:498
virtual void setCandidateRating(double)
Set the candidate&#39;s rating.
Definition: SpatialCell.h:106
std::shared_ptr< SpatialCell > Ptr
Definition: SpatialCell.h:218
static void setWidth(int width)
Set the width of the image that getImage should return.
Definition: SpatialCell.h:146
Base class for candidate objects in a SpatialCell that are able to return an Image of some sort (e...
Definition: SpatialCell.h:132
int status
#define PTR(...)
Definition: base.h:41
Class to ensure constraints for spatial modeling.
Definition: SpatialCell.h:216
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false)
Call the visitor&#39;s processCandidate method for every Candidate in the SpatialCellSet.
Definition: SpatialCell.cc:549
Base class for candidate objects in a SpatialCell.
Definition: SpatialCell.h:74
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
Definition: SpatialCell.h:269
lsst::afw::geom::Box2I _bbox
Definition: SpatialCell.h:296
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
bool operator!=(SpatialCellCandidateIterator const &rhs) const
Are two SpatialCellCandidateIterators unequal?
Definition: SpatialCell.h:190
Basic LSST definitions.
Definition of default types for Masks and Variance Images.
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false)
Call the visitor&#39;s processCandidate method for each Candidate in the SpatialCellSet.
Definition: SpatialCell.cc:513
void insertCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
Add a candidate to the list, preserving ranking.
Definition: SpatialCell.cc:111
SpatialCellCandidateIterator begin()
Return an iterator to the beginning of the Candidates.
Definition: SpatialCell.h:241
An iterator that only returns usable members of the SpatialCell.
Definition: SpatialCell.h:173
SpatialCellCandidateIterator end(bool ignoreBad)
Definition: SpatialCell.h:254
void setChi2(double chi2)
Set the candidate&#39;s chi^2.
Definition: SpatialCell.h:160
SpatialCellCandidate(float const xCenter, float const yCenter)
Definition: SpatialCell.h:81
lsst::afw::geom::Box2I const & getBBox() const
Get SpatialCell&#39;s BBox.
Definition: SpatialCell.h:281
static int getHeight()
Return the height of the image that getImage should return.
Definition: SpatialCell.h:155
CellList & getCellList()
Return our SpatialCells.
Definition: SpatialCell.h:321