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
DecoratedImage.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
27 #include <iostream>
28 #include "boost/format.hpp"
29 
30 #include "lsst/pex/exceptions.h"
31 #include "lsst/afw/image/Image.h"
32 
33 namespace image = lsst::afw::image;
34 namespace geom = lsst::afw::geom;
35 
36 template<typename PixelT>
38  // safer to initialize a smart pointer as a named variable
40  setMetadata(metadata);
41  _gain = 0;
42 }
43 
45 template<typename PixelT>
47  geom::Extent2I const & dimensions
48 ) :
49  lsst::daf::base::Citizen(typeid(this)),
50  _image(new Image<PixelT>(dimensions))
51 {
52  init();
53 }
59 template<typename PixelT>
61  geom::Box2I const & bbox // (width, height) and origin of the desired Image
62 ) :
63  lsst::daf::base::Citizen(typeid(this)),
64  _image(new Image<PixelT>(bbox))
65 {
66  init();
67 }
73 template<typename PixelT>
75  PTR(Image<PixelT>) rhs
76 ) :
77  lsst::daf::base::Citizen(typeid(this)),
78  _image(rhs)
79 {
80  init();
81 }
87 template<typename PixelT>
89  const DecoratedImage& src,
90  const bool deep
91 ) :
92  lsst::daf::base::Citizen(typeid(this)),
93  _image(new Image<PixelT>(*src._image, deep)), _gain(src._gain)
94 {
95  setMetadata(src.getMetadata());
96 }
102 template<typename PixelT>
104  DecoratedImage tmp(src);
105  swap(tmp); // See Meyers, Effective C++, Item 11
106 
107  return *this;
108 }
109 
110 template<typename PixelT>
112  using std::swap; // See Meyers, Effective C++, Item 25
113 
114  swap(_image, rhs._image); // just swapping the pointers
115  swap(_gain, rhs._gain);
116 }
117 
118 template<typename PixelT>
120  a.swap(b);
121 }
122 
123 /************************************************************************************************************/
124 //
125 // FITS code
126 //
127 #include <boost/mpl/vector.hpp>
128 
129 #include "lsst/pex/exceptions.h"
130 #include "lsst/afw/image/Image.h"
131 
132 #include "boost/gil/gil_all.hpp"
138 template<typename PixelT>
140  const int hdu,
141  geom::Box2I const& bbox,
142  ImageOrigin const origin
143  ) :
144  lsst::daf::base::Citizen(typeid(this))
145 {
146  init();
147  _image = typename Image<PixelT>::Ptr(new Image<PixelT>(fileName, hdu, getMetadata(), bbox, origin));
148 }
149 
150 /************************************************************************************************************/
154 template<typename PixelT>
156  std::string const& fileName,
157  CONST_PTR(daf::base::PropertySet) metadata_i,
158  std::string const& mode
159 ) const {
161 
162  if (metadata_i) {
163  metadata = getMetadata()->deepCopy();
164  metadata->combine(metadata_i);
165  } else {
166  metadata = getMetadata();
167  }
168 
169  getImage()->writeFits(fileName, metadata, mode);
170 }
171 
172 /************************************************************************************************************/
173 //
174 // Explicit instantiations
175 //
177 template class image::DecoratedImage<int>;
178 template class image::DecoratedImage<float>;
179 template class image::DecoratedImage<double>;
181 
DecoratedImage(const geom::Extent2I &dimensions=geom::Extent2I())
Create an image of the specified size.
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:291
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
Include files required for standard LSST Exception handling.
boost::shared_ptr< Image< PixelT > > _image
Definition: Image.h:678
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
#define PTR(...)
Definition: base.h:41
void swap(DecoratedImage &rhs)
An integer coordinate rectangle.
Definition: Box.h:53
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
boost::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
Definition: Image.h:639
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:42
Support for 2-D images.
boost::shared_ptr< Image< PixelT > > Ptr
Definition: Image.h:418
DecoratedImage & operator=(const DecoratedImage &image)
void writeFits(std::string const &fileName, boost::shared_ptr< lsst::daf::base::PropertySet const > metadata=boost::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Class for storing generic metadata.
Definition: PropertySet.h:82
#define CONST_PTR(...)
Definition: base.h:47
afw::table::Key< double > b
void setMetadata(boost::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition: Image.h:640
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
A container for an Image and its associated metadata.
Definition: Image.h:614