LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
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
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 & 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
An integer coordinate rectangle.
Definition: Box.h:55
T end(T... args)
STL namespace.