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
ImageSlice.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
30 #include <vector>
31 #include "boost/shared_ptr.hpp"
32 
33 #include "lsst/pex/exceptions.h"
35 
36 namespace afwImage = lsst::afw::image;
37 namespace afwMath = lsst::afw::math;
38 namespace ex = lsst::pex::exceptions;
39 
40 
45 template<typename PixelT>
47  image::Image<PixelT> const &img
48  ) :
49  afwImage::Image<PixelT>(img),
50  _sliceType(ROW)
51 {
52 
53  // verify the img is a slice (row or column)
54  if (img.getWidth() != 1 && img.getHeight() != 1) {
55  throw LSST_EXCEPT(ex::OutOfRangeError, "Input image must be a slice (width or height == 1)");
56  } else if (img.getWidth() == 1 && img.getHeight() == 1) {
57  throw LSST_EXCEPT(ex::InvalidParameterError,
58  "1x1 image ambiguous (could be row or column). "
59  "Perhaps a constant would be better than a slice? ");
60  } else if (img.getWidth() == 1 && img.getHeight() != 1) {
62  } else if (img.getHeight() == 1 && img.getWidth() != 1) {
63  _sliceType = ROW;
64  }
65 
66  // what about 1xn images where a 1x1 row slice is desired? ... use a constant instead of a slice
67  // what about nx1 images wehre a 1x1 column slice is desired? ... use a constant instead of a slice
68 }
69 
70 
71 
72 
73 /**************************************************************************
74  *
75  * column operators
76  *
77  **************************************************************************/
78 
79 
80 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
81 // overload +
82 
88 template<typename PixelT>
90  afwImage::Image<PixelT> const &img,
92  ) {
93  typename afwImage::Image<PixelT>::Ptr retImg(new afwImage::Image<PixelT>(img, true));
94  *retImg += slc;
95  return retImg;
96 }
97 
98 
99 
105 template<typename PixelT>
107  afwImage::ImageSlice<PixelT> const &slc,
108  afwImage::Image<PixelT> const &img
109  ) {
110  return afwImage::operator+(img, slc);
111 }
112 
113 
114 
120 template<typename PixelT>
123  afwImage::ImageSlice<PixelT> const &slc
124  ) {
125  afwImage::details::operate<afwImage::details::Plus<PixelT> >(img, slc, slc.getImageSliceType());
126 }
127 
128 
129 
130 // -----------------------------------------------------------------
131 // overload -
132 
133 
134 
140 template<typename PixelT>
142  afwImage::Image<PixelT> const &img,
143  afwImage::ImageSlice<PixelT> const &slc
144  ) {
145  typename afwImage::Image<PixelT>::Ptr retImg(new afwImage::Image<PixelT>(img, true));
146  *retImg -= slc;
147  return retImg;
148 }
149 
150 
156 template<typename PixelT>
159  afwImage::ImageSlice<PixelT> const &slc
160  ) {
161  details::operate<details::Minus<PixelT> >(img, slc, slc.getImageSliceType());
162 }
163 
164 
165 // ******************************************************************
166 // overload *
167 
168 
174 template<typename PixelT>
176  afwImage::Image<PixelT> const &img,
177  afwImage::ImageSlice<PixelT> const &slc
178  ) {
179  typename afwImage::Image<PixelT>::Ptr retImg(new afwImage::Image<PixelT>(img, true));
180  *retImg *= slc;
181  return retImg;
182 }
183 
184 
190 template<typename PixelT>
192  afwImage::ImageSlice<PixelT> const &slc,
193  afwImage::Image<PixelT> const &img
194  ) {
195  return afwImage::operator*(img, slc);
196 }
197 
203 template<typename PixelT>
206  afwImage::ImageSlice<PixelT> const &slc
207  ) {
208  details::operate<details::Mult<PixelT> >(img, slc, slc.getImageSliceType());
209 }
210 
211 
212 
213 
214 // ///////////////////////////////////////////////////////////////////
215 // overload /
216 
217 
223 template<typename PixelT>
225  afwImage::Image<PixelT> const &img,
226  afwImage::ImageSlice<PixelT> const &slc
227  ) {
228  typename afwImage::Image<PixelT>::Ptr retImg(new afwImage::Image<PixelT>(img, true));
229  *retImg /= slc;
230  return retImg;
231 }
232 
233 
239 template<typename PixelT>
242  afwImage::ImageSlice<PixelT> const &slc
243  ) {
244  details::operate<details::Div<PixelT> >(img, slc, slc.getImageSliceType());
245 }
246 
247 
248 
249 
250 /*
251  * Explicit Instantiations
252  *
253  */
255 #define INSTANTIATE_SLICE_OP_SYM(TYPE, OP) \
256  template afwImage::Image<TYPE>::Ptr afwImage::operator OP(afwImage::Image<TYPE> const &img, \
257  afwImage::ImageSlice<TYPE> const &slc); \
258  template afwImage::Image<TYPE>::Ptr afwImage::operator OP(afwImage::ImageSlice<TYPE> const &slc, \
259  afwImage::Image<TYPE> const &img)
260 
261 
262 #define INSTANTIATE_SLICE_OP_ASYM(TYPE, OP) \
263  template afwImage::Image<TYPE>::Ptr afwImage::operator OP(afwImage::Image<TYPE> const &img, \
264  afwImage::ImageSlice<TYPE> const &slc)
265 
266 
267 #define INSTANTIATE_SLICE_OPEQ(TYPE, OP) \
268  template void afwImage::operator OP(afwImage::Image<TYPE> &img, \
269  afwImage::ImageSlice<TYPE> const &slc)
270 
271 
272 
273 #define INSTANTIATE_SLICES(TYPE) \
274  template afwImage::ImageSlice<TYPE>::ImageSlice(afwImage::Image<TYPE> const &image); \
275  INSTANTIATE_SLICE_OP_SYM(TYPE, +); \
276  INSTANTIATE_SLICE_OP_ASYM(TYPE, -); \
277  INSTANTIATE_SLICE_OP_SYM(TYPE, *); \
278  INSTANTIATE_SLICE_OP_ASYM(TYPE, /); \
279  INSTANTIATE_SLICE_OPEQ(TYPE, +=); \
280  INSTANTIATE_SLICE_OPEQ(TYPE, -=); \
281  INSTANTIATE_SLICE_OPEQ(TYPE, *=); \
282  INSTANTIATE_SLICE_OPEQ(TYPE, /=)
283 
284 
285 INSTANTIATE_SLICES(double);
286 INSTANTIATE_SLICES(float);
const Angle operator/(Angle const a, int d)
Definition: Angle.h:274
ImageSlice(Image< PixelT > const &img)
Constructor for ImageSlice.
Definition: ImageSlice.cc:46
Define a single column or row of an Image.
void operator/=(ExtentBase< int, N > &lhs, double rhs)
Definition: Extent.h:413
Include files required for standard LSST Exception handling.
Extent< double, N > & operator+=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
Definition: Extent.h:429
ImageSliceType getImageSliceType() const
Definition: ImageSlice.h:60
Extent< double, N > & operator-=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
Definition: Extent.h:439
ImageSliceType _sliceType
Definition: ImageSlice.h:63
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
const Angle operator+(Angle const a, Angle const d)
Definition: Angle.h:264
const Angle operator*(Angle const a, Angle const d)
Definition: Angle.h:266
void operator*=(ExtentBase< int, N > &lhs, double rhs)
Definition: Extent.h:402
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:237
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
const Angle operator-(Angle const a, Angle const d)
Definition: Angle.h:265
A class to specify a slice of an image.
Definition: ImageSlice.h:54