LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
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
42namespace lsst {
43namespace afw {
44
45// forward declarations
46namespace image {
47template <typename ImagePixelT>
48class Image;
49template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
50class MaskedImage;
51} // namespace image
52
53namespace math {
54
56class SpatialCellCandidate;
57
59public:
60 CandidateVisitor() = default;
61 virtual ~CandidateVisitor() = default;
62
63 virtual void reset() {}
65};
66
71public:
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
85 virtual ~SpatialCellCandidate() = default;
86
88 float getXCenter() const { return _xCenter; }
89
91 float getYCenter() const { return _yCenter; }
92
94 virtual bool instantiate() { return true; }
95
97 virtual double getCandidateRating() const = 0;
99 virtual void setCandidateRating(double) {}
100
102 int getId() const { return _id; }
104 Status getStatus() const { return _status; }
106 void setStatus(Status status);
108 virtual bool isBad() const { return (_status == BAD); }
109
110private:
111 int _id; // Unique ID for object
112 Status _status; // Is this Candidate good?
113 float const _xCenter; // The object's column-centre
114 float const _yCenter; // The object's row-centre
115
117 static int _CandidateId;
118};
119
125public:
127 SpatialCellImageCandidate(float const xCenter,
128 float const yCenter
129 )
130 : SpatialCellCandidate(xCenter, yCenter), _chi2(std::numeric_limits<double>::max()) {}
133 ~SpatialCellImageCandidate() override = default;
134
136 static void setWidth(int width) { _width = width; }
138 static int getWidth() { return _width; }
139
141 static void setHeight(int height) { _height = height; }
143 static int getHeight() { return _height; }
144
146 double getChi2() const { return _chi2; }
148 void setChi2(double chi2) { _chi2 = chi2; }
149
150private:
151 static int _width; // the width of images to return; may be ignored by subclasses
152 static int _height; // the height of images to return; may be ignored by subclasses
153 double _chi2; // chi^2 for fit
154};
155
160 friend class SpatialCell;
162
163public:
164 // ctors are protected
168 void operator++();
172 size_t operator-(SpatialCellCandidateIterator const& rhs) const;
173
182
184 bool operator==(SpatialCellCandidateIterator const& rhs) const { return _iterator == rhs._iterator; }
186 bool operator!=(SpatialCellCandidateIterator const& rhs) const { return _iterator != rhs._iterator; }
187
188protected:
195 SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end,
196 bool ignoreBad);
203 SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end,
204 bool ignoreBad, bool);
205
206private:
207 CandidateList::iterator _iterator;
208 CandidateList::iterator _end;
209 bool _ignoreBad;
210};
211
224public:
235 CandidateList const& candidateList = CandidateList());
236
237 SpatialCell(SpatialCell const&) = default;
241
245 virtual ~SpatialCell() = default;
246
250 bool empty() const;
254 size_t size() const;
255
259 void sortCandidates();
264 return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), _ignoreBad);
265 }
267 ) {
268 return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad);
269 }
274 return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), _ignoreBad, true);
275 }
277 ) {
278 return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad, true);
279 }
284
292
294 void setIgnoreBad(bool ignoreBad) { _ignoreBad = ignoreBad; }
296 bool getIgnoreBad() const { return _ignoreBad; }
297
306 std::shared_ptr<SpatialCellCandidate> getCandidateById(int id, bool noThrow = false);
310 std::string const& getLabel() const { return _label; }
314 lsst::geom::Box2I const& getBBox() const { return _bbox; }
315 /*
316 * Visit our candidates
317 */
330 void visitCandidates(CandidateVisitor* visitor, int const nMaxPerCell = -1,
331 bool const ignoreExceptions = false, bool const reset = true);
345 void visitCandidates(CandidateVisitor* visitor, int const nMaxPerCell = -1,
346 bool const ignoreExceptions = false, bool const reset = true) const;
356 void visitAllCandidates(CandidateVisitor* visitor, bool const ignoreExceptions = false,
357 bool const reset = true);
370 void visitAllCandidates(CandidateVisitor* visitor, bool const ignoreExceptions = false,
371 bool const reset = true) const;
372
373private:
374 std::string _label; // Name of cell for logging/trace
375 lsst::geom::Box2I _bbox; // Bounding box of cell in overall image
376 CandidateList _candidateList; // List of all candidates in the cell
377 bool _ignoreBad; // Don't include BAD candidates when traversing the list
378};
379
384public:
386
396 SpatialCellSet(lsst::geom::Box2I const& region, int xSize, int ySize = 0);
397
402
406 virtual ~SpatialCellSet() = default;
407
411 CellList& getCellList() { return _cellList; }
412
416 lsst::geom::Box2I getBBox() const { return _region; };
417
422
424 void sortCandidates();
425
437 void visitCandidates(CandidateVisitor* visitor, int const nMaxPerCell = -1,
438 bool const ignoreExceptions = false);
448 void visitCandidates(CandidateVisitor* visitor, int const nMaxPerCell = -1,
449 bool const ignoreExceptions = false) const;
458 void visitAllCandidates(CandidateVisitor* visitor, bool const ignoreExceptions = false);
467 void visitAllCandidates(CandidateVisitor* visitor, bool const ignoreExceptions = false) const;
468
478 std::shared_ptr<SpatialCellCandidate> getCandidateById(int id, bool noThrow = false);
479
481 void setIgnoreBad(bool ignoreBad);
482
483private:
484 lsst::geom::Box2I _region; // Bounding box of overall image
485 CellList _cellList; // List of SpatialCells
486};
487} // namespace math
488} // namespace afw
489} // namespace lsst
490
491#endif
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
int end
int max
Basic LSST definitions.
T begin(T... args)
virtual void processCandidate(SpatialCellCandidate *)
Definition: SpatialCell.h:64
virtual ~CandidateVisitor()=default
Base class for candidate objects in a SpatialCell.
Definition: SpatialCell.h:70
SpatialCellCandidate(float const xCenter, float const yCenter)
Definition: SpatialCell.h:74
virtual void setCandidateRating(double)
Set the candidate's rating.
Definition: SpatialCell.h:99
SpatialCellCandidate(SpatialCellCandidate const &)=default
virtual bool isBad() const
Is this candidate unacceptable?
Definition: SpatialCell.h:108
float getYCenter() const
Return the object's row-centre.
Definition: SpatialCell.h:91
SpatialCellCandidate(SpatialCellCandidate &&)=default
float getXCenter() const
Return the object's column-centre.
Definition: SpatialCell.h:88
int getId() const
Return the candidate's unique ID.
Definition: SpatialCell.h:102
void setStatus(Status status)
Set the candidate's status.
Definition: SpatialCell.cc:53
virtual double getCandidateRating() const =0
Return candidate's rating.
virtual bool instantiate()
Do anything needed to make this candidate usable.
Definition: SpatialCell.h:94
Status getStatus() const
Return the candidate's status.
Definition: SpatialCell.h:104
virtual ~SpatialCellCandidate()=default
(virtual) destructor – this is a base class you know
An iterator that only returns usable members of the SpatialCell.
Definition: SpatialCell.h:159
SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end, bool ignoreBad)
ctor; designed to be used to pass begin to SpatialCellCandidateIterator
Definition: SpatialCell.cc:240
bool operator==(SpatialCellCandidateIterator const &rhs) const
Are two SpatialCellCandidateIterators equal?
Definition: SpatialCell.h:184
void operator++()
Advance the iterator, maybe skipping over candidates labelled BAD.
Definition: SpatialCell.cc:261
size_t operator-(SpatialCellCandidateIterator const &rhs) const
Return the number of candidate between this and rhs.
Definition: SpatialCell.cc:275
bool operator!=(SpatialCellCandidateIterator const &rhs) const
Are two SpatialCellCandidateIterators unequal?
Definition: SpatialCell.h:186
std::shared_ptr< SpatialCellCandidate const > operator*() const
Dereference the iterator to return the Candidate (if there is one)
Definition: SpatialCell.cc:286
Class to ensure constraints for spatial modeling.
Definition: SpatialCell.h:223
SpatialCell(SpatialCell &&)=default
SpatialCellCandidateIterator end()
Return an iterator to (one after) the end of the Candidates.
Definition: SpatialCell.h:273
size_t size() const
Return number of usable candidates in Cell.
Definition: SpatialCell.cc:112
bool getIgnoreBad() const
Get whether we are omitting BAD candidates from candidate list when traversing.
Definition: SpatialCell.h:296
void sortCandidates()
Rearrange the candidates to reflect their current ratings.
Definition: SpatialCell.cc:80
std::vector< std::shared_ptr< SpatialCellCandidate > > CandidateList
Definition: SpatialCell.h:225
void removeCandidate(std::shared_ptr< SpatialCellCandidate > candidate)
Remove a candidate from the list.
Definition: SpatialCell.cc:88
SpatialCell(SpatialCell const &)=default
virtual ~SpatialCell()=default
Destructor.
SpatialCell & operator=(SpatialCell &&)=default
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false, bool const reset=true)
Call the visitor's processCandidate method for each Candidate in the SpatialCell.
Definition: SpatialCell.cc:135
lsst::geom::Box2I const & getBBox() const
Get SpatialCell's BBox.
Definition: SpatialCell.h:314
SpatialCellCandidateIterator begin()
Return an iterator to the beginning of the Candidates.
Definition: SpatialCell.h:263
SpatialCellCandidateIterator begin(bool ignoreBad)
Definition: SpatialCell.h:266
bool empty() const
Determine if cell has no usable candidates.
Definition: SpatialCell.cc:98
std::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
Definition: SpatialCell.cc:120
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
Definition: SpatialCell.h:294
SpatialCell(std::string const &label, lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Constructor.
Definition: SpatialCell.cc:72
SpatialCell & operator=(SpatialCell const &)=default
std::string const & getLabel() const
Get SpatialCell's label.
Definition: SpatialCell.h:310
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false, bool const reset=true)
Call the visitor's processCandidate method for every Candidate in the SpatialCell.
Definition: SpatialCell.cc:192
void insertCandidate(std::shared_ptr< SpatialCellCandidate > candidate)
Add a candidate to the list, preserving ranking.
Definition: SpatialCell.cc:82
SpatialCellCandidateIterator end(bool ignoreBad)
Definition: SpatialCell.h:276
Base class for candidate objects in a SpatialCell that are able to return an Image of some sort (e....
Definition: SpatialCell.h:124
SpatialCellImageCandidate(float const xCenter, float const yCenter)
ctor
Definition: SpatialCell.h:127
static int getWidth()
Return the width of the image that getImage should return.
Definition: SpatialCell.h:138
double getChi2() const
Return the candidate's chi^2.
Definition: SpatialCell.h:146
SpatialCellImageCandidate(SpatialCellImageCandidate &&)=default
static int getHeight()
Return the height of the image that getImage should return.
Definition: SpatialCell.h:143
static void setWidth(int width)
Set the width of the image that getImage should return.
Definition: SpatialCell.h:136
static void setHeight(int height)
Set the height of the image that getImage should return.
Definition: SpatialCell.h:141
SpatialCellImageCandidate(SpatialCellImageCandidate const &)=default
void setChi2(double chi2)
Set the candidate's chi^2.
Definition: SpatialCell.h:148
A collection of SpatialCells covering an entire image.
Definition: SpatialCell.h:383
SpatialCellSet(SpatialCellSet &&)=default
void sortCandidates()
Rearrange the Candidates in all SpatialCells to reflect their current ratings.
Definition: SpatialCell.cc:373
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false)
Call the visitor's processCandidate method for every Candidate in the SpatialCellSet.
Definition: SpatialCell.cc:398
SpatialCellSet & operator=(SpatialCellSet const &)=default
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
Definition: SpatialCell.cc:432
lsst::geom::Box2I getBBox() const
Return the bounding box of the image.
Definition: SpatialCell.h:416
SpatialCellSet & operator=(SpatialCellSet &&)=default
void insertCandidate(std::shared_ptr< SpatialCellCandidate > candidate)
Insert a candidate into the correct cell.
Definition: SpatialCell.cc:360
SpatialCellSet(SpatialCellSet const &)=default
std::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
Definition: SpatialCell.cc:415
std::vector< std::shared_ptr< SpatialCell > > CellList
Definition: SpatialCell.h:385
CellList & getCellList()
Return our SpatialCells.
Definition: SpatialCell.h:411
virtual ~SpatialCellSet()=default
Destructor.
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false)
Call the visitor's processCandidate method for each Candidate in the SpatialCellSet.
Definition: SpatialCell.cc:379
SpatialCellSet(lsst::geom::Box2I const &region, int xSize, int ySize=0)
Constructor.
Definition: SpatialCell.cc:302
An integer coordinate rectangle.
Definition: Box.h:55
T end(T... args)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
A base class for image defects.
STL namespace.