lsst.afw  14.0-52-g19103d347
transformUtils.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2017 AURA/LSST.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #ifndef LSST_AFW_GEOM_TRANSFORMUTILS_H
25 #define LSST_AFW_GEOM_TRANSFORMUTILS_H
26 
27 #include <memory>
28 #include <vector>
29 
30 #include "astshim.h"
31 #include "ndarray.h"
32 
33 #include "lsst/afw/coord/Coord.h"
34 #include "lsst/afw/geom/Endpoint.h"
37 
38 namespace lsst {
39 namespace afw {
40 namespace geom {
41 namespace detail {
43 constexpr int serializationVersion = 1;
44 
56 template<class Transform>
58 
72 template<class Transform>
73 void writeStream(Transform const & transform, std::ostream & os);
74 
75 /*
76  * Provide definitions here in the header file to avoid the need for explicit instantiations
77  */
78 
79 template<class Transform>
81  int version;
82  is >> version;
83  if (version != 1) {
85  "Unsupported version " + std::to_string(version));
86  }
87  std::string shortClassName;
88  is >> shortClassName;
89  if (shortClassName != Transform::getShortClassName()) {
91  os << "Class name in stream " << shortClassName << " != " << Transform::getShortClassName();
93  }
94  auto astStream = ast::Stream(&is, nullptr);
95  auto astObjectPtr = ast::Channel(astStream).read();
96  auto frameSet = std::dynamic_pointer_cast<ast::FrameSet>(astObjectPtr);
97  if (!frameSet) {
99  os << "The AST serialization was read as a " << astObjectPtr->getClassName()
100  << " instead of a FrameSet";
102  }
103 
104  return std::make_shared<Transform>(*frameSet);
105 }
106 
107 template<class Transform>
109  os << serializationVersion << " " << Transform::getShortClassName();
110  transform.getFrameSet()->show(os, false); // false = do not write comments
111 }
112 
113 } // namespace detail
114 } // namespace geom
115 } // namespace afw
116 } // namespace lsst
117 
118 #endif
std::shared_ptr< const ast::FrameSet > getFrameSet() const
Get the contained frameset.
Definition: Transform.h:144
std::shared_ptr< Transform > readStream(std::istream &is)
Deserialize a Transform from an input stream.
T to_string(T... args)
void writeStream(Transform const &transform, std::ostream &os)
Serialize a Transform to an output stream.
STL class.
static std::string getShortClassName()
Return a short version of the class name with no punctuation.
STL class.
A base class for image defects.
table::Key< table::Array< std::uint8_t > > frameSet
T str(T... args)
T dynamic_pointer_cast(T... args)
constexpr int serializationVersion
version of serialization used when writing (older versions may also be supported when reading) ...
#define LSST_EXCEPT(type,...)
table::Key< int > transform
STL class.
std::shared_ptr< Object > read()
Transform LSST spatial data, such as Point2D and IcrsCoord, using an AST transform.
Definition: Transform.h:69