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
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/pex/exceptions.h>
69 #include <lsst/pex/logging/Trace.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 #define EXEC_TRACE 20
111 static void execTrace(std::string s, int level = EXEC_TRACE) {
112  lsst::pex::logging::Trace("afw.math.KernelFormatter", level, s);
113 }
114 
115 namespace afwMath = lsst::afw::math;
116 namespace afwForm = lsst::afw::formatters;
117 namespace dafBase = lsst::daf::base;
118 namespace dafPersist = lsst::daf::persistence;
119 namespace pexPolicy = lsst::pex::policy;
120 
121 using boost::serialization::make_nvp;
122 
128  "Kernel", typeid(afwMath::Kernel), createInstance);
131  "FixedKernel", typeid(afwMath::FixedKernel), createInstance);
134  "AnalyticKernel", typeid(afwMath::AnalyticKernel), createInstance);
137  "DeltaFunctionKernel", typeid(afwMath::DeltaFunctionKernel),
138  createInstance);
141  "LinearCombinationKernel", typeid(afwMath::LinearCombinationKernel),
142  createInstance);
145  "SeparableKernel", typeid(afwMath::SeparableKernel), createInstance);
146 
151  pexPolicy::Policy::Ptr policy) :
152  dafPersist::Formatter(typeid(this)), _policy(policy) {
153 }
154 
158 }
159 
161  dafBase::Persistable const* persistable,
162  dafPersist::Storage::Ptr storage,
164  execTrace("KernelFormatter write start");
165  afwMath::Kernel const* kp =
166  dynamic_cast<afwMath::Kernel const*>(persistable);
167  if (kp == 0) {
168  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Kernel");
169  }
170  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
171  execTrace("KernelFormatter write BoostStorage");
172  dafPersist::BoostStorage* boost =
173  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
174  boost->getOArchive() & kp;
175  execTrace("KernelFormatter write end");
176  return;
177  }
178  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
179  execTrace("KernelFormatter write XmlStorage");
181  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
182  xml->getOArchive() & make_nvp("ptr", kp);
183  execTrace("KernelFormatter write end");
184  return;
185  }
186  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Kernel");
187 }
188 
191  execTrace("KernelFormatter read start");
192  afwMath::Kernel* kp;
193  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
194  execTrace("KernelFormatter read BoostStorage");
195  dafPersist::BoostStorage* boost =
196  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
197  boost->getIArchive() & kp;
198  execTrace("KernelFormatter read end");
199  return kp;
200  }
201  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
202  execTrace("KernelFormatter read XmlStorage");
204  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
205  xml->getIArchive() & make_nvp("ptr", kp);
206  execTrace("KernelFormatter read end");
207  return kp;
208  }
209  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Kernel");
210 }
211 
215  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Kernel");
216 }
217 
224 template <class Archive>
226  Archive& ar, unsigned int const, dafBase::Persistable* persistable) {
227  execTrace("KernelFormatter delegateSerialize start");
228  afwMath::Kernel* kp =
229  dynamic_cast<afwMath::Kernel*>(persistable);
230  if (kp == 0) {
231  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Kernel");
232  }
233  ar & make_nvp("base",
234  boost::serialization::base_object<dafBase::Persistable>(*kp));
235  ar & make_nvp("width", kp->_width);
236  ar & make_nvp("height", kp->_height);
237  ar & make_nvp("ctrX", kp->_ctrX);
238  ar & make_nvp("ctrY", kp->_ctrY);
239  ar & make_nvp("nParams", kp->_nKernelParams);
240  ar & make_nvp("spatialFunctionList", kp->_spatialFunctionList);
241 
242  execTrace("KernelFormatter delegateSerialize end");
243 }
244 
246  boost::archive::text_oarchive& ar, unsigned int const, dafBase::Persistable*);
248  boost::archive::text_iarchive& ar, unsigned int const, dafBase::Persistable*);
250  boost::archive::xml_oarchive& ar, unsigned int const, dafBase::Persistable*);
252  boost::archive::xml_iarchive& ar, unsigned int const, dafBase::Persistable*);
254  boost::archive::binary_oarchive& ar, unsigned int const, dafBase::Persistable*);
256  boost::archive::binary_iarchive& ar, unsigned int const, dafBase::Persistable*);
257 
258 
264  pexPolicy::Policy::Ptr policy) {
266 }
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.
Class for XML file storage.
Definition: XmlStorage.h:57
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
virtual lsst::daf::base::Persistable * read(lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Include files required for standard LSST Exception handling.
virtual boost::archive::text_iarchive & getIArchive(void)
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
definition of the Trace messaging facilities
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:986
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)
limited backward compatibility to the DC2 run-time trace facilities
Definition: Trace.h:93
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
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:814
unsigned int _nKernelParams
Definition: Kernel.h:533
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
boost::shared_ptr< Storage > Ptr
Definition: Storage.h:62
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:524
static lsst::daf::persistence::FormatterRegistration deltaFunctionKernelRegistration
Define the basic Function classes.
Class for boost::serialization storage.
Definition: BoostStorage.h:58
Base class for all persistable classes.
Definition: Persistable.h:74
#define __attribute__(x)
A kernel described by a function.
Definition: Kernel.h:628
Interface for LogicalLocation class.
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:744
A kernel created from an Image.
Definition: Kernel.h:551
static lsst::daf::persistence::FormatterRegistration linearCombinationKernelRegistration
#define EXEC_TRACE
Interface for BoostStorage class.