42 : _footprints(1, footprint), _source(sourceTable->makeRecord()) {
45 _source->set(
keys.footprint,
true);
51 newPeak->set(
keys.peak,
true);
52 newFootprint->getPeaks().push_back(newPeak);
54 _source->setFootprint(newFootprint);
88 KeyTuple const &keys,
float minNewPeakDist = -1.,
float maxSamePeakDist = -1.) {
90 _footprints.push_back(footprint);
91 _source->set(
keys.footprint,
true);
92 _addPeaks(footprint->getPeaks(), &peakSchemaMapper, &
keys, minNewPeakDist, maxSamePeakDist,
nullptr);
110 float maxSamePeakDist = -1.) {
112 _footprints.insert(_footprints.end(), other._footprints.begin(), other._footprints.end());
114 for (
auto const &key :
keys) {
116 _source->set(flagKey, _source->get(flagKey) || other._source->get(flagKey));
118 _addPeaks(other.
getMergedFootprint()->getPeaks(),
nullptr,
nullptr, minNewPeakDist, maxSamePeakDist,
149 KeyTuple const *keys,
float minNewPeakDist,
float maxSamePeakDist,
151 if (minNewPeakDist < 0 && maxSamePeakDist < 0)
return;
153 assert(peakSchemaMapper || filterMap);
159 float minNewPeakDist2 = minNewPeakDist * minNewPeakDist;
160 float maxSamePeakDist2 = maxSamePeakDist * maxSamePeakDist;
166 currentIter != currentPeaks.
end(); ++currentIter) {
167 float dist2 = otherIter->getI().distanceSquared(currentIter->getI());
169 if (dist2 < minDist2) {
171 nearestPeak = currentIter;
175 if (minDist2 < maxSamePeakDist2 && nearestPeak && maxSamePeakDist > 0) {
176 if (peakSchemaMapper) {
177 nearestPeak->set(
keys->peak,
true);
179 for (
auto const &i : *filterMap) {
180 afw::table::Key<afw::table::Flag>
const &flagKey = i.second.peak;
181 nearestPeak->set(flagKey, nearestPeak->
get(flagKey) || otherIter->get(flagKey));
184 }
else if (minDist2 > minNewPeakDist2 && !(minNewPeakDist < 0)) {
185 if (peakSchemaMapper) {
187 newPeak->assign(*otherIter, *peakSchemaMapper);
188 newPeak->set(
keys->peak,
true);
190 newPeaks.push_back(otherIter);
208 : _peakSchemaMapper(initialPeakSchema) {
209 _initialize(sourceSchema, filterList);
214 : _peakSchemaMapper(
PeakTable::makeMinimalSchema()) {
215 _initialize(sourceSchema, filterList);
228 for (
auto const &iter : filterList) {
230 keys.footprint = sourceSchema.
addField<afw::table::Flag>(
231 "merge_footprint_" +
iter,
232 "Detection footprint overlapped with a detection from filter " +
iter);
234 "merge_peak_" +
iter,
"Peak detected in filter " +
iter);
241 float minNewPeakDist,
bool doMerge,
float maxSamePeakDist) {
242 FilterMap::const_iterator keyIter = _filterMap.
find(filter);
243 if (keyIter == _filterMap.
end()) {
245 (boost::format(
"Filter %s not in original list") % filter).str());
249 bool checkForMatches = !_mergeList.
empty() && doMerge;
254 if (srcIter->getParent() != 0)
continue;
262 if (checkForMatches) {
263 FootprintMergeVec::iterator
iter = _mergeList.
begin();
264 while (
iter != _mergeList.
end()) {
268 if (box.
overlaps(foot->getBBox()) && (**iter).overlaps(*foot)) {
276 first->addSpans(foot);
279 first->add(**
iter, _filterMap, minNewPeakDist, maxSamePeakDist);
290 first->add(foot, _peakSchemaMapper, keyIter->second, minNewPeakDist, maxSamePeakDist);
293 _mergeList.
push_back(std::make_shared<FootprintMerge>(foot, sourceTable, _peakTable,
294 _peakSchemaMapper, keyIter->second));
301 for (
auto const &
iter : _mergeList) {
302 outputCat.push_back((*iter).getSource());
#define LSST_EXCEPT(type,...)
Table class for Peaks in Footprints.
static std::shared_ptr< PeakTable > make(afw::table::Schema const &schema, bool forceNew=false)
Obtain a table that can be used to create records with given schema.
Iterator class for CatalogT.
iterator begin()
Iterator access.
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
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.
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).
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
void addMinimalSchema(Schema const &minimal, bool doMap=true)
Add the given minimal schema to the output schema.
Schema const getInputSchema() const
Return the input schema (copy-on-write).
typename Base::const_iterator const_iterator
bool overlaps(Box2I const &other) const noexcept
afw::table::CatalogT< PeakRecord > PeakCatalog
A base class for image defects.