39 : _spans(inputSpans), _peaks(
PeakTable::makeMinimalSchema()), _region(region) {}
43 : _spans(inputSpans), _peaks(peakSchema), _region(region) {}
53 p->setPeakValue(height);
60 return a.get(validatedKey) > b.get(validatedKey);
67 peak.setIx(peak.getIx() + dx);
68 peak.setIy(peak.getIy() + dy);
69 peak.setFx(peak.getFx() + dx);
70 peak.setFy(peak.getFy() + dy);
84 auto srcToTarget = geom::makeWcsPairTransform(*source, *target);
85 return transform(*srcToTarget, region, doClip);
95 return transform(*geom::makeTransform(t), region, doClip);
101 auto transformedSpan =
getSpans()->transformedBy(t);
106 peakPosList.
reserve(_peaks.size());
107 for (
auto const& peak :
getPeaks()) {
110 auto newPeakPosList = t.applyForward(peakPosList);
111 auto newPeakPos = newPeakPosList.cbegin();
112 for (
auto peak =
getPeaks().cbegin(), endPeak =
getPeaks().cend(); peak != endPeak;
113 ++peak, ++newPeakPos) {
114 newFootprint->addPeak(newPeakPos->getX(), newPeakPos->getY(), peak->getPeakValue());
117 newFootprint->clipTo(region);
146 auto key = _peaks.getSchema().find<
double>(
"significance").key;
147 for (
auto& peak : _peaks) {
148 peak.set(key, peak.getPeakValue() / sigma);
153 auto key = _peaks.getSchema().find<
double>(
"significance").key;
154 for (
auto& peak : _peaks) {
155 peak.set(key, polarity * peak.getPeakValue() /
std::sqrt(variance[peak.getI()]));
160 auto splitSpanSets =
getSpans()->split();
162 footprintList.
reserve(splitSpanSets.size());
163 for (
auto& spanPtr : splitSpanSets) {
165 tmpFootprintPointer->_peaks =
getPeaks();
168 if (splitSpanSets.size() > 1) {
169 tmpFootprintPointer->removeOrphanPeaks();
173 return footprintList;
184 for (
auto const& selfPeak :
getPeaks()) {
186 for (
auto const& otherPeak : other.
getPeaks()) {
187 if (selfPeak.getI() == otherPeak.getI() && selfPeak.getF() == otherPeak.getF() &&
188 selfPeak.getPeakValue() == otherPeak.getPeakValue()) {
203std::string getFootprintPersistenceName() {
return "Footprint"; }
205class LegacyFootprintPersistenceHelper {
207 table::Schema spanSchema;
208 table::Key<int> spanY;
209 table::Key<int> spanX0;
210 table::Key<int> spanX1;
212 static LegacyFootprintPersistenceHelper
const& get() {
213 static LegacyFootprintPersistenceHelper instance;
218 LegacyFootprintPersistenceHelper(
const LegacyFootprintPersistenceHelper&) =
delete;
219 LegacyFootprintPersistenceHelper& operator=(
const LegacyFootprintPersistenceHelper&) =
delete;
222 LegacyFootprintPersistenceHelper(LegacyFootprintPersistenceHelper&&) =
delete;
223 LegacyFootprintPersistenceHelper& operator=(LegacyFootprintPersistenceHelper&&) =
delete;
226 LegacyFootprintPersistenceHelper()
228 spanY(spanSchema.addField<int>(
"y",
"The row of the span",
"pixel")),
229 spanX0(spanSchema.addField<int>(
"x0",
"First column of span (inclusive)",
"pixel")),
230 spanX1(spanSchema.addField<int>(
"x1",
"Second column of span (inclusive)",
"pixel")) {}
235 static int initialize =
true;
238 idKey = spanSetIdSchema.
addField<
int>(
"id",
"id of the SpanSet catalog");
257 return loadedFootprint;
266FootprintFactory registration(getFootprintPersistenceName());
273 auto const keys = spanSetPersistenceHelper();
288 int fieldCount = catalog.getSchema().getFieldCount();
291 if (fieldCount == 1) {
293 auto const schemaAndKey = spanSetPersistenceHelper();
294 int persistedSpanSetId = catalog.front().get(schemaAndKey.second);
298 auto const& keys = LegacyFootprintPersistenceHelper::get();
300 tempVec.
reserve(catalog.size());
301 for (
auto const& val : catalog) {
302 tempVec.
emplace_back(val.get(keys.spanY), val.get(keys.spanX0), val.get(keys.spanX1));
307 return loadedFootprint;
311 using namespace std::string_literals;
321 mapper.
addMapping(oldPeakValue,
"peakValue"s);
323 auto peaks = loadedFootprint.
getPeaks();
325 for (
auto const& peak : peakCat) {
326 auto newPeak = peaks.addNew();
327 newPeak->assign(peak, mapper);
328 newPeak->setIx(
static_cast<int>(newPeak->getFx()));
329 newPeak->setIy(
static_cast<int>(newPeak->getFy()));
334 auto& peaks = loadedFootprint.
getPeaks();
336 for (
auto const& peak : peakCat) {
337 peaks.addNew()->assign(peak);
345 "Cannot merge Footprints with different Schemas");
349 auto unionedSpanSet = footprint1.
getSpans()->union_(*(footprint2.
getSpans()));
361 mergedFootprint->sortPeaks();
363 return mergedFootprint;
373 footprint.
getSpans()->setImage(*idImage,
static_cast<PixelT
>(1), fpBBox,
true);
390 while (y0 < height) {
392 for (
int y = y0; y < height; ++y) {
399 int const x0 = first - begin;
400 int const x1 = last - begin;
401 int const x_size = 1 + x1 - x0;
409 for (++y; y < height; ++y) {
410 if (
std::find(idImage->at(x0, y), idImage->at(x0, y) + x_size, 0) !=
411 idImage->at(x0, y) + x_size) {
414 std::fill(idImage->at(x0, y), idImage->at(x0, y) + x_size, 0);
#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.
Record class that represents a peak in a Footprint.
Table class for Peaks in Footprints.
static afw::table::Schema makeMinimalSchema()
Return a minimal schema for Peak tables and records.
static afw::table::Key< float > getPeakValueKey()
A class to represent a 2-dimensional array of pixels.
size_type size() const
Return the number of elements in the catalog.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
iterator begin()
Iterator access.
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Schema getSchema() const
Return the schema associated with the catalog's table.
A class used as a handle to a particular field in a table.
bool isValid() const noexcept
Return true if the key was initialized to valid offset.
Defines the fields and offsets for a table.
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
A mapping between the keys of two Schemas, used to copy data between them.
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
Key< T > addMapping(Key< T > const &inputKey, bool doReplace=false)
Add a new field to the output Schema that is a copy of a field in the input Schema.
void addMinimalSchema(Schema const &minimal, bool doMap=true)
Add the given minimal schema to the output schema.
A vector of catalogs used by Persistable.
An object passed to Persistable::write to allow it to persist itself.
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 CRTP facade class for subclasses of Persistable.
A base class for factory classes used to reconstruct objects from records.
PersistableFactory(std::string const &name)
Constructor for the factory.
An integer coordinate rectangle.
int getMinY() const noexcept
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
int getHeight() const noexcept
int getMinX() const noexcept
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
Reports invalid arguments.
Reports errors in the logical structure of the program.
T emplace_back(T... args)
std::ostream & operator<<(std::ostream &os, Footprint const &rhs)
Print a Footprint to the stream.
std::vector< lsst::geom::Box2I > footprintToBBoxList(Footprint const &footprint)
Return a list of BBoxs, whose union contains exactly the pixels in the footprint, neither more nor le...
afw::table::CatalogT< PeakRecord > PeakCatalog
std::shared_ptr< Footprint > mergeFootprints(Footprint const &footprint1, Footprint const &footprint2)
Merges two Footprints – appends their peaks, and unions their spans, returning a new Footprint.
CatalogT< BaseRecord > BaseCatalog
Extent< int, 2 > Extent2I
T dynamic_pointer_cast(T... args)