43struct CandidatePtrMore {
45 return a->getCandidateRating() >
b->getCandidateRating();
50int SpatialCellCandidate::_CandidateId = 0;
64 (boost::format(
"Saw unknown status %d") % status).str());
67int SpatialCellImageCandidate::_width = 0;
69int SpatialCellImageCandidate::_height = 0;
73 : _label(label), _bbox(
bbox), _candidateList(candidateList), _ignoreBad(true) {
74 LOGL_DEBUG(
"lsst.afw.math.SpatialCell",
"Cell %s : created with %d candidates", this->_label.
c_str(),
75 this->_candidateList.size());
82 CandidateList::iterator pos =
84 _candidateList.
insert(pos, candidate);
88 CandidateList::iterator pos =
std::find(_candidateList.
begin(), _candidateList.
end(), candidate);
89 if (pos == _candidateList.
end()) {
92 (boost::format(
"Unable to find candidate with ID == %d") % candidate->getId()).str());
94 _candidateList.
erase(pos);
102 for (
auto && mthi : *mthis) {
103 if (!(_ignoreBad && (mthi)->isBad())) {
116 return mthis->
end() - mthis->
begin();
121 if ((*ptr)->getId() ==
id) {
130 (boost::format(
"Unable to find object with ID == %d") %
id).str());
136 bool const ignoreExceptions,
bool const reset) {
144 if (nMaxPerCell > 0 && i == nMaxPerCell) {
151 if (ignoreExceptions) {
162 bool const ignoreExceptions,
bool const reset)
const {
171 for (SpatialCell::const_iterator candidate = (*cell)->begin(), candidateEnd = (*cell)->end();
172 candidate != candidateEnd; ++candidate, ++i) {
173 if (i == nMaxPerCell) {
180 if (ignoreExceptions) {
203 if (ignoreExceptions) {
214 bool const reset)
const {
223 for (SpatialCell::const_iterator candidate = (*cell)->begin(
false), candidateEnd = (*cell)->end(
false);
224 candidate != candidateEnd; ++candidate, ++i) {
228 if (ignoreExceptions) {
240 CandidateList::iterator
end,
bool ignoreBad)
241 : _iterator(iterator), _end(
end), _ignoreBad(ignoreBad) {
242 for (; _iterator != _end; ++_iterator) {
243 (*_iterator)->instantiate();
245 if (!(_ignoreBad && (*_iterator)->isBad())) {
252 CandidateList::iterator
end,
bool ignoreBad,
bool)
253 : _iterator(
end), _end(
end), _ignoreBad(ignoreBad) {
261 if (_iterator != _end) {
265 for (; _iterator != _end; ++_iterator) {
266 (*_iterator)->instantiate();
268 if (!(_ignoreBad && (*_iterator)->isBad())) {
277 if (!(_ignoreBad && (*ptr)->isBad())) {
286 if (_iterator == _end) {
294 if (_iterator == _end) {
302 : _region(region), _cellList(
CellList()) {
307 if (xSize <= 0 || ySize <= 0) {
310 (boost::format(
"Please specify cells that contain pixels, not %dx%d") % xSize % ySize).str());
314 if (nx * xSize != region.
getWidth()) {
326 for (
int y = 0;
y < ny; ++
y) {
328 int const y1 = (
y == ny - 1) ? region.
getMaxY() : y0 + ySize - 1;
330 for (
int x = 0;
x < nx; ++
x) {
332 int const x1 = (
x == nx - 1) ? region.
getMaxX() : x0 + xSize - 1;
334 std::string label = (boost::format(
"Cell %dx%d") %
x %
y).str();
336 _cellList.
push_back(std::make_shared<SpatialCell>(label,
bbox));
349 return cell->getBBox().contains(
360 CellList::iterator pos =
std::find_if(_cellList.
begin(), _cellList.
end(), CellContains(candidate));
362 if (pos == _cellList.
end()) {
364 (boost::format(
"Unable to insert a candidate at (%.2f, %.2f)") %
365 candidate->getXCenter() % candidate->getYCenter())
369 (*pos)->insertCandidate(candidate);
373 for (
auto const &cell : _cellList) {
374 cell->sortCandidates();
379 bool const ignoreExceptions) {
382 for (
auto const &cell : _cellList) {
383 cell->visitCandidates(visitor, nMaxPerCell, ignoreExceptions,
false);
388 bool const ignoreExceptions)
const {
391 for (
auto const &cell : _cellList) {
400 for (
auto const &cell : _cellList) {
401 cell->visitAllCandidates(visitor, ignoreExceptions,
false);
408 for (
auto const &cell : _cellList) {
415 for (
auto const &cell : _cellList) {
427 (boost::format(
"Unable to find object with ID == %d") %
id).str());
432 for (
auto const &cell : _cellList) {
433 cell->setIgnoreBad(ignoreBad);
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
LSST DM logging module built on log4cxx.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
virtual void processCandidate(SpatialCellCandidate *)
void setStatus(Status status)
Set the candidate's status.
An iterator that only returns usable members of the SpatialCell.
SpatialCellCandidateIterator(CandidateList::iterator iterator, CandidateList::iterator end, bool ignoreBad)
ctor; designed to be used to pass begin to SpatialCellCandidateIterator
void operator++()
Advance the iterator, maybe skipping over candidates labelled BAD.
size_t operator-(SpatialCellCandidateIterator const &rhs) const
Return the number of candidate between this and rhs.
std::shared_ptr< SpatialCellCandidate const > operator*() const
Dereference the iterator to return the Candidate (if there is one)
Class to ensure constraints for spatial modeling.
SpatialCellCandidateIterator end()
Return an iterator to (one after) the end of the Candidates.
size_t size() const
Return number of usable candidates in Cell.
void sortCandidates()
Rearrange the candidates to reflect their current ratings.
void removeCandidate(std::shared_ptr< SpatialCellCandidate > candidate)
Remove a candidate from the list.
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.
SpatialCellCandidateIterator begin()
Return an iterator to the beginning of the Candidates.
bool empty() const
Determine if cell has no usable candidates.
std::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
SpatialCell(std::string const &label, lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), CandidateList const &candidateList=CandidateList())
Constructor.
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(std::shared_ptr< SpatialCellCandidate > candidate)
Add a candidate to the list, preserving ranking.
void sortCandidates()
Rearrange the Candidates in all SpatialCells to reflect their current ratings.
void visitAllCandidates(CandidateVisitor *visitor, bool const ignoreExceptions=false)
Call the visitor's processCandidate method for every Candidate in the SpatialCellSet.
void setIgnoreBad(bool ignoreBad)
Set whether we should omit BAD candidates from candidate list when traversing.
void insertCandidate(std::shared_ptr< SpatialCellCandidate > candidate)
Insert a candidate into the correct cell.
std::shared_ptr< SpatialCellCandidate > getCandidateById(int id, bool noThrow=false)
Return the SpatialCellCandidate with the specified id.
void visitCandidates(CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false)
Call the visitor's processCandidate method for each Candidate in the SpatialCellSet.
SpatialCellSet(lsst::geom::Box2I const ®ion, int xSize, int ySize=0)
Constructor.
An integer coordinate rectangle.
int getMinY() const noexcept
int getHeight() const noexcept
int getMinX() const noexcept
int getWidth() const noexcept
int getMaxX() const noexcept
int getMaxY() const noexcept
Provides consistent interface for LSST exceptions.
Reports invalid arguments.
Reports attempts to exceed implementation-defined length limits for some classes.
Reports attempts to access elements using an invalid key.
Reports attempts to access elements outside a valid range of indices.
int positionToIndex(double pos)
Convert image position to nearest integer index.