422{
423 ImGui::SetNextWindowSize(ImVec2{256, 256}, ImGuiCond_FirstUseEver);
424 bool t_open = ImGui::Begin(title.c_str(),
pb_open, ImGuiWindowFlags_NoScrollbar);
425 if (t_open)
426 {
427 bool fr_switch = detect_frame_switch(fr_count);
430 {
431 render_image();
432 }
433
435 {
436 ImGui::SameLine();
437 if (ImGui::Button("Save Image as..."))
438 {
439 saveFileDialog.Open();
440 }
441 saveFileDialog.Display();
442 if (saveFileDialog.HasSelected())
443 {
444 std::string img_file = saveFileDialog.GetSelected().string();
445 saveFileDialog.ClearSelected();
447 }
448 }
449
451 {
452 ImGui::SameLine();
453 if (ImGui::Button("Save Data as..."))
454 {
455 saveDataDialog.Open();
456 }
457 saveDataDialog.Display();
458 if (saveDataDialog.HasSelected())
459 {
460 std::string com_file = saveDataDialog.GetSelected().string();
461 saveDataDialog.ClearSelected();
463 }
464 }
465
467 {
468 ImGui::SameLine();
469 bool fft_button_press = ImGui::Button("Compute FFT");
470 if (fft_button_press)
471 {
473 }
475 {
476 if (b_data_set)
477 {
478 compute_fft();
481 }
482 else
483 {
484 std::cout << "FFT was not performed, because no data was found in " + this->title + "!" << std::endl;
485 }
486 }
487 }
488
490 {
491 ImGui::SameLine();
492 ImGui::SetNextItemWidth(64);
493 if (ImGui::DragFloat("Power", &power, 0.05f, 0.05f, 2.0f, "%.2f"))
494 {
495 this->last_idr = 0;
496 this->last_y = 0;
497 render_image((fr_count == 0) ? nxy : fr_count);
499 }
500 }
501
503 {
504 ImGui::SameLine();
505 ImGui::SetNextItemWidth(100);
506 if (ImGui::Combo("Colormap", &data_cmap, cmaps, IM_ARRAYSIZE(cmaps)))
507 {
508 this->last_idr = 0;
509 this->last_y = 0;
510 render_image((fr_count == 0) ? nxy : fr_count);
512 }
513 }
514
515
516 ImGui::SameLine();
517 ImGui::SetNextItemWidth(60);
518 if (ImGui::Combo("Bin", &bin_factor_idx, bin_options, IM_ARRAYSIZE(bin_options)))
519 {
520 bin_factor = 1 << bin_factor_idx;
521 recreate_surface();
522 this->last_idr = 0;
523 this->last_y = 0;
524 render_image((fr_count == 0) ? nxy : fr_count);
526 }
527
528 if (b_redraw && auto_render && fr_count > 0)
529 render_image(fr_count);
530
531 ImGui::SetNextWindowBgAlpha(0.0f);
532 ImGui::BeginChildFrame(ImGui::GetID("ImageFrame"), ImVec2(0.0f, 0.0f), ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
533 ImVec2 vAvail = ImGui::GetContentRegionAvail();
534 float scale = (std::min)(vAvail.x / sdl_srf->w, vAvail.y / sdl_srf->h);
535 float tex_h = sdl_srf->h * scale;
536 float tex_w = sdl_srf->w * scale;
537 float tex_h_z = tex_h * zoom;
538 float tex_w_z = tex_w * zoom;
540 {
541 glBindTexture(GL_TEXTURE_2D, (*tex_id));
542 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, sdl_srf->w, sdl_srf->h, 0,
543 GL_BGRA, GL_UNSIGNED_BYTE, sdl_srf->pixels);
544 }
545 ImVec2 pos = ImGui::GetCursorScreenPos();
546 ImGui::Image((ImTextureID)(*tex_id), ImVec2(tex_w_z, tex_h_z), uv_min, uv_max, tint_col, border_col);
547 if (ImGui::IsItemHovered())
548 {
549
550
551 float dz = (float)io.MouseWheel;
552 ImVec2 xy = ImGui::GetMousePos();
553
554
555 float rel_x = xy.x - pos.x - ImGui::GetScrollX();
556 float rel_y = xy.y - pos.y - ImGui::GetScrollY();
557
558
559
560 if ((std::abs(dz) > 0.0f) || ImGui::IsMouseClicked(ImGuiMouseButton_Left))
561 {
562 start_x = rel_x;
563 start_y = rel_y;
564 start_xs = ImGui::GetScrollX();
565 start_ys = ImGui::GetScrollY();
566 }
567
568
569 if (ImGui::IsMouseDown(ImGuiMouseButton_Left))
570 {
571 ImGui::SetScrollX(start_xs - (rel_x - start_x));
572 ImGui::SetScrollY(start_ys - (rel_y - start_y));
573 }
574
575
576 if (std::abs(dz) > 0.0f)
577 {
578
579 float zoom2 = zoom + dz * 0.1;
580 zoom2 = (std::max)(1.0f, zoom2);
581
582 float dx = ((xy.x - pos.x) / tex_w_z) * tex_w * (zoom2 - zoom);
583 float dy = ((xy.y - pos.y) / tex_h_z) * tex_h * (zoom2 - zoom);
584
585 ImGui::SetScrollX(start_xs + dx);
586 ImGui::SetScrollY(start_ys + dy);
587
588 zoom = zoom2;
589 }
590
591
592 if (ImGui::IsMouseDown(ImGuiMouseButton_Right))
593 {
594 float scale_fct = scale * zoom;
595 int x = (int)std::floor((xy.x - pos.x) / scale_fct);
596 int y = (int)std::floor((xy.y - pos.y) / scale_fct);
597 value_tooltip(x, y, zoom);
598 }
599 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
600 {
601 zoom = 1.0f;
602 ImGui::SetScrollX(0.0f);
603 ImGui::SetScrollY(0.0f);
604 }
605 }
606 ImGui::EndChildFrame();
607 }
608 ImGui::End();
610}
void save_numpy(std::string *path, int nx, int ny, std::vector< T > *data)
void save_image(std::string *path, SDL_Surface *sdl_srf)
ImGuiImageWindow< float > * fft_window