48 struct CandidatePtrMore :
public std::binary_function<SpatialCellCandidate::Ptr,
49 SpatialCellCandidate::Ptr,
52 return a->getCandidateRating() > b->getCandidateRating();
72 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
90 _candidateList(candidateList),
93 LOGL_DEBUG(
"afw.math.SpatialCell",
"Cell %s : created with %d candidates",
113 candidate, CandidatePtrMore());
121 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
123 candidate->getId()).str());
153 return mthis->
end() - mthis->
begin();
166 if ((*ptr)->getId() ==
id) {
174 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
175 (
boost::format(
"Unable to find object with ID == %d") %
id).str());
187 int const nMaxPerCell,
188 bool const ignoreExceptions,
199 candidate != candidateEnd; ++candidate, ++i) {
200 if (nMaxPerCell > 0 && i == nMaxPerCell) {
207 if (ignoreExceptions) {
227 int const nMaxPerCell,
228 bool const ignoreExceptions,
239 for (SpatialCell::const_iterator candidate = (*cell)->begin(), candidateEnd = (*cell)->end();
240 candidate != candidateEnd; ++candidate, ++i) {
241 if (i == nMaxPerCell) {
247 }
catch(lsst::pex::exceptions::LengthError &e) {
248 if (ignoreExceptions) {
265 bool const ignoreExceptions,
274 candidate != candidateEnd; ++candidate, ++i) {
277 }
catch(lsst::pex::exceptions::LengthError &e) {
278 if (ignoreExceptions) {
298 bool const ignoreExceptions,
309 for (SpatialCell::const_iterator candidate = (*cell)->begin(
false), candidateEnd = (*cell)->end(
false);
310 candidate != candidateEnd; ++candidate, ++i) {
313 }
catch(lsst::pex::exceptions::LengthError &e) {
314 if (ignoreExceptions) {
328 CandidateList::iterator iterator,
329 CandidateList::iterator end,
332 : _iterator(iterator), _end(end), _ignoreBad(ignoreBad) {
334 (*_iterator)->instantiate();
344 CandidateList::iterator,
345 CandidateList::iterator end,
349 : _iterator(end), _end(end), _ignoreBad(ignoreBad) {
365 (*_iterator)->instantiate();
394 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
"Iterator points to end");
403 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
"Iterator points to end");
420 _region(region), _cellList(
CellList()) {
425 if (xSize <= 0 || ySize <= 0) {
426 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
427 (
boost::format(
"Please specify cells that contain pixels, not %dx%d") %
428 xSize % ySize).str());
432 if (nx*xSize != region.
getWidth()) {
444 for (
int y = 0;
y < ny; ++
y) {
446 int const y1 = (
y == ny - 1) ? region.
getMaxY() : y0 + ySize - 1;
448 for (
int x = 0;
x < nx; ++
x) {
450 int const x1 = (
x == nx - 1) ? region.
getMaxX() : x0 + xSize - 1;
465 struct CellContains :
public std::unary_function<SpatialCell::Ptr,
482 CellList::iterator pos = std::find_if(
_cellList.begin(),
_cellList.end(), CellContains(candidate));
485 throw LSST_EXCEPT(lsst::pex::exceptions::OutOfRangeError,
486 (
boost::format(
"Unable to insert a candidate at (%.2f, %.2f)") %
487 candidate->getXCenter() % candidate->getYCenter()).str());
490 (*pos)->insertCandidate(candidate);
500 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
501 (*cell)->sortCandidates();
515 int const nMaxPerCell,
516 bool const ignoreExceptions
520 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
521 (*cell)->visitCandidates(visitor, nMaxPerCell, ignoreExceptions,
false);
532 int const nMaxPerCell,
533 bool const ignoreExceptions
537 for (CellList::const_iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
551 bool const ignoreExceptions
555 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
556 (*cell)->visitAllCandidates(visitor, ignoreExceptions,
false);
567 bool const ignoreExceptions
571 for (CellList::const_iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
587 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
598 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
599 (
boost::format(
"Unable to find object with ID == %d") %
id).str());
605 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
606 (*cell)->setIgnoreBad(ignoreBad);
CandidateList::iterator _iterator
void setStatus(Status status)
Set the candidate's status.
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(boost::shared_ptr< SpatialCellCandidate > candidate)
Insert a candidate into the correct cell.
bool empty() const
Determine if cell has no usable candidates.
SpatialCellCandidateIterator end()
Return an iterator to (one after) the end of the Candidates.
int positionToIndex(double pos)
Convert image position to nearest integer index.
SpatialCellSet(lsst::afw::geom::Box2I const ®ion, int xSize, int ySize=0)
Constructor.
std::shared_ptr< const SpatialCellCandidate > ConstPtr
std::vector< boost::shared_ptr< SpatialCell > > CellList
size_t operator-(SpatialCellCandidateIterator const &rhs) const
Return the number of candidate between this and rhs.
static int _CandidateId
Unique identifier for candidates; useful for preserving current candidate following insertion...
std::shared_ptr< SpatialCellCandidate > Ptr
void sortCandidates()
Rearrange the candidates to reflect their current ratings.
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
A set of classes of general utility in connection with images.
SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end, bool ignoreBad)
ctor; designed to be used to pass begin to SpatialCellCandidateIterator
virtual void processCandidate(SpatialCellCandidate *)
SpatialCellCandidate::Ptr _candidate
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
An integer coordinate rectangle.
table::Key< table::Array< Kernel::Pixel > > image
boost::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
void operator++()
Advance the iterator, maybe skipping over candidates labelled BAD.
LSST DM logging module built on log4cxx.
boost::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
metadata import lsst afw display as afwDisplay n
std::vector< boost::shared_ptr< SpatialCellCandidate > > CandidateList
void removeCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
Remove a candidate from the list.
SpatialCell(std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Constructor.
geom::Box2I const & _bbox
boost::shared_ptr< SpatialCellCandidate const > operator*() const
Dereference the iterator to return the Candidate (if there is one)
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. ...
CandidateList _candidateList
size_t size() const
Return number of usable candidates in Cell.
void sortCandidates()
Rearrange the Candidates in all SpatialCells to reflect their current ratings.
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
std::shared_ptr< SpatialCell > Ptr
CandidateList::iterator _end
Class to ensure constraints for spatial modeling.
Class to ensure constraints for spatial modeling.
afw::table::Key< double > b
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false)
Call the visitor's processCandidate method for every Candidate in the SpatialCellSet.
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it...
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false)
Call the visitor's processCandidate method for each Candidate in the SpatialCellSet.
void insertCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
Add a candidate to the list, preserving ranking.
SpatialCellCandidateIterator begin()
Return an iterator to the beginning of the Candidates.
An iterator that only returns usable members of the SpatialCell.