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);
83 KeyTuple
const &keys,
float minNewPeakDist = -1.,
float maxSamePeakDist = -1.) {
84 if (_addSpans(footprint)) {
85 _footprints.push_back(footprint);
86 _source->set(keys.footprint,
true);
87 _addPeaks(footprint->getPeaks(), &peakSchemaMapper, &keys, minNewPeakDist, maxSamePeakDist, NULL);
105 float maxSamePeakDist = -1.) {
107 _footprints.insert(_footprints.end(), other._footprints.begin(), other._footprints.end());
109 for (FilterMap::const_iterator i = keys.
begin(); i != keys.
end(); ++i) {
111 _source->set(flagKey, _source->get(flagKey) || other._source->get(flagKey));
113 _addPeaks(other.
getMergedFootprint()->getPeaks(), NULL, NULL, minNewPeakDist, maxSamePeakDist,
144 KeyTuple
const *keys,
float minNewPeakDist,
float maxSamePeakDist,
145 FilterMap
const *filterMap) {
146 if (minNewPeakDist < 0 && maxSamePeakDist < 0)
return;
148 assert(peakSchemaMapper || filterMap);
154 float minNewPeakDist2 = minNewPeakDist * minNewPeakDist;
155 float maxSamePeakDist2 = maxSamePeakDist * maxSamePeakDist;
161 currentIter != currentPeaks.
end(); ++currentIter) {
162 float dist2 = otherIter->getI().distanceSquared(currentIter->getI());
164 if (dist2 < minDist2) {
166 nearestPeak = currentIter;
170 if (minDist2 < maxSamePeakDist2 && nearestPeak && maxSamePeakDist > 0) {
171 if (peakSchemaMapper) {
172 nearestPeak->set(keys->peak,
true);
174 for (FilterMap::const_iterator i = filterMap->
begin(); i != filterMap->
end(); ++i) {
176 nearestPeak->set(flagKey, nearestPeak->
get(flagKey) || otherIter->get(flagKey));
179 }
else if (minDist2 > minNewPeakDist2 && !(minNewPeakDist < 0)) {
180 if (peakSchemaMapper) {
182 newPeak->assign(*otherIter, *peakSchemaMapper);
183 newPeak->set(keys->peak,
true);
185 newPeaks.push_back(otherIter);
203 : _peakSchemaMapper(initialPeakSchema) {
204 _initialize(sourceSchema, filterList);
209 : _peakSchemaMapper(
PeakTable::makeMinimalSchema()) {
210 _initialize(sourceSchema, filterList);
219 KeyTuple &keys = _filterMap[*iter];
220 keys.footprint = sourceSchema.
addField<afw::table::Flag>(
221 "merge_footprint_" + *iter,
222 "Detection footprint overlapped with a detection from filter " + *iter);
224 "merge_peak_" + *iter,
"Peak detected in filter " + *iter);
231 float minNewPeakDist,
bool doMerge,
float maxSamePeakDist) {
232 FilterMap::const_iterator keyIter = _filterMap.
find(filter);
233 if (keyIter == _filterMap.
end()) {
235 (boost::format(
"Filter %s not in original list") % filter).str());
239 bool checkForMatches = (_mergeList.
size() > 0);
244 if (srcIter->getParent() != 0)
continue;
252 if (checkForMatches) {
253 FootprintMergeVec::iterator iter = _mergeList.
begin();
254 while (iter != _mergeList.
end()) {
258 if (
box.overlaps(foot->getBBox()) && (**iter).overlaps(*foot)) {
263 first->add(foot, _peakSchemaMapper, keyIter->second, minNewPeakDist,
269 first->add(**iter, _filterMap, minNewPeakDist, maxSamePeakDist);
270 iter = _mergeList.
erase(iter);
280 _mergeList.
push_back(std::make_shared<FootprintMerge>(foot, sourceTable, _peakTable,
281 _peakSchemaMapper, keyIter->second));
288 for (FootprintMergeVec::iterator iter = _mergeList.
begin(); iter != _mergeList.
end(); ++iter) {
289 outputCat.push_back((**iter).getSource());
Defines the fields and offsets for a table.
Schema const getInputSchema() const
Return the input schema (copy-on-write).
A mapping between the keys of two Schemas, used to copy data between them.
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Table class for Peaks in Footprints.
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
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.
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
An integer coordinate rectangle.
A base class for image defects.
afw::table::CatalogT< PeakRecord > PeakCatalog
iterator end()
Iterator access.
Iterator class for CatalogT.
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
#define LSST_EXCEPT(type,...)
void addMinimalSchema(Schema const &minimal, bool doMap=true)
Add the given minimal schema to the output schema.
iterator begin()
Iterator access.