LSST Applications g00274db5b6+edbf708997,g00d0e8bbd7+edbf708997,g199a45376c+5137f08352,g1fd858c14a+1d4b6db739,g262e1987ae+f4d9505c4f,g29ae962dfc+7156fb1a53,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3e17d7035e+5b3adc59f5,g3fd5ace14f+852fa6fbcb,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+9f17e571f4,g67b6fd64d1+6dc8069a4c,g74acd417e5+ae494d68d9,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+536efcc10a,g7cc15d900a+d121454f8d,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d7436a09f+28c28d8d6d,g8ea07a8fe4+db21c37724,g92c671f44c+9f17e571f4,g98df359435+b2e6376b13,g99af87f6a8+b0f4ad7b8d,gac66b60396+966efe6077,gb88ae4c679+7dec8f19df,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gc24b5d6ed1+9f17e571f4,gca7fc764a6+6dc8069a4c,gcc769fe2a4+97d0256649,gd7ef33dd92+6dc8069a4c,gdab6d2f7ff+ae494d68d9,gdbb4c4dda9+9f17e571f4,ge410e46f29+6dc8069a4c,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst::afw::cameraGeom::Camera::Builder Class Reference

A helper class for creating and modifying cameras. More...

#include <Camera.h>

Inheritance diagram for lsst::afw::cameraGeom::Camera::Builder:
lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >

Public Types

using NameMap
 
using NameMap
 
using IdMap
 
using IdMap
 
using List
 
using List
 

Public Member Functions

virtual ~Builder () noexcept
 
 Builder (std::string const &name)
 Construct a Builder for a completely new Camera with the given name.
 
 Builder (Camera const &camera)
 Construct a Builder with the state of an existing Camera.
 
std::shared_ptr< Camera const > finish () const
 Construct a new Camera from the state of the Builder.
 
std::string getName () const
 Return the name of the camera.
 
void setName (std::string const &name)
 Set the name of the camera.
 
std::string getPupilFactoryName () const
 Return the fully-qualified name of the Python class that provides this Camera's PupilFactory.
 
void setPupilFactoryName (std::string const &pupilFactoryName)
 Set the fully-qualified name of the Python class that provides this Camera's PupilFactory.
 
bool getFocalPlaneParity () const noexcept
 Return True if there is an x-axis flip from FOCAL_PLANE to FIELD_ANGLE, False otherwise.
 
void setFocalPlaneParity (bool flipX)
 Set whether an x-axis flip should be included in the FOCAL_PLANE to FIELD_ANGLE transform.
 
void setTransformFromFocalPlaneTo (CameraSys const &toSys, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform)
 Set the transformation from FOCAL_PLANE to the given coordinate system.
 
bool discardTransformFromFocalPlaneTo (CameraSys const &toSys)
 Remove any transformation from FOCAL_PLANE to the given coordinate system.
 
std::shared_ptr< Detector::InCameraBuilderadd (std::string const &name, int id)
 Add a new Detector with the given name and ID.
 
void remove (std::string const &name)
 Remove the detector with the given name or ID.
 
void remove (int id)
 
NameMap const & getNameMap () const noexcept
 Get a map keyed and ordered by name.
 
NameMap const & getNameMap () const noexcept
 Get a map keyed and ordered by name.
 
IdMap const & getIdMap () const noexcept
 Get a map keyed and ordered by ID.
 
IdMap const & getIdMap () const noexcept
 Get a map keyed and ordered by ID.
 
std::size_t size () const noexcept
 Get the number of detectors.
 
std::size_t size () const noexcept
 Get the number of detectors.
 
bool empty () const noexcept
 Determine if the collection contains any detectors.
 
bool empty () const noexcept
 Determine if the collection contains any detectors.
 
std::shared_ptr< Detector::InCameraBuilderoperator[] (std::string const &name) const
 Implement the [name] operator.
 
std::shared_ptr< Detector::InCameraBuilderoperator[] (int id) const
 Implement the [id] operator.
 
std::shared_ptr< Detector::InCameraBuilderoperator[] (std::string const &name) const
 Implement the [name] operator.
 
std::shared_ptr< Detector::InCameraBuilderoperator[] (int id) const
 Implement the [id] operator.
 
std::shared_ptr< Detector::InCameraBuilderget (std::string const &name, std::shared_ptr< Detector::InCameraBuilder > def=nullptr) const
 Retrieve a detector by name, or fall back to a default.
 
std::shared_ptr< Detector::InCameraBuilderget (int id, std::shared_ptr< Detector::InCameraBuilder > def=nullptr) const
 Retrieve a detector by ID, or fall back to a default.
 
std::shared_ptr< Detector::InCameraBuilderget (std::string const &name, std::shared_ptr< Detector::InCameraBuilder > def=nullptr) const
 Retrieve a detector by name, or fall back to a default.
 
std::shared_ptr< Detector::InCameraBuilderget (int id, std::shared_ptr< Detector::InCameraBuilder > def=nullptr) const
 Retrieve a detector by ID, or fall back to a default.
 

Protected Member Functions

void add (std::shared_ptr< Detector::InCameraBuilder > detector)
 Add a detector to the collection.
 

Detailed Description

A helper class for creating and modifying cameras.

Camera and Camera::Builder have no direct inheritance relationship, but both inherit from different specializations of DetectorCollectionBase, so their container-of-detectors interfaces can generally be used the same way in both Python and templated C++.

Definition at line 210 of file Camera.h.

Member Typedef Documentation

◆ IdMap [1/2]

◆ IdMap [2/2]

◆ List [1/2]

◆ List [2/2]

◆ NameMap [1/2]

◆ NameMap [2/2]

Constructor & Destructor Documentation

◆ ~Builder()

lsst::afw::cameraGeom::Camera::Builder::~Builder ( )
virtualdefaultnoexcept

◆ Builder() [1/2]

lsst::afw::cameraGeom::Camera::Builder::Builder ( std::string const & name)
explicit

Construct a Builder for a completely new Camera with the given name.

Definition at line 194 of file Camera.cc.

194: _name(name), _pupilFactoryName(), _focalPlaneParity(false) {}

◆ Builder() [2/2]

lsst::afw::cameraGeom::Camera::Builder::Builder ( Camera const & camera)
explicit

Construct a Builder with the state of an existing Camera.

Definition at line 196 of file Camera.cc.

197 : _name(camera.getName()), _pupilFactoryName(camera.getPupilFactoryName()), _focalPlaneParity(false) {
198 // Add Detector Builders for all Detectors; does not (yet) include
199 // coordinate transform information.
200 for (auto const &pair : camera.getIdMap()) {
201 BaseCollection::add(Camera::makeDetectorBuilder(*pair.second));
202 }
203 // Iterate over connections in TransformMap, distributing them between the
204 // Camera Builder and the Detector Builders.
205 for (auto const &connection : camera.getTransformMap()->getConnections()) {
206 // asserts below are on Detector, Camera, and TransformMap invariants:
207 // - Connections should always be from native sys to something else.
208 // - The only connections between full-camera and per-detector sys
209 // should be from the camera native sys (FOCAL_PLANE) to the
210 // detector native sys (PIXELS).
211 // - When TransformMap standardizes connections, it should maintain
212 // these directions, as that's consistent with "pointing away" from
213 // the overall reference sys (the camera native sys).
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);
220 } else {
221 assert(connection.fromSys == getNativeCameraSys());
222 if (!connection.toSys.hasDetectorName()) {
223 _connections.push_back(connection);
224 }
225 // We ignore the FOCAL_PLANE to PIXELS transforms transforms, as
226 // those are always regenerated from the Orientation when we
227 // rebuild the Camera.
228 }
229 }
230}
void add(std::shared_ptr< Detector::InCameraBuilder > detector)

Member Function Documentation

◆ add() [1/2]

std::shared_ptr< Detector::InCameraBuilder > lsst::afw::cameraGeom::Camera::Builder::add ( std::string const & name,
int id )

Add a new Detector with the given name and ID.

This is the only way to create a completely new detector (as opposed to a copy of an existing one), and it permanently sets that Detector's name and ID.

Exceptions
pex::exceptions::RuntimeErrorThrown if the ID and/or name conflict with those of detectors already in the collection.
Exception Safety
Strong for pex::exceptions::RuntimeError, none otherwise.

Definition at line 331 of file Camera.cc.

331 {
332 auto detector = makeDetectorBuilder(name, id);
333 BaseCollection::add(detector);
334 return detector;
335}

◆ add() [2/2]

Add a detector to the collection.

Parameters
[in]detectorNew detector to add to the collection.
Exceptions
pex::exceptions::RuntimeErrorThrown if the ID and/or name conflict with those of detectors already in the collection.
Exception Safety
Strong for pex::exceptions::RuntimeError, weak (collection is made empty) otherwise.

◆ discardTransformFromFocalPlaneTo()

bool lsst::afw::cameraGeom::Camera::Builder::discardTransformFromFocalPlaneTo ( CameraSys const & toSys)

Remove any transformation from FOCAL_PLANE to the given coordinate system.

Parameters
toSysCoordinate system this transform returns points in.
Returns
true if a transform was removed; false otherwise.

Definition at line 322 of file Camera.cc.

322 {
323 auto iter = findConnection(_connections.begin(), _connections.end(), toSys);
324 if (iter != _connections.end()) {
325 _connections.erase(iter);
326 return true;
327 }
328 return false;
329}

◆ empty() [1/2]

bool lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::empty ( ) const
inlinenoexceptinherited

Determine if the collection contains any detectors.

Definition at line 72 of file DetectorCollection.h.

72{ return _idDict.empty(); }
An abstract base class for collections of Detectors and specific subclasses thereof.
bool empty() const noexcept
Determine if the collection contains any detectors.

◆ empty() [2/2]

bool lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::empty ( ) const
inlinenoexceptinherited

Determine if the collection contains any detectors.

Definition at line 72 of file DetectorCollection.h.

72{ return _idDict.empty(); }

◆ finish()

std::shared_ptr< Camera const > lsst::afw::cameraGeom::Camera::Builder::finish ( ) const

Construct a new Camera from the state of the Builder.

Definition at line 236 of file Camera.cc.

236 {
237 // Make a big vector of all coordinate transform connections;
238 // start with general transforms for the camera as a whole:
239 std::vector<TransformMap::Connection> connections(_connections);
240 // Check that the FOCAL_PLANE <-> FIELD_ANGLE transform is consistent with
241 // the set parity, and add an x-axis flip if not.
242 auto field_angle_connection =
243 std::find_if(connections.begin(), connections.end(), [](TransformMap::Connection const &c) {
244 return c.fromSys == FOCAL_PLANE && c.toSys == FIELD_ANGLE;
245 });
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 =
250 field_angle_connection->transform->then(*afw::geom::makeTransform(
251 lsst::geom::AffineTransform(lsst::geom::LinearTransform::makeScaling(-1, 1))));
252 }
253 }
254 // Loop over detectors and add the transforms from FOCAL_PLANE
255 // to PIXELS (via the Orientation), and then any extra transforms
256 // from PIXELS to other things.
257 for (auto const &pair : getIdMap()) {
258 auto const &detectorBuilder = *pair.second;
259 std::vector<TransformMap::Connection> detectorConnections =
260 getDetectorBuilderConnections(detectorBuilder);
261 std::vector<std::vector<CameraSys>> allDetConnections;
262 for (auto const &connection : detectorConnections) {
263 std::vector<CameraSys> tmpConnection = {connection.fromSys, connection.toSys};
264 allDetConnections.push_back(tmpConnection);
265 }
266 std::vector<CameraSys> connection = {detectorBuilder.getNativeCoordSys(), getNativeCameraSys()};
267 std::vector<CameraSys> invConnection = {getNativeCameraSys(), detectorBuilder.getNativeCoordSys()};
268 if ((std::find(allDetConnections.begin(), allDetConnections.end(), connection) ==
269 allDetConnections.end()) &&
270 (std::find(allDetConnections.begin(), allDetConnections.end(), invConnection) ==
271 allDetConnections.end())) {
272 connections.push_back(TransformMap::Connection{
273 detectorBuilder.getOrientation().makeFpPixelTransform(detectorBuilder.getPixelSize()),
274 getNativeCameraSys(), detectorBuilder.getNativeCoordSys()});
275 }
276 connections.insert(connections.end(), getDetectorBuilderConnections(detectorBuilder).begin(),
277 getDetectorBuilderConnections(detectorBuilder).end());
278 }
279 // Make a single big TransformMap.
280 auto transformMap = TransformMap::make(getNativeCameraSys(), connections);
281 // Make actual Detector objects, giving each the full TransformMap.
282 DetectorList detectors;
283 detectors.reserve(size());
284 for (auto const &pair : getIdMap()) {
285 auto const &detectorBuilder = *pair.second;
286 detectors.push_back(detectorBuilder.finish(transformMap));
287 }
288 return std::shared_ptr<Camera>(
289 new Camera(_name, std::move(detectors), std::move(transformMap), _pupilFactoryName));
290}
T begin(T... args)
Camera(Camera const &)=delete
DetectorCollection::List DetectorList
Definition Camera.h:46
static std::shared_ptr< TransformMap const > make(CameraSys const &reference, Transforms const &transforms)
Construct a TransformMap with all transforms relative to a single reference CameraSys.
static LinearTransform makeScaling(double s) noexcept
T end(T... args)
T find_if(T... args)
T move(T... args)
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(lsst::geom::AffineTransform const &affine)
Wrap an lsst::geom::AffineTransform as a Transform.
Point< double, 2 > Point2D
Definition Point.h:324
T push_back(T... args)
T reserve(T... args)

◆ get() [1/4]

Retrieve a detector by ID, or fall back to a default.

Parameters
[in]iddetector id
[in]defdefault detector to return. This defaults to nullptr.
Returns
pointer to detector entry if the entry exists, else return the default value

◆ get() [2/4]

Retrieve a detector by ID, or fall back to a default.

Parameters
[in]iddetector id
[in]defdefault detector to return. This defaults to nullptr.
Returns
pointer to detector entry if the entry exists, else return the default value

Definition at line 110 of file DetectorCollection.cc.

65 {
66 auto i = _idDict.find(id);
67 if (i == _idDict.end()) {
68 return def;
69 }
70 return i->second;
71}

◆ get() [3/4]

Retrieve a detector by name, or fall back to a default.

Parameters
[in]namedetector name
[in]defdefault detector to return. This defaults to nullptr.
Returns
pointer to detector entry if the entry exists, else return the default value

◆ get() [4/4]

Retrieve a detector by name, or fall back to a default.

Parameters
[in]namedetector name
[in]defdefault detector to return. This defaults to nullptr.
Returns
pointer to detector entry if the entry exists, else return the default value

Definition at line 99 of file DetectorCollection.cc.

56 {
57 auto i = _nameDict.find(name);
58 if (i == _nameDict.end()) {
59 return def;
60 }
61 return i->second;
62}

◆ getFocalPlaneParity()

bool lsst::afw::cameraGeom::Camera::Builder::getFocalPlaneParity ( ) const
inlinenoexcept

Return True if there is an x-axis flip from FOCAL_PLANE to FIELD_ANGLE, False otherwise.

Cameras with an even number of reflective surfaces (e.g. LATISS) or a particular choice for the PIXEL coordinates (e.g. DECam) require this x-axis flip between their FOCAL_PLANE and FIELD_ANGLE coordinate systems to match our conventions.

Definition at line 244 of file Camera.h.

244{ return _focalPlaneParity; }

◆ getIdMap() [1/2]

IdMap const & lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::getIdMap ( ) const
inlinenoexceptinherited

Get a map keyed and ordered by ID.

Definition at line 62 of file DetectorCollection.h.

62{ return _idDict; }

◆ getIdMap() [2/2]

IdMap const & lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::getIdMap ( ) const
inlinenoexceptinherited

Get a map keyed and ordered by ID.

Definition at line 62 of file DetectorCollection.h.

62{ return _idDict; }

◆ getName()

std::string lsst::afw::cameraGeom::Camera::Builder::getName ( ) const
inline

Return the name of the camera.

Definition at line 232 of file Camera.h.

232{ return _name; }

◆ getNameMap() [1/2]

NameMap const & lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::getNameMap ( ) const
inlinenoexceptinherited

Get a map keyed and ordered by name.

Definition at line 59 of file DetectorCollection.h.

59{ return _nameDict; }

◆ getNameMap() [2/2]

NameMap const & lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::getNameMap ( ) const
inlinenoexceptinherited

Get a map keyed and ordered by name.

Definition at line 59 of file DetectorCollection.h.

59{ return _nameDict; }

◆ getPupilFactoryName()

std::string lsst::afw::cameraGeom::Camera::Builder::getPupilFactoryName ( ) const
inline

Return the fully-qualified name of the Python class that provides this Camera's PupilFactory.

Definition at line 238 of file Camera.h.

238{ return _pupilFactoryName; }

◆ operator[]() [1/4]

Implement the [id] operator.

Parameters
[in]iddetector name
Returns
pointer to detector entry

◆ operator[]() [2/4]

Implement the [id] operator.

Parameters
[in]iddetector name
Returns
pointer to detector entry

Definition at line 88 of file DetectorCollection.cc.

46 {
47 auto det = get(id);
48 if (det == nullptr) {
50 (boost::format("Detector with ID %s not found") % id).str());
51 }
52 return det;
53}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48

◆ operator[]() [3/4]

Implement the [name] operator.

Parameters
[in]namedetector name
Returns
pointer to detector entry

◆ operator[]() [4/4]

Implement the [name] operator.

Parameters
[in]namedetector name
Returns
pointer to detector entry

Definition at line 80 of file DetectorCollection.cc.

36 {
37 auto det = get(name);
38 if (det == nullptr) {
40 (boost::format("Detector with name %s not found") % name).str());
41 }
42 return det;
43}

◆ remove() [1/2]

void lsst::afw::cameraGeom::Camera::Builder::remove ( int id)
inline

Definition at line 305 of file Camera.h.

◆ remove() [2/2]

void lsst::afw::cameraGeom::Camera::Builder::remove ( std::string const & name)
inline

Remove the detector with the given name or ID.

Wrapped as __delitem__ in Python.

Exceptions
pex::exceptions::NotFoundErrorif no such detector exists.

Definition at line 304 of file Camera.h.

304{ return BaseCollection::remove(name); }

◆ setFocalPlaneParity()

void lsst::afw::cameraGeom::Camera::Builder::setFocalPlaneParity ( bool flipX)

Set whether an x-axis flip should be included in the FOCAL_PLANE to FIELD_ANGLE transform.

When a Camera is constructed from this Builder via the finish, method, the current parity of the FOCAL_PLANE to FIELD_ANGLE transform is checked. If the set focal plane parity is true but the transform has a positive determinant, or if the set focal plane parity is false but the transform has a negative determinant, the built camera's transform will compose an x-coordinate flip to the builder's transform. Note that there is no other checking that these coordinate systems have aligned axes or that any existing parity flip is along the X axis (as should be the case).

Definition at line 234 of file Camera.cc.

234{ _focalPlaneParity = flipX; }

◆ setName()

void lsst::afw::cameraGeom::Camera::Builder::setName ( std::string const & name)
inline

Set the name of the camera.

Definition at line 235 of file Camera.h.

◆ setPupilFactoryName()

void lsst::afw::cameraGeom::Camera::Builder::setPupilFactoryName ( std::string const & pupilFactoryName)
inline

Set the fully-qualified name of the Python class that provides this Camera's PupilFactory.

Definition at line 241 of file Camera.h.

241{ _pupilFactoryName = pupilFactoryName; }

◆ setTransformFromFocalPlaneTo()

void lsst::afw::cameraGeom::Camera::Builder::setTransformFromFocalPlaneTo ( CameraSys const & toSys,
std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform )

Set the transformation from FOCAL_PLANE to the given coordinate system.

Parameters
toSysCoordinate system this transform returns points in.
transformTransform from FOCAL_PLANE to toSys.

If a transform already exists from FOCAL_PLANE to toSys, it is overwritten.

Definition at line 306 of file Camera.cc.

307 {
308 if (toSys.hasDetectorName()) {
309 throw LSST_EXCEPT(pex::exceptions::LogicError,
310 (boost::format("%s should be added to Detector %s, not Camera") %
311 toSys.getSysName() % toSys.getDetectorName())
312 .str());
313 }
314 auto iter = findConnection(_connections.begin(), _connections.end(), toSys);
315 if (iter == _connections.end()) {
316 _connections.push_back(TransformMap::Connection{transform, getNativeCameraSys(), toSys});
317 } else {
318 iter->transform = transform;
319 }
320}
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.
Definition Camera.cc:87

◆ size() [1/2]

Get the number of detectors.

Renamed to __len__ in Python.

Definition at line 67 of file DetectorCollection.h.

67{ return _idDict.size(); }

◆ size() [2/2]

Get the number of detectors.

Renamed to __len__ in Python.

Definition at line 67 of file DetectorCollection.h.

67{ return _idDict.size(); }

The documentation for this class was generated from the following files: