39 # define __attribute__(x)
43 #include "boost/scoped_ptr.hpp"
44 #include "boost/serialization/shared_ptr.hpp"
45 #include "boost/serialization/binary_object.hpp"
46 #include "boost/serialization/nvp.hpp"
48 #include <boost/archive/text_oarchive.hpp>
49 #include <boost/archive/text_iarchive.hpp>
50 #include <boost/archive/binary_oarchive.hpp>
51 #include <boost/archive/binary_iarchive.hpp>
61 static void execTrace(std::string s,
int level =
EXEC_TRACE) {
65 using boost::serialization::make_nvp;
74 namespace afwGeom = lsst::afw::geom;
78 namespace formatters {
80 template <
typename ImagePixelT>
83 static std::string
name();
87 static std::string
name =
"ImageU";
91 static std::string
name =
"ImageI";
95 static std::string
name =
"ImageF";
99 static std::string
name =
"ImageD";
103 static std::string
name =
"ImageL";
107 template <
typename ImagePixelT>
113 template <
typename ImagePixelT>
118 lsst::daf::persistence::Formatter(typeid(this))
122 template <
typename ImagePixelT>
128 namespace dafBase = lsst::daf::base;
132 template <
typename ImagePixelT>
135 Storage::Ptr storage,
138 execTrace(
"ImageFormatter write start");
141 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-Image");
144 execTrace(
"ImageFormatter write BoostStorage");
147 execTrace(
"ImageFormatter write end");
150 else if (
typeid(*storage) ==
typeid(
XmlStorage)) {
151 execTrace(
"ImageFormatter write XmlStorage");
154 execTrace(
"ImageFormatter write end");
157 else if (
typeid(*storage) ==
typeid(
FitsStorage)) {
158 execTrace(
"ImageFormatter write FitsStorage");
166 execTrace(
"ImageFormatter write end");
169 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Image");
172 template <
typename ImagePixelT>
175 execTrace(
"ImageFormatter read start");
177 execTrace(
"ImageFormatter read BoostStorage");
181 execTrace(
"ImageFormatter read end");
184 else if (
typeid(*storage) ==
typeid(
XmlStorage)) {
185 execTrace(
"ImageFormatter read XmlStorage");
189 execTrace(
"ImageFormatter read end");
194 execTrace(
"ImageFormatter read FitsStorage");
197 if (additionalData->exists(
"llcX")) {
198 int llcX = additionalData->get<
int>(
"llcX");
199 int llcY = additionalData->get<
int>(
"llcY");
200 int width = additionalData->get<
int>(
"width");
201 int height = additionalData->get<
int>(
"height");
208 if (additionalData->exists(
"imageOrigin")) {
209 std::string originStr = additionalData->get<std::string>(
"imageOrigin");
210 if (originStr ==
"LOCAL") {
212 }
else if (originStr ==
"PARENT") {
216 lsst::pex::exceptions::RuntimeError,
217 (
boost::format(
"Unknown ImageOrigin type %s specified in additional"
218 "data for retrieving Image from fits")%originStr
235 execTrace(
"ImageFormatter read end");
238 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Image");
241 template <
typename ImagePixelT>
246 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for Image");
249 template <
typename ImagePixelT>
template <
class Archive>
251 Archive& ar,
int const,
Persistable* persistable) {
252 execTrace(
"ImageFormatter delegateSerialize start");
255 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-Image");
258 if (Archive::is_saving::value) {
262 ar & make_nvp(
"width", width) & make_nvp(
"height", height);
263 if (Archive::is_loading::value) {
264 boost::scoped_ptr<Image<ImagePixelT> > ni(
268 ar & make_nvp(
"array",
269 boost::serialization::make_array(array.getData(), array.getNumElements()));
279 template <
typename ImagePixelT>
285 #define InstantiateFormatter(ImagePixelT) \
286 template class ImageFormatter<ImagePixelT >; \
287 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::text_oarchive&, int const, Persistable*); \
288 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::text_iarchive&, int const, Persistable*); \
289 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::xml_oarchive&, int const, Persistable*); \
290 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::xml_iarchive&, int const, Persistable*); \
291 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::binary_oarchive&, int const, Persistable*); \
292 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::binary_iarchive&, int const, Persistable*);
300 #undef InstantiateSerializer
Class for XML file storage.
table::Key< std::string > name
daf_persistence package header file
virtual boost::archive::text_iarchive & getIArchive(void)
boost::shared_ptr< PropertySet > Ptr
virtual std::string const & getPath(void)
boost::shared_ptr< Policy > Ptr
Array< T, N, C_ > dynamic_dimension_cast(Array< T, N, C > const &array)
definition of the Trace messaging facilities
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
limited backward compatibility to the DC2 run-time trace facilities
Class for FITS file storage.
virtual boost::archive::xml_iarchive & getIArchive(void)
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
Write an image to a regular FITS file.
An integer coordinate rectangle.
table::Key< table::Array< Kernel::Pixel > > image
void ImageT ImageT int float saturatedPixelValue int const width
int getNumElements() const
Return the total number of elements in the array.
int getHeight() const
Return the number of rows in the image.
Element * getData() const
Return a raw pointer to the first element of the array.
void ImageT ImageT int float saturatedPixelValue int const height
#define LSST_EXCEPT(type,...)
bool empty() const
Return true if the first dimension has no elements.
virtual boost::archive::text_oarchive & getOArchive(void)
A multidimensional strided array.
virtual boost::archive::xml_oarchive & getOArchive(void)
Class for boost::serialization storage.
Base class for all persistable classes.
int getWidth() const
Return the number of columns in the image.
A class to represent a 2-dimensional array of pixels.
Abstract base class for storage implementations.