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,
86 _candidateList(candidateList),
89 LOGL_DEBUG(
"afw.math.SpatialCell",
"Cell %s : created with %d candidates",
109 candidate, CandidatePtrMore());
117 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
119 candidate->getId()).str());
149 return mthis->
end() - mthis->
begin();
162 if ((*ptr)->getId() ==
id) {
170 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
171 (
boost::format(
"Unable to find object with ID == %d") %
id).str());
183 int const nMaxPerCell,
184 bool const ignoreExceptions,
195 candidate != candidateEnd; ++candidate, ++i) {
196 if (nMaxPerCell > 0 && i == nMaxPerCell) {
203 if (ignoreExceptions) {
223 int const nMaxPerCell,
224 bool const ignoreExceptions,
235 for (SpatialCell::const_iterator candidate = (*cell)->begin(), candidateEnd = (*cell)->end();
236 candidate != candidateEnd; ++candidate, ++i) {
237 if (i == nMaxPerCell) {
243 }
catch(lsst::pex::exceptions::LengthError &e) {
244 if (ignoreExceptions) {
261 bool const ignoreExceptions,
270 candidate != candidateEnd; ++candidate, ++i) {
273 }
catch(lsst::pex::exceptions::LengthError &e) {
274 if (ignoreExceptions) {
294 bool const ignoreExceptions,
305 for (SpatialCell::const_iterator candidate = (*cell)->begin(
false), candidateEnd = (*cell)->end(
false);
306 candidate != candidateEnd; ++candidate, ++i) {
309 }
catch(lsst::pex::exceptions::LengthError &e) {
310 if (ignoreExceptions) {
324 CandidateList::iterator iterator,
325 CandidateList::iterator end,
328 : _iterator(iterator), _end(end), _ignoreBad(ignoreBad) {
330 (*_iterator)->instantiate();
340 CandidateList::iterator,
341 CandidateList::iterator end,
345 : _iterator(end), _end(end), _ignoreBad(ignoreBad) {
361 (*_iterator)->instantiate();
390 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
"Iterator points to end");
399 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
"Iterator points to end");
416 _region(region), _cellList(
CellList()) {
421 if (xSize <= 0 || ySize <= 0) {
422 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
423 (
boost::format(
"Please specify cells that contain pixels, not %dx%d") %
424 xSize % ySize).str());
428 if (nx*xSize != region.
getWidth()) {
440 for (
int y = 0;
y < ny; ++
y) {
442 int const y1 = (
y == ny - 1) ? region.
getMaxY() : y0 + ySize - 1;
444 for (
int x = 0;
x < nx; ++
x) {
446 int const x1 = (
x == nx - 1) ? region.
getMaxX() : x0 + xSize - 1;
461 struct CellContains :
public std::unary_function<SpatialCell::Ptr,
478 CellList::iterator pos = std::find_if(
_cellList.begin(),
_cellList.end(), CellContains(candidate));
481 throw LSST_EXCEPT(lsst::pex::exceptions::OutOfRangeError,
482 (
boost::format(
"Unable to insert a candidate at (%.2f, %.2f)") %
483 candidate->getXCenter() % candidate->getYCenter()).str());
486 (*pos)->insertCandidate(candidate);
496 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
497 (*cell)->sortCandidates();
511 int const nMaxPerCell,
512 bool const ignoreExceptions
516 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
517 (*cell)->visitCandidates(visitor, nMaxPerCell, ignoreExceptions,
false);
528 int const nMaxPerCell,
529 bool const ignoreExceptions
533 for (CellList::const_iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
547 bool const ignoreExceptions
551 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
552 (*cell)->visitAllCandidates(visitor, ignoreExceptions,
false);
563 bool const ignoreExceptions
567 for (CellList::const_iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
583 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
594 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
595 (
boost::format(
"Unable to find object with ID == %d") %
id).str());
601 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
602 (*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)
void insertCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
A set of classes of general utility in connection with images.
#define LOGL_DEBUG(logger, message...)
SpatialCellCandidateIterator end()
int positionToIndex(double pos)
Convert image position to nearest integer index.
SpatialCellSet(lsst::afw::geom::Box2I const ®ion, int xSize, int ySize=0)
std::shared_ptr< const SpatialCellCandidate > ConstPtr
std::vector< boost::shared_ptr< SpatialCell > > CellList
size_t operator-(SpatialCellCandidateIterator const &rhs) const
static int _CandidateId
Unique identifier for candidates; useful for preserving current candidate following insertion...
std::shared_ptr< SpatialCellCandidate > Ptr
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
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
An integer coordinate rectangle.
table::Key< table::Array< Kernel::Pixel > > image
boost::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
boost::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
std::vector< boost::shared_ptr< SpatialCellCandidate > > CandidateList
void removeCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
SpatialCell(std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
geom::Box2I const & _bbox
boost::shared_ptr< SpatialCellCandidate const > operator*() const
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false, bool const reset=true)
CandidateList _candidateList
#define LSST_EXCEPT(type,...)
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)
#define LSST_EXCEPT_ADD(e, m)
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false)
void insertCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
SpatialCellCandidateIterator begin()
An iterator that only returns usable members of the SpatialCell.