30 #define __attribute__(x) 40 #include <boost/archive/text_oarchive.hpp> 41 #include <boost/archive/text_iarchive.hpp> 42 #include <boost/archive/binary_oarchive.hpp> 43 #include <boost/archive/binary_iarchive.hpp> 44 #include <boost/archive/xml_oarchive.hpp> 45 #include <boost/archive/xml_iarchive.hpp> 46 #include <boost/serialization/nvp.hpp> 47 #include <boost/serialization/vector.hpp> 49 #include <boost/serialization/export.hpp> 54 #include "lsst/daf/persistence/FormatterImpl.h" 55 #include "lsst/daf/persistence/LogicalLocation.h" 56 #include "lsst/daf/persistence/BoostStorage.h" 57 #include "lsst/daf/persistence/XmlStorage.h" 58 #include "lsst/log/Log.h" 59 #include <lsst/pex/exceptions.h> 60 #include <lsst/pex/policy/Policy.h> 100 LOG_LOGGER _log = LOG_GET(
"afw.math.KernelFormatter");
105 namespace formatters {
111 using boost::serialization::make_nvp;
113 dafPersist::FormatterRegistration KernelFormatter::kernelRegistration(
"Kernel",
typeid(math::Kernel),
115 dafPersist::FormatterRegistration KernelFormatter::fixedKernelRegistration(
"FixedKernel",
116 typeid(math::FixedKernel),
118 dafPersist::FormatterRegistration KernelFormatter::analyticKernelRegistration(
"AnalyticKernel",
119 typeid(math::AnalyticKernel),
121 dafPersist::FormatterRegistration KernelFormatter::deltaFunctionKernelRegistration(
122 "DeltaFunctionKernel",
typeid(math::DeltaFunctionKernel), createInstance);
123 dafPersist::FormatterRegistration KernelFormatter::linearCombinationKernelRegistration(
124 "LinearCombinationKernel",
typeid(math::LinearCombinationKernel), createInstance);
125 dafPersist::FormatterRegistration KernelFormatter::separableKernelRegistration(
"SeparableKernel",
126 typeid(math::SeparableKernel),
129 KernelFormatter::KernelFormatter(std::shared_ptr<pexPolicy::Policy> policy)
130 : dafPersist::Formatter(
typeid(
this)), _policy(policy) {}
132 KernelFormatter::~KernelFormatter(
void) {}
134 void KernelFormatter::write(dafBase::Persistable
const*
persistable,
135 std::shared_ptr<dafPersist::FormatterStorage> storage,
136 std::shared_ptr<dafBase::PropertySet>) {
137 LOGL_DEBUG(_log,
"KernelFormatter write start");
140 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
"Persisting non-Kernel");
143 auto boost = std::dynamic_pointer_cast<dafPersist::BoostStorage>(storage);
145 LOGL_DEBUG(_log,
"KernelFormatter write BoostStorage");
146 boost->getOArchive() & kp;
147 LOGL_DEBUG(_log,
"KernelFormatter write end");
150 auto xml = std::dynamic_pointer_cast<dafPersist::XmlStorage>(storage);
152 LOGL_DEBUG(_log,
"KernelFormatter write XmlStorage");
153 xml->getOArchive() & make_nvp(
"ptr", kp);
154 LOGL_DEBUG(_log,
"KernelFormatter write end");
157 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for Kernel");
160 dafBase::Persistable* KernelFormatter::read(std::shared_ptr<dafPersist::FormatterStorage> storage,
161 std::shared_ptr<dafBase::PropertySet>) {
162 LOGL_DEBUG(_log,
"KernelFormatter read start");
165 auto boost = std::dynamic_pointer_cast<dafPersist::BoostStorage>(storage);
167 LOGL_DEBUG(_log,
"KernelFormatter read BoostStorage");
168 boost->getIArchive() & kp;
169 LOGL_DEBUG(_log,
"KernelFormatter read end");
172 auto xml = std::dynamic_pointer_cast<dafPersist::XmlStorage>(storage);
174 LOGL_DEBUG(_log,
"KernelFormatter read XmlStorage");
175 xml->getIArchive() & make_nvp(
"ptr", kp);
176 LOGL_DEBUG(_log,
"KernelFormatter read end");
179 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for Kernel");
182 void KernelFormatter::update(dafBase::Persistable*, std::shared_ptr<dafPersist::FormatterStorage>,
183 std::shared_ptr<dafBase::PropertySet>) {
184 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
"Unexpected call to update for Kernel");
187 template <
class Archive>
188 void KernelFormatter::delegateSerialize(Archive& ar,
unsigned int const, dafBase::Persistable*
persistable) {
189 LOGL_DEBUG(_log,
"KernelFormatter delegateSerialize start");
192 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
"Serializing non-Kernel");
194 ar& make_nvp(
"base", boost::serialization::base_object<dafBase::Persistable>(*kp));
195 ar& make_nvp(
"width", kp->_width);
196 ar& make_nvp(
"height", kp->_height);
197 ar& make_nvp(
"ctrX", kp->_ctrX);
198 ar& make_nvp(
"ctrY", kp->_ctrY);
199 ar& make_nvp(
"nParams", kp->_nKernelParams);
202 LOGL_DEBUG(_log,
"KernelFormatter delegateSerialize end");
207 template void KernelFormatter::delegateSerialize(boost::archive::text_oarchive& ar,
unsigned int const,
208 dafBase::Persistable*);
209 template void KernelFormatter::delegateSerialize(boost::archive::text_iarchive& ar,
unsigned int const,
210 dafBase::Persistable*);
211 template void KernelFormatter::delegateSerialize(boost::archive::xml_oarchive& ar,
unsigned int const,
212 dafBase::Persistable*);
213 template void KernelFormatter::delegateSerialize(boost::archive::xml_iarchive& ar,
unsigned int const,
214 dafBase::Persistable*);
215 template void KernelFormatter::delegateSerialize(boost::archive::binary_oarchive& ar,
unsigned int const,
216 dafBase::Persistable*);
217 template void KernelFormatter::delegateSerialize(boost::archive::binary_iarchive& ar,
unsigned int const,
218 dafBase::Persistable*);
221 std::shared_ptr<dafPersist::Formatter> KernelFormatter::createInstance(
222 std::shared_ptr<pexPolicy::Policy> policy) {
223 return std::shared_ptr<dafPersist::Formatter>(
new KernelFormatter(policy));
2-dimensional weighted sum of Chebyshev polynomials of the first kind.
1-dimensional Lanczos function
double Guassian (sum of two Gaussians)
2-dimensional polynomial function with cross terms
1-dimensional weighted sum of Chebyshev polynomials of the first kind.
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
2-dimensional integer delta function.
2-dimensional separable Lanczos function
a class used in function calls to indicate that no Function2 is being provided
A base class for image defects.
A kernel that is a linear combination of fixed basis kernels.
a class used in function calls to indicate that no Function1 is being provided
std::vector< SpatialFunctionPtr > _spatialFunctionList
A kernel described by a function.
Kernels are used for convolution with MaskedImages and (eventually) Images.
A kernel that has only one non-zero pixel (of value 1)
A kernel created from an Image.
1-dimensional polynomial function.