51 auto nativePoint =
transform(point, cameraSys, getNativeCameraSys());
54 for (
auto const &item :
getIdMap()) {
55 auto detector = item.second;
56 auto pointPixels = detector->transform(nativePoint, getNativeCameraSys(),
PIXELS);
67 auto nativePointList =
transform(pointList, cameraSys, getNativeCameraSys());
69 for (
auto const &item :
getIdMap()) {
70 auto const &detector = item.second;
71 auto pointPixelsList = detector->transform(nativePointList, getNativeCameraSys(),
PIXELS);
72 for (
std::size_t i = 0; i < pointPixelsList.size(); ++i) {
73 auto const &pointPixels = pointPixelsList[i];
79 return detectorListList;
108 Detector::InCameraBuilder
const &detector) {
109 return detector._connections;
114class PersistenceHelper {
116 static PersistenceHelper
const &get() {
117 static PersistenceHelper
const instance;
121 table::Schema schema;
122 table::Key<std::string> name;
123 table::Key<std::string> pupilFactoryName;
124 table::Key<int> transformMap;
129 name(schema.addField<std::string>(
"name",
"Camera name",
"", 0)),
130 pupilFactoryName(schema.addField<std::string>(
131 "pupilFactoryName",
"Fully-qualified name of a Python PupilFactory class",
"", 0)),
132 transformMap(schema.addField<
int>(
"transformMap",
"archive ID for Camera's TransformMap")) {}
134 PersistenceHelper(PersistenceHelper
const &) =
delete;
135 PersistenceHelper(PersistenceHelper &&) =
delete;
137 PersistenceHelper &operator=(PersistenceHelper
const &) =
delete;
138 PersistenceHelper &operator=(PersistenceHelper &&) =
delete;
145 auto const &keys = PersistenceHelper::get();
147 auto record = cat.
addNew();
148 record->set(keys.name,
getName());
173 _pupilFactoryName(pupilFactoryName),
174 _transformMap(
std::move(transformMap)) {}
181 auto const &keys = PersistenceHelper::get();
183 auto const &cat = catalogs[1];
186 auto const &record = cat.front();
187 _name = record.get(keys.name);
188 _pupilFactoryName = record.get(keys.pupilFactoryName);
189 _transformMap = archive.
get<
TransformMap>(record.get(keys.transformMap));
200 for (
auto const &pair : camera.getIdMap()) {
201 BaseCollection::add(Camera::makeDetectorBuilder(*pair.second));
205 for (
auto const &connection : camera.getTransformMap()->getConnections()) {
214 if (connection.fromSys.hasDetectorName()) {
215 assert(connection.toSys.getDetectorName() == connection.fromSys.getDetectorName());
216 auto detector = (*this)[connection.fromSys.getDetectorName()];
217 assert(connection.fromSys == detector->getNativeCoordSys());
218 detector->setTransformFromPixelsTo(CameraSysPrefix(connection.toSys.getSysName()),
219 connection.transform);
221 assert(connection.fromSys == getNativeCameraSys());
222 if (!connection.toSys.hasDetectorName()) {
223 _connections.push_back(connection);
232Camera::Builder::~Builder() noexcept = default;
242 auto field_angle_connection =
244 return c.fromSys == FOCAL_PLANE && c.toSys == FIELD_ANGLE;
246 if (field_angle_connection != connections.
end()) {
247 auto jacobian = field_angle_connection->transform->getJacobian(
lsst::geom::Point2D(0.0, 0.0));
248 if ((jacobian.determinant() < 0) != _focalPlaneParity) {
249 field_angle_connection->transform =
257 for (
auto const &pair :
getIdMap()) {
258 auto const &detectorBuilder = *pair.second;
260 getDetectorBuilderConnections(detectorBuilder);
262 for (
auto const &connection : detectorConnections) {
264 allDetConnections.
push_back(tmpConnection);
268 if ((
std::find(allDetConnections.
begin(), allDetConnections.
end(), connection) ==
269 allDetConnections.
end()) &&
271 allDetConnections.
end())) {
273 detectorBuilder.getOrientation().makeFpPixelTransform(detectorBuilder.getPixelSize()),
274 getNativeCameraSys(), detectorBuilder.getNativeCoordSys()});
276 connections.
insert(connections.
end(), getDetectorBuilderConnections(detectorBuilder).begin(),
277 getDetectorBuilderConnections(detectorBuilder).end());
284 for (
auto const &pair :
getIdMap()) {
285 auto const &detectorBuilder = *pair.second;
286 detectors.
push_back(detectorBuilder.finish(transformMap));
299template <
typename Iter>
300Iter findConnection(Iter first, Iter last,
CameraSys const &toSys) {
301 return std::find_if(first, last, [&toSys](
auto const &connection) {
return connection.toSys == toSys; });
310 (boost::format(
"%s should be added to Detector %s, not Camera") %
314 auto iter = findConnection(_connections.begin(), _connections.end(), toSys);
315 if (iter == _connections.end()) {
323 auto iter = findConnection(_connections.begin(), _connections.end(), toSys);
324 if (iter != _connections.end()) {
325 _connections.erase(iter);
332 auto detector = makeDetectorBuilder(name,
id);
342template class PersistableFacade<cameraGeom::Camera>;
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
A helper class for creating and modifying cameras.
void setTransformFromFocalPlaneTo(CameraSys const &toSys, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform)
Set the transformation from FOCAL_PLANE to the given coordinate system.
Builder(std::string const &name)
Construct a Builder for a completely new Camera with the given name.
std::string getName() const
Return the name of the camera.
void setFocalPlaneParity(bool flipX)
Set whether an x-axis flip should be included in the FOCAL_PLANE to FIELD_ANGLE transform.
std::string getPupilFactoryName() const
Return the fully-qualified name of the Python class that provides this Camera's PupilFactory.
std::shared_ptr< Detector::InCameraBuilder > add(std::string const &name, int id)
Add a new Detector with the given name and ID.
bool discardTransformFromFocalPlaneTo(CameraSys const &toSys)
Remove any transformation from FOCAL_PLANE to the given coordinate system.
std::shared_ptr< Camera const > finish() const
Construct a new Camera from the state of the Builder.
std::shared_ptr< Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const override
Construct a new object from the given InputArchive and vector of catalogs.
static Factory const registration
Camera(Camera const &)=delete
DetectorCollection::List DetectorList
Camera::Builder rebuild() const
Create a Camera::Builder object initialized with this camera's state.
std::shared_ptr< TransformMap const > getTransformMap() const noexcept
Obtain the transform registry.
std::string getPupilFactoryName() const
Return the fully-qualified name of the Python class that provides this Camera's PupilFactory.
std::string getName() const
Return the name of the camera.
DetectorList findDetectors(lsst::geom::Point2D const &point, CameraSys const &cameraSys) const
Find the detectors that cover a point in any camera system.
virtual ~Camera() noexcept
std::vector< DetectorList > findDetectorsList(std::vector< lsst::geom::Point2D > const &pointList, CameraSys const &cameraSys) const
Find the detectors that cover a list of points in any camera system.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
lsst::geom::Point2D transform(lsst::geom::Point2D const &point, CameraSys const &fromSys, CameraSys const &toSys) const
Transform a point from one camera coordinate system to another.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::shared_ptr< afw::geom::TransformPoint2ToPoint2 > getTransform(CameraSys const &fromSys, CameraSys const &toSys) const
Get a transform from one CameraSys to another.
Camera coordinate system; used as a key in in TransformMap.
bool hasDetectorName() const noexcept
Does this have a non-blank detector name?
std::string getSysName() const
Get coordinate system name.
std::string getDetectorName() const
Get detector name, or "" if not a detector-specific coordinate system.
A helper class that allows the properties of a detector to be modified in the course of modifying a f...
std::size_t size() const noexcept
IdMap const & getIdMap() const noexcept
Get a map keyed and ordered by ID.
void add(std::shared_ptr< Detector::InCameraBuilder > detector)
An immutable collection of Detectors that can be accessed by name or ID.
DetectorCollection(List const &list)
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
A vector of catalogs used by Persistable.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
A base class for factory classes used to reconstruct objects from records.
io::CatalogVector CatalogVector
io::InputArchive InputArchive
PersistableFactory(std::string const &name)
Constructor for the factory.
io::OutputArchiveHandle OutputArchiveHandle
A floating-point coordinate rectangle geometry.
bool contains(Point2D const &point) const noexcept
Return true if the box contains the point.
Reports errors in the logical structure of the program.
CameraSys const FOCAL_PLANE
Focal plane coordinates: Position on a 2-d planar approximation to the focal plane (x,...
CameraSysPrefix const PIXELS
Pixel coordinates: Nominal position on the entry surface of a given detector (x, y unbinned pixels).
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(lsst::geom::AffineTransform const &affine)
Wrap an lsst::geom::AffineTransform as a Transform.
Point< double, 2 > Point2D