30 #ifndef LSST_AFW_IMAGE_IMAGEBASE_H
31 #define LSST_AFW_IMAGE_IMAGEBASE_H
45 #include "lsst/daf/base.h"
46 #include "lsst/daf/base/Citizen.h"
47 #include "lsst/pex/exceptions.h"
56 struct ImageWriteOptions;
69 template <
typename ImageT>
81 operator bool()
const {
return _check; }
88 template <
typename PixelT>
90 typedef typename boost::gil::channel_traits<PixelT>::reference
type;
93 template <
typename PixelT>
95 typedef typename boost::gil::channel_traits<PixelT>::const_reference
type;
105 template <
typename PixelT>
106 class ImageBase :
public lsst::daf::base::Persistable,
public lsst::daf::base::Citizen {
108 typedef typename lsst::afw::image::detail::types_traits<PixelT>::view_t _view_t;
109 typedef typename lsst::afw::image::detail::types_traits<PixelT>::const_view_t _const_view_t;
111 typedef ndarray::Manager Manager;
153 typedef typename ndarray::Array<PixelT, 2, 1>
Array;
155 typedef typename ndarray::Array<PixelT const, 2, 1>
ConstArray;
157 template <
typename OtherPixelT>
161 template <
typename SinglePixelT>
171 template <
typename,
typename,
typename>
212 const bool deep =
false);
219 template <
typename OtherPixelT>
222 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
223 "Only deep copies are permitted for ImageBases with different pixel types");
227 copy_and_convert_pixels(rhs._gilView, tmp._gilView);
336 int const roundedIndex =
static_cast<int>(fullIndex + 0.5);
337 double const residual = fullIndex - roundedIndex;
338 return std::pair<int, double>(roundedIndex, residual);
455 Manager::Ptr _manager;
464 const _view_t& view);
471 template <
typename PixelT>
472 void swap(ImageBase<PixelT>& a, ImageBase<PixelT>& b);
477 template <
typename PixelT>
479 int rowStride =
reinterpret_cast<PixelT*
>(row_begin(1)) - reinterpret_cast<PixelT*>(row_begin(0));
480 return ndarray::external(reinterpret_cast<PixelT*>(row_begin(0)),
481 ndarray::makeVector(getHeight(), getWidth()), ndarray::makeVector(rowStride, 1),
485 template <
typename PixelT>
487 int rowStride =
reinterpret_cast<PixelT*
>(row_begin(1)) - reinterpret_cast<PixelT*>(row_begin(0));
488 return ndarray::external(reinterpret_cast<PixelT*>(row_begin(0)),
489 ndarray::makeVector(getHeight(), getWidth()), ndarray::makeVector(rowStride, 1),
boost::gil::channel_traits< PixelT >::reference type
reference type
PixelConstReference get0(int x, int y, CheckIndices const &check) const
void setXY0(geom::Point2I const origin)
Set the ImageBase's origin.
afw::table::PointKey< int > dimensions
iterator begin() const
Return an STL compliant iterator to the start of the image.
_const_view_t::reverse_iterator const_reverse_iterator
An STL compliant const reverse iterator.
x_iterator fast_iterator
A fast STL compliant iterator for contiguous images N.b.
ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
_view_t::reverse_iterator reverse_iterator
An STL compliant reverse iterator.
_view_t::x_iterator xy_x_iterator
An iterator for traversing the pixels in a row, created from an xy_locator.
void set0(int x, int y, const PixelT v, CheckIndices const &check)
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
detail::basic_tag image_category
trait class to identify type of image
_const_view_t::x_iterator const_x_iterator
A const iterator for traversing the pixels in a row.
bool isContiguous() const
PixelT Pixel
A pixel in this ImageBase.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
std::pair< int, double > positionToIndex(double const pos, lsst::afw::image::xOrY const xy) const
Convert image position to index (nearest integer and fractional parts)
double indexToPosition(double ind, lsst::afw::image::xOrY const xy) const
Convert image index to image position.
void assign(ImageBase const &rhs, geom::Box2I const &bbox=geom::Box2I(), ImageOrigin origin=PARENT)
Copy pixels from another image to a specified subregion of this image.
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
Extent< int, 2 > Extent2I
The base class for all image classed (Image, Mask, MaskedImage, ...)
int getX0() const
Return the image's column-origin.
iterator at(int x, int y) const
Return an STL compliant iterator at the point (x, y)
_const_view_t::iterator const_iterator
An STL compliant const iterator.
An integer coordinate rectangle.
_view_t::iterator iterator
An STL compliant iterator.
geom::Point2I getXY0() const
Return the image's origin.
ImageBase & operator<<=(const ImageBase &rhs)
Set the lhs's pixel values to equal the rhs's.
ImageBase & operator=(const ImageBase &rhs)
Shallow assignment operator.
geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
void set0(int x, int y, const PixelT v)
x_iterator row_end(int y) const
Return an x_iterator to the end of the y'th row.
_view_t _getRawView() const
A class to manipulate images, masks, and variance as a single object.
_view_t::y_iterator y_iterator
An iterator for traversing the pixels in a column.
traits class for image categories
A class used to request that array accesses be checked.
int getHeight() const
Return the number of rows in the image.
void swap(ImageBase &rhs)
y_iterator col_end(int x) const
Return an y_iterator to the start of the y'th row.
y_iterator y_at(int x, int y) const
Return an y_iterator to the point (x, y) in the image.
ndarray::Array< PixelT const, 2, 1 > ConstArray
An immutable ndarray representation of the image.
PixelConstReference get0(int x, int y) const
reverse_iterator rbegin() const
Return an STL compliant reverse iterator to the start of the image.
void setXY0(int const x0, int const y0)
Set the ImageBase's origin.
_view_t::xy_locator::const_t const_xy_locator
A const_xy_locator.
void swap(Image< PixelT > &a, Image< PixelT > &b)
reverse_iterator rend() const
Return an STL compliant reverse iterator to the end of the image.
y_iterator col_begin(int x) const
Return an y_iterator to the start of the y'th row.
_const_view_t::y_iterator const_y_iterator
A const iterator for traversing the pixels in a column.
static _view_t _allocateView(geom::Extent2I const &dimensions, Manager::Ptr &manager)
Reference< PixelT >::type PixelReference
A Reference to a PixelT.
static SinglePixel PixelCast(SinglePixelT rhs)
Convert a type to our SinglePixel type.
ImageT::image_category image_category
xy_locator xy_at(int x, int y) const
Return an xy_locator at the point (x, y) in the image.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
static _view_t _makeSubView(geom::Extent2I const &dimensions, geom::Extent2I const &offset, const _view_t &view)
const double PixelZeroPos
position of center of pixel 0
_view_t::xy_locator xy_locator
An xy_locator.
ImageBase(const ImageBase< OtherPixelT > &rhs, const bool deep)
generalised copy constructor
int getWidth() const
Return the number of columns in the image.
ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
PixelT SinglePixel
A single Pixel of the same type as those in the ImageBase.
CheckIndices(bool check=true)
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
std::string const wcsNameForXY0
boost::gil::channel_traits< PixelT >::const_reference type
const reference type
iterator end() const
Return an STL compliant iterator to the end of the image.
A container for an Image and its associated metadata.
metafunction to extract reference type from PixelT
int getY0() const
Return the image's row-origin.
_view_t::y_iterator xy_y_iterator
An iterator for traversing the pixels in a row, created from an xy_locator.
metafunction to extract const reference type from PixelT