24 #include "boost/bind.hpp"
43 : _footprints(1, footprint), _source(sourceTable->makeRecord()) {
46 _source->set(
keys.footprint,
true);
52 newPeak->set(
keys.peak,
true);
53 newFootprint->getPeaks().push_back(newPeak);
55 _source->setFootprint(newFootprint);
89 KeyTuple const &
keys,
float minNewPeakDist = -1.,
float maxSamePeakDist = -1.) {
91 _footprints.push_back(footprint);
92 _source->set(
keys.footprint,
true);
93 _addPeaks(footprint->getPeaks(), &peakSchemaMapper, &
keys, minNewPeakDist, maxSamePeakDist, NULL);
111 float maxSamePeakDist = -1.) {
113 _footprints.insert(_footprints.end(),
other._footprints.begin(),
other._footprints.end());
115 for (FilterMap::const_iterator i =
keys.begin(); i !=
keys.end(); ++i) {
117 _source->set(flagKey, _source->
get(flagKey) ||
other._source->get(flagKey));
119 _addPeaks(
other.getMergedFootprint()->getPeaks(), NULL, NULL, minNewPeakDist, maxSamePeakDist,
150 KeyTuple const *
keys,
float minNewPeakDist,
float maxSamePeakDist,
152 if (minNewPeakDist < 0 && maxSamePeakDist < 0)
return;
154 assert(peakSchemaMapper || filterMap);
160 float minNewPeakDist2 = minNewPeakDist * minNewPeakDist;
161 float maxSamePeakDist2 = maxSamePeakDist * maxSamePeakDist;
167 currentIter != currentPeaks.
end(); ++currentIter) {
168 float dist2 = otherIter->getI().distanceSquared(currentIter->getI());
170 if (dist2 < minDist2) {
172 nearestPeak = currentIter;
176 if (minDist2 < maxSamePeakDist2 && nearestPeak && maxSamePeakDist > 0) {
177 if (peakSchemaMapper) {
178 nearestPeak->set(
keys->peak,
true);
180 for (FilterMap::const_iterator i = filterMap->begin(); i != filterMap->end(); ++i) {
181 afw::table::Key<afw::table::Flag>
const &flagKey = i->second.peak;
182 nearestPeak->set(flagKey, nearestPeak->
get(flagKey) || otherIter->get(flagKey));
185 }
else if (minDist2 > minNewPeakDist2 && !(minNewPeakDist < 0)) {
186 if (peakSchemaMapper) {
188 newPeak->assign(*otherIter, *peakSchemaMapper);
189 newPeak->set(
keys->peak,
true);
191 newPeaks.push_back(otherIter);
209 : _peakSchemaMapper(initialPeakSchema) {
210 _initialize(sourceSchema, filterList);
215 : _peakSchemaMapper(
PeakTable::makeMinimalSchema()) {
216 _initialize(sourceSchema, filterList);
232 keys.footprint = sourceSchema.
addField<afw::table::Flag>(
233 "merge_footprint_" + *
iter,
234 "Detection footprint overlapped with a detection from filter " + *
iter);
236 "merge_peak_" + *
iter,
"Peak detected in filter " + *
iter);
243 float minNewPeakDist,
bool doMerge,
float maxSamePeakDist) {
244 FilterMap::const_iterator keyIter = _filterMap.
find(
filter);
245 if (keyIter == _filterMap.
end()) {
251 bool checkForMatches = !_mergeList.
empty() && doMerge;
256 if (srcIter->getParent() != 0)
continue;
264 if (checkForMatches) {
265 FootprintMergeVec::iterator
iter = _mergeList.
begin();
266 while (
iter != _mergeList.
end()) {
270 if (box.
overlaps(foot->getBBox()) && (**iter).overlaps(*foot)) {
278 first->addSpans(foot);
281 first->add(**
iter, _filterMap, minNewPeakDist, maxSamePeakDist);
292 first->add(foot, _peakSchemaMapper, keyIter->second, minNewPeakDist, maxSamePeakDist);
295 _mergeList.
push_back(std::make_shared<FootprintMerge>(foot, sourceTable, _peakTable,
296 _peakSchemaMapper, keyIter->second));
304 outputCat.push_back((**iter).getSource());