LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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?
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.
void setStatus(Status status)
Set the candidate's status.
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.
virtual ~SpatialCellCandidate()=default
(virtual) destructor – this is a base class you know
An iterator that only returns usable members of the SpatialCell.
SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end, bool ignoreBad)
ctor; designed to be used to pass begin to SpatialCellCandidateIterator
bool operator==(SpatialCellCandidateIterator const &rhs) const
Are two SpatialCellCandidateIterators equal?
void operator++()
Advance the iterator, maybe skipping over candidates labelled BAD.
size_t operator-(SpatialCellCandidateIterator const &rhs) const
Return the number of candidate between this and rhs.
bool operator!=(SpatialCellCandidateIterator const &rhs) const
Are two SpatialCellCandidateIterators unequal?
std::shared_ptr< SpatialCellCandidate const > operator*() const
Dereference the iterator to return the Candidate (if there is one)
Class to ensure constraints for spatial modeling.
SpatialCell(SpatialCell &&)=default
SpatialCellCandidateIterator end()
Return an iterator to (one after) the end of the Candidates.
size_t size() const
Return number of usable candidates in Cell.
bool getIgnoreBad() const
Get whether we are omitting BAD candidates from candidate list when traversing.
void sortCandidates()
Rearrange the candidates to reflect their current ratings.
void removeCandidate(std::shared_ptr< SpatialCellCandidate > candidate)
Remove a candidate from the list.
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.
lsst::geom::Box2I const & getBBox() const
Get SpatialCell's BBox.
SpatialCellCandidateIterator begin()
Return an iterator to the beginning of the Candidates.
SpatialCellCandidateIterator begin(bool ignoreBad)
std::vector< std::shared_ptr< SpatialCellCandidate > > CandidateList
bool empty() const
Determine if cell has no usable candidates.
std::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
SpatialCell(std::string const &label, lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Constructor.
SpatialCell & operator=(SpatialCell const &)=default
std::string const & getLabel() const
Get SpatialCell's label.
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false, bool const reset=true)
Call the visitor's processCandidate method for every Candidate in the SpatialCell.
void insertCandidate(std::shared_ptr< SpatialCellCandidate > candidate)
Add a candidate to the list, preserving ranking.
SpatialCellCandidateIterator end(bool ignoreBad)
Base class for candidate objects in a SpatialCell that are able to return an Image of some sort (e....
SpatialCellImageCandidate(float const xCenter, float const yCenter)
ctor
static int getWidth()
Return the width of the image that getImage should return.
double getChi2() const
Return the candidate's chi^2.
SpatialCellImageCandidate(SpatialCellImageCandidate &&)=default
static int getHeight()
Return the height of the image that getImage should return.
static void setWidth(int width)
Set the width of the image that getImage should return.
static void setHeight(int height)
Set the height of the image that getImage should return.
SpatialCellImageCandidate(SpatialCellImageCandidate const &)=default
void setChi2(double chi2)
Set the candidate's chi^2.
A collection of SpatialCells covering an entire image.
SpatialCellSet(SpatialCellSet &&)=default
void sortCandidates()
Rearrange the Candidates in all SpatialCells to reflect their current ratings.
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false)
Call the visitor's processCandidate method for every Candidate in the SpatialCellSet.
SpatialCellSet & operator=(SpatialCellSet const &)=default
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
lsst::geom::Box2I getBBox() const
Return the bounding box of the image.
SpatialCellSet & operator=(SpatialCellSet &&)=default
void insertCandidate(std::shared_ptr< SpatialCellCandidate > candidate)
Insert a candidate into the correct cell.
SpatialCellSet(SpatialCellSet const &)=default
std::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
CellList & getCellList()
Return our SpatialCells.
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.
SpatialCellSet(lsst::geom::Box2I const &region, int xSize, int ySize=0)
Constructor.
std::vector< std::shared_ptr< SpatialCell > > CellList
An integer coordinate rectangle.
Definition Box.h:55
T end(T... args)
STL namespace.