Skip to content

Commit 11d4ef3

Browse files
committed
Updates HexitecSummedImagePlugin
Single, accumulated 'Heat map' image now written on acquisition completion.
1 parent b219fdb commit 11d4ef3

File tree

4 files changed

+79
-58
lines changed

4 files changed

+79
-58
lines changed

control/src/hexitec/adapter.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,12 @@ def acquisition(self, put_data=None):
569569
request.body = "{}".format(1)
570570
self.adapters["fp"].put(command, request)
571571

572+
# Issue reset to summed_image
573+
command = "config/summed_image/reset_image"
574+
request = ApiAdapterRequest(self.file_dir, content_type="application/json")
575+
request.body = "{}".format(1)
576+
self.adapters["fp"].put(command, request)
577+
572578
self.daq_target = time.time()
573579
self.daq.prepare_daq(self.number_frames)
574580
# Acquisition starts here
@@ -606,19 +612,14 @@ def monitor_fem_progress(self):
606612
607613
Busy either:
608614
-Initialising
609-
-Waiting for data collection to complete, either single/multi run
615+
-Waiting for data collection to complete
610616
"""
611617
# print("\n adpt.monitor_fem_progress() called")
612618
if (self.fem.hardware_busy):
613619
# Still sending data
614620
IOLoop.instance().call_later(0.5, self.monitor_fem_progress)
615621
return
616622
# print("\n adpt.monitor_fem_progress() fem done")
617-
# Issue reset to summed_image
618-
command = "config/summed_image/reset_image"
619-
request = ApiAdapterRequest(self.file_dir, content_type="application/json")
620-
request.body = "{}".format(1)
621-
self.adapters["fp"].put(command, request)
622623

623624
self.reset_state_variables()
624625

data/frameProcessor/include/HexitecSummedImagePlugin.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ namespace FrameProcessor
6363
std::string sensors_layout_str_;
6464
HexitecSensorLayoutMap sensors_layout_;
6565

66+
void process_end_of_acquisition();
6667
void process_frame(boost::shared_ptr<Frame> frame);
67-
void apply_summed_image_algorithm(float *in, uint32_t *out);
68+
void apply_summed_image_algorithm(float *in);
69+
void pushSummedDataset();
6870

6971
/** Pointer to logger **/
7072
LoggerPtr logger_;
@@ -79,7 +81,6 @@ namespace FrameProcessor
7981
int threshold_lower_;
8082
int threshold_upper_;
8183
int image_frequency_;
82-
int images_written_;
8384
int reset_image_;
8485
int node_index_;
8586

data/frameProcessor/src/HexitecHistogramPlugin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ namespace FrameProcessor
286286
*/
287287
void HexitecHistogramPlugin::process_end_of_acquisition()
288288
{
289-
LOG4CXX_DEBUG_LEVEL(3, logger_, "End of acquisition frame received, writing histograms to disk");
289+
LOG4CXX_DEBUG_LEVEL(2, logger_, "End of acquisition frame received, pushing histograms");
290290
writeHistogramsToDisk();
291291
histograms_written_ = frames_processed_;
292292
end_of_acquisition_processed_ = true;

data/frameProcessor/src/HexitecSummedImagePlugin.cpp

+68-49
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace FrameProcessor
1515
const std::string HexitecSummedImagePlugin::CONFIG_THRESHOLD_LOWER = "threshold_lower";
1616
const std::string HexitecSummedImagePlugin::CONFIG_THRESHOLD_UPPER = "threshold_upper";
1717
const std::string HexitecSummedImagePlugin::CONFIG_IMAGE_FREQUENCY = "image_frequency";
18-
const std::string HexitecSummedImagePlugin::CONFIG_IMAGES_WRITTEN = "images_written";
1918
const std::string HexitecSummedImagePlugin::CONFIG_RESET_IMAGE = "reset_image";
2019

2120
/**
@@ -35,7 +34,6 @@ namespace FrameProcessor
3534
threshold_lower_ = 0;
3635
threshold_upper_ = 16382;
3736
image_frequency_ = 1;
38-
images_written_ = 0;
3937
reset_image_ = 0;
4038
node_index_ = 1000;
4139
}
@@ -126,7 +124,6 @@ namespace FrameProcessor
126124
{
127125
// Clear all pixels to be 0
128126
memset(summed_image_, 0, image_pixels_ * sizeof(uint32_t));
129-
images_written_ = 0;
130127
reset_image_ = 0;
131128
}
132129
}
@@ -140,7 +137,6 @@ namespace FrameProcessor
140137
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_THRESHOLD_LOWER, threshold_lower_);
141138
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_THRESHOLD_UPPER, threshold_upper_);
142139
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_IMAGE_FREQUENCY, image_frequency_);
143-
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_IMAGES_WRITTEN, images_written_);
144140
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_RESET_IMAGE, reset_image_);
145141
}
146142

@@ -157,7 +153,6 @@ namespace FrameProcessor
157153
status.set_param(get_name() + "/threshold_lower", threshold_lower_);
158154
status.set_param(get_name() + "/threshold_upper", threshold_upper_);
159155
status.set_param(get_name() + "/image_frequency", image_frequency_);
160-
status.set_param(get_name() + "/images_written", images_written_);
161156
status.set_param(get_name() + "/reset_image", reset_image_);
162157
}
163158

@@ -170,6 +165,16 @@ namespace FrameProcessor
170165
return true;
171166
}
172167

168+
/** Process an EndOfAcquisition Frame.
169+
*
170+
* Push Summed Data set on end of acquisition
171+
*/
172+
void HexitecSummedImagePlugin::process_end_of_acquisition()
173+
{
174+
LOG4CXX_DEBUG_LEVEL(2, logger_, "End of acquisition frame received, pushing dataset");
175+
pushSummedDataset();
176+
}
177+
173178
/**
174179
* Perform processing on the frame.
175180
*
@@ -187,57 +192,32 @@ namespace FrameProcessor
187192
long long frame_number = incoming_frame_meta.get_frame_number();
188193

189194
// Push dataset
190-
LOG4CXX_DEBUG_LEVEL(3, logger_, "Pushing " << dataset << " dataset, frame number: "
195+
LOG4CXX_DEBUG_LEVEL(2, logger_, "Pushing " << dataset << " dataset, frame number: "
191196
<< frame_number);
192197
this->push(frame);
193198

194199
if (dataset.compare(std::string("processed_frames")) == 0)
195200
{
196201
try
197202
{
198-
if (frame_number < node_index_)
199-
{
200-
node_index_ = frame_number;
201-
}
203+
// Determine node index, i.e. 0 for first node, 1 = 2nd node, 2 = 3rd, etc
204+
if (frame_number < node_index_)
205+
{
206+
node_index_ = frame_number;
207+
}
208+
209+
// Define pointer to the input image data
210+
void* input_ptr = static_cast<void *>(
211+
static_cast<char *>(const_cast<void *>(data_ptr)));
212+
213+
// Apply algorithm
214+
apply_summed_image_algorithm(static_cast<float *>(input_ptr));
215+
216+
217+
// How often to write accumulated data to disk?
202218
if ((frame_number % image_frequency_) == 0)
203219
{
204-
// Create summed_image dataset
205-
206-
FrameMetaData summed_image_meta;
207-
dimensions_t dims(2);
208-
dims[0] = image_height_;
209-
dims[1] = image_width_;
210-
summed_image_meta.set_dimensions(dims);
211-
summed_image_meta.set_compression_type(no_compression);
212-
summed_image_meta.set_data_type(raw_32bit);
213-
summed_image_meta.set_frame_number(node_index_);
214-
summed_image_meta.set_dataset_name("summed_images");
215-
216-
const std::size_t summed_image_size = image_width_ * image_height_ * sizeof(uint32_t);
217-
218-
boost::shared_ptr<Frame> summed_frame;
219-
summed_frame = boost::shared_ptr<Frame>(new DataBlockFrame(summed_image_meta,
220-
summed_image_size));
221-
222-
// Ensure frame is empty
223-
float *summed = static_cast<float *>(summed_frame->get_data_ptr());
224-
memset(summed, 0, image_pixels_ * sizeof(uint32_t));
225-
226-
// Define pointer to the input image data
227-
void* input_ptr = static_cast<void *>(
228-
static_cast<char *>(const_cast<void *>(data_ptr)));
229-
230-
void* output_ptr = summed_frame->get_data_ptr();
231-
232-
// Apply algorithm
233-
apply_summed_image_algorithm(static_cast<float *>(input_ptr),
234-
static_cast<uint32_t *>(output_ptr));
235-
236-
const std::string& dataset_name = summed_image_meta.get_dataset_name();
237-
LOG4CXX_DEBUG_LEVEL(3, logger_, "Pushing " << dataset_name << " dataset, frame number: "
238-
<< summed_image_meta.get_frame_number());
239-
this->push(summed_frame);
240-
images_written_++;
220+
pushSummedDataset();
241221
}
242222
}
243223
catch (const std::exception& e)
@@ -256,17 +236,56 @@ namespace FrameProcessor
256236
*
257237
* \param[frame] frame - Pointer to a frame object.
258238
*/
259-
void HexitecSummedImagePlugin::apply_summed_image_algorithm(float *in, uint32_t *out)
239+
void HexitecSummedImagePlugin::apply_summed_image_algorithm(float *in)
260240
{
261241
for (int i=0; i<image_pixels_; i++)
262242
{
263243
if (((uint32_t)in[i] > threshold_lower_) && ((uint32_t)in[i] < threshold_upper_))
264244
{
265245
summed_image_[i] += 1;
266246
}
267-
// Maintain history from previous frame(s)
247+
}
248+
}
249+
250+
/**
251+
* Create and push summed data set
252+
*/
253+
void HexitecSummedImagePlugin::pushSummedDataset()
254+
{
255+
// Create summed_image dataset
256+
257+
FrameMetaData summed_image_meta;
258+
dimensions_t dims(2);
259+
dims[0] = image_height_;
260+
dims[1] = image_width_;
261+
summed_image_meta.set_dimensions(dims);
262+
summed_image_meta.set_compression_type(no_compression);
263+
summed_image_meta.set_data_type(raw_32bit);
264+
summed_image_meta.set_frame_number(node_index_);
265+
summed_image_meta.set_dataset_name("summed_images");
266+
267+
const std::size_t summed_image_size = image_width_ * image_height_ * sizeof(uint32_t);
268+
269+
boost::shared_ptr<Frame> summed_frame;
270+
summed_frame = boost::shared_ptr<Frame>(new DataBlockFrame(summed_image_meta,
271+
summed_image_size));
272+
273+
// Ensure frame is empty
274+
float *summed = static_cast<float *>(summed_frame->get_data_ptr());
275+
memset(summed, 0, image_pixels_ * sizeof(uint32_t));
276+
277+
// void* output_ptr = summed_frame->get_data_ptr();
278+
279+
uint32_t *out = static_cast<uint32_t *>(summed_frame->get_data_ptr());
280+
for (int i=0; i<image_pixels_; i++)
281+
{
268282
out[i] = summed_image_[i];
269283
}
284+
285+
const std::string& dataset_name = summed_image_meta.get_dataset_name();
286+
LOG4CXX_DEBUG_LEVEL(2, logger_, "Pushing " << dataset_name << " dataset, frame number: "
287+
<< summed_image_meta.get_frame_number());
288+
this->push(summed_frame);
270289
}
271290

272291
/**

0 commit comments

Comments
 (0)