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,
151 FilterMap
const *filterMap) {
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) {
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()) {
247 (
boost::format(
"Filter %s not in original list") % filter).str());
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);
282 iter = _mergeList.
erase(iter);
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());
Defines the fields and offsets for a table.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
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.
ItemVariant const * other
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.
Reports errors in the logical structure of the program.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
void addMinimalSchema(Schema const &minimal, bool doMap=true)
Add the given minimal schema to the output schema.
iterator begin()
Iterator access.
An integer coordinate rectangle.
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.