SourceXtractorPlusPlus  0.10
Please provide a description of the project.
Cleaning.cpp
Go to the documentation of this file.
1 
17 /*
18  * Cleaning.cpp
19  *
20  * Created on: 2018 M12 18
21  * Author: mschefer
22  */
23 
24 #include <vector>
25 #include <set>
26 #include <tuple>
27 
31 
34 
36 
38 
39 namespace SourceXtractor {
40 
42  return &(*a) < &(*b);
43 }
44 
46  if (group.size() <= 1) {
47  return;
48  }
49 
52 
53  // iterate through all sources
54  for (auto it = group.begin(); it != group.end(); ++it) {
55  if (shouldClean(*it, group)) {
56  sources_to_clean.push_back(it);
57  } else {
58  remaining_sources.push_back(it);
59  }
60  }
61 
62  if (sources_to_clean.size() > 0) {
63  if (remaining_sources.size() > 1) {
65  for (auto it : sources_to_clean) {
66  auto influential_source = findMostInfluentialSource(*it, remaining_sources);
67  merging_map[influential_source].push_back(it);
68  }
69 
70  for (auto merging_pair : merging_map) {
71  if (merging_pair.second.size() > 0) {
72  auto new_source = mergeSources(*merging_pair.first, merging_pair.second);
73  group.addSource(new_source);
74  group.removeSource(merging_pair.first);
75  }
76  }
77  } else if (remaining_sources.size() == 1) {
78  auto new_source = mergeSources(*remaining_sources[0], sources_to_clean);
79  group.addSource(new_source);
80  group.removeSource(remaining_sources[0]);
81  }
82 
83  for (auto& it : sources_to_clean) {
84  group.removeSource(it);
85  }
86  }
87 }
88 
90  const auto& pixel_list = source.getProperty<PixelCoordinateList>().getCoordinateList();
91 
92  std::vector<double> group_influence(pixel_list.size());
93 
94  // iterate through all other sources in the group
95  for (auto it = group.begin(); it != group.end(); ++it) {
96  if (&(*it) == &source) { // skip self
97  continue;
98  }
99 
100  auto &model = it->getProperty<MoffatModelEvaluator>();
101  int i = 0;
102  for (auto pixel : pixel_list) {
103  auto pixel_value = model.getValue(pixel.m_x, pixel.m_y);
104  group_influence[i++] += pixel_value;
105  }
106  }
107 
108  unsigned int still_valid_pixels = 0;
109  const auto& pixel_values = source.getProperty<DetectionFramePixelValues>().getFilteredValues();
110  int i = 0;
111  for (auto value : pixel_values) {
112  if (value > group_influence[i++]) {
113  still_valid_pixels++;
114  }
115  }
116 
117  return still_valid_pixels < m_min_area;
118 }
119 
121  SourceInterface& source, const std::vector<SourceGroupInterface::iterator>& candidates) const {
122 
123  const auto& pixel_list = source.getProperty<PixelCoordinateList>().getCoordinateList();
124 
125  std::vector<double> total_influence_of_sources(candidates.size());
126 
127  // iterate through all other sources in the group
128  for (size_t i = 0; i < candidates.size(); i++) {
129  auto &model = candidates[i]->getProperty<MoffatModelEvaluator>();
130  for (auto pixel : pixel_list) {
131  auto pixel_value = model.getValue(pixel.m_x, pixel.m_y);
132  total_influence_of_sources[i] += pixel_value;
133  }
134  }
135 
136  SourceGroupInterface::iterator most_influential_source(candidates[0]);
137  double most_influential_source_value = 0;
138  for (size_t i = 0; i < candidates.size(); i++) {
139  if (total_influence_of_sources[i] >= most_influential_source_value) {
140  most_influential_source = candidates[i];
141  most_influential_source_value = total_influence_of_sources[i];
142  }
143  }
144  return most_influential_source;
145 }
146 
148  const std::vector<SourceGroupInterface::iterator> children) const {
149 
150  // Start with a copy of the pixel list of the parent
151  auto pixel_list = parent.getProperty<PixelCoordinateList>().getCoordinateList();
152 
153  // Merge the pixel lists of all the child sources
154  for (const auto& child : children) {
155  const auto& pixel_list_to_merge = child->getProperty<PixelCoordinateList>().getCoordinateList();
156  pixel_list.insert(pixel_list.end(), pixel_list_to_merge.begin(), pixel_list_to_merge.end());
157  }
158 
159  // Create a new source with the minimum necessary properties
160  auto new_source = m_source_factory->createSource();
161  new_source->setProperty<PixelCoordinateList>(pixel_list);
162  new_source->setProperty<DetectionFrame>(parent.getProperty<DetectionFrame>().getFrame());
163  new_source->setProperty<SourceId>(parent.getProperty<SourceId>().getSourceId());
164 
165  return new_source;
166 }
167 
168 }
169 
double getValue(double x, double y) const
std::shared_ptr< SourceFactory > m_source_factory
Definition: Cleaning.h:54
STL class.
bool shouldClean(SourceInterface &source, SourceGroupInterface &group) const
Definition: Cleaning.cpp:89
std::list< SourceWrapper >::iterator iterator
SourceGroupInterface::iterator findMostInfluentialSource(SourceInterface &source, const std::vector< SourceGroupInterface::iterator > &candidates) const
Definition: Cleaning.cpp:120
virtual void addSource(std::shared_ptr< SourceInterface > source)=0
std::shared_ptr< SourceInterface > mergeSources(SourceInterface &parent, const std::vector< SourceGroupInterface::iterator > children) const
Definition: Cleaning.cpp:147
STL class.
T push_back(T... args)
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
unsigned int m_min_area
Definition: Cleaning.h:55
Defines the interface used to group sources.
T size(T... args)
STL class.
The values of a Source's pixels in the detection image. They are returned as a vector in the same ord...
bool operator<(std::reference_wrapper< const SourceInterface > a, std::reference_wrapper< const SourceInterface > b)
void deblend(SourceGroupInterface &group) const override
Definition: Cleaning.cpp:45
virtual iterator removeSource(iterator pos)=0
The SourceInterface is an abstract "source" that has properties attached to it.
virtual unsigned int size() const =0