LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
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. More...
 
 SpatialCell (SpatialCell const &)=default
 
 SpatialCell (SpatialCell &&)=default
 
SpatialCelloperator= (SpatialCell const &)=default
 
SpatialCelloperator= (SpatialCell &&)=default
 
virtual ~SpatialCell ()=default
 Destructor. More...
 
bool empty () const
 Determine if cell has no usable candidates. More...
 
size_t size () const
 Return number of usable candidates in Cell. More...
 
void sortCandidates ()
 Rearrange the candidates to reflect their current ratings. More...
 
SpatialCellCandidateIterator begin ()
 Return an iterator to the beginning of the Candidates. More...
 
SpatialCellCandidateIterator begin (bool ignoreBad)
 
SpatialCellCandidateIterator end ()
 Return an iterator to (one after) the end of the Candidates. More...
 
SpatialCellCandidateIterator end (bool ignoreBad)
 
void insertCandidate (std::shared_ptr< SpatialCellCandidate > candidate)
 Add a candidate to the list, preserving ranking. More...
 
void removeCandidate (std::shared_ptr< SpatialCellCandidate > candidate)
 Remove a candidate from the list. More...
 
void setIgnoreBad (bool ignoreBad)
 Set whether we should omit BAD candidates from candidate list when traversing. More...
 
bool getIgnoreBad () const
 Get whether we are omitting BAD candidates from candidate list when traversing. More...
 
std::shared_ptr< SpatialCellCandidategetCandidateById (int id, bool noThrow=false)
 Return the SpatialCellCandidate with the specified id. More...
 
std::string const & getLabel () const
 Get SpatialCell's label. More...
 
lsst::geom::Box2I const & getBBox () const
 Get SpatialCell's BBox. More...
 
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. More...
 
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) More...
 
void visitAllCandidates (CandidateVisitor *visitor, bool const ignoreExceptions=false, bool const reset=true)
 Call the visitor's processCandidate method for every Candidate in the SpatialCell. More...
 
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) More...
 

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 72 of file SpatialCell.cc.

74  : _label(label), _bbox(bbox), _candidateList(candidateList), _ignoreBad(true) {
75  LOGL_DEBUG("lsst.afw.math.SpatialCell", "Cell %s : created with %d candidates", this->_label.c_str(),
76  this->_candidateList.size());
78 }
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.
Definition: SpatialCell.cc:80

◆ 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 98 of file SpatialCell.cc.

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

◆ 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 120 of file SpatialCell.cc.

120  {
121  for (SpatialCellCandidateIterator ptr = begin(), end = this->end(); ptr != end; ++ptr) {
122  if ((*ptr)->getId() == id) {
123  return *ptr;
124  }
125  }
126 
127  if (noThrow) {
129  } else {
131  (boost::format("Unable to find object with ID == %d") % id).str());
132  }
133 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
uint64_t * ptr
Definition: RangeSet.cc:88
SpatialCellCandidateIterator end()
Return an iterator to (one after) the end of the Candidates.
Definition: SpatialCell.h:273
SpatialCellCandidateIterator begin()
Return an iterator to the beginning of the Candidates.
Definition: SpatialCell.h:263
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ 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 82 of file SpatialCell.cc.

82  {
83  CandidateList::iterator pos =
84  std::lower_bound(_candidateList.begin(), _candidateList.end(), candidate, CandidatePtrMore());
85  _candidateList.insert(pos, candidate);
86 }
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 88 of file SpatialCell.cc.

88  {
89  CandidateList::iterator pos = std::find(_candidateList.begin(), _candidateList.end(), candidate);
90  if (pos == _candidateList.end()) {
91  throw LSST_EXCEPT(
93  (boost::format("Unable to find candidate with ID == %d") % candidate->getId()).str());
94  }
95  _candidateList.erase(pos);
96 }
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 112 of file SpatialCell.cc.

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

◆ sortCandidates()

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

Rearrange the candidates to reflect their current ratings.

Definition at line 80 of file SpatialCell.cc.

80 { 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 192 of file SpatialCell.cc.

193  {
194  if (reset) {
195  visitor->reset();
196  }
197 
198  int i = 0;
199  for (SpatialCell::iterator candidate = begin(false), candidateEnd = end(false); candidate != candidateEnd;
200  ++candidate, ++i) {
201  try {
202  visitor->processCandidate((*candidate).get());
204  if (ignoreExceptions) {
205  ;
206  } else {
207  LSST_EXCEPT_ADD(e, "Visiting candidate");
208  throw e;
209  }
210  }
211  }
212 }
#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
Definition: SpatialCell.h:226
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 214 of file SpatialCell.cc.

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

◆ 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 135 of file SpatialCell.cc.

137  {
138  if (reset) {
139  visitor->reset();
140  }
141 
142  int i = 0;
143  for (SpatialCell::iterator candidate = begin(), candidateEnd = end(); candidate != candidateEnd;
144  ++candidate, ++i) {
145  if (nMaxPerCell > 0 && i == nMaxPerCell) { // we've processed all the candidates we want
146  return;
147  }
148 
149  try {
150  visitor->processCandidate((*candidate).get());
151  } catch (lsst::pex::exceptions::Exception &e) {
152  if (ignoreExceptions) {
153  ;
154  } else {
155  LSST_EXCEPT_ADD(e, "Visiting candidate");
156  throw e;
157  }
158  }
159  }
160 }
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 162 of file SpatialCell.cc.

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

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