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 lsst::pex::logging::TTrace<3>(
"lsst.afw.math.SpatialCell",
90 "Cell %s : created with %d candidates",
110 candidate, CandidatePtrMore());
118 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
120 candidate->getId()).str());
150 return mthis->
end() - mthis->
begin();
163 if ((*ptr)->getId() ==
id) {
171 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
172 (
boost::format(
"Unable to find object with ID == %d") %
id).str());
184 int const nMaxPerCell,
185 bool const ignoreExceptions,
196 candidate != candidateEnd; ++candidate, ++i) {
197 if (nMaxPerCell > 0 && i == nMaxPerCell) {
204 if (ignoreExceptions) {
224 int const nMaxPerCell,
225 bool const ignoreExceptions,
236 for (SpatialCell::const_iterator candidate = (*cell)->begin(), candidateEnd = (*cell)->end();
237 candidate != candidateEnd; ++candidate, ++i) {
238 if (i == nMaxPerCell) {
244 }
catch(lsst::pex::exceptions::LengthError &e) {
245 if (ignoreExceptions) {
262 bool const ignoreExceptions,
271 candidate != candidateEnd; ++candidate, ++i) {
274 }
catch(lsst::pex::exceptions::LengthError &e) {
275 if (ignoreExceptions) {
295 bool const ignoreExceptions,
306 for (SpatialCell::const_iterator candidate = (*cell)->begin(
false), candidateEnd = (*cell)->end(
false);
307 candidate != candidateEnd; ++candidate, ++i) {
310 }
catch(lsst::pex::exceptions::LengthError &e) {
311 if (ignoreExceptions) {
325 CandidateList::iterator iterator,
326 CandidateList::iterator end,
329 : _iterator(iterator), _end(end), _ignoreBad(ignoreBad) {
331 (*_iterator)->instantiate();
341 CandidateList::iterator,
342 CandidateList::iterator end,
346 : _iterator(end), _end(end), _ignoreBad(ignoreBad) {
362 (*_iterator)->instantiate();
391 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
"Iterator points to end");
400 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
"Iterator points to end");
417 _region(region), _cellList(
CellList()) {
422 if (xSize <= 0 || ySize <= 0) {
423 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
424 (
boost::format(
"Please specify cells that contain pixels, not %dx%d") %
425 xSize % ySize).str());
429 if (nx*xSize != region.
getWidth()) {
441 for (
int y = 0;
y < ny; ++
y) {
443 int const y1 = (
y == ny - 1) ? region.
getMaxY() : y0 + ySize - 1;
445 for (
int x = 0;
x < nx; ++
x) {
447 int const x1 = (
x == nx - 1) ? region.
getMaxX() : x0 + xSize - 1;
462 struct CellContains :
public std::unary_function<SpatialCell::Ptr,
479 CellList::iterator pos = std::find_if(
_cellList.begin(),
_cellList.end(), CellContains(candidate));
482 throw LSST_EXCEPT(lsst::pex::exceptions::OutOfRangeError,
483 (
boost::format(
"Unable to insert a candidate at (%.2f, %.2f)") %
484 candidate->getXCenter() % candidate->getYCenter()).str());
487 (*pos)->insertCandidate(candidate);
497 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
498 (*cell)->sortCandidates();
512 int const nMaxPerCell,
513 bool const ignoreExceptions
517 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
518 (*cell)->visitCandidates(visitor, nMaxPerCell, ignoreExceptions,
false);
529 int const nMaxPerCell,
530 bool const ignoreExceptions
534 for (CellList::const_iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
548 bool const ignoreExceptions
552 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
553 (*cell)->visitAllCandidates(visitor, ignoreExceptions,
false);
564 bool const ignoreExceptions
568 for (CellList::const_iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
584 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
595 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
596 (
boost::format(
"Unable to find object with ID == %d") %
id).str());
602 for (CellList::iterator cell =
_cellList.begin(), end =
_cellList.end(); cell != end; ++cell) {
603 (*cell)->setIgnoreBad(ignoreBad);
CandidateList::iterator _end
SpatialCell(std::string const &label, lsst::afw::geom::Box2I const &bbox=lsst::afw::geom::Box2I(), CandidateList const &candidateList=CandidateList())
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false, bool const reset=true)
boost::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
CandidateList::iterator _iterator
int positionToIndex(double pos)
Convert image position to nearest integer index.
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false)
definition of the Trace messaging facilities
static int _CandidateId
Unique identifier for candidates; useful for preserving current candidate following insertion...
void setStatus(Status status)
Set the candidate's status.
SpatialCellCandidate::Ptr _candidate
boost::shared_ptr< const SpatialCellCandidate > ConstPtr
size_t operator-(SpatialCellCandidateIterator const &rhs) const
An integer coordinate rectangle.
table::Key< table::Array< Kernel::Pixel > > image
A set of classes of general utility in connection with images.
std::vector< boost::shared_ptr< SpatialCell > > CellList
geom::Box2I const & _bbox
boost::shared_ptr< SpatialCell > Ptr
boost::shared_ptr< SpatialCellCandidate > Ptr
void removeCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
boost::shared_ptr< SpatialCellCandidate const > operator*() const
#define LSST_EXCEPT(type,...)
SpatialCellCandidateIterator end()
CandidateList _candidateList
SpatialCellSet(lsst::afw::geom::Box2I const ®ion, int xSize, int ySize=0)
Class to ensure constraints for spatial modeling.
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
Class to ensure constraints for spatial modeling.
afw::table::Key< double > b
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false, bool const reset=true)
void insertCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
virtual void processCandidate(SpatialCellCandidate *)
SpatialCellCandidateIterator begin()
boost::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false)
std::vector< boost::shared_ptr< SpatialCellCandidate > > CandidateList
#define LSST_EXCEPT_ADD(e, m)
An iterator that only returns usable members of the SpatialCell.
void insertCandidate(boost::shared_ptr< SpatialCellCandidate > candidate)
SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end, bool ignoreBad)
ctor; designed to be used to pass begin to SpatialCellCandidateIterator