Skip to content

Commit 9dd55ff

Browse files
committed
Updates HexitecSummedImagePlugin
Single, accumulated 'Heat map' image now written on acquisition completion Changes added from branch 2024_xray_test.
1 parent a373db9 commit 9dd55ff

File tree

4 files changed

+81
-54
lines changed

4 files changed

+81
-54
lines changed

control/src/hexitec/adapter.py

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

552+
# Issue reset to summed_image
553+
command = "config/summed_image/reset_image"
554+
request = ApiAdapterRequest(self.file_dir, content_type="application/json")
555+
request.body = "{}".format(1)
556+
self.adapters["fp"].put(command, request)
557+
552558
self.daq_target = time.time()
553559
self.daq.prepare_daq(self.number_frames)
554560
# Acquisition starts here
@@ -586,19 +592,14 @@ def monitor_fem_progress(self):
586592
587593
Busy either:
588594
-Initialising
589-
-Waiting for data collection to complete, either single/multi run
595+
-Waiting for data collection to complete
590596
"""
591597
# print("\n adpt.monitor_fem_progress() called")
592598
if (self.fem.hardware_busy):
593599
# Still sending data
594600
IOLoop.instance().call_later(0.5, self.monitor_fem_progress)
595601
return
596602
# print("\n adpt.monitor_fem_progress() fem done")
597-
# Issue reset to summed_image
598-
command = "config/summed_image/reset_image"
599-
request = ApiAdapterRequest(self.file_dir, content_type="application/json")
600-
request.body = "{}".format(1)
601-
self.adapters["fp"].put(command, request)
602603

603604
self.reset_state_variables()
604605

data/frameProcessor/include/HexitecSummedImagePlugin.h

+4-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,8 +81,8 @@ namespace FrameProcessor
7981
int threshold_lower_;
8082
int threshold_upper_;
8183
int image_frequency_;
82-
int images_written_;
8384
int reset_image_;
85+
int node_index_;
8486

8587
void reset_summed_image_values();
8688
};

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

+69-45
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,8 +34,8 @@ namespace FrameProcessor
3534
threshold_lower_ = 0;
3635
threshold_upper_ = 16382;
3736
image_frequency_ = 1;
38-
images_written_ = 0;
3937
reset_image_ = 0;
38+
node_index_ = 1000;
4039
}
4140

4241
/**
@@ -125,7 +124,6 @@ namespace FrameProcessor
125124
{
126125
// Clear all pixels to be 0
127126
memset(summed_image_, 0, image_pixels_ * sizeof(uint32_t));
128-
images_written_ = 0;
129127
reset_image_ = 0;
130128
}
131129
}
@@ -139,7 +137,6 @@ namespace FrameProcessor
139137
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_THRESHOLD_LOWER, threshold_lower_);
140138
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_THRESHOLD_UPPER, threshold_upper_);
141139
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_IMAGE_FREQUENCY, image_frequency_);
142-
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_IMAGES_WRITTEN, images_written_);
143140
reply.set_param(base_str + HexitecSummedImagePlugin::CONFIG_RESET_IMAGE, reset_image_);
144141
}
145142

@@ -156,7 +153,6 @@ namespace FrameProcessor
156153
status.set_param(get_name() + "/threshold_lower", threshold_lower_);
157154
status.set_param(get_name() + "/threshold_upper", threshold_upper_);
158155
status.set_param(get_name() + "/image_frequency", image_frequency_);
159-
status.set_param(get_name() + "/images_written", images_written_);
160156
status.set_param(get_name() + "/reset_image", reset_image_);
161157
}
162158

@@ -169,6 +165,16 @@ namespace FrameProcessor
169165
return true;
170166
}
171167

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+
172178
/**
173179
* Perform processing on the frame.
174180
*
@@ -186,53 +192,32 @@ namespace FrameProcessor
186192
long long frame_number = incoming_frame_meta.get_frame_number();
187193

188194
// Push dataset
189-
LOG4CXX_DEBUG_LEVEL(3, logger_, "Pushing " << dataset << " dataset, frame number: "
195+
LOG4CXX_DEBUG_LEVEL(2, logger_, "Pushing " << dataset << " dataset, frame number: "
190196
<< frame_number);
191197
this->push(frame);
192198

193199
if (dataset.compare(std::string("processed_frames")) == 0)
194200
{
195201
try
196202
{
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?
197218
if ((frame_number % image_frequency_) == 0)
198219
{
199-
// Create summed_image dataset
200-
201-
FrameMetaData summed_image_meta;
202-
dimensions_t dims(2);
203-
dims[0] = image_height_;
204-
dims[1] = image_width_;
205-
summed_image_meta.set_dimensions(dims);
206-
summed_image_meta.set_compression_type(no_compression);
207-
summed_image_meta.set_data_type(raw_32bit);
208-
summed_image_meta.set_frame_number(frame_number);
209-
summed_image_meta.set_dataset_name("summed_images");
210-
211-
const std::size_t summed_image_size = image_width_ * image_height_ * sizeof(uint32_t);
212-
213-
boost::shared_ptr<Frame> summed_frame;
214-
summed_frame = boost::shared_ptr<Frame>(new DataBlockFrame(summed_image_meta,
215-
summed_image_size));
216-
217-
// Ensure frame is empty
218-
float *summed = static_cast<float *>(summed_frame->get_data_ptr());
219-
memset(summed, 0, image_pixels_ * sizeof(uint32_t));
220-
221-
// Define pointer to the input image data
222-
void* input_ptr = static_cast<void *>(
223-
static_cast<char *>(const_cast<void *>(data_ptr)));
224-
225-
void* output_ptr = summed_frame->get_data_ptr();
226-
227-
// Apply algorithm
228-
apply_summed_image_algorithm(static_cast<float *>(input_ptr),
229-
static_cast<uint32_t *>(output_ptr));
230-
231-
const std::string& dataset_name = summed_image_meta.get_dataset_name();
232-
LOG4CXX_DEBUG_LEVEL(3, logger_, "Pushing " << dataset_name << " dataset, frame number: "
233-
<< summed_image_meta.get_frame_number());
234-
this->push(summed_frame);
235-
images_written_++;
220+
pushSummedDataset();
236221
}
237222
}
238223
catch (const std::exception& e)
@@ -251,17 +236,56 @@ namespace FrameProcessor
251236
*
252237
* \param[frame] frame - Pointer to a frame object.
253238
*/
254-
void HexitecSummedImagePlugin::apply_summed_image_algorithm(float *in, uint32_t *out)
239+
void HexitecSummedImagePlugin::apply_summed_image_algorithm(float *in)
255240
{
256241
for (int i=0; i<image_pixels_; i++)
257242
{
258243
if (((uint32_t)in[i] > threshold_lower_) && ((uint32_t)in[i] < threshold_upper_))
259244
{
260245
summed_image_[i] += 1;
261246
}
262-
// 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+
{
263282
out[i] = summed_image_[i];
264283
}
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);
265289
}
266290

267291
/**

0 commit comments

Comments
 (0)