LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Attributes | List of all members
lsst::afw::math::SpatialCellSet Class Reference

A collection of SpatialCells covering an entire image. More...

#include <SpatialCell.h>

Public Types

typedef boost::shared_ptr
< SpatialCellSet
Ptr
 
typedef boost::shared_ptr
< const SpatialCellSet
ConstPtr
 
typedef std::vector
< boost::shared_ptr
< SpatialCell > > 
CellList
 

Public Member Functions

 SpatialCellSet (lsst::afw::geom::Box2I const &region, int xSize, int ySize=0)
 
virtual ~SpatialCellSet ()
 
CellListgetCellList ()
 
lsst::afw::geom::Box2I getBBox () const
 
void insertCandidate (boost::shared_ptr< SpatialCellCandidate > candidate)
 
void sortCandidates ()
 
void visitCandidates (CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false)
 
void visitCandidates (CandidateVisitor *visitor, int const nMaxPerCell=-1, bool const ignoreExceptions=false) const
 
void visitAllCandidates (CandidateVisitor *visitor, bool const ignoreExceptions=false)
 
void visitAllCandidates (CandidateVisitor *visitor, bool const ignoreExceptions=false) const
 
boost::shared_ptr
< SpatialCellCandidate
getCandidateById (int id, bool noThrow=false)
 
void setIgnoreBad (bool ignoreBad)
 Set whether we should omit BAD candidates from candidate list when traversing. More...
 

Private Attributes

lsst::afw::geom::Box2I _region
 
CellList _cellList
 

Detailed Description

A collection of SpatialCells covering an entire image.

Definition at line 378 of file SpatialCell.h.

Member Typedef Documentation

typedef std::vector<boost::shared_ptr< SpatialCell > > lsst::afw::math::SpatialCellSet::CellList

Definition at line 383 of file SpatialCell.h.

Definition at line 381 of file SpatialCell.h.

Definition at line 380 of file SpatialCell.h.

Constructor & Destructor Documentation

lsst::afw::math::SpatialCellSet::SpatialCellSet ( lsst::afw::geom::Box2I const &  region,
int  xSize,
int  ySize = 0 
)

Constructor

Exceptions
lsst::pex::exceptions::LengthErrorif nx or ny is non-positive
Parameters
regionBounding box for image
xSizesize of cells in the column direction
ySizesize of cells in the row direction (0: == xSize)

Definition at line 413 of file SpatialCell.cc.

416  :
417  _region(region), _cellList(CellList()) {
418  if (ySize == 0) {
419  ySize = xSize;
420  }
421 
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());
426  }
427 
428  int nx = region.getWidth()/xSize;
429  if (nx*xSize != region.getWidth()) {
430  nx++;
431  }
432 
433  int ny = region.getHeight()/ySize;
434  if (ny*ySize != region.getHeight()) {
435  ny++;
436  }
437  //
438  // N.b. the SpatialCells will be sorted in y at the end of this
439  //
440  int y0 = region.getMinY();
441  for (int y = 0; y < ny; ++y) {
442  // ny may not be a factor of height
443  int const y1 = (y == ny - 1) ? region.getMaxY() : y0 + ySize - 1;
444  int x0 = region.getMinX();
445  for (int x = 0; x < nx; ++x) {
446  // nx may not be a factor of width
447  int const x1 = (x == nx - 1) ? region.getMaxX() : x0 + xSize - 1;
448  geom::Box2I bbox(geom::Point2I(x0, y0), geom::Point2I(x1, y1));
449  std::string label = (boost::format("Cell %dx%d") % x % y).str();
450 
451  _cellList.push_back(SpatialCell::Ptr(new SpatialCell(label, bbox)));
452 
453  x0 = x1 + 1;
454  }
455  y0 = y1 + 1;
456  }
457 }
int y
std::vector< boost::shared_ptr< SpatialCell > > CellList
Definition: SpatialCell.h:383
boost::shared_ptr< SpatialCell > Ptr
Definition: SpatialCell.h:292
lsst::afw::geom::Box2I _region
Definition: SpatialCell.h:418
int const x0
Definition: saturated.cc:45
An integer coordinate rectangle.
Definition: Box.h:53
double x
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int const y0
Definition: saturated.cc:45
virtual lsst::afw::math::SpatialCellSet::~SpatialCellSet ( )
inlinevirtual

Destructor

Definition at line 390 of file SpatialCell.h.

390 {;};

Member Function Documentation

lsst::afw::geom::Box2I lsst::afw::math::SpatialCellSet::getBBox ( ) const
inline

Return the bounding box of the image

Definition at line 400 of file SpatialCell.h.

400 { return _region; };
lsst::afw::geom::Box2I _region
Definition: SpatialCell.h:418
SpatialCellCandidate::Ptr lsst::afw::math::SpatialCellSet::getCandidateById ( int  id,
bool  noThrow = false 
)

Return the SpatialCellCandidate with the specified id

Exceptions
lsst::pex::exceptions::NotFoundErrorif no candidate matches the id (unless noThrow is true, in which case a Ptr(NULL) is returned
Parameters
idThe desired ID
noThrowReturn NULL in case of error

Definition at line 581 of file SpatialCell.cc.

583  {
584  for (CellList::iterator cell = _cellList.begin(), end = _cellList.end(); cell != end; ++cell) {
585  SpatialCellCandidate::Ptr cand = (*cell)->getCandidateById(id, true);
586 
587  if (cand) {
588  return cand;
589  }
590  }
591 
592  if (noThrow) {
593  return SpatialCellCandidate::Ptr();
594  } else {
595  throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
596  (boost::format("Unable to find object with ID == %d") % id).str());
597  }
598 }
boost::shared_ptr< SpatialCellCandidate > Ptr
Definition: SpatialCell.h:76
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
CellList& lsst::afw::math::SpatialCellSet::getCellList ( )
inline

Return our SpatialCells

Definition at line 395 of file SpatialCell.h.

395 { return _cellList; }
void lsst::afw::math::SpatialCellSet::insertCandidate ( boost::shared_ptr< SpatialCellCandidate candidate)

Insert a candidate into the correct cell

Definition at line 478 of file SpatialCell.cc.

478  {
479  CellList::iterator pos = std::find_if(_cellList.begin(), _cellList.end(), CellContains(candidate));
480 
481  if (pos == _cellList.end()) {
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());
485  }
486 
487  (*pos)->insertCandidate(candidate);
488 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void lsst::afw::math::SpatialCellSet::setIgnoreBad ( bool  ignoreBad)

Set whether we should omit BAD candidates from candidate list when traversing.

Definition at line 601 of file SpatialCell.cc.

601  {
602  for (CellList::iterator cell = _cellList.begin(), end = _cellList.end(); cell != end; ++cell) {
603  (*cell)->setIgnoreBad(ignoreBad);
604  }
605 }
void lsst::afw::math::SpatialCellSet::sortCandidates ( )

Rearrange the Candidates in all SpatialCells to reflect their current ratings

Definition at line 495 of file SpatialCell.cc.

496 {
497  for (CellList::iterator cell = _cellList.begin(), end = _cellList.end(); cell != end; ++cell) {
498  (*cell)->sortCandidates();
499  }
500 }
void lsst::afw::math::SpatialCellSet::visitAllCandidates ( CandidateVisitor visitor,
bool const  ignoreExceptions = false 
)

Call the visitor's processCandidate method for every Candidate in the SpatialCellSet

See Also
visitCandidates
Parameters
visitorPass this object to every Candidate
ignoreExceptionsIgnore any exceptions thrown by the processing

Definition at line 546 of file SpatialCell.cc.

549  {
550  visitor->reset();
551 
552  for (CellList::iterator cell = _cellList.begin(), end = _cellList.end(); cell != end; ++cell) {
553  (*cell)->visitAllCandidates(visitor, ignoreExceptions, false);
554  }
555 }
void lsst::afw::math::SpatialCellSet::visitAllCandidates ( CandidateVisitor visitor,
bool const  ignoreExceptions = false 
) const

Call the visitor's processCandidate method for every Candidate in the SpatialCellSet (const version)

This is the const version of SpatialCellSet::visitAllCandidates

Parameters
visitorPass this object to every Candidate
ignoreExceptionsIgnore any exceptions thrown by the processing

Definition at line 562 of file SpatialCell.cc.

565  {
566  visitor->reset();
567 
568  for (CellList::const_iterator cell = _cellList.begin(), end = _cellList.end(); cell != end; ++cell) {
569  SpatialCell const *ccell = cell->get(); // the SpatialCellSet's SpatialCells should be const too
570  ccell->visitAllCandidates(visitor, ignoreExceptions, false);
571  }
572 }
void lsst::afw::math::SpatialCellSet::visitCandidates ( CandidateVisitor visitor,
int const  nMaxPerCell = -1,
bool const  ignoreExceptions = false 
)

Call the visitor's processCandidate method for each Candidate in the SpatialCellSet

Note
This is obviously similar to the Design Patterns (Go4) Visitor pattern, but we've simplified the double dispatch (i.e. we don't call a virtual method on SpatialCellCandidate that in turn calls processCandidate(*this), but can be re-defined)
Parameters
visitorPass this object to every Candidate
nMaxPerCellVisit no more than this many Candidates (<= 0: all)
ignoreExceptionsIgnore any exceptions thrown by the processing

Definition at line 510 of file SpatialCell.cc.

514  {
515  visitor->reset();
516 
517  for (CellList::iterator cell = _cellList.begin(), end = _cellList.end(); cell != end; ++cell) {
518  (*cell)->visitCandidates(visitor, nMaxPerCell, ignoreExceptions, false);
519  }
520 }
void lsst::afw::math::SpatialCellSet::visitCandidates ( CandidateVisitor visitor,
int const  nMaxPerCell = -1,
bool const  ignoreExceptions = false 
) const

Call the visitor's processCandidate method for each Candidate in the SpatialCellSet (const version)

This is the const version of SpatialCellSet::visitCandidates

Parameters
visitorPass this object to every Candidate
nMaxPerCellVisit no more than this many Candidates (-ve: all)
ignoreExceptionsIgnore any exceptions thrown by the processing

Definition at line 527 of file SpatialCell.cc.

531  {
532  visitor->reset();
533 
534  for (CellList::const_iterator cell = _cellList.begin(), end = _cellList.end(); cell != end; ++cell) {
535  SpatialCell const *ccell = cell->get(); // the SpatialCellSet's SpatialCells should be const too
536  ccell->visitCandidates(visitor, nMaxPerCell, ignoreExceptions, false);
537  }
538 }

Member Data Documentation

CellList lsst::afw::math::SpatialCellSet::_cellList
private

Definition at line 419 of file SpatialCell.h.

lsst::afw::geom::Box2I lsst::afw::math::SpatialCellSet::_region
private

Definition at line 418 of file SpatialCell.h.


The documentation for this class was generated from the following files: