Skip to content

Commit

Permalink
fix open file bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Chu-Ping committed Nov 6, 2023
1 parent 2973dea commit 9eea1a4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 47 deletions.
20 changes: 17 additions & 3 deletions src/Ricom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,13 @@ void Ricom::line_processor(

if (n_threads > 1)
{
pool->push_task([=]
{ icom_group_classical(idxx); });
if (b_ricom)
pool->push_task([=]{ icom_group_classical(idxx); });
}
else
{
icom_group_classical(idxx);
if (b_ricom)
icom_group_classical(idxx);
}
// end of line handler
int update_line = idxx / nx - kernel.kernel_size*2;
Expand Down Expand Up @@ -673,6 +674,19 @@ void Ricom::run(int mode)
detector.compute_detector(n_cam, n_cam, offset);

// Allocate memory for image arrays
switch (camera)
{
case RICOM::ADVAPIX:
{
n_cam = 256;
break;
}
case RICOM::CHEETAH:
{
n_cam = 512;
break;
}
}
offset[0] = n_cam / 2;
offset[1] = n_cam / 2;
stem_data.assign(nxy, 0);
Expand Down
71 changes: 34 additions & 37 deletions src/RunGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,27 @@ int run_gui(Ricom *ricom)
{
std::thread run_thread;
std::thread py_thread;
// if (SDL_Init(SDL_INIT_EVERYTHING) != 0) // fail here
// {
// printf("Error: %s\n", SDL_GetError());
// return -1;
// }

if (SDL_Init(SDL_INIT_TIMER) != 0) // fail here
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) // fail here
{
printf("Error: %s\n", SDL_GetError());
return -1;
}
if (SDL_Init(SDL_INIT_AUDIO) != 0) // fail here
{
printf("Error: %s\n", SDL_GetError());
return -1;
}
if (SDL_Init(SDL_INIT_VIDEO) != 0) // fail here
{
printf("Error: %s\n", SDL_GetError());
return -1;
}
}

// if (SDL_Init(SDL_INIT_TIMER) != 0) // fail here
// {
// printf("Error: %s\n", SDL_GetError());
// return -1;
// }
// if (SDL_Init(SDL_INIT_AUDIO) != 0) // fail here
// {
// printf("Error: %s\n", SDL_GetError());
// return -1;
// }
// if (SDL_Init(SDL_INIT_VIDEO) != 0) // fail here
// {
// printf("Error: %s\n", SDL_GetError());
// return -1;
// }
// if (SDL_Init(SDL_INIT_EVERYTHING) != 0) // fail here
// {
// printf("Error: %s\n", SDL_GetError());
Expand Down Expand Up @@ -331,25 +331,21 @@ int run_gui(Ricom *ricom)
{
ini_cfg["Hardware"]["Queue Size"] = std::to_string(ricom->queue_size);
}
ImGui::Separator();

ImGui::Text("Advapix Camera");
// ImGui::Checkbox("Live Interface Menu", &b_timepix_live_menu);
if (ImGui::DragScalar("nx/y Advapix", ImGuiDataType_U16, &ricom->n_cam, 1, &drag_min_pos))
{
ini_cfg["Advapix"]["nx/y"] = std::to_string(ricom->n_cam);
}
ImGui::Separator();

ImGui::Text("Cheetah Camera");
if (ImGui::DragScalar("nx/y Cheetah", ImGuiDataType_U16, &ricom->n_cam, 1, &drag_min_pos))
{
ini_cfg["Cheetah"]["nx/y"] = std::to_string(ricom->n_cam);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Additional Imaging Modes"))
if (ImGui::BeginMenu("Imaging Modes"))
{
if (ImGui::Checkbox("Show riCOM", &ricom->b_ricom))
{
if (&ricom->b_ricom)
{
GENERIC_WINDOW("RICOM").set_data(ricom->nx, ricom->ny, &ricom->ricom_data);
}
else
{
*GENERIC_WINDOW("RICOM").pb_open = false;
}
}
if (ImGui::Checkbox("Show CoM-X", &show_com_x))
{
if (show_com_x)
Expand Down Expand Up @@ -523,7 +519,7 @@ int run_gui(Ricom *ricom)
std::this_thread::sleep_for(std::chrono::milliseconds(500));
cheetah_comm.start();
// RICOM::run(ricom, RICOM::TCP);
GENERIC_WINDOW("RICOM").set_data(ricom->nx, ricom->ny, &ricom->ricom_data);
// GENERIC_WINDOW("RICOM").set_data(ricom->nx, ricom->ny, &ricom->ricom_data);
}

if (ImGui::Button("Acquire", ImVec2(-1.0f, 0.0f)))
Expand All @@ -538,7 +534,7 @@ int run_gui(Ricom *ricom)
run_thread.detach();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
cheetah_comm.start();
GENERIC_WINDOW("RICOM").set_data(ricom->nx, ricom->ny, &ricom->ricom_data);
// GENERIC_WINDOW("RICOM").set_data(ricom->nx, ricom->ny, &ricom->ricom_data);
}

if (ImGui::Button("Stop", ImVec2(-1.0f, 0.0f)))
Expand Down Expand Up @@ -569,6 +565,7 @@ int run_gui(Ricom *ricom)
b_file_selected = true;
openFileDialog.ClearSelected();
ricom->mode = 0;
ricom->file_path = filename;
if (std::filesystem::path(filename).extension() == ".t3p")
{
ricom->camera = RICOM::ADVAPIX;
Expand All @@ -588,7 +585,7 @@ int run_gui(Ricom *ricom)
b_started = true;
b_restarted = true;
run_thread.detach();
GENERIC_WINDOW("RICOM").set_data(ricom->nx, ricom->ny, &ricom->ricom_data);
// GENERIC_WINDOW("RICOM").set_data(ricom->nx, ricom->ny, &ricom->ricom_data);
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/cameras/Cheetah.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ inline void CHEETAH::process_buffer()
type = which_type(&(buffer[buffer_id])[j]);
if ((type == 2) & rise_fall[chip_id] & (line_count[chip_id] != 0))
{
process_event(&(buffer[buffer_id])[j]);
for (int i_proc=0; i_proc<n_proc; i_proc++) { process[i_proc](); }
if (process_event(&(buffer[buffer_id])[j]))
for (int i_proc=0; i_proc<n_proc; i_proc++) { process[i_proc](); }
}
}
++n_buffer_processed;
Expand All @@ -107,7 +107,7 @@ inline void CHEETAH::process_buffer()
}
}

inline void CHEETAH::process_event(CHEETAH_ADDITIONAL::EVENT *packet)
inline bool CHEETAH::process_event(CHEETAH_ADDITIONAL::EVENT *packet)
{
toa = (((*packet & 0xFFFF) << 14) + ((*packet >> 30) & 0x3FFF)) << 4;
probe_position = ( toa - (rise_t[chip_id] * 2)) / dwell_time;
Expand All @@ -123,7 +123,9 @@ inline void CHEETAH::process_event(CHEETAH_ADDITIONAL::EVENT *packet)
(((pack_44 & 0x001F8) >> 1) +
(pack_44 & 0x00003)) +
address_bias_y[chip_id]);
return true;
}
return false;
}

int CHEETAH::which_type(CHEETAH_ADDITIONAL::EVENT *packet)
Expand Down
6 changes: 2 additions & 4 deletions src/cameras/Cheetah.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ class CHEETAH : public TIMEPIX
uint64_t dwell_time;
// event
uint64_t toa;
uint64_t probe_position;
uint64_t pack_44;
uint16_t kx;
uint16_t ky;
int address_multiplier[4] = {1,-1,-1,1};
int address_bias_x[4] = {256, 511, 255, 0};
int address_bias_y[4] = {0, 511, 511, 0};
Expand All @@ -70,14 +67,15 @@ class CHEETAH : public TIMEPIX
inline void process_tdc(EVENT *packet);

public:

inline void read_file();
inline void read_socket();
int buffer_size = BUFFER_SIZE;
int n_buffer = N_BUFFER;
std::array<std::array<EVENT, BUFFER_SIZE>, N_BUFFER> buffer;
using event = EVENT;

inline void process_event(EVENT *packet);
inline bool process_event(EVENT *packet);
inline void process_buffer();
void run();

Expand Down

0 comments on commit 9eea1a4

Please sign in to comment.