LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
KernelFormatter.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 
25 
26 
38 #ifndef __GNUC__
39 # define __attribute__(x) /*NOTHING*/
40 #endif
41 static char const* SVNid __attribute__((unused)) =
42  "$Id$";
43 
45 
46 #include <stdexcept>
47 #include <string>
48 #include <vector>
49 
50 #include <boost/archive/text_oarchive.hpp>
51 #include <boost/archive/text_iarchive.hpp>
52 #include <boost/archive/binary_oarchive.hpp>
53 #include <boost/archive/binary_iarchive.hpp>
54 #include <boost/archive/xml_oarchive.hpp>
55 #include <boost/archive/xml_iarchive.hpp>
56 #include <boost/serialization/nvp.hpp>
57 #include <boost/serialization/vector.hpp>
58 
59 #include <boost/serialization/export.hpp>
60 
61 #include "lsst/afw/math/Kernel.h"
62 #include "lsst/afw/math/Function.h"
68 #include "lsst/log/Log.h"
69 #include <lsst/pex/exceptions.h>
70 #include <lsst/pex/policy/Policy.h>
71 
72 
73 BOOST_CLASS_EXPORT(lsst::afw::math::Kernel)
74 BOOST_CLASS_EXPORT(lsst::afw::math::FixedKernel)
75 BOOST_CLASS_EXPORT(lsst::afw::math::AnalyticKernel)
76 BOOST_CLASS_EXPORT(lsst::afw::math::DeltaFunctionKernel)
77 BOOST_CLASS_EXPORT(lsst::afw::math::LinearCombinationKernel)
78 BOOST_CLASS_EXPORT(lsst::afw::math::SeparableKernel)
79 
80 BOOST_CLASS_EXPORT(lsst::afw::math::Function<float>)
81 BOOST_CLASS_EXPORT(lsst::afw::math::NullFunction1<float>)
82 BOOST_CLASS_EXPORT(lsst::afw::math::NullFunction2<float>)
83 
84 BOOST_CLASS_EXPORT(lsst::afw::math::Function<double>)
85 BOOST_CLASS_EXPORT(lsst::afw::math::NullFunction1<double>)
86 BOOST_CLASS_EXPORT(lsst::afw::math::NullFunction2<double>)
87 
88 BOOST_CLASS_EXPORT(lsst::afw::math::IntegerDeltaFunction2<float>)
89 BOOST_CLASS_EXPORT(lsst::afw::math::GaussianFunction1<float>)
90 BOOST_CLASS_EXPORT(lsst::afw::math::GaussianFunction2<float>)
91 BOOST_CLASS_EXPORT(lsst::afw::math::DoubleGaussianFunction2<float>)
92 BOOST_CLASS_EXPORT(lsst::afw::math::PolynomialFunction1<float>)
93 BOOST_CLASS_EXPORT(lsst::afw::math::PolynomialFunction2<float>)
94 BOOST_CLASS_EXPORT(lsst::afw::math::Chebyshev1Function1<float>)
95 BOOST_CLASS_EXPORT(lsst::afw::math::Chebyshev1Function2<float>)
96 BOOST_CLASS_EXPORT(lsst::afw::math::LanczosFunction1<float>)
97 BOOST_CLASS_EXPORT(lsst::afw::math::LanczosFunction2<float>)
98 
99 BOOST_CLASS_EXPORT(lsst::afw::math::IntegerDeltaFunction2<double>)
100 BOOST_CLASS_EXPORT(lsst::afw::math::GaussianFunction1<double>)
101 BOOST_CLASS_EXPORT(lsst::afw::math::GaussianFunction2<double>)
102 BOOST_CLASS_EXPORT(lsst::afw::math::DoubleGaussianFunction2<double>)
103 BOOST_CLASS_EXPORT(lsst::afw::math::PolynomialFunction1<double>)
104 BOOST_CLASS_EXPORT(lsst::afw::math::PolynomialFunction2<double>)
105 BOOST_CLASS_EXPORT(lsst::afw::math::Chebyshev1Function1<double>)
106 BOOST_CLASS_EXPORT(lsst::afw::math::Chebyshev1Function2<double>)
107 BOOST_CLASS_EXPORT(lsst::afw::math::LanczosFunction1<double>)
108 BOOST_CLASS_EXPORT(lsst::afw::math::LanczosFunction2<double>)
109 
110 namespace {
111 LOG_LOGGER _log = LOG_GET("afw.math.KernelFormatter");
112 }
113 
114 namespace afwMath = lsst::afw::math;
115 namespace afwForm = lsst::afw::formatters;
116 namespace dafBase = lsst::daf::base;
117 namespace dafPersist = lsst::daf::persistence;
118 namespace pexPolicy = lsst::pex::policy;
119 
120 using boost::serialization::make_nvp;
121 
127  "Kernel", typeid(afwMath::Kernel), createInstance);
130  "FixedKernel", typeid(afwMath::FixedKernel), createInstance);
133  "AnalyticKernel", typeid(afwMath::AnalyticKernel), createInstance);
136  "DeltaFunctionKernel", typeid(afwMath::DeltaFunctionKernel),
137  createInstance);
140  "LinearCombinationKernel", typeid(afwMath::LinearCombinationKernel),
141  createInstance);
144  "SeparableKernel", typeid(afwMath::SeparableKernel), createInstance);
145 
150  pexPolicy::Policy::Ptr policy) :
151  dafPersist::Formatter(typeid(this)), _policy(policy) {
152 }
153 
157 }
158 
160  dafBase::Persistable const* persistable,
161  dafPersist::Storage::Ptr storage,
163  LOGL_DEBUG(_log, "KernelFormatter write start");
164  afwMath::Kernel const* kp =
165  dynamic_cast<afwMath::Kernel const*>(persistable);
166  if (kp == 0) {
167  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Kernel");
168  }
169  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
170  LOGL_DEBUG(_log, "KernelFormatter write BoostStorage");
171  dafPersist::BoostStorage* boost =
172  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
173  boost->getOArchive() & kp;
174  LOGL_DEBUG(_log, "KernelFormatter write end");
175  return;
176  }
177  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
178  LOGL_DEBUG(_log, "KernelFormatter write XmlStorage");
180  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
181  xml->getOArchive() & make_nvp("ptr", kp);
182  LOGL_DEBUG(_log, "KernelFormatter write end");
183  return;
184  }
185  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Kernel");
186 }
187 
190  LOGL_DEBUG(_log, "KernelFormatter read start");
191  afwMath::Kernel* kp;
192  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
193  LOGL_DEBUG(_log, "KernelFormatter read BoostStorage");
194  dafPersist::BoostStorage* boost =
195  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
196  boost->getIArchive() & kp;
197  LOGL_DEBUG(_log, "KernelFormatter read end");
198  return kp;
199  }
200  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
201  LOGL_DEBUG(_log, "KernelFormatter read XmlStorage");
203  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
204  xml->getIArchive() & make_nvp("ptr", kp);
205  LOGL_DEBUG(_log, "KernelFormatter read end");
206  return kp;
207  }
208  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Kernel");
209 }
210 
214  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Kernel");
215 }
216 
222 template <class Archive>
224  Archive& ar, unsigned int const, dafBase::Persistable* persistable) {
225  LOGL_DEBUG(_log, "KernelFormatter delegateSerialize start");
226  afwMath::Kernel* kp =
227  dynamic_cast<afwMath::Kernel*>(persistable);
228  if (kp == 0) {
229  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Kernel");
230  }
231  ar & make_nvp("base",
232  boost::serialization::base_object<dafBase::Persistable>(*kp));
233  ar & make_nvp("width", kp->_width);
234  ar & make_nvp("height", kp->_height);
235  ar & make_nvp("ctrX", kp->_ctrX);
236  ar & make_nvp("ctrY", kp->_ctrY);
237  ar & make_nvp("nParams", kp->_nKernelParams);
238  ar & make_nvp("spatialFunctionList", kp->_spatialFunctionList);
239 
240  LOGL_DEBUG(_log, "KernelFormatter delegateSerialize end");
241 }
242 
244  boost::archive::text_oarchive& ar, unsigned int const, dafBase::Persistable*);
246  boost::archive::text_iarchive& ar, unsigned int const, dafBase::Persistable*);
248  boost::archive::xml_oarchive& ar, unsigned int const, dafBase::Persistable*);
250  boost::archive::xml_iarchive& ar, unsigned int const, dafBase::Persistable*);
252  boost::archive::binary_oarchive& ar, unsigned int const, dafBase::Persistable*);
254  boost::archive::binary_iarchive& ar, unsigned int const, dafBase::Persistable*);
255 
256 
262  pexPolicy::Policy::Ptr policy) {
264 }
static lsst::daf::persistence::Formatter::Ptr createInstance(lsst::pex::policy::Policy::Ptr policy)
static lsst::daf::persistence::FormatterRegistration fixedKernelRegistration
Declare the Kernel class and subclasses.
std::shared_ptr< Storage > Ptr
Definition: Storage.h:62
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:85
Class for XML file storage.
Definition: XmlStorage.h:58
#define LOGL_DEBUG(logger, message...)
Definition: Log.h:513
virtual lsst::daf::base::Persistable * read(lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
std::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
virtual boost::archive::text_iarchive & getIArchive(void)
std::shared_ptr< Policy > Ptr
Definition: Policy.h:172
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:983
static lsst::daf::persistence::FormatterRegistration separableKernelRegistration
static lsst::daf::persistence::FormatterRegistration kernelRegistration
Define a collection of useful Functions.
virtual void write(lsst::daf::base::Persistable const *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Construct a static instance of this helper class to register a Formatter subclass in the FormatterReg...
Definition: Formatter.h:138
virtual boost::archive::xml_iarchive & getIArchive(void)
Definition: XmlStorage.cc:114
#define LOG_GET(logger)
Definition: Log.h:83
virtual void update(lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
static lsst::daf::persistence::FormatterRegistration analyticKernelRegistration
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Interface for XmlStorage class.
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:811
unsigned int _nKernelParams
Definition: Kernel.h:530
KernelFormatter(lsst::pex::policy::Policy::Ptr policy)
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual boost::archive::text_oarchive & getOArchive(void)
Auxiliary global template function for Formatter subclasses.
Interface for KernelFormatter class.
virtual boost::archive::xml_oarchive & getOArchive(void)
Definition: XmlStorage.cc:107
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:521
static lsst::daf::persistence::FormatterRegistration deltaFunctionKernelRegistration
Define the basic Function classes.
Class for boost::serialization storage.
Definition: BoostStorage.h:59
Base class for all persistable classes.
Definition: Persistable.h:74
#define __attribute__(x)
Include files required for standard LSST Exception handling.
A kernel described by a function.
Definition: Kernel.h:625
Interface for LogicalLocation class.
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:131
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:741
#define LOG_LOGGER
Definition: Log.h:712
A kernel created from an Image.
Definition: Kernel.h:548
static lsst::daf::persistence::FormatterRegistration linearCombinationKernelRegistration
Interface for BoostStorage class.