LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
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.
g2d::python::Image< double > Image
Definition test_image.cc:14