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 _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)
SpatialCellCandidateIterator end()
int positionToIndex(double pos)
Convert image position to nearest integer index.
A set of classes of general utility in connection with images.
SpatialCellSet(lsst::afw::geom::Box2I const ®ion, int xSize, int ySize=0)
std::vector< boost::shared_ptr< SpatialCell > > CellList
size_t operator-(SpatialCellCandidateIterator const &rhs) const
boost::shared_ptr< SpatialCell > Ptr
static int _CandidateId
Unique identifier for candidates; useful for preserving current candidate following insertion...
definition of the Trace messaging facilities
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 *)
boost::shared_ptr< const SpatialCellCandidate > ConstPtr
SpatialCellCandidate::Ptr _candidate
boost::shared_ptr< SpatialCellCandidate > Ptr
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,...)
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.