40 : _footprints(1, footprint), _source(sourceTable->makeRecord()) {
43 _source->set(
keys.footprint,
true);
49 newPeak->set(
keys.peak,
true);
50 newPeak->setId((*newFootprint->getPeaks().getTable()->getIdFactory())());
51 newFootprint->getPeaks().push_back(newPeak);
53 _source->setFootprint(newFootprint);
87 KeyTuple const &keys,
float minNewPeakDist = -1.,
float maxSamePeakDist = -1.) {
89 _footprints.push_back(footprint);
90 _source->set(
keys.footprint,
true);
91 _addPeaks(footprint->getPeaks(), &peakSchemaMapper, &
keys, minNewPeakDist, maxSamePeakDist,
nullptr);
109 float maxSamePeakDist = -1.) {
111 _footprints.insert(_footprints.end(), other._footprints.begin(), other._footprints.end());
113 for (
auto const &key :
keys) {
115 _source->set(flagKey, _source->get(flagKey) || other._source->get(flagKey));
117 _addPeaks(other.
getMergedFootprint()->getPeaks(),
nullptr,
nullptr, minNewPeakDist, maxSamePeakDist,
148 KeyTuple const *keys,
float minNewPeakDist,
float maxSamePeakDist,
150 if (minNewPeakDist < 0 && maxSamePeakDist < 0)
return;
152 assert(peakSchemaMapper || filterMap);
158 float minNewPeakDist2 = minNewPeakDist * minNewPeakDist;
159 float maxSamePeakDist2 = maxSamePeakDist * maxSamePeakDist;
165 currentIter != currentPeaks.
end(); ++currentIter) {
166 float dist2 = otherIter->getI().distanceSquared(currentIter->getI());
168 if (dist2 < minDist2) {
170 nearestPeak = currentIter;
174 if (minDist2 < maxSamePeakDist2 && nearestPeak && maxSamePeakDist > 0) {
175 if (peakSchemaMapper) {
176 nearestPeak->set(
keys->peak,
true);
178 for (
auto const &i : *filterMap) {
179 afw::table::Key<afw::table::Flag>
const &flagKey = i.second.peak;
180 nearestPeak->set(flagKey, nearestPeak->
get(flagKey) || otherIter->get(flagKey));
183 }
else if (minDist2 > minNewPeakDist2 && !(minNewPeakDist < 0)) {
184 if (peakSchemaMapper) {
186 newPeak->assign(*otherIter, *peakSchemaMapper);
187 newPeak->set(
keys->peak,
true);
188 newPeak->setId((*currentPeaks.
getTable()->getIdFactory())());
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.
A class used as a handle to a particular field in a table.
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