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);
103 auto newFootprint = std::make_shared<Footprint>(transformedSpan,
getPeaks().getSchema(), region);
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) {
164 auto tmpFootprintPointer = std::make_shared<Footprint>(spanPtr,
getPeaks().getSchema(),
getRegion());
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 {
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()
229 spanX0(
spanSchema.addField<int>(
"x0",
"First column of span (inclusive)",
"pixel")),
230 spanX1(
spanSchema.addField<int>(
"x1",
"Second column of span (inclusive)",
"pixel")) {}
234 static afw::table::Schema spanSetIdSchema;
235 static int initialize =
true;
236 static table::Key<int> idKey;
238 idKey = spanSetIdSchema.addField<
int>(
"id",
"id of the SpanSet catalog");
257 return loadedFootprint;
266FootprintFactory registration(getFootprintPersistenceName());
273 auto const keys = spanSetPersistenceHelper();
277 auto record = spanSetCat.
addNew();
288 int fieldCount = catalog.getSchema().getFieldCount();
291 if (fieldCount == 1) {
293 auto const schemaAndKey = spanSetPersistenceHelper();
294 int persistedSpanSetId = catalog.front().get(schemaAndKey.second);
295 loadedSpanSet = std::dynamic_pointer_cast<geom::SpanSet>(archive.
get(persistedSpanSetId));
298 auto const& keys = LegacyFootprintPersistenceHelper::get();
300 tempVec.
reserve(catalog.size());
301 for (
auto const&
val : catalog) {
304 loadedSpanSet = std::make_shared<geom::SpanSet>(
std::move(tempVec));
307 return loadedFootprint;
311 using namespace std::string_literals;
319 mapper.addMapping(oldX,
"f.x"s);
320 mapper.addMapping(oldY,
"f.y"s);
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()));
352 auto mergedFootprint = std::make_shared<Footprint>(unionedSpanSet, footprint1.
getPeaks().
getSchema());
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);
table::Key< std::string > name
Key< Flag > const & target
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
afw::table::Key< double > sigma
#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()
typename _view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
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.
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
SchemaItem< T > find(std::string const &name) const
Find a SchemaItem in the Schema by name.
A mapping between the keys of two Schemas, used to copy data between them.
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 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
int getHeight() const noexcept
int getMinX() const noexcept
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.
afw::table::CatalogT< PeakRecord > PeakCatalog
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...
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.