LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Attributes | List of all members
lsst.afw.math::SpatialCell Class Reference

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

#include <SpatialCell.h>

Public Types

typedef boost::shared_ptr
< SpatialCell
Ptr
 
typedef boost::shared_ptr
< const SpatialCell
ConstPtr
 
typedef std::vector
< boost::shared_ptr
< SpatialCellCandidate > > 
CandidateList
 
typedef
SpatialCellCandidateIterator 
iterator
 

Public Member Functions

 SpatialCell (std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
 
virtual ~SpatialCell ()
 
bool empty () const
 
size_t size () const
 
void sortCandidates ()
 
SpatialCellCandidateIterator begin ()
 
SpatialCellCandidateIterator begin (bool ignoreBad)
 
SpatialCellCandidateIterator end ()
 
SpatialCellCandidateIterator end (bool ignoreBad)
 
void insertCandidate (boost::shared_ptr< SpatialCellCandidate > candidate)
 
void removeCandidate (boost::shared_ptr< SpatialCellCandidate > candidate)
 
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...
 
boost::shared_ptr
< SpatialCellCandidate
getCandidateById (int id, bool noThrow=false)
 
std::string const & getLabel () const
 
lsst::afw::geom::Box2I const & getBBox () const
 
void visitCandidates (CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false, bool const reset=true)
 
void visitCandidates (CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false, bool const reset=true) const
 
void visitAllCandidates (CandidateVisitor *visitor, bool const ignoreExceptions=false, bool const reset=true)
 
void visitAllCandidates (CandidateVisitor *visitor, bool const ignoreExceptions=false, bool const reset=true) const
 

Private Attributes

std::string _label
 
lsst::afw::geom::Box2I _bbox
 
CandidateList _candidateList
 
bool _ignoreBad
 

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
SpatialCellSetExample

Definition at line 290 of file SpatialCell.h.

Member Typedef Documentation

typedef std::vector<boost::shared_ptr< SpatialCellCandidate > > lsst.afw.math::SpatialCell::CandidateList

Definition at line 294 of file SpatialCell.h.

typedef boost::shared_ptr<const SpatialCell> lsst.afw.math::SpatialCell::ConstPtr

Definition at line 293 of file SpatialCell.h.

Examples:
spatialCellExample.cc.

Definition at line 295 of file SpatialCell.h.

typedef boost::shared_ptr<SpatialCell> lsst.afw.math::SpatialCell::Ptr
Examples:
spatialCellExample.cc.

Definition at line 292 of file SpatialCell.h.

Constructor & Destructor Documentation

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

Constructor

Ctor

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

Definition at line 80 of file SpatialCell.cc.

83  :
84  _label(label),
85  _bbox(bbox),
86  _candidateList(candidateList),
87  _ignoreBad(true)
88 {
89  lsst::pex::logging::TTrace<3>("lsst.afw.math.SpatialCell",
90  "Cell %s : created with %d candidates",
91  this->_label.c_str(), this->_candidateList.size());
93 }
CandidateList _candidateList
Definition: SpatialCell.h:371
lsst::afw::geom::Box2I _bbox
Definition: SpatialCell.h:370
virtual lsst.afw.math::SpatialCell::~SpatialCell ( )
inlinevirtual

Destructor

Definition at line 306 of file SpatialCell.h.

306 {;};

Member Function Documentation

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

Return an iterator to the beginning of the Candidates

Definition at line 315 of file SpatialCell.h.

315  {
316  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), _ignoreBad);
317  }
CandidateList _candidateList
Definition: SpatialCell.h:371
SpatialCellCandidateIterator lsst.afw.math::SpatialCell::begin ( bool  ignoreBad)
inline
Parameters
ignoreBadIf true, ignore BAD candidates

Definition at line 318 of file SpatialCell.h.

319  {
320  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad);
321  }
CandidateList _candidateList
Definition: SpatialCell.h:371
bool lsst.afw.math::SpatialCell::empty ( ) const

Determine if cell has no usable candidates

Definition at line 128 of file SpatialCell.cc.

128  {
129  // Cast away const; end is only non-const as it provides access to the Candidates
130  // and we don't (yet) have SpatialCellCandidateConstIterator
131  SpatialCell *mthis = const_cast<SpatialCell *>(this);
132 
133  for (SpatialCellCandidateIterator ptr = mthis->begin(), end = mthis->end(); ptr != end; ++ptr) {
134  if (!(_ignoreBad && (*ptr)->isBad())) { // found a good candidate, or don't care
135  return false;
136  }
137  }
138 
139  return true;
140 }
SpatialCell(std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Definition: SpatialCell.cc:80
SpatialCellCandidateIterator end()
Definition: SpatialCell.h:325
SpatialCellCandidateIterator lsst.afw.math::SpatialCell::end ( void  )
inline

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

Definition at line 325 of file SpatialCell.h.

325  {
326  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), _ignoreBad, true);
327  }
CandidateList _candidateList
Definition: SpatialCell.h:371
SpatialCellCandidateIterator lsst.afw.math::SpatialCell::end ( bool  ignoreBad)
inline
Parameters
ignoreBadIf true, ignore BAD candidates

Definition at line 328 of file SpatialCell.h.

329  {
330  return SpatialCellCandidateIterator(_candidateList.begin(), _candidateList.end(), ignoreBad, true);
331  }
CandidateList _candidateList
Definition: SpatialCell.h:371
lsst::afw::geom::Box2I const& lsst.afw.math::SpatialCell::getBBox ( ) const
inline

Get SpatialCell's BBox

Definition at line 355 of file SpatialCell.h.

355 { return _bbox; }
lsst::afw::geom::Box2I _bbox
Definition: SpatialCell.h:370
SpatialCellCandidate::Ptr lsst.afw.math::SpatialCell::getCandidateById ( int  id,
bool  noThrow = false 
)

Return the SpatialCellCandidate with the specified id

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

Definition at line 159 of file SpatialCell.cc.

161  {
162  for (SpatialCellCandidateIterator ptr = begin(), end = this->end(); ptr != end; ++ptr) {
163  if ((*ptr)->getId() == id) {
164  return *ptr;
165  }
166  }
167 
168  if (noThrow) {
169  return SpatialCellCandidate::Ptr();
170  } else {
171  throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
172  (boost::format("Unable to find object with ID == %d") % id).str());
173  }
174 }
boost::shared_ptr< SpatialCellCandidate > Ptr
Definition: SpatialCell.h:76
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
SpatialCellCandidateIterator end()
Definition: SpatialCell.h:325
int id
Definition: CR.cc:151
SpatialCellCandidateIterator begin()
Definition: SpatialCell.h:315
bool lsst.afw.math::SpatialCell::getIgnoreBad ( ) const
inline

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

Definition at line 345 of file SpatialCell.h.

345 { return _ignoreBad; }
std::string const& lsst.afw.math::SpatialCell::getLabel ( ) const
inline

Get SpatialCell's label

Definition at line 351 of file SpatialCell.h.

351 { return _label; }
void lsst.afw.math::SpatialCell::insertCandidate ( boost::shared_ptr< SpatialCellCandidate candidate)

Add a candidate to the list, preserving ranking

Definition at line 108 of file SpatialCell.cc.

108  {
109  CandidateList::iterator pos = std::lower_bound(_candidateList.begin(), _candidateList.end(),
110  candidate, CandidatePtrMore());
111  _candidateList.insert(pos, candidate);
112 }
CandidateList _candidateList
Definition: SpatialCell.h:371
void lsst.afw.math::SpatialCell::removeCandidate ( boost::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 114 of file SpatialCell.cc.

115 {
116  CandidateList::iterator pos = std::find(_candidateList.begin(), _candidateList.end(), candidate);
117  if (pos == _candidateList.end()) {
118  throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
119  (boost::format("Unable to find candidate with ID == %d") %
120  candidate->getId()).str());
121  }
122  _candidateList.erase(pos);
123 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
CandidateList _candidateList
Definition: SpatialCell.h:371
void lsst.afw.math::SpatialCell::setIgnoreBad ( bool  ignoreBad)
inline

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

Definition at line 343 of file SpatialCell.h.

343 { _ignoreBad = ignoreBad; }
size_t lsst.afw.math::SpatialCell::size ( ) const

Return number of usable candidates in Cell

Definition at line 145 of file SpatialCell.cc.

145  {
146  // Cast away const; begin/end is only non-const as they provide access to the Candidates
147  // and we don't (yet) have SpatialCellCandidateConstIterator
148  SpatialCell *mthis = const_cast<SpatialCell *>(this);
149 
150  return mthis->end() - mthis->begin();
151 }
SpatialCell(std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Definition: SpatialCell.cc:80
void lsst.afw.math::SpatialCell::sortCandidates ( )

Rearrange the candidates to reflect their current ratings

Definition at line 99 of file SpatialCell.cc.

100 {
101  sort(_candidateList.begin(), _candidateList.end(), CandidatePtrMore());
102 }
CandidateList _candidateList
Definition: SpatialCell.h:371
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

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

Definition at line 261 of file SpatialCell.cc.

264  {
265  if (reset) {
266  visitor->reset();
267  }
268 
269  int i = 0;
270  for (SpatialCell::iterator candidate = begin(false), candidateEnd = end(false);
271  candidate != candidateEnd; ++candidate, ++i) {
272  try {
273  visitor->processCandidate((*candidate).get());
274  } catch(lsst::pex::exceptions::LengthError &e) {
275  if (ignoreExceptions) {
276  ;
277  } else {
278  LSST_EXCEPT_ADD(e, "Visiting candidate");
279  throw e;
280  }
281  }
282  }
283 }
SpatialCellCandidateIterator end()
Definition: SpatialCell.h:325
SpatialCellCandidateIterator begin()
Definition: SpatialCell.h:315
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51
SpatialCellCandidateIterator iterator
Definition: SpatialCell.h:295
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

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

Definition at line 293 of file SpatialCell.cc.

297  {
298 #if 1
299  //
300  // This const_cast must go!
301  //
302  SpatialCell *mthis = const_cast<SpatialCell *>(this);
303  mthis->visitAllCandidates(visitor, ignoreExceptions, reset);
304 #else
305  int i = 0;
306  for (SpatialCell::const_iterator candidate = (*cell)->begin(false), candidateEnd = (*cell)->end(false);
307  candidate != candidateEnd; ++candidate, ++i) {
308  try {
309  visitor->processCandidate((*candidate).get());
310  } catch(lsst::pex::exceptions::LengthError &e) {
311  if (ignoreExceptions) {
312  ;
313  } else {
314  LSST_EXCEPT_ADD(e, "Visiting candidate");
315  throw e;
316  }
317  }
318  }
319 #endif
320 }
SpatialCell(std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Definition: SpatialCell.cc:80
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51
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

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)
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

Definition at line 183 of file SpatialCell.cc.

189  {
190  if (reset) {
191  visitor->reset();
192  }
193 
194  int i = 0;
195  for (SpatialCell::iterator candidate = begin(), candidateEnd = end();
196  candidate != candidateEnd; ++candidate, ++i) {
197  if (nMaxPerCell > 0 && i == nMaxPerCell) { // we've processed all the candidates we want
198  return;
199  }
200 
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 }
SpatialCellCandidateIterator end()
Definition: SpatialCell.h:325
SpatialCellCandidateIterator begin()
Definition: SpatialCell.h:315
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51
SpatialCellCandidateIterator iterator
Definition: SpatialCell.h:295
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

Todo:
This is currently implemented via a const_cast (arghhh). The problem is that SpatialCell::begin() const isn't yet implemented
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

Definition at line 222 of file SpatialCell.cc.

227  {
228 #if 1
229  //
230  // This const_cast must go!
231  //
232  SpatialCell *mthis = const_cast<SpatialCell *>(this);
233  mthis->visitCandidates(visitor, nMaxPerCell, ignoreExceptions, reset);
234 #else
235  int i = 0;
236  for (SpatialCell::const_iterator candidate = (*cell)->begin(), candidateEnd = (*cell)->end();
237  candidate != candidateEnd; ++candidate, ++i) {
238  if (i == nMaxPerCell) { // we've processed all the candidates we want
239  return;
240  }
241 
242  try {
243  visitor->processCandidate((*candidate).get());
244  } catch(lsst::pex::exceptions::LengthError &e) {
245  if (ignoreExceptions) {
246  ;
247  } else {
248  LSST_EXCEPT_ADD(e, "Visiting candidate");
249  throw e;
250  }
251  }
252  }
253 #endif
254 }
SpatialCell(std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Definition: SpatialCell.cc:80
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51

Member Data Documentation

lsst::afw::geom::Box2I lsst.afw.math::SpatialCell::_bbox
private

Definition at line 370 of file SpatialCell.h.

CandidateList lsst.afw.math::SpatialCell::_candidateList
private

Definition at line 371 of file SpatialCell.h.

bool lsst.afw.math::SpatialCell::_ignoreBad
private

Definition at line 372 of file SpatialCell.h.

std::string lsst.afw.math::SpatialCell::_label
private

Definition at line 369 of file SpatialCell.h.


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