LSSTApplications  16.0+42,16.0-1-gce273f5+8,16.0-10-g230e10e+1,16.0-11-g9fe0e56+17,16.0-11-gce733cf+17,16.0-12-g5ad1ebf+9,16.0-12-gc85596e+2,16.0-13-gde155d7+2,16.0-14-g9428de4d,16.0-14-gc1cf4a94+2,16.0-15-g8e16a51+14,16.0-2-g0febb12+7,16.0-2-g839ba83+32,16.0-2-g9d5294e+22,16.0-2-gab3db49+7,16.0-2-gf41ba6b+6,16.0-2-gf4e7cdd+5,16.0-3-g6923fb6+15,16.0-3-g8e51203+2,16.0-3-g9645794+6,16.0-3-gcfd6c53+20,16.0-35-g34c7dfe62+1,16.0-4-g03cf288+11,16.0-4-g32d12de,16.0-4-g5f3a788+7,16.0-4-g7690030+30,16.0-4-g8a0f11a+16,16.0-4-ga5d8928+16,16.0-5-g0da18be+7,16.0-5-g4940a70,16.0-5-g563880a+2,16.0-5-g7742071+2,16.0-5-gb3f8a4b+26,16.0-6-g3610b4f+5,16.0-6-gf0acd13+14,16.0-8-g4dec96c+7,16.0-8-gc315727+16,16.0-9-g1de645c+7,16.0-9-gcc4efb7+6,w.2018.36
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  * Implementation of KernelFormatter class
27  */
28 
29 #ifndef __GNUC__
30 #define __attribute__(x) /*NOTHING*/
31 #endif
32 static char const* SVNid __attribute__((unused)) = "$Id$";
33 
35 
36 #include <stdexcept>
37 #include <string>
38 #include <vector>
39 
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>
48 
49 #include <boost/serialization/export.hpp>
50 
51 #include "lsst/afw/math/Kernel.h"
52 #include "lsst/afw/math/Function.h"
58 #include "lsst/log/Log.h"
59 #include <lsst/pex/exceptions.h>
60 #include <lsst/pex/policy/Policy.h>
61 
62 BOOST_CLASS_EXPORT(lsst::afw::math::Kernel)
63 BOOST_CLASS_EXPORT(lsst::afw::math::FixedKernel)
64 BOOST_CLASS_EXPORT(lsst::afw::math::AnalyticKernel)
65 BOOST_CLASS_EXPORT(lsst::afw::math::DeltaFunctionKernel)
67 BOOST_CLASS_EXPORT(lsst::afw::math::SeparableKernel)
68 
69 BOOST_CLASS_EXPORT(lsst::afw::math::Function<float>)
70 BOOST_CLASS_EXPORT(lsst::afw::math::NullFunction1<float>)
71 BOOST_CLASS_EXPORT(lsst::afw::math::NullFunction2<float>)
72 
73 BOOST_CLASS_EXPORT(lsst::afw::math::Function<double>)
76 
87 
98 
99 namespace {
100 LOG_LOGGER _log = LOG_GET("afw.math.KernelFormatter");
101 }
102 
103 namespace lsst {
104 namespace afw {
105 namespace formatters {
106 
107 namespace dafBase = lsst::daf::base;
109 namespace pexPolicy = lsst::pex::policy;
110 
111 using boost::serialization::make_nvp;
112 
113 dafPersist::FormatterRegistration KernelFormatter::kernelRegistration("Kernel", typeid(math::Kernel),
114  createInstance);
115 dafPersist::FormatterRegistration KernelFormatter::fixedKernelRegistration("FixedKernel",
116  typeid(math::FixedKernel),
117  createInstance);
118 dafPersist::FormatterRegistration KernelFormatter::analyticKernelRegistration("AnalyticKernel",
119  typeid(math::AnalyticKernel),
120  createInstance);
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),
127  createInstance);
128 
129 KernelFormatter::KernelFormatter(std::shared_ptr<pexPolicy::Policy> policy)
130  : dafPersist::Formatter(typeid(this)), _policy(policy) {}
131 
132 KernelFormatter::KernelFormatter(KernelFormatter const&) = default;
133 KernelFormatter::KernelFormatter(KernelFormatter&&) = default;
134 KernelFormatter& KernelFormatter::operator=(KernelFormatter const&) = default;
135 KernelFormatter& KernelFormatter::operator=(KernelFormatter&&) = default;
136 
137 KernelFormatter::~KernelFormatter() = default;
138 
139 void KernelFormatter::write(dafBase::Persistable const* persistable,
142  LOGL_DEBUG(_log, "KernelFormatter write start");
143  math::Kernel const* kp = dynamic_cast<math::Kernel const*>(persistable);
144  if (kp == 0) {
145  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Persisting non-Kernel");
146  }
147  // TODO: Replace this with something better in DM-10776
149  if (boost) {
150  LOGL_DEBUG(_log, "KernelFormatter write BoostStorage");
151  boost->getOArchive() & kp;
152  LOGL_DEBUG(_log, "KernelFormatter write end");
153  return;
154  }
156  if (xml) {
157  LOGL_DEBUG(_log, "KernelFormatter write XmlStorage");
158  xml->getOArchive() & make_nvp("ptr", kp);
159  LOGL_DEBUG(_log, "KernelFormatter write end");
160  return;
161  }
162  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Kernel");
163 }
164 
167  LOGL_DEBUG(_log, "KernelFormatter read start");
168  math::Kernel* kp;
169  // TODO: Replace this with something better in DM-10776
171  if (boost) {
172  LOGL_DEBUG(_log, "KernelFormatter read BoostStorage");
173  boost->getIArchive() & kp;
174  LOGL_DEBUG(_log, "KernelFormatter read end");
175  return kp;
176  }
178  if (xml) {
179  LOGL_DEBUG(_log, "KernelFormatter read XmlStorage");
180  xml->getIArchive() & make_nvp("ptr", kp);
181  LOGL_DEBUG(_log, "KernelFormatter read end");
182  return kp;
183  }
184  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Kernel");
185 }
186 
189  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Unexpected call to update for Kernel");
190 }
191 
192 template <class Archive>
193 void KernelFormatter::delegateSerialize(Archive& ar, unsigned int const, dafBase::Persistable* persistable) {
194  LOGL_DEBUG(_log, "KernelFormatter delegateSerialize start");
195  math::Kernel* kp = dynamic_cast<math::Kernel*>(persistable);
196  if (kp == 0) {
197  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Serializing non-Kernel");
198  }
199  ar& make_nvp("base", boost::serialization::base_object<dafBase::Persistable>(*kp));
200  ar& make_nvp("width", kp->_width);
201  ar& make_nvp("height", kp->_height);
202  ar& make_nvp("ctrX", kp->_ctrX);
203  ar& make_nvp("ctrY", kp->_ctrY);
204  ar& make_nvp("nParams", kp->_nKernelParams);
205  ar& make_nvp("spatialFunctionList", kp->_spatialFunctionList);
206 
207  LOGL_DEBUG(_log, "KernelFormatter delegateSerialize end");
208 }
209 
210 // Explicit template specializations confuse Doxygen, tell it to ignore them
212 template void KernelFormatter::delegateSerialize(boost::archive::text_oarchive& ar, unsigned int const,
214 template void KernelFormatter::delegateSerialize(boost::archive::text_iarchive& ar, unsigned int const,
216 template void KernelFormatter::delegateSerialize(boost::archive::xml_oarchive& ar, unsigned int const,
218 template void KernelFormatter::delegateSerialize(boost::archive::xml_iarchive& ar, unsigned int const,
220 template void KernelFormatter::delegateSerialize(boost::archive::binary_oarchive& ar, unsigned int const,
222 template void KernelFormatter::delegateSerialize(boost::archive::binary_iarchive& ar, unsigned int const,
225 
226 std::shared_ptr<dafPersist::Formatter> KernelFormatter::createInstance(
229 }
230 } // namespace formatters
231 } // namespace afw
232 } // namespace lsst
2-dimensional weighted sum of Chebyshev polynomials of the first kind.
#define LOG_LOGGER
Definition: Log.h:712
Class for XML file storage.
Definition: XmlStorage.h:58
Definition: Span.h:36
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)
Definition: Kernel.h:949
2-dimensional integer delta function.
Construct a static instance of this helper class to register a Formatter subclass in the FormatterReg...
Definition: Formatter.h:138
2-dimensional separable Lanczos function
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
LSST DM logging module built on log4cxx.
a class used in function calls to indicate that no Function2 is being provided
Definition: Function.h:502
Interface for XmlStorage class.
A base class for image defects.
Definition: cameraGeom.dox:3
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:777
T dynamic_pointer_cast(T... args)
Abstract base class for all formatters.
Definition: Formatter.h:79
Basic Function class.
Definition: Function.h:90
a class used in function calls to indicate that no Function1 is being provided
Definition: Function.h:478
Formatter for persistence of Kernel instances.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
Auxiliary global template function for Formatter subclasses.
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:499
Class for boost::serialization storage.
Definition: BoostStorage.h:59
Base class for all persistable classes.
Definition: Persistable.h:73
void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Template function that serializes a Persistable using boost::serialization.
Definition: FormatterImpl.h:58
#define __attribute__(x)
A kernel described by a function.
Definition: Kernel.h:595
#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:123
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:710
A kernel created from an Image.
Definition: Kernel.h:523
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
1-dimensional polynomial function.
Interface for BoostStorage class.