LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
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)
Factory method for KernelFormatter.
static lsst::daf::persistence::FormatterRegistration fixedKernelRegistration
std::shared_ptr< Policy > Ptr
Definition: Policy.h:172
Declare the Kernel class and subclasses.
#define LOG_LOGGER
Definition: Log.h:712
Class for XML file storage.
Definition: XmlStorage.h:58
virtual ~KernelFormatter(void)
Minimal destructor.
virtual lsst::daf::base::Persistable * read(lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Read a Persistable instance from a Storage instance.
Include files required for standard LSST Exception handling.
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
std::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
static lsst::daf::persistence::FormatterRegistration kernelRegistration
Register this Formatter subclass through a static instance of FormatterRegistration.
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)
Write a Persistable instance to a Storage instance.
Construct a static instance of this helper class to register a Formatter subclass in the FormatterReg...
Definition: Formatter.h:138
virtual boost::archive::text_oarchive & getOArchive(void)
Get a boost::serialization archive suitable for output.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
virtual void update(lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Update an existing Persistable instance with information from an additional Storage instance...
LSST DM logging module built on log4cxx.
static lsst::daf::persistence::FormatterRegistration analyticKernelRegistration
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Serialize a Kernel to a Boost archive.
Interface for XmlStorage class.
virtual boost::archive::xml_iarchive & getIArchive(void)
Get a boost::serialization XML archive suitable for input.
Definition: XmlStorage.cc:114
std::shared_ptr< Storage > Ptr
Definition: Storage.h:62
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)
Constructor.
virtual boost::archive::text_iarchive & getIArchive(void)
Get a boost::serialization archive suitable for input.
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
Auxiliary global template function for Formatter subclasses.
Interface for KernelFormatter class.
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
virtual boost::archive::xml_oarchive & getOArchive(void)
Get a boost::serialization XML archive suitable for output.
Definition: XmlStorage.cc:107
#define __attribute__(x)
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:85
A kernel described by a function.
Definition: Kernel.h:625
#define LOG_GET(logger)
Returns a Log object associated with logger.
Definition: Log.h:83
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
A kernel created from an Image.
Definition: Kernel.h:548
static lsst::daf::persistence::FormatterRegistration linearCombinationKernelRegistration
Interface for BoostStorage class.