riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
Public Member Functions | Public Attributes | List of all members
Ricom Class Reference

#include <Ricom.h>

Collaboration diagram for Ricom:
[legend]

Public Member Functions

void draw_ricom_image ()
 
void draw_ricom_image (int y0, int ye)
 
void draw_stem_image ()
 
void draw_stem_image (int y0, int ye)
 
void draw_e_field_image ()
 
void draw_e_field_image (int y0, int ye)
 
void run (int mode)
 
void reset ()
 
void process_data ()
 
 Ricom ()
 
 ~Ricom ()
 

Public Attributes

SocketConnector socket
 
std::string file_path
 
bool b_print2file
 
int redraw_interval
 
std::atomic< int > last_y
 
ProgressMonitorp_prog_mon
 
bool b_busy
 
bool update_offset
 
bool b_continuous =false
 
bool b_cumulative =false
 
bool b_plot_cbed
 
std::array< std::atomic< size_t >, 3 > frame_id_plot_cbed = {0, 1, 0}
 
bool b_vSTEM
 
bool b_e_mag
 
bool b_ricom
 
bool b_airpi
 
bool b_plot2SDL
 
bool b_recompute_detector
 
bool b_recompute_kernel
 
Ricom_detector detector
 
Ricom_kernel kernel
 
std::array< float, 2 > offset
 
std::array< float, 2 > com_public
 
std::vector< float > comx_image
 
std::vector< float > comy_image
 
std::vector< float > ricom_image
 
std::vector< float > stem_image
 
std::vector< float > airpi_image
 
std::vector< size_t > dose_data [2]
 
std::vector< size_t > sumx_data [2]
 
std::vector< size_t > sumy_data [2]
 
std::vector< size_t > stem_data [2]
 
std::vector< size_t > frame
 
std::vector< std::complex< float > > e_field_data
 
int mode
 
RICOM::cameras camera
 
int nx
 
int ny
 
int nxy
 
int n_cam
 
int dt
 
int rep
 
int fr_total
 
int skip_row
 
int skip_img
 
int processor_line
 
int preprocessor_line
 
int id_image
 
int n_threads
 
int n_threads_max
 
int queue_size
 
float fr_freq
 
float fr_count
 
float fr_count_total
 
std::atomic< bool > rescale_ricom
 
std::atomic< bool > rescale_stem
 
std::atomic< bool > rescale_e_mag
 
bool rc_quit
 
SDL_Surface * srf_ricom
 
int ricom_cmap
 
SDL_Surface * srf_stem
 
int stem_cmap
 
SDL_Surface * srf_cbed
 
int cbed_cmap
 
SDL_Surface * srf_e_mag
 
int e_mag_cmap
 

Detailed Description

Definition at line 153 of file Ricom.h.

Constructor & Destructor Documentation

◆ Ricom()

Ricom::Ricom ( )

Definition at line 222 of file Ricom.cpp.

222  : stem_max(-FLT_MAX), stem_min(FLT_MAX),
223  e_mag_max(-FLT_MAX), e_mag_min(FLT_MAX),
224  ricom_max(-FLT_MAX), ricom_min(FLT_MAX),
225  cbed_log(),
226  ricom_mutex(), stem_mutex(), counter_mutex(), e_field_mutex(),
227  socket(), file_path(""),
228  camera(),
229  mode(0),
230  b_print2file(false),
231  redraw_interval(50),
232  last_y(0),
233  p_prog_mon(nullptr),
234  b_busy(false),
235  update_offset(true),
236  b_ricom(false),
237  b_airpi(false),
238  b_vSTEM(false),
239  b_e_mag(false),
240  b_plot_cbed(true),
241  b_plot2SDL(false), b_recompute_detector(false),
242  b_recompute_kernel(false), detector(),
243  kernel(),
244  offset{128, 128}, com_public{0.0, 0.0},
245  comx_image(), comy_image(),
246  ricom_image(),
247  stem_image(),
248  nx(1024), ny(1024), nxy(0),
249  rep(1), fr_total(0),
250  skip_row(1), skip_img(0),
251  n_threads(1), queue_size(64),
252  fr_freq(0.0), fr_count(0.0), fr_count_total(0.0),
253  rescale_ricom(false), rescale_stem(false),
254  rc_quit(false),
255  srf_ricom(NULL), ricom_cmap(9),
256  srf_stem(NULL), stem_cmap(9),
257  srf_cbed(NULL), cbed_cmap(5),
258  srf_e_mag(NULL), e_mag_cmap(12)
259 {
260  n_threads_max = std::thread::hardware_concurrency();
261 }
std::vector< float > stem_image
Definition: Ricom.h:248
std::vector< float > comy_image
Definition: Ricom.h:246
int skip_img
Definition: Ricom.h:270
std::array< float, 2 > com_public
Definition: Ricom.h:244
SocketConnector socket
Definition: Ricom.h:220
int nxy
Definition: Ricom.h:264
int redraw_interval
Definition: Ricom.h:223
bool b_busy
Definition: Ricom.h:226
int mode
Definition: Ricom.h:258
int cbed_cmap
Definition: Ricom.h:292
bool b_recompute_detector
Definition: Ricom.h:239
int e_mag_cmap
Definition: Ricom.h:294
int n_threads
Definition: Ricom.h:276
int rep
Definition: Ricom.h:267
bool update_offset
Definition: Ricom.h:227
bool b_plot2SDL
Definition: Ricom.h:238
bool b_airpi
Definition: Ricom.h:236
SDL_Surface * srf_e_mag
Definition: Ricom.h:293
std::atomic< bool > rescale_ricom
Definition: Ricom.h:282
float fr_count_total
Definition: Ricom.h:281
int n_threads_max
Definition: Ricom.h:277
float fr_count
Definition: Ricom.h:280
std::vector< float > comx_image
Definition: Ricom.h:245
std::string file_path
Definition: Ricom.h:221
int nx
Definition: Ricom.h:262
RICOM::cameras camera
Definition: Ricom.h:259
Ricom_detector detector
Definition: Ricom.h:241
bool rc_quit
Definition: Ricom.h:285
int queue_size
Definition: Ricom.h:278
bool b_e_mag
Definition: Ricom.h:234
SDL_Surface * srf_ricom
Definition: Ricom.h:287
SDL_Surface * srf_cbed
Definition: Ricom.h:291
int fr_total
Definition: Ricom.h:268
ProgressMonitor * p_prog_mon
Definition: Ricom.h:225
int ricom_cmap
Definition: Ricom.h:288
bool b_plot_cbed
Definition: Ricom.h:230
float fr_freq
Definition: Ricom.h:279
SDL_Surface * srf_stem
Definition: Ricom.h:289
bool b_recompute_kernel
Definition: Ricom.h:240
std::vector< float > ricom_image
Definition: Ricom.h:247
std::atomic< int > last_y
Definition: Ricom.h:224
int skip_row
Definition: Ricom.h:269
bool b_ricom
Definition: Ricom.h:235
bool b_vSTEM
Definition: Ricom.h:233
int ny
Definition: Ricom.h:263
bool b_print2file
Definition: Ricom.h:222
std::array< float, 2 > offset
Definition: Ricom.h:243
std::atomic< bool > rescale_stem
Definition: Ricom.h:283
int stem_cmap
Definition: Ricom.h:290
Ricom_kernel kernel
Definition: Ricom.h:242

◆ ~Ricom()

Ricom::~Ricom ( )

Definition at line 263 of file Ricom.cpp.

263 {};

Member Function Documentation

◆ draw_e_field_image() [1/2]

void Ricom::draw_e_field_image ( )

Definition at line 357 of file Ricom.cpp.

358 {
359  std::lock_guard<std::mutex> lock(e_field_mutex);
360  for (int y = 0; y < ny; y++)
361  {
362  for (int x = 0; x < nx; x++)
363  {
364  set_e_field_pixel(x, y);
365  }
366  }
367 }

◆ draw_e_field_image() [2/2]

void Ricom::draw_e_field_image ( int  y0,
int  ye 
)

Definition at line 343 of file Ricom.cpp.

344 {
345  std::lock_guard<std::mutex> lock(e_field_mutex);
346  int idr;
347  for (int y = y0; y <= ye; y++)
348  {
349  for (int x = 0; x < nx; x++)
350  {
351  set_e_field_pixel(x, y);
352  idr = y * nx + x;
353  }
354  }
355 }

◆ draw_ricom_image() [1/2]

void Ricom::draw_ricom_image ( )

Definition at line 266 of file Ricom.cpp.

267 {
268  std::lock_guard<std::mutex> lock(ricom_mutex);
269  for (int y = 0; y < ny; y++)
270  {
271  for (int x = 0; x < nx; x++)
272  {
273  set_ricom_pixel(x, y);
274  }
275  }
276 }

◆ draw_ricom_image() [2/2]

void Ricom::draw_ricom_image ( int  y0,
int  ye 
)

Definition at line 279 of file Ricom.cpp.

280 {
281  std::lock_guard<std::mutex> lock(ricom_mutex);
282  if (y0 < (kernel.kernel_size+2)) {
283  ricom_min = 0;
284  ricom_max = 0;
285  }
286 
287  for (int y = y0; y <= ye; y++)
288  {
289  for (int x = 0; x < nx; x++)
290  {
291  set_ricom_pixel(x, y);
292  }
293  }
294 }
int kernel_size
Definition: Ricom.h:59

◆ draw_stem_image() [1/2]

void Ricom::draw_stem_image ( )

Definition at line 313 of file Ricom.cpp.

314 {
315  std::lock_guard<std::mutex> lock(stem_mutex);
316  for (int y = 0; y < ny; y++)
317  {
318  for (int x = 0; x < nx; x++)
319  {
320  set_stem_pixel(x, y);
321  }
322  }
323 }

◆ draw_stem_image() [2/2]

void Ricom::draw_stem_image ( int  y0,
int  ye 
)

Definition at line 326 of file Ricom.cpp.

327 {
328  if (y0==0) {
329  stem_min = stem_image[y0*nx];
330  stem_max = stem_image[y0*nx];
331  }
332 
333  std::lock_guard<std::mutex> lock(stem_mutex);
334  for (int y = y0; y <= ye; y++)
335  {
336  for (int x = 0; x < nx; x++)
337  {
338  set_stem_pixel(x, y);
339  }
340  }
341 }

◆ process_data()

void Ricom::process_data ( )

Definition at line 471 of file Ricom.cpp.

472 {
473  // Start Thread Pool
474  BoundedThreadPool pool;
475  if (n_threads > 1)
476  pool.init(n_threads, queue_size);
477 
478  frame_id_plot_cbed[0] = 0;
479  frame_id_plot_cbed[2] = 0;
480 
481  size_t img_num = 0;
482  size_t first_frame = img_num * nxy;
483  size_t end_frame = (img_num + 1) * nxy;
484  size_t fr_total_u = (size_t)fr_total;
485 
487  p_prog_mon = &prog_mon;
488 
489  reinit_vectors_limits();
490 
491  while (processor_line != -1)
492  {
493  line_processor(
494  img_num,
495  first_frame,
496  end_frame,
497  p_prog_mon,
498  fr_total_u,
499  &pool
500  );
501  }
502  p_prog_mon = nullptr;
503 }
void init(int n_threads, int limit)
int processor_line
Definition: Ricom.h:271
std::array< std::atomic< size_t >, 3 > frame_id_plot_cbed
Definition: Ricom.h:231

◆ reset()

void Ricom::reset ( )

Definition at line 767 of file Ricom.cpp.

768 {
769  rc_quit = false;
770  fr_freq = 0;
771  reinit_vectors_limits();
772 
773  // Initializations
774  nxy = nx * ny;
775  id_image = 0;
776  fr_total = nxy * rep;
777  fr_count = 0;
778  init_surface();
779 
780  // Imaging tools
781  switch (camera)
782  {
783  case RICOM::ADVAPIX:
784  {
785  n_cam = 256;
786  break;
787  }
788  case RICOM::CHEETAH:
789  {
790  n_cam = 512;
791  break;
792  }
793  }
794  // offset[0] = n_cam / 2;
795  // offset[1] = n_cam / 2;
798 
799  // Allocate memory for image arrays
800  stem_image.assign(nxy, 0);
801  ricom_image.assign(nxy, 0);
802  comx_image.assign(nxy, 0);
803  comy_image.assign(nxy, 0);
804  for (int i=0; i<2; i++)
805  {
806  dose_data[i].assign(nxy, 0);
807  sumx_data[i].assign(nxy, 0);
808  sumy_data[i].assign(nxy, 0);
809  stem_data[i].assign(nxy, 0);
810  }
811  frame.assign(n_cam * n_cam, 0);
812  airpi_image.assign(nxy, 0); // not correct, airpi_image size will be larger due to super resolution
813 
814  // Data Processing Progress
815  processor_line = 0;
816  preprocessor_line = 0;
817 
818 }
void compute_detector(int nx_cam, int ny_cam, std::array< float, 2 > &offset)
Definition: Ricom.cpp:160
void compute_kernel()
Definition: Ricom.cpp:21
std::vector< size_t > frame
Definition: Ricom.h:254
std::vector< size_t > sumy_data[2]
Definition: Ricom.h:252
int id_image
Definition: Ricom.h:273
std::vector< float > airpi_image
Definition: Ricom.h:249
int preprocessor_line
Definition: Ricom.h:272
std::vector< size_t > sumx_data[2]
Definition: Ricom.h:251
std::vector< size_t > stem_data[2]
Definition: Ricom.h:253
std::vector< size_t > dose_data[2]
Definition: Ricom.h:250
int n_cam
Definition: Ricom.h:265
@ ADVAPIX
Definition: Ricom.h:148
@ CHEETAH
Definition: Ricom.h:149

◆ run()

void Ricom::run ( int  mode)

Definition at line 661 of file Ricom.cpp.

662 {
663  this->mode = mode;
664  reset();
665  b_busy = true;
666 
667  // Run camera dependent pipeline
668  switch (camera)
669  {
670  // Merlin not implemented
671  case RICOM::ADVAPIX:
672  {
673  using namespace ADVAPIX_ADDITIONAL;
674  ADVAPIX<EVENT, BUFFER_SIZE, N_BUFFER> cam(
675  nx,
676  ny,
677  n_cam,
678  dt,
679  b_vSTEM,
680  b_ricom,
681  b_e_mag,
682  b_airpi,
683  &b_cumulative,
684  &detector.radius2,
685  &offset,
686  &dose_data,
687  &sumx_data,
688  &sumy_data,
689  &stem_data,
690  &frame,
693  mode,
694  file_path,
695  &socket
696  );
697  cam.run();
698  process_data();
699  cam.terminate();
700  break;
701  }
702  case RICOM::CHEETAH:
703  {
704  using namespace CHEETAH_ADDITIONAL;
705  CHEETAH<EVENT, BUFFER_SIZE, N_BUFFER> cam(
706  nx,
707  ny,
708  n_cam,
709  dt,
710  b_vSTEM,
711  b_ricom,
712  b_e_mag,
713  b_airpi,
714  &b_cumulative,
715  &detector.radius2,
716  &offset,
717  &dose_data,
718  &sumx_data,
719  &sumy_data,
720  &stem_data,
721  &frame,
724  mode,
725  file_path,
726  &socket
727  );
728  cam.run();
729  process_data();
730  cam.terminate();
731  break;
732  }
733  }
734 
735 
736  // std::this_thread::sleep_for(std::chrono::milliseconds(10*1000));
737 
738 
739  // close the reading and preprocess threads ??
740 
741  b_busy = false;
742  std::cout << std::endl
743  << "Reconstruction finished successfully." << std::endl;
744 }
std::array< float, 2 > radius2
Definition: Ricom.h:132
void process_data()
Definition: Ricom.cpp:471
void reset()
Definition: Ricom.cpp:767
bool b_cumulative
Definition: Ricom.h:229
int dt
Definition: Ricom.h:266

Member Data Documentation

◆ airpi_image

std::vector<float> Ricom::airpi_image

Definition at line 249 of file Ricom.h.

◆ b_airpi

bool Ricom::b_airpi

Definition at line 236 of file Ricom.h.

◆ b_busy

bool Ricom::b_busy

Definition at line 226 of file Ricom.h.

◆ b_continuous

bool Ricom::b_continuous =false

Definition at line 228 of file Ricom.h.

◆ b_cumulative

bool Ricom::b_cumulative =false

Definition at line 229 of file Ricom.h.

◆ b_e_mag

bool Ricom::b_e_mag

Definition at line 234 of file Ricom.h.

◆ b_plot2SDL

bool Ricom::b_plot2SDL

Definition at line 238 of file Ricom.h.

◆ b_plot_cbed

bool Ricom::b_plot_cbed

Definition at line 230 of file Ricom.h.

◆ b_print2file

bool Ricom::b_print2file

Definition at line 222 of file Ricom.h.

◆ b_recompute_detector

bool Ricom::b_recompute_detector

Definition at line 239 of file Ricom.h.

◆ b_recompute_kernel

bool Ricom::b_recompute_kernel

Definition at line 240 of file Ricom.h.

◆ b_ricom

bool Ricom::b_ricom

Definition at line 235 of file Ricom.h.

◆ b_vSTEM

bool Ricom::b_vSTEM

Definition at line 233 of file Ricom.h.

◆ camera

RICOM::cameras Ricom::camera

Definition at line 259 of file Ricom.h.

◆ cbed_cmap

int Ricom::cbed_cmap

Definition at line 292 of file Ricom.h.

◆ com_public

std::array<float, 2> Ricom::com_public

Definition at line 244 of file Ricom.h.

◆ comx_image

std::vector<float> Ricom::comx_image

Definition at line 245 of file Ricom.h.

◆ comy_image

std::vector<float> Ricom::comy_image

Definition at line 246 of file Ricom.h.

◆ detector

Ricom_detector Ricom::detector

Definition at line 241 of file Ricom.h.

◆ dose_data

std::vector<size_t> Ricom::dose_data[2]

Definition at line 250 of file Ricom.h.

◆ dt

int Ricom::dt

Definition at line 266 of file Ricom.h.

◆ e_field_data

std::vector<std::complex<float> > Ricom::e_field_data

Definition at line 255 of file Ricom.h.

◆ e_mag_cmap

int Ricom::e_mag_cmap

Definition at line 294 of file Ricom.h.

◆ file_path

std::string Ricom::file_path

Definition at line 221 of file Ricom.h.

◆ fr_count

float Ricom::fr_count

Definition at line 280 of file Ricom.h.

◆ fr_count_total

float Ricom::fr_count_total

Definition at line 281 of file Ricom.h.

◆ fr_freq

float Ricom::fr_freq

Definition at line 279 of file Ricom.h.

◆ fr_total

int Ricom::fr_total

Definition at line 268 of file Ricom.h.

◆ frame

std::vector<size_t> Ricom::frame

Definition at line 254 of file Ricom.h.

◆ frame_id_plot_cbed

std::array<std::atomic<size_t>, 3> Ricom::frame_id_plot_cbed = {0, 1, 0}

Definition at line 231 of file Ricom.h.

◆ id_image

int Ricom::id_image

Definition at line 273 of file Ricom.h.

◆ kernel

Ricom_kernel Ricom::kernel

Definition at line 242 of file Ricom.h.

◆ last_y

std::atomic<int> Ricom::last_y

Definition at line 224 of file Ricom.h.

◆ mode

int Ricom::mode

Definition at line 258 of file Ricom.h.

◆ n_cam

int Ricom::n_cam

Definition at line 265 of file Ricom.h.

◆ n_threads

int Ricom::n_threads

Definition at line 276 of file Ricom.h.

◆ n_threads_max

int Ricom::n_threads_max

Definition at line 277 of file Ricom.h.

◆ nx

int Ricom::nx

Definition at line 262 of file Ricom.h.

◆ nxy

int Ricom::nxy

Definition at line 264 of file Ricom.h.

◆ ny

int Ricom::ny

Definition at line 263 of file Ricom.h.

◆ offset

std::array<float, 2> Ricom::offset

Definition at line 243 of file Ricom.h.

◆ p_prog_mon

ProgressMonitor* Ricom::p_prog_mon

Definition at line 225 of file Ricom.h.

◆ preprocessor_line

int Ricom::preprocessor_line

Definition at line 272 of file Ricom.h.

◆ processor_line

int Ricom::processor_line

Definition at line 271 of file Ricom.h.

◆ queue_size

int Ricom::queue_size

Definition at line 278 of file Ricom.h.

◆ rc_quit

bool Ricom::rc_quit

Definition at line 285 of file Ricom.h.

◆ redraw_interval

int Ricom::redraw_interval

Definition at line 223 of file Ricom.h.

◆ rep

int Ricom::rep

Definition at line 267 of file Ricom.h.

◆ rescale_e_mag

std::atomic<bool> Ricom::rescale_e_mag

Definition at line 284 of file Ricom.h.

◆ rescale_ricom

std::atomic<bool> Ricom::rescale_ricom

Definition at line 282 of file Ricom.h.

◆ rescale_stem

std::atomic<bool> Ricom::rescale_stem

Definition at line 283 of file Ricom.h.

◆ ricom_cmap

int Ricom::ricom_cmap

Definition at line 288 of file Ricom.h.

◆ ricom_image

std::vector<float> Ricom::ricom_image

Definition at line 247 of file Ricom.h.

◆ skip_img

int Ricom::skip_img

Definition at line 270 of file Ricom.h.

◆ skip_row

int Ricom::skip_row

Definition at line 269 of file Ricom.h.

◆ socket

SocketConnector Ricom::socket

Definition at line 220 of file Ricom.h.

◆ srf_cbed

SDL_Surface* Ricom::srf_cbed

Definition at line 291 of file Ricom.h.

◆ srf_e_mag

SDL_Surface* Ricom::srf_e_mag

Definition at line 293 of file Ricom.h.

◆ srf_ricom

SDL_Surface* Ricom::srf_ricom

Definition at line 287 of file Ricom.h.

◆ srf_stem

SDL_Surface* Ricom::srf_stem

Definition at line 289 of file Ricom.h.

◆ stem_cmap

int Ricom::stem_cmap

Definition at line 290 of file Ricom.h.

◆ stem_data

std::vector<size_t> Ricom::stem_data[2]

Definition at line 253 of file Ricom.h.

◆ stem_image

std::vector<float> Ricom::stem_image

Definition at line 248 of file Ricom.h.

◆ sumx_data

std::vector<size_t> Ricom::sumx_data[2]

Definition at line 251 of file Ricom.h.

◆ sumy_data

std::vector<size_t> Ricom::sumy_data[2]

Definition at line 252 of file Ricom.h.

◆ update_offset

bool Ricom::update_offset

Definition at line 227 of file Ricom.h.


The documentation for this class was generated from the following files: