LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
lsst::afw::math::SpatialCell Class Reference

Class to ensure constraints for spatial modeling. More...

#include <SpatialCell.h>

Public Types

using CandidateList = std::vector<std::shared_ptr<SpatialCellCandidate>>
 
using iterator = SpatialCellCandidateIterator
 

Public Member Functions

 SpatialCell (std::string const &label, lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), CandidateList const &candidateList=CandidateList())
 Constructor.
 
 SpatialCell (SpatialCell const &)=default
 
 SpatialCell (SpatialCell &&)=default
 
SpatialCelloperator= (SpatialCell const &)=default
 
SpatialCelloperator= (SpatialCell &&)=default
 
virtual ~SpatialCell ()=default
 Destructor.
 
bool empty () const
 Determine if cell has no usable candidates.
 
size_t size () const
 Return number of usable candidates in Cell.
 
void sortCandidates ()
 Rearrange the candidates to reflect their current ratings.
 
SpatialCellCandidateIterator begin ()
 Return an iterator to the beginning of the Candidates.
 
SpatialCellCandidateIterator begin (bool ignoreBad)
 
SpatialCellCandidateIterator end ()
 Return an iterator to (one after) the end of the Candidates.
 
SpatialCellCandidateIterator end (bool ignoreBad)
 
void insertCandidate (std::shared_ptr< SpatialCellCandidate > candidate)
 Add a candidate to the list, preserving ranking.
 
void removeCandidate (std::shared_ptr< SpatialCellCandidate > candidate)
 Remove a candidate from the list.
 
void setIgnoreBad (bool ignoreBad)
 Set whether we should omit BAD candidates from candidate list when traversing.
 
bool getIgnoreBad () const
 Get whether we are omitting BAD candidates from candidate list when traversing.
 
std::shared_ptr< SpatialCellCandidategetCandidateById (int id, bool noThrow=false)
 Return the SpatialCellCandidate with the specified id.
 
std::string const & getLabel () const
 Get SpatialCell's label.
 
lsst::geom::Box2I const & getBBox () const
 Get SpatialCell's BBox.
 
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.
 
void visitCandidates (CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false, bool const reset=true) const
 Call the visitor's processCandidate method for each Candidate in the SpatialCell (const version)
 
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 visitAllCandidates (CandidateVisitor *visitor, bool const ignoreExceptions=false, bool const reset=true) const
 Call the visitor's processCandidate method for each Candidate in the SpatialCell (const version)
 

Detailed Description

Class to ensure constraints for spatial modeling.

A given image is divided up into cells, with each cell represented by an instance of this class. Each cell itself contains a list of instances of classes derived from SpatialCellCandidate. One class member from each cell will be chosen to fit to a spatial model. In case of a poor fit, the next class instance in the list will be fit for. If all instances in a list are rejected from the spatial model, the best one will be used.

See also
The SpatialCellSet example in the module documentation.

Definition at line 223 of file SpatialCell.h.

Member Typedef Documentation

◆ CandidateList

Definition at line 225 of file SpatialCell.h.

◆ iterator

Definition at line 226 of file SpatialCell.h.

Constructor & Destructor Documentation

◆ SpatialCell() [1/3]

lsst::afw::math::SpatialCell::SpatialCell ( std::string const & label,
lsst::geom::Box2I const & bbox = lsst::geom::Box2I(),
CandidateList const & candidateList = CandidateList() )

Constructor.

Parameters
labelstring representing "name" of cell
bboxBounding box of cell in overall image
candidateListlist of candidates to represent this cell

Definition at line 71 of file SpatialCell.cc.

73 : _label(label), _bbox(bbox), _candidateList(candidateList), _ignoreBad(true) {
74 LOGL_DEBUG("lsst.afw.math.SpatialCell", "Cell %s : created with %d candidates", this->_label.c_str(),
75 this->_candidateList.size());
77}
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition Log.h:515
T c_str(T... args)
void sortCandidates()
Rearrange the candidates to reflect their current ratings.

◆ SpatialCell() [2/3]

lsst::afw::math::SpatialCell::SpatialCell ( SpatialCell const & )
default

◆ SpatialCell() [3/3]

lsst::afw::math::SpatialCell::SpatialCell ( SpatialCell && )
default

◆ ~SpatialCell()

virtual lsst::afw::math::SpatialCell::~SpatialCell ( )
virtualdefault

Destructor.

Member Function Documentation

◆ begin() [1/2]

SpatialCellCandidateIterator lsst::afw::math::SpatialCell::begin ( )
inline

Return an iterator to the beginning of the Candidates.

Definition at line 263 of file SpatialCell.h.

263 {
264 return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), _ignoreBad);
265 }
T begin(T... args)
T end(T... args)

◆ begin() [2/2]

SpatialCellCandidateIterator lsst::afw::math::SpatialCell::begin ( bool ignoreBad)
inline
Parameters
ignoreBadIf true, ignore BAD candidates

Definition at line 266 of file SpatialCell.h.

267 {
268 return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad);
269 }

◆ empty()

bool lsst::afw::math::SpatialCell::empty ( ) const

Determine if cell has no usable candidates.

Definition at line 97 of file SpatialCell.cc.

97 {
98 // Cast away const; end is only non-const as it provides access to the Candidates
99 // and we don't (yet) have SpatialCellCandidateConstIterator
100 SpatialCell *mthis = const_cast<SpatialCell *>(this);
101
102 for (auto && mthi : *mthis) {
103 if (!(_ignoreBad && (mthi)->isBad())) { // found a good candidate, or don't care
104 return false;
105 }
106 }
107
108 return true;
109}

◆ end() [1/2]

SpatialCellCandidateIterator lsst::afw::math::SpatialCell::end ( )
inline

Return an iterator to (one after) the end of the Candidates.

Definition at line 273 of file SpatialCell.h.

273 {
274 return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), _ignoreBad, true);
275 }

◆ end() [2/2]

SpatialCellCandidateIterator lsst::afw::math::SpatialCell::end ( bool ignoreBad)
inline
Parameters
ignoreBadIf true, ignore BAD candidates

Definition at line 276 of file SpatialCell.h.

277 {
278 return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad, true);
279 }

◆ getBBox()

lsst::geom::Box2I const & lsst::afw::math::SpatialCell::getBBox ( ) const
inline

Get SpatialCell's BBox.

Definition at line 314 of file SpatialCell.h.

314{ return _bbox; }

◆ getCandidateById()

std::shared_ptr< SpatialCellCandidate > lsst::afw::math::SpatialCell::getCandidateById ( int id,
bool noThrow = false )

Return the SpatialCellCandidate with the specified id.

Parameters
idThe desired ID
noThrowReturn NULL in case of error
Exceptions
lsst::pex::exceptions::NotFoundErrorif no candidate matches the id

Definition at line 119 of file SpatialCell.cc.

119 {
120 for (SpatialCellCandidateIterator ptr = begin(), end = this->end(); ptr != end; ++ptr) {
121 if ((*ptr)->getId() == id) {
122 return *ptr;
123 }
124 }
125
126 if (noThrow) {
128 } else {
130 (boost::format("Unable to find object with ID == %d") % id).str());
131 }
132}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
std::uint64_t * ptr
Definition RangeSet.cc:95
SpatialCellCandidateIterator end()
Return an iterator to (one after) the end of the Candidates.
SpatialCellCandidateIterator begin()
Return an iterator to the beginning of the Candidates.
Reports attempts to access elements using an invalid key.
Definition Runtime.h:151

◆ getIgnoreBad()

bool lsst::afw::math::SpatialCell::getIgnoreBad ( ) const
inline

Get whether we are omitting BAD candidates from candidate list when traversing.

Definition at line 296 of file SpatialCell.h.

296{ return _ignoreBad; }

◆ getLabel()

std::string const & lsst::afw::math::SpatialCell::getLabel ( ) const
inline

Get SpatialCell's label.

Definition at line 310 of file SpatialCell.h.

310{ return _label; }

◆ insertCandidate()

void lsst::afw::math::SpatialCell::insertCandidate ( std::shared_ptr< SpatialCellCandidate > candidate)

Add a candidate to the list, preserving ranking.

Definition at line 81 of file SpatialCell.cc.

81 {
82 CandidateList::iterator pos =
83 std::lower_bound(_candidateList.begin(), _candidateList.end(), candidate, CandidatePtrMore());
84 _candidateList.insert(pos, candidate);
85}
T insert(T... args)
T lower_bound(T... args)

◆ operator=() [1/2]

SpatialCell & lsst::afw::math::SpatialCell::operator= ( SpatialCell && )
default

◆ operator=() [2/2]

SpatialCell & lsst::afw::math::SpatialCell::operator= ( SpatialCell const & )
default

◆ removeCandidate()

void lsst::afw::math::SpatialCell::removeCandidate ( std::shared_ptr< SpatialCellCandidate > candidate)

Remove a candidate from the list.

This is not a particularly efficient operation, since we're using a std::vector, but should not hurt too much if the number of candidates in a cell is small.

Definition at line 87 of file SpatialCell.cc.

87 {
88 CandidateList::iterator pos = std::find(_candidateList.begin(), _candidateList.end(), candidate);
89 if (pos == _candidateList.end()) {
90 throw LSST_EXCEPT(
92 (boost::format("Unable to find candidate with ID == %d") % candidate->getId()).str());
93 }
94 _candidateList.erase(pos);
95}
T erase(T... args)
T find(T... args)

◆ setIgnoreBad()

void lsst::afw::math::SpatialCell::setIgnoreBad ( bool ignoreBad)
inline

Set whether we should omit BAD candidates from candidate list when traversing.

Definition at line 294 of file SpatialCell.h.

294{ _ignoreBad = ignoreBad; }

◆ size()

size_t lsst::afw::math::SpatialCell::size ( ) const

Return number of usable candidates in Cell.

Definition at line 111 of file SpatialCell.cc.

111 {
112 // Cast away const; begin/end is only non-const as they provide access to the Candidates
113 // and we don't (yet) have SpatialCellCandidateConstIterator
114 SpatialCell *mthis = const_cast<SpatialCell *>(this);
115
116 return mthis->end() - mthis->begin();
117}

◆ sortCandidates()

void lsst::afw::math::SpatialCell::sortCandidates ( )

Rearrange the candidates to reflect their current ratings.

Definition at line 79 of file SpatialCell.cc.

79{ sort(_candidateList.begin(), _candidateList.end(), CandidatePtrMore()); }
T sort(T... args)

◆ visitAllCandidates() [1/2]

void lsst::afw::math::SpatialCell::visitAllCandidates ( CandidateVisitor * visitor,
bool const ignoreExceptions = false,
bool const reset = true )

Call the visitor's processCandidate method for every Candidate in the SpatialCell.

Parameters
visitorPass this object to every Candidate
ignoreExceptionsIgnore any exceptions thrown by
resetReset visitor before passing it around
See also
visitCandidates

Definition at line 191 of file SpatialCell.cc.

192 {
193 if (reset) {
194 visitor->reset();
195 }
196
197 int i = 0;
198 for (SpatialCell::iterator candidate = begin(false), candidateEnd = end(false); candidate != candidateEnd;
199 ++candidate, ++i) {
200 try {
201 visitor->processCandidate((*candidate).get());
203 if (ignoreExceptions) {
204 ;
205 } else {
206 LSST_EXCEPT_ADD(e, "Visiting candidate");
207 throw e;
208 }
209 }
210 }
211}
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
Definition Exception.h:54
SpatialCellCandidateIterator iterator
Reports attempts to exceed implementation-defined length limits for some classes.
Definition Runtime.h:76

◆ visitAllCandidates() [2/2]

void lsst::afw::math::SpatialCell::visitAllCandidates ( CandidateVisitor * visitor,
bool const ignoreExceptions = false,
bool const reset = true ) const

Call the visitor's processCandidate method for each Candidate in the SpatialCell (const version)

This is the const version of SpatialCellSet::visitAllCandidates

Parameters
visitorPass this object to every Candidate
ignoreExceptionsIgnore any exceptions thrown by the processing
resetReset visitor before passing it around
Todo
This is currently implemented via a const_cast (arghhh). The problem is that SpatialCell::begin() const isn't yet implemented

Definition at line 213 of file SpatialCell.cc.

214 {
215#if 1
216 //
217 // This const_cast must go!
218 //
219 SpatialCell *mthis = const_cast<SpatialCell *>(this);
220 mthis->visitAllCandidates(visitor, ignoreExceptions, reset);
221#else
222 int i = 0;
223 for (SpatialCell::const_iterator candidate = (*cell)->begin(false), candidateEnd = (*cell)->end(false);
224 candidate != candidateEnd; ++candidate, ++i) {
225 try {
226 visitor->processCandidate((*candidate).get());
228 if (ignoreExceptions) {
229 ;
230 } else {
231 LSST_EXCEPT_ADD(e, "Visiting candidate");
232 throw e;
233 }
234 }
235 }
236#endif
237}

◆ visitCandidates() [1/2]

void lsst::afw::math::SpatialCell::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.

Parameters
visitorPass this object to every Candidate
nMaxPerCellVisit no more than this many Candidates (<= 0: all)
ignoreExceptionsIgnore any exceptions thrown by the processing
resetReset visitor before passing it around
Note
This is obviously similar to the Design Patterns (Go4) Visitor pattern, but we've simplified the double dispatch (i.e. we don't call a virtual method on SpatialCellCandidate that in turn calls processCandidate(*this), but can be re-defined)

Definition at line 134 of file SpatialCell.cc.

136 {
137 if (reset) {
138 visitor->reset();
139 }
140
141 int i = 0;
142 for (SpatialCell::iterator candidate = begin(), candidateEnd = end(); candidate != candidateEnd;
143 ++candidate, ++i) {
144 if (nMaxPerCell > 0 && i == nMaxPerCell) { // we've processed all the candidates we want
145 return;
146 }
147
148 try {
149 visitor->processCandidate((*candidate).get());
151 if (ignoreExceptions) {
152 --i; // Don't count the candidate if it raises an exception
153 } else {
154 LSST_EXCEPT_ADD(e, "Visiting candidate");
155 throw e;
156 }
157 }
158 }
159}
Provides consistent interface for LSST exceptions.
Definition Exception.h:107

◆ visitCandidates() [2/2]

void lsst::afw::math::SpatialCell::visitCandidates ( CandidateVisitor * visitor,
int const nMaxPerCell = -1,
bool const ignoreExceptions = false,
bool const reset = true ) const

Call the visitor's processCandidate method for each Candidate in the SpatialCell (const version)

This is the const version of SpatialCellSet::visitCandidates

Parameters
visitorPass this object to every Candidate
nMaxPerCellVisit no more than this many Candidates (-ve: all)
ignoreExceptionsIgnore any exceptions thrown by the processing
resetReset visitor before passing it around
Todo
This is currently implemented via a const_cast (arghhh). The problem is that SpatialCell::begin() const isn't yet implemented

Definition at line 161 of file SpatialCell.cc.

162 {
163#if 1
164 //
165 // This const_cast must go!
166 //
167 SpatialCell *mthis = const_cast<SpatialCell *>(this);
168 mthis->visitCandidates(visitor, nMaxPerCell, ignoreExceptions, reset);
169#else
170 int i = 0;
171 for (SpatialCell::const_iterator candidate = (*cell)->begin(), candidateEnd = (*cell)->end();
172 candidate != candidateEnd; ++candidate, ++i) {
173 if (i == nMaxPerCell) { // we've processed all the candidates we want
174 return;
175 }
176
177 try {
178 visitor->processCandidate((*candidate).get());
180 if (ignoreExceptions) {
181 ;
182 } else {
183 LSST_EXCEPT_ADD(e, "Visiting candidate");
184 throw e;
185 }
186 }
187 }
188#endif
189}

The documentation for this class was generated from the following files: