diff --git a/src/Makefile.am b/src/Makefile.am index 50851c3e8..d87f5d469 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -773,7 +773,7 @@ cisTEM_CPPFLAGS = $(WX_CPPFLAGS) cisTEM_LDADD = libguicore.a libcore.a $(WX_LIBS) $(MKL_LIBS) cisTEM_LIBTOOLFLAGS = $(LIBTOOL_FLAGS) -cisTEM_display_SOURCES = programs/cisTEM_display/cisTEM_display.cpp programs/cisTEM_display/display_gui.cpp gui/DisplayPanel.cpp gui/DisplayFrame.cpp +cisTEM_display_SOURCES = programs/cisTEM_display/cisTEM_display.cpp programs/cisTEM_display/display_gui.cpp gui/DisplayPanel.cpp gui/DisplayFrame.cpp programs/cisTEM_display/DisplayServer.cpp cisTEM_display_CXXFLAGS = $(WX_CPPFLAGS) cisTEM_display_CPPFLAGS = $(WX_CPPFLAGS) cisTEM_display_LDADD = libguicore.a libcore.a $(WX_LIBS) $(MKL_LIBS) diff --git a/src/gui/DisplayFrame.cpp b/src/gui/DisplayFrame.cpp index 55a405aeb..53dce186c 100644 --- a/src/gui/DisplayFrame.cpp +++ b/src/gui/DisplayFrame.cpp @@ -1,4 +1,6 @@ #include "../core/gui_core_headers.h" +#include "../programs/cisTEM_display/DisplayServer.h" // includes wxEVT_SERVER_OPEN_FILE +#include DisplayFrame::DisplayFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : DisplayFrameParent(NULL, wxID_ANY, title, pos, size, style) { @@ -36,6 +38,7 @@ DisplayFrame::DisplayFrame(wxWindow* parent, wxWindowID id, const wxString& titl } Bind(wxEVT_CHAR_HOOK, &DisplayFrame::OnCharHook, this); + Bind(EVT_SERVER_OPEN_FILE, &DisplayFrame::OnServerOpenFile, this); } DisplayFrame::~DisplayFrame( ) { @@ -59,6 +62,165 @@ void DisplayFrame::OnFileOpenClick(wxCommandEvent& event) { cisTEMDisplayPanel->OnOpen(event); } +void DisplayFrame::OnSaveDisplayedImagesClick(wxCommandEvent& event) { + // Mimics the logic ProperOverwriteCheckSaveDialog in my_controls.cpp + wxFileDialog save_file_dialog(this, _("Save png image"), wxEmptyString, wxEmptyString, "PNG files (*.png)|*.png", wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, wxFileDialogNameStr); + + wxString wanted_extension = ".png"; + wxString default_dir = cisTEMDisplayPanel->ReturnCurrentPanel( )->filename; + + // Strip away the filename to get the directory + default_dir = default_dir.BeforeLast('/'); + + save_file_dialog.SetDirectory(default_dir); + wxString extension_lowercase = wanted_extension.Lower( ); + wxString extension_uppercase = wanted_extension.Upper( ); + + if ( save_file_dialog.ShowModal( ) == wxID_CANCEL ) { + save_file_dialog.Destroy( ); + return; + } + + // Crop out the blank space around the image: get the true width of the relevant area on the bitmap. + wxBitmap sub_bitmap = CropImageForSaving( ); + DrawScaleBarOnBitmap(sub_bitmap); + sub_bitmap.SaveFile(save_file_dialog.GetPath( ), wxBITMAP_TYPE_PNG); +} + +void DisplayFrame::OnSaveDisplayedImagesWithLegendClick(wxCommandEvent& event) { + // Mimics the logic ProperOverwriteCheckSaveDialog in my_controls.cpp + wxFileDialog save_file_dialog(this, _("Save png image with legend"), wxEmptyString, wxEmptyString, "PNG files (*.png)|*.png", wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, wxFileDialogNameStr); + + wxString wanted_extension = ".png"; + wxString default_dir = cisTEMDisplayPanel->ReturnCurrentPanel( )->filename; + + // Strip away the filename to get the directory + default_dir = default_dir.BeforeLast('/'); + + save_file_dialog.SetDirectory(default_dir); + wxString extension_lowercase = wanted_extension.Lower( ); + wxString extension_uppercase = wanted_extension.Upper( ); + + if ( save_file_dialog.ShowModal( ) == wxID_CANCEL ) { + save_file_dialog.Destroy( ); + return; + } + + // Crop out the blank space around the image: get the true width of the relevant area on the bitmap. + wxBitmap sub_bitmap = CropImageForSaving( ); + DrawScaleBarOnBitmap(sub_bitmap); + int sub_bmp_width = sub_bitmap.GetWidth( ); + int sub_bmp_height = sub_bitmap.GetHeight( ); + + // Create legend, width of 80 pixels + int legend_width = 80; + + int legend_height = sub_bmp_height; + wxImage legend_img(legend_width, legend_height); + + // Draw color bar gradient; this method calculates a value for each row + // of the legend and fills it in with a grayscale color by using the + // proportional distance from the top (max) to the bottom (min). + for ( int y = 0; y < legend_height; ++y ) { + double t = 1.0 - double(y) / legend_height; + + // Simple grayscale: interpolate between min and max + unsigned char val = static_cast(255 * t); + for ( int x = 0; x < legend_width; ++x ) { + legend_img.SetRGB(x, y, val, val, val); + } + } + + // Draw min/max text + // Note: wxImage does not support drawing directly, so we convert to wxBitmap for this step + // and then convert back to wxImage + wxBitmap legend_bmp(legend_img); + wxMemoryDC dc(legend_bmp); + + // Add a spacer between the image and the legend + int spacer_width = 15; + wxImage spacer_img(spacer_width, sub_bmp_height); + for ( int y = 0; y < sub_bmp_height; ++y ) { + for ( int x = 0; x < spacer_width; ++x ) { + spacer_img.SetRGB(x, y, 255, 255, 255); + } + } + + int combined_width = sub_bmp_width + legend_width + spacer_width; + int white_space = 200; + wxImage background_img(combined_width + white_space, sub_bmp_height + white_space); + for ( int i = 0; i < background_img.GetWidth( ); ++i ) { + for ( int j = 0; j < background_img.GetHeight( ); ++j ) { + background_img.SetRGB(i, j, 255, 255, 255); + } + } + + // Minimum tick spacing should be about 1/5 of the legend height to balance readability and clutter; + // if there is not much space, only use 2 gradations (min and max) + int min_tick_spacing = sub_bmp_height / 5; + int num_gradations = std::max(2, legend_height / min_tick_spacing); + + float min_pixel, max_pixel; + cisTEMDisplayPanel->ReturnCurrentPanel( )->image_memory_buffer->GetMinMax(min_pixel, max_pixel); + float pixel_range = max_pixel - min_pixel; + + // Convert to bitmap to be able to draw + wxBitmap background_bmp(background_img); + dc.SelectObject(background_bmp); + dc.SetPen(wxPen(*wxBLACK, 2)); + + for ( int i = 0; i < num_gradations; ++i ) { + // Spread gradations only across the legend area + int legend_top_y = white_space / 2; + int legend_bottom_y = legend_top_y + legend_height - 1; + int y = legend_top_y + int(i * (legend_height - 1) / (num_gradations - 1)); + + // Calculate the value corresponding to this gradation by interpolating between min and max + double value = max_pixel - (pixel_range * i) / (num_gradations - 1); + + int legend_right_x = sub_bmp_width + spacer_width + white_space / 2 + legend_width; + int gradation_start_x = legend_right_x; + int gradation_end_x = gradation_start_x + 10; + + dc.DrawLine(gradation_start_x, y, gradation_end_x, y); + + // Subtract 12 from y to better align text with gradation line, add 5 to starting point + // to space out from the gradation line + dc.DrawText(wxString::Format("%.2f", value), gradation_end_x + 5, y - 12); + } + + dc.SelectObject(wxNullBitmap); + + // Combine all the images + wxImage combined_img(background_img.GetWidth( ), background_img.GetHeight( ), true); + combined_img.Paste(background_bmp.ConvertToImage( ), 0, 0); + combined_img.Paste(sub_bitmap.ConvertToImage( ), white_space / 2, white_space / 2); + combined_img.Paste(spacer_img, sub_bmp_width + white_space / 2, white_space / 2); + combined_img.Paste(legend_bmp.ConvertToImage( ), sub_bmp_width + spacer_width + white_space / 2, white_space / 2); + + // Finally, draw a rectangle around the legend area to separate it from the background + // This is done last to ensure the rectangle is on top of everything else and transparent + // so there's nothing blocking the view of the legend, but the rectangle border is still + // visible. + wxBitmap combined_bmp(combined_img); + dc.SelectObject(combined_bmp); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(sub_bmp_width + spacer_width + white_space / 2, white_space / 2, legend_width, legend_height); + combined_img = combined_bmp.ConvertToImage( ); + dc.SelectObject(wxNullBitmap); + + combined_img.SaveFile(save_file_dialog.GetPath( ), wxBITMAP_TYPE_PNG); +} + +void DisplayFrame::OnServerOpenFile(wxCommandEvent& event) { + wxString filename = event.GetString( ); + if ( cisTEMDisplayPanel ) { + cisTEMDisplayPanel->OpenFile(filename, filename); + this->Raise( ); + this->SetFocus( ); + } +} + void DisplayFrame::OnCloseTabClick(wxCommandEvent& event) { if ( cisTEMDisplayPanel->ReturnCurrentPanel( ) != NULL ) { cisTEMDisplayPanel->my_notebook->DeletePage(cisTEMDisplayPanel->my_notebook->GetSelection( )); @@ -81,6 +243,43 @@ void DisplayFrame::OnLocationNumberClick(wxCommandEvent& event) { cisTEMDisplayPanel->ReturnCurrentPanel( )->ReDrawPanel( ); } +void DisplayFrame::OnLabelScaleBarClick(wxCommandEvent& event) { + if ( ! cisTEMDisplayPanel->ReturnCurrentPanel( )->single_image ) + return; + + // Turning the scale bar off needs no pixel size check + if ( cisTEMDisplayPanel->ReturnCurrentPanel( )->draw_scale_bar ) { + cisTEMDisplayPanel->ReturnCurrentPanel( )->draw_scale_bar = false; + cisTEMDisplayPanel->ReturnCurrentPanel( )->ReDrawPanel( ); + return; + } + + // Turning it on: we need a real pixel size. If none has been set yet, + // prompt the user exactly as OnShowResolution does. + if ( ! cisTEMDisplayPanel->ReturnCurrentPanel( )->resolution_instead_of_radius ) { + double wanted_pixel_size; + wxTextEntryDialog text_dialog(this, wxT("Pixel Size (Angstroms)"), wxT("Select Pixel Size"), + wxString::Format(wxT("%.2f"), cisTEMDisplayPanel->ReturnCurrentPanel( )->pixel_size), + wxOK | wxCANCEL | wxCENTRE, wxDefaultPosition); + if ( text_dialog.ShowModal( ) != wxID_OK ) { + // User cancelled — uncheck the menu item and bail + LabelScaleBar->Check(false); + return; + } + wxString current_value = text_dialog.GetValue( ); + if ( current_value.ToDouble(&wanted_pixel_size) && wanted_pixel_size > 0.0 ) { + cisTEMDisplayPanel->ReturnCurrentPanel( )->pixel_size = wanted_pixel_size; + } + else { + LabelScaleBar->Check(false); + return; + } + } + + cisTEMDisplayPanel->ReturnCurrentPanel( )->draw_scale_bar = true; + cisTEMDisplayPanel->ReturnCurrentPanel( )->ReDrawPanel( ); +} + void DisplayFrame::OnImageSelectionModeClick(wxCommandEvent& event) { // if we are already in selections mode, we don't want to do anything, so // make a check. @@ -443,14 +642,99 @@ void DisplayFrame::OnDocumentationClick(wxCommandEvent& event) { wxLaunchDefaultBrowser("http://www.cistem.org/documentation"); } +void DisplayFrame::OnDisplayControlsClick(wxCommandEvent& event) { + // 1. Create a simple scroll window dialog + wxDialog* manual_dialog = new wxDialog(this, wxID_ANY, "cisTEM Display Manual", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, "cisTEM Display Manual"); + + // 2. Populate the dialog with text that explains the display controls + wxScrolledWindow* scrolled_window = new wxScrolledWindow(manual_dialog, wxID_ANY); + wxBoxSizer* content_sizer = new wxBoxSizer(wxVERTICAL); + + wxRichTextCtrl* text_ctrl = new wxRichTextCtrl(scrolled_window, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY); + + text_ctrl->BeginFontSize(16); + text_ctrl->BeginAlignment(wxTEXT_ALIGNMENT_LEFT); + text_ctrl->BeginBold( ); + text_ctrl->WriteText("cisTEM Display Manual\n\n"); + text_ctrl->EndBold( ); + text_ctrl->EndAlignment( ); + text_ctrl->EndFontSize( ); + + text_ctrl->BeginFontSize(12); + text_ctrl->BeginBold( ); + text_ctrl->WriteText("\nKeyboard Shortcuts\n\n"); + text_ctrl->EndBold( ); + text_ctrl->EndFontSize( ); + + text_ctrl->BeginBold( ); + text_ctrl->WriteText("\n1. Left Arrow Key"); + text_ctrl->EndBold( ); + text_ctrl->WriteText(": Scroll to the previous open image tab.\n"); + text_ctrl->BeginBold( ); + text_ctrl->WriteText("2. Right Arrow Key"); + text_ctrl->EndBold( ); + text_ctrl->WriteText(": Scroll to the next open image tab.\n"); + text_ctrl->BeginBold( ); + text_ctrl->WriteText("3. Up Arrow Key"); + text_ctrl->EndBold( ); + text_ctrl->WriteText(": Scroll to the next section of images/slices that will fit within the current display window.\n"); + text_ctrl->BeginBold( ); + text_ctrl->WriteText("4. Down Arrow Key"); + text_ctrl->EndBold( ); + text_ctrl->WriteText(": Scroll to the previous section of images/slices that will fit within the current display window.\n"); + + text_ctrl->BeginBold( ); + text_ctrl->BeginFontSize(12); + text_ctrl->WriteText("\nMouse Controls\n\n"); + text_ctrl->EndFontSize( ); + text_ctrl->WriteText("\n1. Left Mouse Button"); + text_ctrl->EndBold( ); + text_ctrl->WriteText(": Select or deselect images or coordinates, depending on the current picking mode (found within the Select menu).\n"); + text_ctrl->BeginBold( ); + text_ctrl->WriteText("2. Right Mouse Button"); + text_ctrl->EndBold( ); + text_ctrl->WriteText(": Create a zoomed/upscaled subwindow that will display a more detailed view of the image contents below the mouse position. This can be dragged to view different areas of the image.\n"); + text_ctrl->BeginBold( ); + text_ctrl->WriteText("3. Middle Mouse Button"); + text_ctrl->EndBold( ); + text_ctrl->WriteText(": When in Single Image Mode (selected from the Options menu), dragging the mouse will shift the displayed window in the direction of the drag.\n\n"); + + text_ctrl->BeginBold( ); + text_ctrl->BeginFontSize(12); + text_ctrl->WriteText("\nSaving with Scale Bar\n\n\n"); + text_ctrl->EndFontSize( ); + text_ctrl->EndBold( ); + text_ctrl->WriteText("To save a displayed image or slice with a scale bar, first make sure the display is in Single Image Mode to enable the scale bar option.\n\nThen, select the Label Menu and select the scale bar option. A prompt will appear requesting the pixel size of the image or volume, and upon entering the scale bar will be drawn on the image, adjusting for different scaling levels.\n\nWhen saving as a PNG, the scale bar will be present on the image.\n"); + + wxStdDialogButtonSizer* button_sizer = new wxStdDialogButtonSizer( ); + wxButton* ok_button = new wxButton(manual_dialog, wxID_OK); + button_sizer->AddButton(ok_button); + button_sizer->Realize( ); + + content_sizer->Add(text_ctrl, 1, wxEXPAND | wxALL, 10); + scrolled_window->SetSizer(content_sizer); + scrolled_window->SetScrollRate(5, 5); + wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL); + main_sizer->Add(scrolled_window, 1, wxEXPAND); + main_sizer->Add(button_sizer, 0, wxALIGN_RIGHT | wxALL, 5); + manual_dialog->SetSizerAndFit(main_sizer); + manual_dialog->SetMinSize(wxSize(900, 500)); + + manual_dialog->Layout( ); + manual_dialog->Show( ); +} + // This prevents using buttons when an image or stack is not open to act on void DisplayFrame::DisableAllToolbarButtons( ) { // Open menu only needs close tab disabled DisplayCloseTab->Enable(false); + SaveDisplayedImages->Enable(false); + SaveDisplayedImagesWithLegend->Enable(false); // Label menu LabelLocationNumber->Enable(false); + LabelScaleBar->Enable(false); // Select menu SelectImageSelectionMode->Enable(false); @@ -471,9 +755,12 @@ void DisplayFrame::DisableAllToolbarButtons( ) { void DisplayFrame::EnableAllToolbarButtons( ) { // Open menu only needs close tab disabled DisplayCloseTab->Enable( ); + SaveDisplayedImages->Enable( ); + SaveDisplayedImagesWithLegend->Enable( ); // Label menu LabelLocationNumber->Enable( ); + LabelScaleBar->Enable( ); // Select menu SelectImageSelectionMode->Enable(true); @@ -528,6 +815,16 @@ void DisplayFrame::OnUpdateUI(wxUpdateUIEvent& event) { else if ( cisTEMDisplayPanel->ReturnCurrentPanel( )->selected_point_size == 10 ) CoordSize10->Check(true); + LabelScaleBar->Enable(cisTEMDisplayPanel->ReturnCurrentPanel( )->single_image); + if ( cisTEMDisplayPanel->ReturnCurrentPanel( )->draw_scale_bar ) { + if ( ! LabelScaleBar->IsChecked( ) ) + LabelScaleBar->Check(true); + } + else { + if ( LabelScaleBar->IsChecked( ) ) + LabelScaleBar->Check(false); + } + // Make sure single image mode is checked/unchecked based on current panel if ( cisTEMDisplayPanel->ReturnCurrentPanel( )->single_image ) { if ( ! OptionsSingleImageMode->IsChecked( ) ) @@ -629,4 +926,112 @@ void DisplayFrame::ClearTextFileFromPanel( ) { cisTEMDisplayPanel->ReturnCurrentPanel( )->short_txt_filename = wxEmptyString; cisTEMDisplayPanel->ReturnCurrentPanel( )->current_file_path = wxEmptyString; cisTEMDisplayPanel->SetTabNameSaved( ); +} + +/** + * @brief Crops the current image at the borders to remove excess blank space aroudn the image(s) being displayed. + * + * @return wxBitmap The cropped bitmap ready for saving. + */ +wxBitmap DisplayFrame::CropImageForSaving( ) { + + // TODO: must also account for the case of a single image being displayed but not being in single image mode; + // failure to do so causes the saved image to have excessively large legend (speicfically in terms of legend height) + // because the image is small but the legend is sized for the full panel. + wxBitmap sub_bitmap; + int sub_bmp_width; + int sub_bmp_height; + int single_image_x = cisTEMDisplayPanel->ReturnCurrentPanel( )->single_image_x; + int single_image_y = cisTEMDisplayPanel->ReturnCurrentPanel( )->single_image_y; + float scale_factor = cisTEMDisplayPanel->ReturnCurrentPanel( )->actual_scale_factor; + if ( cisTEMDisplayPanel->ReturnCurrentPanel( )->single_image ) { + cisTEMDisplayPanel->ReturnCurrentPanel( )->GetClientSize(&sub_bmp_width, &sub_bmp_height); + if ( single_image_x * scale_factor + sub_bmp_width > cisTEMDisplayPanel->ReturnCurrentPanel( )->panel_image->GetWidth( ) ) { + sub_bmp_width = cisTEMDisplayPanel->ReturnCurrentPanel( )->panel_image->GetWidth( ) - single_image_x * scale_factor; + } + if ( single_image_y * scale_factor + sub_bmp_height > cisTEMDisplayPanel->ReturnCurrentPanel( )->panel_image->GetHeight( ) ) { + sub_bmp_height = cisTEMDisplayPanel->ReturnCurrentPanel( )->panel_image->GetHeight( ) - single_image_y * scale_factor; + } + wxRect sub_bmp_dims(single_image_x * scale_factor, single_image_y * scale_factor, sub_bmp_width, sub_bmp_height); + wxImage tmp_sub_img(cisTEMDisplayPanel->ReturnCurrentPanel( )->panel_image->GetSubImage(sub_bmp_dims)); + sub_bitmap = wxBitmap(tmp_sub_img); + } + else { + int num_rows_with_imgs = cisTEMDisplayPanel->ReturnCurrentPanel( )->images_in_current_view / cisTEMDisplayPanel->ReturnCurrentPanel( )->images_in_x; + + // if columns_in_x is 0, then we have less than one full row of images, the number of rows shown is 1 + // if columns_in_x is > 0, then we have at least one full row of images, and the number of rows shown is either 1 or more; + // we can check if it's more than one by using modulus; if it's 0, then all rows are filled, otherwise we have a partial row + // and must increment by 1. + if ( num_rows_with_imgs > 0 ) { + // We have a partial row, so increment filled_rows by 1 + if ( cisTEMDisplayPanel->ReturnCurrentPanel( )->images_in_current_view % cisTEMDisplayPanel->ReturnCurrentPanel( )->images_in_x != 0 ) { + num_rows_with_imgs++; + } + } + else { + num_rows_with_imgs = 1; + } + + sub_bmp_width = cisTEMDisplayPanel->ReturnCurrentPanel( )->ReturnImageXSize( ) * cisTEMDisplayPanel->ReturnCurrentPanel( )->actual_scale_factor * cisTEMDisplayPanel->ReturnCurrentPanel( )->images_in_x; + sub_bmp_height = cisTEMDisplayPanel->ReturnCurrentPanel( )->ReturnImageYSize( ) * cisTEMDisplayPanel->ReturnCurrentPanel( )->actual_scale_factor * num_rows_with_imgs; + wxRect sub_bmp_dims(single_image_x * scale_factor, single_image_y * scale_factor, sub_bmp_width, sub_bmp_height); + sub_bitmap = cisTEMDisplayPanel->ReturnCurrentPanel( )->panel_bitmap.GetSubBitmap(sub_bmp_dims); + } + return sub_bitmap; +} + +void DisplayFrame::DrawScaleBarOnBitmap(wxBitmap& target_bitmap) { + if ( ! cisTEMDisplayPanel->ReturnCurrentPanel( )->draw_scale_bar || + ! cisTEMDisplayPanel->ReturnCurrentPanel( )->single_image ) + return; + + const int bmp_width = target_bitmap.GetWidth( ); + const int bmp_height = target_bitmap.GetHeight( ); + const float actual_scale_factor = cisTEMDisplayPanel->ReturnCurrentPanel( )->actual_scale_factor; + const float pixel_size = cisTEMDisplayPanel->ReturnCurrentPanel( )->pixel_size; + const float image_in_bitmap_pixel_size = pixel_size / actual_scale_factor; + + int scalebar_length; + { + const float bar_must_be_multiple_of = 5.0f; + float ideal_length_in_pixels = float(bmp_width) * 0.1f; + float ideal_length_in_nm = ideal_length_in_pixels * image_in_bitmap_pixel_size * 0.1f; + ideal_length_in_nm = roundf(ideal_length_in_nm / bar_must_be_multiple_of) * bar_must_be_multiple_of; + if ( ideal_length_in_nm < bar_must_be_multiple_of ) + ideal_length_in_nm = bar_must_be_multiple_of; + ideal_length_in_pixels = ideal_length_in_nm * 10.0f / image_in_bitmap_pixel_size; + scalebar_length = myroundint(ideal_length_in_pixels); + } + + int scalebar_thickness = int(float(bmp_height) / 50.0f); + if ( scalebar_thickness < 2 ) + scalebar_thickness = 2; + + int scalebar_x_start = int(float(bmp_width) * 0.85f) - scalebar_length / 2; + int scalebar_y_pos = int(float(bmp_height) * 0.95f) - scalebar_thickness; + + if ( scalebar_x_start < 0 ) + scalebar_x_start = 0; + if ( scalebar_x_start + scalebar_length > bmp_width ) + scalebar_x_start = bmp_width - scalebar_length; + + wxMemoryDC dc(target_bitmap); + dc.SetPen(wxPen(*wxWHITE)); + dc.SetBrush(*wxWHITE_BRUSH); + dc.DrawRectangle(scalebar_x_start, scalebar_y_pos, scalebar_length, scalebar_thickness); + + dc.SetTextForeground(*wxWHITE); + int label_font_size = std::max(9, int(float(scalebar_thickness) * 0.75f)); + dc.SetFont(wxFont(label_font_size, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); + + wxString scalebar_label = wxString::Format("%.0f nm", float(scalebar_length) * image_in_bitmap_pixel_size * 0.1f); + int scalebar_label_width; + int scalebar_label_height; + dc.GetTextExtent(scalebar_label, &scalebar_label_width, &scalebar_label_height); + dc.DrawText(scalebar_label, + scalebar_x_start + scalebar_length / 2 - scalebar_label_width / 2, + scalebar_y_pos - scalebar_label_height - scalebar_thickness / 8); + + dc.SelectObject(wxNullBitmap); } \ No newline at end of file diff --git a/src/gui/DisplayFrame.h b/src/gui/DisplayFrame.h index ef38cd609..d8070496d 100644 --- a/src/gui/DisplayFrame.h +++ b/src/gui/DisplayFrame.h @@ -13,6 +13,7 @@ class DisplayFrame : public DisplayFrameParent { //Additional functions void DisableAllToolbarButtons( ); void EnableAllToolbarButtons( ); + void OnServerOpenFile(wxCommandEvent& event); // GUI event functions void OnCharHook(wxKeyEvent& event); @@ -20,11 +21,14 @@ class DisplayFrame : public DisplayFrameParent { // File menu void OnFileOpenClick(wxCommandEvent& event); + void OnSaveDisplayedImagesClick(wxCommandEvent& event); + void OnSaveDisplayedImagesWithLegendClick(wxCommandEvent& event); void OnCloseTabClick(wxCommandEvent& event); void OnExitClick(wxCommandEvent& event); // Label menu void OnLocationNumberClick(wxCommandEvent& event); + void OnLabelScaleBarClick(wxCommandEvent& event); // Select menu void OnImageSelectionModeClick(wxCommandEvent& event); @@ -46,6 +50,7 @@ class DisplayFrame : public DisplayFrameParent { // Help menu void OnDocumentationClick(wxCommandEvent& event); + void OnDisplayControlsClick(wxCommandEvent& event); private: bool is_fullscreen; @@ -53,6 +58,8 @@ class DisplayFrame : public DisplayFrameParent { bool LoadCoords(wxString current_line, long& x, long& y, long& image_number); bool LoadImageSelections(wxString current_line); void ClearTextFileFromPanel( ); + wxBitmap CropImageForSaving( ); + void DrawScaleBarOnBitmap(wxBitmap& target_bitmap); }; #endif \ No newline at end of file diff --git a/src/gui/DisplayPanel.cpp b/src/gui/DisplayPanel.cpp index 207a85817..1a2862ba2 100644 --- a/src/gui/DisplayPanel.cpp +++ b/src/gui/DisplayPanel.cpp @@ -407,7 +407,6 @@ void DisplayPanel::OnOpen(wxCommandEvent& WXUNUSED(event)) { extension is included in this list, which is not robust against the various extensions that could exist*/ OpenFile(path, this_filename); - ReturnCurrentPanel( )->short_image_filename = this_filename; } else wxMessageBox(wxT("This file is not a compatible type; must be mrc file format."), wxT("Error"), wxOK | wxICON_INFORMATION); @@ -855,6 +854,8 @@ void DisplayPanel::OpenFile(wxString wanted_filename, wxString wanted_tab_title, return; } + my_panel->short_image_filename = wanted_tab_title; + // which images are we including.. if ( wanted_included_image_numbers == NULL ) { @@ -1432,6 +1433,7 @@ DisplayNotebookPanel::DisplayNotebookPanel(wxWindow* parent, wxWindowID id, cons use_7bit_greys = false; show_selection_distances = false; resolution_instead_of_radius = false; + draw_scale_bar = false; blue_selection_square_location = -1; @@ -1570,14 +1572,16 @@ void DisplayNotebookPanel::UpdateImageStatusInfo(int x_pos, int y_pos) { StatusText += wxT(", Value=") + wxString::Format(wxT("%f"), raw_pixel_value); - //if (selected_distance != 0 && show_selection_distances ) StatusText += wxT(", Dist=") + wxString::Format(wxT("%f"), selected_distance); + if ( selected_distance != 0 && show_selection_distances ) + StatusText += wxT(", Dist=") + wxString::Format(wxT("%f"), selected_distance); //if (image_picking_mode_enabled == INTEGRATE_PICK && integrate_box_x_pos != -1 && integrate_box_y_pos != -1) StatusText += wxT(", Integrated Value =") + wxString::Format(wxT("%f"), integrated_value); parent_display_panel->StatusText->SetLabel(StatusText); } else { wxString StatusText = wxT(""); - //if (selected_distance != 0 && show_selection_distances ) StatusText += wxT("Dist=") + wxString::Format(wxT("%f"), selected_distance); + if ( selected_distance != 0 && show_selection_distances ) + StatusText += wxT("Dist=") + wxString::Format(wxT("%f"), selected_distance); // if (image_picking_mode_enabled == INTEGRATE_PICK && integrate_box_x_pos != -1 && integrate_box_y_pos != -1) StatusText += wxT("Integrated Value =") + wxString::Format(wxT("%f"), integrated_value); parent_display_panel->StatusText->SetLabel(StatusText); } @@ -1614,14 +1618,16 @@ void DisplayNotebookPanel::UpdateImageStatusInfo(int x_pos, int y_pos) { StatusText += wxT(", Value=") + wxString::Format(wxT("%f"), raw_pixel_value); - // if (selected_distance != 0 && show_selection_distances ) StatusText += wxT(", Dist=") + wxString::Format(wxT("%f"), selected_distance); + if ( selected_distance != 0 && show_selection_distances ) + StatusText += wxT(", Dist=") + wxString::Format(wxT("%f"), selected_distance); // if (image_picking_mode_enabled == INTEGRATE_PICK && integrate_box_x_pos != -1 && integrate_box_y_pos != -1) StatusText += wxT(", Integrated Value =") + wxString::Format(wxT("%f"), integrated_value); parent_display_panel->StatusText->SetLabel(StatusText); } else { wxString StatusText = wxT(""); - // if (selected_distance != 0 && show_selection_distances ) StatusText += wxT("Dist=") + wxString::Format(wxT("%f"), selected_distance); + if ( selected_distance != 0 && show_selection_distances ) + StatusText += wxT("Dist=") + wxString::Format(wxT("%f"), selected_distance); // if (image_picking_mode_enabled == INTEGRATE_PICK && integrate_box_x_pos != -1 && integrate_box_y_pos != -1) StatusText += wxT("Integrated Value =") + wxString::Format(wxT("%f"), integrated_value); parent_display_panel->StatusText->SetLabel(StatusText); } @@ -1629,7 +1635,8 @@ void DisplayNotebookPanel::UpdateImageStatusInfo(int x_pos, int y_pos) { else { wxString StatusText = wxT(""); - // if (selected_distance != 0 && show_selection_distances ) StatusText += wxT("Dist=") + wxString::Format(wxT("%f"), selected_distance); + if ( selected_distance != 0 && show_selection_distances ) + StatusText += wxT("Dist=") + wxString::Format(wxT("%f"), selected_distance); // if (image_picking_mode_enabled == INTEGRATE_PICK && integrate_box_x_pos != -1 && integrate_box_y_pos != -1) StatusText += wxT(" Integrated Value =") + wxString::Format(wxT("%f"), integrated_value); parent_display_panel->StatusText->SetLabel(StatusText); } @@ -2333,8 +2340,17 @@ void DisplayNotebookPanel::ReDrawPanel(void) { images_in_x = 1; images_in_y = 1; } - else - images_in_current_view = images_in_x * images_in_y; + else { + // Checks if the number of images that will be displayed on the panel will fill the available + // space; if not, then we adjust the images_in_current_view to be accurate. + const int imgs_remaining = ReturnNumberofImages( ) + 1 - current_location; + if ( imgs_remaining < images_in_x * images_in_y ) { + images_in_current_view = imgs_remaining; + } + else { + images_in_current_view = images_in_x * images_in_y; + } + } if ( current_location != location_on_last_draw || images_in_x != images_in_x_on_last_draw || images_in_y != images_in_y_on_last_draw ) { //dc.Clear(); @@ -2893,6 +2909,63 @@ void DisplayNotebookPanel::OnPaint(wxPaintEvent& evt) { } } } + + // Scale bar overlay (single-image mode only) + if ( draw_scale_bar && single_image ) { + // Compute the actual screen-pixel extent of the drawn image, + // which may be smaller than the window if the image is small. + int image_screen_width = panel_image->GetWidth( ) - int(single_image_x * actual_scale_factor); + int image_screen_height = panel_image->GetHeight( ) - int(single_image_y * actual_scale_factor); + if ( image_screen_width > window_x_size ) + image_screen_width = window_x_size; + if ( image_screen_height > window_y_size ) + image_screen_height = window_y_size; + + // Å per screen pixel, then *0.1 converts Å→nm in the formula + const float image_in_bitmap_pixel_size = pixel_size / actual_scale_factor; + + int scalebar_length; + { + const float bar_must_be_multiple_of = 5.0f; // nm + float ideal_length_in_pixels = float(image_screen_width) * 0.1f; + float ideal_length_in_nm = ideal_length_in_pixels * image_in_bitmap_pixel_size * 0.1f; + ideal_length_in_nm = roundf(ideal_length_in_nm / bar_must_be_multiple_of) * bar_must_be_multiple_of; + if ( ideal_length_in_nm < bar_must_be_multiple_of ) + ideal_length_in_nm = bar_must_be_multiple_of; + ideal_length_in_pixels = ideal_length_in_nm * 10.0f / image_in_bitmap_pixel_size; + scalebar_length = myroundint(ideal_length_in_pixels); + } + + int scalebar_thickness = int(float(image_screen_height) / 50.0f); + if ( scalebar_thickness < 2 ) + scalebar_thickness = 2; + + int scalebar_x_start = int(float(image_screen_width) * 0.85f) - scalebar_length / 2; + int scalebar_y_pos = int(float(image_screen_height) * 0.95f) - scalebar_thickness; + + // Clamp so the bar never spills outside the image area + if ( scalebar_x_start < 0 ) + scalebar_x_start = 0; + if ( scalebar_x_start + scalebar_length > image_screen_width ) + scalebar_x_start = image_screen_width - scalebar_length; + + wxPen scalebar_pen(*wxWHITE); + dc.SetPen(scalebar_pen); + dc.SetBrush(*wxWHITE_BRUSH); + dc.DrawRectangle(scalebar_x_start, scalebar_y_pos, scalebar_length, scalebar_thickness); + + dc.SetTextForeground(*wxWHITE); + int label_font_size = std::max(9, int(float(scalebar_thickness) * 0.75f)); + dc.SetFont(wxFont(label_font_size, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); + + wxString scalebar_label = wxString::Format("%.0f nm", float(scalebar_length) * image_in_bitmap_pixel_size * 0.1f); + int scalebar_label_width; + int scalebar_label_height; + dc.GetTextExtent(scalebar_label, &scalebar_label_width, &scalebar_label_height); + dc.DrawText(scalebar_label, + scalebar_x_start + scalebar_length / 2 - scalebar_label_width / 2, + scalebar_y_pos - scalebar_label_height - scalebar_thickness / 8); + } } } diff --git a/src/gui/DisplayPanel.h b/src/gui/DisplayPanel.h index 59eebd981..6dd0aedef 100644 --- a/src/gui/DisplayPanel.h +++ b/src/gui/DisplayPanel.h @@ -369,6 +369,7 @@ class bool show_label; bool show_crosshair; bool single_image; + bool draw_scale_bar; bool txt_is_saved; bool have_txt_filename; diff --git a/src/gui/MyRefinementResultsPanel.cpp b/src/gui/MyRefinementResultsPanel.cpp index c42b07dac..a4372e492 100644 --- a/src/gui/MyRefinementResultsPanel.cpp +++ b/src/gui/MyRefinementResultsPanel.cpp @@ -25,11 +25,15 @@ MyRefinementResultsPanel::MyRefinementResultsPanel(wxWindow* parent) #include "icons/show_angles.cpp" #include "icons/show_text.cpp" +#include "icons/small_save_icon.cpp" - wxBitmap angles_popup_bmp = wxBITMAP_PNG_FROM_DATA(show_angles); - wxBitmap parameters_popup_bmp = wxBITMAP_PNG_FROM_DATA(show_text); + wxBitmap angles_popup_bmp = wxBITMAP_PNG_FROM_DATA(show_angles); + wxBitmap parameters_popup_bmp = wxBITMAP_PNG_FROM_DATA(show_text); + wxBitmap binned_angles_save_bmp = wxBITMAP_PNG_FROM_DATA(small_save_icon); AngularPlotDetailsButton->SetBitmap(angles_popup_bmp); ParametersDetailButton->SetBitmap(parameters_popup_bmp); + SaveBinnedAngularPlotButton->SetBitmap(binned_angles_save_bmp); + Layout( ); // FSCPlotPanel->ClassComboBox->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( MyRefinementResultsPanel::OnClassComboBoxChange ), NULL, this ); } @@ -329,6 +333,22 @@ void MyRefinementResultsPanel::AngularPlotPopupClick(wxCommandEvent& event) { } } +void MyRefinementResultsPanel::SaveBinnedPlotClick(wxCommandEvent& event) { + ProperOverwriteCheckSaveDialog* saveFileDialog; + saveFileDialog = new ProperOverwriteCheckSaveDialog(this, _("Save png image"), "PNG files (*.png)|*.png", ".png"); + if ( saveFileDialog->ShowModal( ) == wxID_CANCEL ) { + saveFileDialog->Destroy( ); + return; + } + + // save the file then.. + + // TODO: this would likely be the only difference; change the source of data + // for the saving of the file + AngularPlotPanel->buffer_bitmap.SaveFile(saveFileDialog->ReturnProperPath( ), wxBITMAP_TYPE_PNG); + saveFileDialog->Destroy( ); +} + void MyRefinementResultsPanel::PopupParametersClick(wxCommandEvent& event) { if ( RefinementPackageComboBox->GetSelection( ) >= 0 && OrthPanel->my_notebook->GetPageCount( ) > 0 ) { UpdateBufferedFullRefinement( ); diff --git a/src/gui/MyRefinementResultsPanel.h b/src/gui/MyRefinementResultsPanel.h index eee092119..34995ab26 100644 --- a/src/gui/MyRefinementResultsPanel.h +++ b/src/gui/MyRefinementResultsPanel.h @@ -26,6 +26,7 @@ class MyRefinementResultsPanel : public RefinementResultsPanel { void OnClassComboBoxChange(wxCommandEvent& event); void AngularPlotPopupClick(wxCommandEvent& event); void PopupParametersClick(wxCommandEvent& event); + void SaveBinnedPlotClick(wxCommandEvent& event); void UpdateCachedRefinement( ); void UpdateBufferedFullRefinement( ); diff --git a/src/gui/ProjectX_gui_refine3d.cpp b/src/gui/ProjectX_gui_refine3d.cpp index a69b1fffa..41e395628 100644 --- a/src/gui/ProjectX_gui_refine3d.cpp +++ b/src/gui/ProjectX_gui_refine3d.cpp @@ -102,12 +102,15 @@ RefinementResultsPanel::RefinementResultsPanel( wxWindow* parent, wxWindowID id, ParametersDetailButton = new NoFocusBitmapButton( m_panel125, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); ParametersDetailButton->SetDefault(); - bSizer497->Add( ParametersDetailButton, 0, wxLEFT|wxTOP, 5 ); + bSizer497->Add( ParametersDetailButton, 0, wxEXPAND|wxTOP, 5 ); AngularPlotDetailsButton = new NoFocusBitmapButton( m_panel125, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); AngularPlotDetailsButton->SetDefault(); - bSizer497->Add( AngularPlotDetailsButton, 0, wxRIGHT|wxTOP, 5 ); + bSizer497->Add( AngularPlotDetailsButton, 0, wxEXPAND|wxTOP, 5 ); + + SaveBinnedAngularPlotButton = new NoFocusBitmapButton( m_panel125, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); + bSizer497->Add( SaveBinnedAngularPlotButton, 0, wxEXPAND|wxTOP, 5 ); bSizer495->Add( bSizer497, 0, wxEXPAND, 5 ); @@ -614,6 +617,7 @@ RefinementResultsPanel::RefinementResultsPanel( wxWindow* parent, wxWindowID id, this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( RefinementResultsPanel::OnUpdateUI ) ); ParametersDetailButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( RefinementResultsPanel::PopupParametersClick ), NULL, this ); AngularPlotDetailsButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( RefinementResultsPanel::AngularPlotPopupClick ), NULL, this ); + SaveBinnedAngularPlotButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( RefinementResultsPanel::SaveBinnedPlotClick ), NULL, this ); JobDetailsToggleButton->Connect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( RefinementResultsPanel::OnJobDetailsToggle ), NULL, this ); } @@ -623,6 +627,7 @@ RefinementResultsPanel::~RefinementResultsPanel() this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( RefinementResultsPanel::OnUpdateUI ) ); ParametersDetailButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( RefinementResultsPanel::PopupParametersClick ), NULL, this ); AngularPlotDetailsButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( RefinementResultsPanel::AngularPlotPopupClick ), NULL, this ); + SaveBinnedAngularPlotButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( RefinementResultsPanel::SaveBinnedPlotClick ), NULL, this ); JobDetailsToggleButton->Disconnect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( RefinementResultsPanel::OnJobDetailsToggle ), NULL, this ); } diff --git a/src/gui/ProjectX_gui_refine3d.h b/src/gui/ProjectX_gui_refine3d.h index 7e42a48a3..cf3cd19cf 100644 --- a/src/gui/ProjectX_gui_refine3d.h +++ b/src/gui/ProjectX_gui_refine3d.h @@ -169,6 +169,7 @@ class RefinementResultsPanel : public wxPanel virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void PopupParametersClick( wxCommandEvent& event ) { event.Skip(); } virtual void AngularPlotPopupClick( wxCommandEvent& event ) { event.Skip(); } + virtual void SaveBinnedPlotClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnJobDetailsToggle( wxCommandEvent& event ) { event.Skip(); } @@ -177,6 +178,7 @@ class RefinementResultsPanel : public wxPanel RefinementPickerComboPanel* InputParametersComboBox; NoFocusBitmapButton* ParametersDetailButton; NoFocusBitmapButton* AngularPlotDetailsButton; + NoFocusBitmapButton* SaveBinnedAngularPlotButton; RefinementResultsPanel( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 1007,587 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); diff --git a/src/gui/wxformbuilder/ProjectX_refine3d.fbp b/src/gui/wxformbuilder/ProjectX_refine3d.fbp index 1f78f29cc..bb2dc7fe3 100644 --- a/src/gui/wxformbuilder/ProjectX_refine3d.fbp +++ b/src/gui/wxformbuilder/ProjectX_refine3d.fbp @@ -814,7 +814,7 @@ 5 - wxLEFT|wxTOP + wxEXPAND|wxTOP 0 1 @@ -888,7 +888,7 @@ 5 - wxRIGHT|wxTOP + wxEXPAND|wxTOP 0 1 @@ -960,6 +960,80 @@ AngularPlotPopupClick + + 5 + wxEXPAND|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + MyButton + + 0 + + 0 + + + 0 + + 1 + SaveBinnedAngularPlotButton + 1 + + + public + 1 + + + + Resizable + 1 + + + NoFocusBitmapButton; my_controls.h; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + SaveBinnedPlotClick + + @@ -6642,6 +6716,7 @@ 952,539 + 0 wxTAB_TRAVERSAL @@ -7514,6 +7589,7 @@ 500,300 + 0 wxTAB_TRAVERSAL diff --git a/src/gui/wxformbuilder/cisTEM_display.fbp b/src/gui/wxformbuilder/cisTEM_display.fbp index e70d170f0..cebb99be2 100644 --- a/src/gui/wxformbuilder/cisTEM_display.fbp +++ b/src/gui/wxformbuilder/cisTEM_display.fbp @@ -29,7 +29,7 @@ 0 1 0 - + 0 wxAUI_MGR_DEFAULT @@ -53,7 +53,7 @@ wxTAB_TRAVERSAL OnMiddleUp - + MainSizer wxVERTICAL @@ -151,7 +151,7 @@ wxTAB_TRAVERSAL 1 OnUpdateUI - + 1 @@ -172,7 +172,7 @@ - + File DisplayFileMenu protected @@ -208,6 +208,38 @@ m_separator7 none + + + 0 + 0 + + wxID_ANY + wxITEM_NORMAL + Save Displayed Image(s) As PNG + SaveDisplayedImages + protected + + + OnSaveDisplayedImagesClick + + + + 0 + 0 + + wxID_ANY + wxITEM_NORMAL + Save Displayed Image(s) As PNG with Legend + SaveDisplayedImagesWithLegend + protected + + + OnSaveDisplayedImagesWithLegendClick + + + m_separator71 + none + 0 @@ -269,7 +301,7 @@ OnExitClick - + Label DisplayLabelMenu protected @@ -287,6 +319,20 @@ OnLocationNumberClick + + + 0 + 1 + + wxID_ANY + wxITEM_CHECK + Show Scale Bar + LabelScaleBar + protected + + + OnLabelScaleBarClick + Select @@ -470,6 +516,20 @@ Help DisplayHelpMenu protected + + + 0 + 1 + User Manual for cisTEM Display + wxID_ANY + wxITEM_NORMAL + Display Controls + HelpDisplayControls + protected + + + OnDisplayControlsClick + 0 @@ -550,7 +610,7 @@ - + 0 wxAUI_MGR_DEFAULT @@ -582,7 +642,7 @@ OnMotion OnPaint OnRightDown - + MainSizer wxVERTICAL diff --git a/src/programs/cisTEM_display/DisplayServer.cpp b/src/programs/cisTEM_display/DisplayServer.cpp new file mode 100644 index 000000000..134c191ec --- /dev/null +++ b/src/programs/cisTEM_display/DisplayServer.cpp @@ -0,0 +1,87 @@ +#include "DisplayServer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// #include "DisplayConfig.h" + +wxDEFINE_EVENT(EVT_SERVER_OPEN_FILE, wxCommandEvent); + +DisplayServer& DisplayServer::GetInstance( ) { + static DisplayServer instance; + return instance; +} + +bool DisplayServer::Start( ) { + unlink(SOCKET_PATH.c_str( )); + socket_fd = socket(AF_UNIX, SOCK_STREAM, 0); + if ( socket_fd < 0 ) + return false; + + sockaddr_un addr{ }; + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, SOCKET_PATH.c_str( ), sizeof(addr.sun_path) - 1); + unlink(SOCKET_PATH.c_str( )); + + if ( bind(socket_fd, (sockaddr*)&addr, sizeof(addr)) < 0 ) { + perror("bind"); + return false; + } + + if ( listen(socket_fd, 5) < 0 ) { + perror("listen"); + return false; + } + std::thread([this]( ) { ServerLoop( ); }).detach( ); + return true; +} + +void DisplayServer::ServerLoop( ) { + while ( true ) { + int client_fd = accept(socket_fd, nullptr, nullptr); + if ( client_fd < 0 ) { + perror("accept"); + continue; + } + + std::string buffer; + char tmp[512]; + ssize_t len; + while ( (len = read(client_fd, tmp, sizeof(tmp))) > 0 ) { + buffer.append(tmp, len); + } + close(client_fd); + size_t start = 0; + while ( true ) { + size_t pos = buffer.find('\n', start); + if ( pos == std::string::npos ) + break; + + std::string filename = buffer.substr(start, pos - start); + start = pos + 1; + + if ( ! filename.empty( ) ) { + wxString message = wxString::FromUTF8(filename.c_str( )).Trim( ); + wxCommandEvent evt(EVT_SERVER_OPEN_FILE, 1000); + evt.SetString(message); + wxQueueEvent(wxTheApp->GetTopWindow( )->GetEventHandler( ), new wxCommandEvent(evt)); + } + } + close(client_fd); + } +} + +void DisplayServer::Stop( ) { + if ( socket_fd != -1 ) { + close(socket_fd); + unlink(SOCKET_PATH.c_str( )); + } +} diff --git a/src/programs/cisTEM_display/DisplayServer.h b/src/programs/cisTEM_display/DisplayServer.h new file mode 100644 index 000000000..0865b8f70 --- /dev/null +++ b/src/programs/cisTEM_display/DisplayServer.h @@ -0,0 +1,57 @@ +#ifndef _src_programs_cisTEM_display_IpcServer_h_ +#define _src_programs_cisTEM_display_IpcServer_h_ + +#pragma once +#include +#include +#include +#include +#include +#include +#include + +wxDECLARE_EVENT(EVT_SERVER_OPEN_FILE, wxCommandEvent); + +class DisplayServer { + public: + static DisplayServer& GetInstance( ); + + bool Start( ); + void Stop( ); + + private: + int socket_fd = -1; + void ServerLoop( ); +}; + +// These two functions will ensure that no matter how the display program +// is closed, the existing socket in /tmp will be deleted + +inline const std::string GetUserSocketPath( ) { + const char* username = getenv("USER"); + if ( ! username ) { + struct passwd* pw = getpwuid(getuid( )); + if ( pw ) + username = pw->pw_name; + else + username = "unknown"; + } + return username; +}; + +inline std::string SOCKET_PATH = ("/tmp/cisTEM_display_ipc_socket_" + GetUserSocketPath( )).c_str( ); + +inline void CleanupSocketFile(int sig_num) { + unlink(SOCKET_PATH.c_str( )); + signal(sig_num, SIG_DFL); + raise(sig_num); +}; + +inline void SetupSignalHandlers( ) { + signal(SIGINT, CleanupSocketFile); + signal(SIGTERM, CleanupSocketFile); + signal(SIGQUIT, CleanupSocketFile); + signal(SIGTSTP, CleanupSocketFile); +}; + +#endif \ No newline at end of file diff --git a/src/programs/cisTEM_display/cisTEM_display.cpp b/src/programs/cisTEM_display/cisTEM_display.cpp index de1bc3c5f..b471b12cd 100644 --- a/src/programs/cisTEM_display/cisTEM_display.cpp +++ b/src/programs/cisTEM_display/cisTEM_display.cpp @@ -1,4 +1,14 @@ #include "../../core/gui_core_headers.h" +#include "DisplayServer.h" +#include +#include +#include +#include + +// #define IPC_PORT 3456 +// #define IPC_SERVICE_NAME "CistemDisplayService" + +class MyServer; class DisplayApp : public wxApp { public: @@ -6,28 +16,79 @@ class DisplayApp : public wxApp { virtual int OnExit( ); virtual void OnInitCmdLine(wxCmdLineParser& parser); virtual bool OnCmdLineParsed(wxCmdLineParser& parser); + ~DisplayApp( ); + + private: + wxSingleInstanceChecker* m_checker; + bool new_instance; + wxArrayString files_to_open; + // MyServer* m_server; }; +static const wxCmdLineEntryDesc display_cmd_line_desc[] = { + {wxCMD_LINE_SWITCH, "h", "help", "displays help on the command line parameters", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP}, + {wxCMD_LINE_SWITCH, "n", "new-instance", "force starting a new instance, even if another is already running", wxCMD_LINE_VAL_NONE, 0}, + {wxCMD_LINE_PARAM, nullptr, nullptr, "file(s) to open", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE}, + {wxCMD_LINE_NONE}}; + IMPLEMENT_APP(DisplayApp) -DisplayFrame* display_frame; +DisplayFrame* + display_frame; + +DisplayApp::~DisplayApp( ) { + DisplayServer::GetInstance( ).Stop( ); +} bool DisplayApp::OnInit( ) { + if ( ! wxApp::OnInit( ) ) + return false; + + // new_instance = m_parser->Found(wxT("n")); + + const wxString name = wxString::Format("cisTEM_Display-%s", wxGetUserId( )); + m_checker = new wxSingleInstanceChecker(name); + if ( m_checker->IsAnotherRunning( ) && ! new_instance ) { + if ( argc > 1 ) { + int sock = socket(AF_UNIX, SOCK_STREAM, 0); + if ( sock != -1 ) { + struct sockaddr_un addr; + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, SOCKET_PATH.c_str( )); + if ( connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == 0 ) { + for ( size_t i = 0; i < files_to_open.GetCount( ); i++ ) { + wxScopedCharBuffer buffer = files_to_open[i].ToUTF8( ); + write(sock, buffer.data( ), buffer.length( )); + write(sock, "\n", 1); + } + } + else { + perror("client connect failed\n"); + } + close(sock); + } + return false; + } + } + else if ( m_checker->IsAnotherRunning( ) && new_instance ) { + // Now make sure we proceed with opening a new application instance + wxPrintf("Proceding with opening a new instance...\n"); + } + else { + SetupSignalHandlers( ); + DisplayServer::GetInstance( ).Start( ); + } + wxInitAllImageHandlers( ); display_frame = new DisplayFrame(NULL, wxID_ANY, "cisTEM Display", wxPoint(-1, -1), wxSize(-1, -1), wxDEFAULT_FRAME_STYLE); wxString cmd_full_filename; wxString cmd_filename; - // Check if filenames are present; if so, open them - if ( argc > 1 ) { - for ( int i = 1; i < argc; i++ ) { - cmd_filename = argv[i]; - wxFileName filename(cmd_filename); - filename.Normalize(wxPATH_NORM_LONG | wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE); - cmd_full_filename = filename.GetFullPath( ); - display_frame->cisTEMDisplayPanel->OpenFile(cmd_full_filename, cmd_full_filename); - } + for ( int i = 0; i < files_to_open.GetCount( ); i++ ) { + wxString tab_title = wxFileName(files_to_open[i]).GetFullName( ); + display_frame->cisTEMDisplayPanel->OpenFile(files_to_open[i], tab_title); } display_frame->Layout( ); @@ -36,13 +97,24 @@ bool DisplayApp::OnInit( ) { } void DisplayApp::OnInitCmdLine(wxCmdLineParser& parser) { + parser.SetDesc(display_cmd_line_desc); + parser.SetSwitchChars(wxT("-")); } bool DisplayApp::OnCmdLineParsed(wxCmdLineParser& parser) { + new_instance = parser.Found(wxT("n")); + for ( size_t arg_counter = 0; arg_counter < parser.GetParamCount( ); arg_counter++ ) { + wxString cmd_filename = parser.GetParam(arg_counter); + wxFileName filename(cmd_filename); + filename.Normalize(wxPATH_NORM_LONG | wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE); + wxString cmd_full_filename = filename.GetFullPath( ); + files_to_open.Add(cmd_full_filename); + } return true; } int DisplayApp::OnExit( ) { + DisplayServer::GetInstance( ).Stop( ); return 0; } diff --git a/src/programs/cisTEM_display/display_gui.cpp b/src/programs/cisTEM_display/display_gui.cpp index 4659306b6..e9e2acf5a 100644 --- a/src/programs/cisTEM_display/display_gui.cpp +++ b/src/programs/cisTEM_display/display_gui.cpp @@ -11,306 +11,303 @@ /////////////////////////////////////////////////////////////////////////// -DisplayPanelParent::DisplayPanelParent( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name ) -{ - MainSizer = new wxBoxSizer( wxVERTICAL ); +DisplayPanelParent::DisplayPanelParent(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxPanel(parent, id, pos, size, style, name) { + MainSizer = new wxBoxSizer(wxVERTICAL); - Toolbar = new wxToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT|wxTB_HORIZONTAL ); - Toolbar->Realize(); + Toolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_HORIZONTAL); + Toolbar->Realize( ); - MainSizer->Add( Toolbar, 0, wxEXPAND, 5 ); + MainSizer->Add(Toolbar, 0, wxEXPAND, 5); + this->SetSizer(MainSizer); + this->Layout( ); - this->SetSizer( MainSizer ); - this->Layout(); - - // Connect Events - this->Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( DisplayPanelParent::OnMiddleUp ) ); + // Connect Events + this->Connect(wxEVT_MIDDLE_UP, wxMouseEventHandler(DisplayPanelParent::OnMiddleUp)); } -DisplayPanelParent::~DisplayPanelParent() -{ - // Disconnect Events - this->Disconnect( wxEVT_MIDDLE_UP, wxMouseEventHandler( DisplayPanelParent::OnMiddleUp ) ); - +DisplayPanelParent::~DisplayPanelParent( ) { + // Disconnect Events + this->Disconnect(wxEVT_MIDDLE_UP, wxMouseEventHandler(DisplayPanelParent::OnMiddleUp)); } -DisplayFrameParent::DisplayFrameParent( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) -{ - this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - - m_menubar2 = new wxMenuBar( 0 ); - DisplayFileMenu = new wxMenu(); - DisplayFileOpen = new wxMenuItem( DisplayFileMenu, wxID_ANY, wxString( wxT("Open Image") ) , wxEmptyString, wxITEM_NORMAL ); - DisplayFileMenu->Append( DisplayFileOpen ); - - DisplayCloseTab = new wxMenuItem( DisplayFileMenu, wxID_ANY, wxString( wxT("Close tab") ) , wxEmptyString, wxITEM_NORMAL ); - DisplayFileMenu->Append( DisplayCloseTab ); - DisplayCloseTab->Enable( false ); - - DisplayFileMenu->AppendSeparator(); - - SelectOpenTxt = new wxMenuItem( DisplayFileMenu, wxID_ANY, wxString( wxT("Open Text File") ) , wxEmptyString, wxITEM_NORMAL ); - DisplayFileMenu->Append( SelectOpenTxt ); - SelectOpenTxt->Enable( false ); - - SelectSaveTxt = new wxMenuItem( DisplayFileMenu, wxID_ANY, wxString( wxT("Save Text File") ) , wxEmptyString, wxITEM_NORMAL ); - DisplayFileMenu->Append( SelectSaveTxt ); - SelectSaveTxt->Enable( false ); - - SelectSaveTxtAs = new wxMenuItem( DisplayFileMenu, wxID_ANY, wxString( wxT("Save Text File As") ) , wxEmptyString, wxITEM_NORMAL ); - DisplayFileMenu->Append( SelectSaveTxtAs ); - SelectSaveTxtAs->Enable( false ); +DisplayFrameParent::DisplayFrameParent(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style) { + this->SetSizeHints(wxDefaultSize, wxDefaultSize); - DisplayFileMenu->AppendSeparator(); + m_menubar2 = new wxMenuBar(0); + DisplayFileMenu = new wxMenu( ); + DisplayFileOpen = new wxMenuItem(DisplayFileMenu, wxID_ANY, wxString(wxT("Open Image")), wxEmptyString, wxITEM_NORMAL); + DisplayFileMenu->Append(DisplayFileOpen); - DisplayExit = new wxMenuItem( DisplayFileMenu, wxID_ANY, wxString( wxT("Exit") ) , wxEmptyString, wxITEM_NORMAL ); - DisplayFileMenu->Append( DisplayExit ); + DisplayCloseTab = new wxMenuItem(DisplayFileMenu, wxID_ANY, wxString(wxT("Close tab")), wxEmptyString, wxITEM_NORMAL); + DisplayFileMenu->Append(DisplayCloseTab); + DisplayCloseTab->Enable(false); - m_menubar2->Append( DisplayFileMenu, wxT("File") ); + DisplayFileMenu->AppendSeparator( ); - DisplayLabelMenu = new wxMenu(); - LabelLocationNumber = new wxMenuItem( DisplayLabelMenu, wxID_ANY, wxString( wxT("Location Number") ) , wxEmptyString, wxITEM_CHECK ); - DisplayLabelMenu->Append( LabelLocationNumber ); - LabelLocationNumber->Enable( false ); - LabelLocationNumber->Check( true ); + SaveDisplayedImages = new wxMenuItem(DisplayFileMenu, wxID_ANY, wxString(wxT("Save Displayed Image(s) As PNG")), wxEmptyString, wxITEM_NORMAL); + DisplayFileMenu->Append(SaveDisplayedImages); + SaveDisplayedImages->Enable(false); - m_menubar2->Append( DisplayLabelMenu, wxT("Label") ); + SaveDisplayedImagesWithLegend = new wxMenuItem(DisplayFileMenu, wxID_ANY, wxString(wxT("Save Displayed Image(s) As PNG with Legend")), wxEmptyString, wxITEM_NORMAL); + DisplayFileMenu->Append(SaveDisplayedImagesWithLegend); + SaveDisplayedImagesWithLegend->Enable(false); - DisplaySelectMenu = new wxMenu(); - SelectImageSelectionMode = new wxMenuItem( DisplaySelectMenu, wxID_ANY, wxString( wxT("Image Selection Mode") ) , wxEmptyString, wxITEM_RADIO ); - DisplaySelectMenu->Append( SelectImageSelectionMode ); - SelectImageSelectionMode->Enable( false ); - SelectImageSelectionMode->Check( true ); + DisplayFileMenu->AppendSeparator( ); - SelectCoordsSelectionMode = new wxMenuItem( DisplaySelectMenu, wxID_ANY, wxString( wxT("Coords Selection Mode") ) , wxEmptyString, wxITEM_RADIO ); - DisplaySelectMenu->Append( SelectCoordsSelectionMode ); - SelectCoordsSelectionMode->Enable( false ); + SelectOpenTxt = new wxMenuItem(DisplayFileMenu, wxID_ANY, wxString(wxT("Open Text File")), wxEmptyString, wxITEM_NORMAL); + DisplayFileMenu->Append(SelectOpenTxt); + SelectOpenTxt->Enable(false); - DisplaySelectMenu->AppendSeparator(); + SelectSaveTxt = new wxMenuItem(DisplayFileMenu, wxID_ANY, wxString(wxT("Save Text File")), wxEmptyString, wxITEM_NORMAL); + DisplayFileMenu->Append(SelectSaveTxt); + SelectSaveTxt->Enable(false); - SelectInvertSelection = new wxMenuItem( DisplaySelectMenu, wxID_ANY, wxString( wxT("Invert Selection") ) , wxEmptyString, wxITEM_NORMAL ); - DisplaySelectMenu->Append( SelectInvertSelection ); - SelectInvertSelection->Enable( false ); + SelectSaveTxtAs = new wxMenuItem(DisplayFileMenu, wxID_ANY, wxString(wxT("Save Text File As")), wxEmptyString, wxITEM_NORMAL); + DisplayFileMenu->Append(SelectSaveTxtAs); + SelectSaveTxtAs->Enable(false); - SelectClearSelection = new wxMenuItem( DisplaySelectMenu, wxID_ANY, wxString( wxT("Clear Selection") ) , wxEmptyString, wxITEM_NORMAL ); - DisplaySelectMenu->Append( SelectClearSelection ); - SelectClearSelection->Enable( false ); + DisplayFileMenu->AppendSeparator( ); - m_menubar2->Append( DisplaySelectMenu, wxT("Select") ); + DisplayExit = new wxMenuItem(DisplayFileMenu, wxID_ANY, wxString(wxT("Exit")), wxEmptyString, wxITEM_NORMAL); + DisplayFileMenu->Append(DisplayExit); - DisplayOptionsMenu = new wxMenu(); - OptionsSetPointSize = new wxMenu(); - wxMenuItem* OptionsSetPointSizeItem = new wxMenuItem( DisplayOptionsMenu, wxID_ANY, wxT("Set Point Size"), wxEmptyString, wxITEM_NORMAL, OptionsSetPointSize ); - CoordSize3 = new wxMenuItem( OptionsSetPointSize, wxID_ANY, wxString( wxT("3") ) , wxEmptyString, wxITEM_RADIO ); - OptionsSetPointSize->Append( CoordSize3 ); + m_menubar2->Append(DisplayFileMenu, wxT("File")); - CoordSize5 = new wxMenuItem( OptionsSetPointSize, wxID_ANY, wxString( wxT("5") ) , wxEmptyString, wxITEM_RADIO ); - OptionsSetPointSize->Append( CoordSize5 ); + DisplayLabelMenu = new wxMenu( ); + LabelLocationNumber = new wxMenuItem(DisplayLabelMenu, wxID_ANY, wxString(wxT("Location Number")), wxEmptyString, wxITEM_CHECK); + DisplayLabelMenu->Append(LabelLocationNumber); + LabelLocationNumber->Enable(false); + LabelLocationNumber->Check(true); - CoordSize7 = new wxMenuItem( OptionsSetPointSize, wxID_ANY, wxString( wxT("7") ) , wxEmptyString, wxITEM_RADIO ); - OptionsSetPointSize->Append( CoordSize7 ); + LabelScaleBar = new wxMenuItem(DisplayLabelMenu, wxID_ANY, wxString(wxT("Show Scale Bar")), wxEmptyString, wxITEM_CHECK); + DisplayLabelMenu->Append(LabelScaleBar); - CoordSize10 = new wxMenuItem( OptionsSetPointSize, wxID_ANY, wxString( wxT("10") ) , wxEmptyString, wxITEM_RADIO ); - OptionsSetPointSize->Append( CoordSize10 ); + m_menubar2->Append(DisplayLabelMenu, wxT("Label")); - DisplayOptionsMenu->Append( OptionsSetPointSizeItem ); + DisplaySelectMenu = new wxMenu( ); + SelectImageSelectionMode = new wxMenuItem(DisplaySelectMenu, wxID_ANY, wxString(wxT("Image Selection Mode")), wxEmptyString, wxITEM_RADIO); + DisplaySelectMenu->Append(SelectImageSelectionMode); + SelectImageSelectionMode->Enable(false); + SelectImageSelectionMode->Check(true); - OptionsSingleImageMode = new wxMenuItem( DisplayOptionsMenu, wxID_ANY, wxString( wxT("Single Image Mode") ) , wxEmptyString, wxITEM_CHECK ); - DisplayOptionsMenu->Append( OptionsSingleImageMode ); - OptionsSingleImageMode->Enable( false ); + SelectCoordsSelectionMode = new wxMenuItem(DisplaySelectMenu, wxID_ANY, wxString(wxT("Coords Selection Mode")), wxEmptyString, wxITEM_RADIO); + DisplaySelectMenu->Append(SelectCoordsSelectionMode); + SelectCoordsSelectionMode->Enable(false); - OptionsShowSelectionDistances = new wxMenuItem( DisplayOptionsMenu, wxID_ANY, wxString( wxT("Show Selection Distances") ) , wxEmptyString, wxITEM_CHECK ); - DisplayOptionsMenu->Append( OptionsShowSelectionDistances ); - OptionsShowSelectionDistances->Enable( false ); + DisplaySelectMenu->AppendSeparator( ); - DisplayOptionsMenu->AppendSeparator(); + SelectInvertSelection = new wxMenuItem(DisplaySelectMenu, wxID_ANY, wxString(wxT("Invert Selection")), wxEmptyString, wxITEM_NORMAL); + DisplaySelectMenu->Append(SelectInvertSelection); + SelectInvertSelection->Enable(false); - OptionsShowResolution = new wxMenuItem( DisplayOptionsMenu, wxID_ANY, wxString( wxT("Show Resolution Instead of Radius") ) , wxEmptyString, wxITEM_CHECK ); - DisplayOptionsMenu->Append( OptionsShowResolution ); - OptionsShowResolution->Enable( false ); + SelectClearSelection = new wxMenuItem(DisplaySelectMenu, wxID_ANY, wxString(wxT("Clear Selection")), wxEmptyString, wxITEM_NORMAL); + DisplaySelectMenu->Append(SelectClearSelection); + SelectClearSelection->Enable(false); - m_menubar2->Append( DisplayOptionsMenu, wxT("Options") ); + m_menubar2->Append(DisplaySelectMenu, wxT("Select")); - DisplayHelpMenu = new wxMenu(); - HelpAbout = new wxMenuItem( DisplayHelpMenu, wxID_ANY, wxString( wxT("Documentation") ) , wxEmptyString, wxITEM_NORMAL ); - DisplayHelpMenu->Append( HelpAbout ); + DisplayOptionsMenu = new wxMenu( ); + OptionsSetPointSize = new wxMenu( ); + wxMenuItem* OptionsSetPointSizeItem = new wxMenuItem(DisplayOptionsMenu, wxID_ANY, wxT("Set Point Size"), wxEmptyString, wxITEM_NORMAL, OptionsSetPointSize); + CoordSize3 = new wxMenuItem(OptionsSetPointSize, wxID_ANY, wxString(wxT("3")), wxEmptyString, wxITEM_RADIO); + OptionsSetPointSize->Append(CoordSize3); - m_menubar2->Append( DisplayHelpMenu, wxT("Help") ); + CoordSize5 = new wxMenuItem(OptionsSetPointSize, wxID_ANY, wxString(wxT("5")), wxEmptyString, wxITEM_RADIO); + OptionsSetPointSize->Append(CoordSize5); - this->SetMenuBar( m_menubar2 ); + CoordSize7 = new wxMenuItem(OptionsSetPointSize, wxID_ANY, wxString(wxT("7")), wxEmptyString, wxITEM_RADIO); + OptionsSetPointSize->Append(CoordSize7); - bSizer631 = new wxBoxSizer( wxVERTICAL ); + CoordSize10 = new wxMenuItem(OptionsSetPointSize, wxID_ANY, wxString(wxT("10")), wxEmptyString, wxITEM_RADIO); + OptionsSetPointSize->Append(CoordSize10); - cisTEMDisplayPanel = new DisplayPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - bSizer631->Add( cisTEMDisplayPanel, 1, wxEXPAND | wxALL, 5 ); + DisplayOptionsMenu->Append(OptionsSetPointSizeItem); + OptionsSingleImageMode = new wxMenuItem(DisplayOptionsMenu, wxID_ANY, wxString(wxT("Single Image Mode")), wxEmptyString, wxITEM_CHECK); + DisplayOptionsMenu->Append(OptionsSingleImageMode); + OptionsSingleImageMode->Enable(false); - this->SetSizer( bSizer631 ); - this->Layout(); + OptionsShowSelectionDistances = new wxMenuItem(DisplayOptionsMenu, wxID_ANY, wxString(wxT("Show Selection Distances")), wxEmptyString, wxITEM_CHECK); + DisplayOptionsMenu->Append(OptionsShowSelectionDistances); + OptionsShowSelectionDistances->Enable(false); - this->Centre( wxBOTH ); + DisplayOptionsMenu->AppendSeparator( ); - // Connect Events - this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DisplayFrameParent::OnUpdateUI ) ); - DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnFileOpenClick ), this, DisplayFileOpen->GetId()); - DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnCloseTabClick ), this, DisplayCloseTab->GetId()); - DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnOpenTxtClick ), this, SelectOpenTxt->GetId()); - DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnSaveTxtClick ), this, SelectSaveTxt->GetId()); - DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnSaveTxtAsClick ), this, SelectSaveTxtAs->GetId()); - DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnExitClick ), this, DisplayExit->GetId()); - DisplayLabelMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnLocationNumberClick ), this, LabelLocationNumber->GetId()); - DisplaySelectMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnImageSelectionModeClick ), this, SelectImageSelectionMode->GetId()); - DisplaySelectMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnCoordsSelectionModeClick ), this, SelectCoordsSelectionMode->GetId()); - DisplaySelectMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnInvertSelectionClick ), this, SelectInvertSelection->GetId()); - DisplaySelectMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnClearSelectionClick ), this, SelectClearSelection->GetId()); - OptionsSetPointSize->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnSize3 ), this, CoordSize3->GetId()); - OptionsSetPointSize->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnSize5 ), this, CoordSize5->GetId()); - OptionsSetPointSize->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnSize7 ), this, CoordSize7->GetId()); - OptionsSetPointSize->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnSize10 ), this, CoordSize10->GetId()); - DisplayOptionsMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnSingleImageModeClick ), this, OptionsSingleImageMode->GetId()); - DisplayOptionsMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnShowSelectionDistancesClick ), this, OptionsShowSelectionDistances->GetId()); - DisplayOptionsMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnShowResolution ), this, OptionsShowResolution->GetId()); - DisplayHelpMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( DisplayFrameParent::OnDocumentationClick ), this, HelpAbout->GetId()); -} - -DisplayFrameParent::~DisplayFrameParent() -{ - // Disconnect Events - this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DisplayFrameParent::OnUpdateUI ) ); - -} + OptionsShowResolution = new wxMenuItem(DisplayOptionsMenu, wxID_ANY, wxString(wxT("Show Resolution Instead of Radius")), wxEmptyString, wxITEM_CHECK); + DisplayOptionsMenu->Append(OptionsShowResolution); + OptionsShowResolution->Enable(false); -DisplayManualDialogParent::DisplayManualDialogParent( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) -{ - this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + m_menubar2->Append(DisplayOptionsMenu, wxT("Options")); - MainSizer = new wxBoxSizer( wxVERTICAL ); + DisplayHelpMenu = new wxMenu( ); + HelpDisplayControls = new wxMenuItem(DisplayHelpMenu, wxID_ANY, wxString(wxT("Display Controls")), wxT("User Manual for cisTEM Display"), wxITEM_NORMAL); + DisplayHelpMenu->Append(HelpDisplayControls); + HelpAbout = new wxMenuItem(DisplayHelpMenu, wxID_ANY, wxString(wxT("Documentation")), wxEmptyString, wxITEM_NORMAL); + DisplayHelpMenu->Append(HelpAbout); - MainSizer->Add( 400, 200, 0, wxFIXED_MINSIZE, 5 ); + m_menubar2->Append(DisplayHelpMenu, wxT("Help")); - m_staticline58 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - MainSizer->Add( m_staticline58, 0, wxEXPAND | wxALL, 5 ); + this->SetMenuBar(m_menubar2); - wxBoxSizer* bSizer262; - bSizer262 = new wxBoxSizer( wxHORIZONTAL ); + bSizer631 = new wxBoxSizer(wxVERTICAL); + cisTEMDisplayPanel = new DisplayPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + bSizer631->Add(cisTEMDisplayPanel, 1, wxEXPAND | wxALL, 5); - bSizer262->Add( 0, 0, 1, wxEXPAND, 5 ); + this->SetSizer(bSizer631); + this->Layout( ); - m_staticText315 = new wxStaticText( this, wxID_ANY, wxT("Min : "), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText315->Wrap( -1 ); - bSizer262->Add( m_staticText315, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + this->Centre(wxBOTH); - minimum_text_ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxTE_CENTER ); - bSizer262->Add( minimum_text_ctrl, 0, wxALL, 5 ); - - m_staticText316 = new wxStaticText( this, wxID_ANY, wxT("/"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText316->Wrap( -1 ); - bSizer262->Add( m_staticText316, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + // Connect Events + this->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(DisplayFrameParent::OnUpdateUI)); + DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnFileOpenClick), this, DisplayFileOpen->GetId( )); + DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnCloseTabClick), this, DisplayCloseTab->GetId( )); + DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSaveDisplayedImagesClick), this, SaveDisplayedImages->GetId( )); + DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSaveDisplayedImagesWithLegendClick), this, SaveDisplayedImagesWithLegend->GetId( )); + DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnOpenTxtClick), this, SelectOpenTxt->GetId( )); + DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSaveTxtClick), this, SelectSaveTxt->GetId( )); + DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSaveTxtAsClick), this, SelectSaveTxtAs->GetId( )); + DisplayFileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnExitClick), this, DisplayExit->GetId( )); + DisplayLabelMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnLocationNumberClick), this, LabelLocationNumber->GetId( )); + DisplayLabelMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnLabelScaleBarClick), this, LabelScaleBar->GetId( )); + DisplaySelectMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnImageSelectionModeClick), this, SelectImageSelectionMode->GetId( )); + DisplaySelectMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnCoordsSelectionModeClick), this, SelectCoordsSelectionMode->GetId( )); + DisplaySelectMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnInvertSelectionClick), this, SelectInvertSelection->GetId( )); + DisplaySelectMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnClearSelectionClick), this, SelectClearSelection->GetId( )); + OptionsSetPointSize->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSize3), this, CoordSize3->GetId( )); + OptionsSetPointSize->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSize5), this, CoordSize5->GetId( )); + OptionsSetPointSize->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSize7), this, CoordSize7->GetId( )); + OptionsSetPointSize->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSize10), this, CoordSize10->GetId( )); + DisplayOptionsMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnSingleImageModeClick), this, OptionsSingleImageMode->GetId( )); + DisplayOptionsMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnShowSelectionDistancesClick), this, OptionsShowSelectionDistances->GetId( )); + DisplayOptionsMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnShowResolution), this, OptionsShowResolution->GetId( )); + DisplayHelpMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnDisplayControlsClick), this, HelpDisplayControls->GetId( )); + DisplayHelpMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DisplayFrameParent::OnDocumentationClick), this, HelpAbout->GetId( )); +} - maximum_text_ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxTE_CENTER ); - bSizer262->Add( maximum_text_ctrl, 0, wxALL, 5 ); +DisplayFrameParent::~DisplayFrameParent( ) { + // Disconnect Events + this->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(DisplayFrameParent::OnUpdateUI)); +} - m_staticText317 = new wxStaticText( this, wxID_ANY, wxT(": Max"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText317->Wrap( -1 ); - bSizer262->Add( m_staticText317, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); +DisplayManualDialogParent::DisplayManualDialogParent(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxDialog(parent, id, title, pos, size, style) { + this->SetSizeHints(wxDefaultSize, wxDefaultSize); + MainSizer = new wxBoxSizer(wxVERTICAL); - bSizer262->Add( 0, 0, 1, wxEXPAND, 5 ); + MainSizer->Add(400, 200, 0, wxFIXED_MINSIZE, 5); + m_staticline58 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL); + MainSizer->Add(m_staticline58, 0, wxEXPAND | wxALL, 5); - MainSizer->Add( bSizer262, 0, wxEXPAND, 5 ); + wxBoxSizer* bSizer262; + bSizer262 = new wxBoxSizer(wxHORIZONTAL); - wxBoxSizer* bSizer265; - bSizer265 = new wxBoxSizer( wxHORIZONTAL ); + bSizer262->Add(0, 0, 1, wxEXPAND, 5); + m_staticText315 = new wxStaticText(this, wxID_ANY, wxT("Min : "), wxDefaultPosition, wxDefaultSize, 0); + m_staticText315->Wrap(-1); + bSizer262->Add(m_staticText315, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); - bSizer265->Add( 0, 0, 1, wxEXPAND, 5 ); + minimum_text_ctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_CENTER); + bSizer262->Add(minimum_text_ctrl, 0, wxALL, 5); - Toolbar = new wxToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL ); - Toolbar->Realize(); + m_staticText316 = new wxStaticText(this, wxID_ANY, wxT("/"), wxDefaultPosition, wxDefaultSize, 0); + m_staticText316->Wrap(-1); + bSizer262->Add(m_staticText316, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); - bSizer265->Add( Toolbar, 0, 0, 5 ); + maximum_text_ctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_CENTER); + bSizer262->Add(maximum_text_ctrl, 0, wxALL, 5); + m_staticText317 = new wxStaticText(this, wxID_ANY, wxT(": Max"), wxDefaultPosition, wxDefaultSize, 0); + m_staticText317->Wrap(-1); + bSizer262->Add(m_staticText317, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); - bSizer265->Add( 0, 0, 1, wxEXPAND, 5 ); + bSizer262->Add(0, 0, 1, wxEXPAND, 5); + MainSizer->Add(bSizer262, 0, wxEXPAND, 5); - MainSizer->Add( bSizer265, 0, wxEXPAND, 5 ); + wxBoxSizer* bSizer265; + bSizer265 = new wxBoxSizer(wxHORIZONTAL); - m_staticline61 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - MainSizer->Add( m_staticline61, 0, wxEXPAND | wxALL, 5 ); + bSizer265->Add(0, 0, 1, wxEXPAND, 5); - wxGridSizer* gSizer13; - gSizer13 = new wxGridSizer( 0, 2, 0, 0 ); + Toolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL); + Toolbar->Realize( ); - histogram_checkbox = new wxCheckBox( this, wxID_ANY, wxT("Use Entire File For Histogram"), wxDefaultPosition, wxDefaultSize, 0 ); - gSizer13->Add( histogram_checkbox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 ); + bSizer265->Add(Toolbar, 0, 0, 5); - live_checkbox = new wxCheckBox( this, wxID_ANY, wxT("Live Update of Display"), wxDefaultPosition, wxDefaultSize, 0 ); - live_checkbox->SetValue(true); - gSizer13->Add( live_checkbox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 ); + bSizer265->Add(0, 0, 1, wxEXPAND, 5); + MainSizer->Add(bSizer265, 0, wxEXPAND, 5); - MainSizer->Add( gSizer13, 0, wxEXPAND, 5 ); + m_staticline61 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL); + MainSizer->Add(m_staticline61, 0, wxEXPAND | wxALL, 5); - m_staticline63 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - MainSizer->Add( m_staticline63, 0, wxEXPAND | wxALL, 5 ); + wxGridSizer* gSizer13; + gSizer13 = new wxGridSizer(0, 2, 0, 0); - wxBoxSizer* bSizer264; - bSizer264 = new wxBoxSizer( wxHORIZONTAL ); + histogram_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Use Entire File For Histogram"), wxDefaultPosition, wxDefaultSize, 0); + gSizer13->Add(histogram_checkbox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); + live_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Live Update of Display"), wxDefaultPosition, wxDefaultSize, 0); + live_checkbox->SetValue(true); + gSizer13->Add(live_checkbox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); - bSizer264->Add( 0, 0, 1, wxEXPAND, 5 ); + MainSizer->Add(gSizer13, 0, wxEXPAND, 5); - m_button94 = new wxButton( this, wxID_ANY, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer264->Add( m_button94, 0, wxALL, 5 ); + m_staticline63 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL); + MainSizer->Add(m_staticline63, 0, wxEXPAND | wxALL, 5); - m_button95 = new wxButton( this, wxID_ANY, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer264->Add( m_button95, 0, wxALL, 5 ); + wxBoxSizer* bSizer264; + bSizer264 = new wxBoxSizer(wxHORIZONTAL); + bSizer264->Add(0, 0, 1, wxEXPAND, 5); - bSizer264->Add( 0, 0, 1, wxEXPAND, 5 ); + m_button94 = new wxButton(this, wxID_ANY, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0); + bSizer264->Add(m_button94, 0, wxALL, 5); + m_button95 = new wxButton(this, wxID_ANY, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0); + bSizer264->Add(m_button95, 0, wxALL, 5); - MainSizer->Add( bSizer264, 0, wxEXPAND, 5 ); + bSizer264->Add(0, 0, 1, wxEXPAND, 5); + MainSizer->Add(bSizer264, 0, wxEXPAND, 5); - this->SetSizer( MainSizer ); - this->Layout(); - MainSizer->Fit( this ); + this->SetSizer(MainSizer); + this->Layout( ); + MainSizer->Fit(this); - this->Centre( wxBOTH ); + this->Centre(wxBOTH); - // Connect Events - this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DisplayManualDialogParent::OnClose ) ); - this->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DisplayManualDialogParent::OnLeftDown ) ); - this->Connect( wxEVT_MOTION, wxMouseEventHandler( DisplayManualDialogParent::OnMotion ) ); - this->Connect( wxEVT_PAINT, wxPaintEventHandler( DisplayManualDialogParent::OnPaint ) ); - this->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( DisplayManualDialogParent::OnRightDown ) ); - minimum_text_ctrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DisplayManualDialogParent::OnLowChange ), NULL, this ); - maximum_text_ctrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DisplayManualDialogParent::OnHighChange ), NULL, this ); - histogram_checkbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DisplayManualDialogParent::OnHistogramCheck ), NULL, this ); - live_checkbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DisplayManualDialogParent::OnRealtimeCheck ), NULL, this ); - m_button94->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DisplayManualDialogParent::OnButtonOK ), NULL, this ); - m_button95->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DisplayManualDialogParent::OnButtonCancel ), NULL, this ); + // Connect Events + this->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(DisplayManualDialogParent::OnClose)); + this->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(DisplayManualDialogParent::OnLeftDown)); + this->Connect(wxEVT_MOTION, wxMouseEventHandler(DisplayManualDialogParent::OnMotion)); + this->Connect(wxEVT_PAINT, wxPaintEventHandler(DisplayManualDialogParent::OnPaint)); + this->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(DisplayManualDialogParent::OnRightDown)); + minimum_text_ctrl->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(DisplayManualDialogParent::OnLowChange), NULL, this); + maximum_text_ctrl->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(DisplayManualDialogParent::OnHighChange), NULL, this); + histogram_checkbox->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(DisplayManualDialogParent::OnHistogramCheck), NULL, this); + live_checkbox->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(DisplayManualDialogParent::OnRealtimeCheck), NULL, this); + m_button94->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(DisplayManualDialogParent::OnButtonOK), NULL, this); + m_button95->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(DisplayManualDialogParent::OnButtonCancel), NULL, this); } -DisplayManualDialogParent::~DisplayManualDialogParent() -{ - // Disconnect Events - this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DisplayManualDialogParent::OnClose ) ); - this->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DisplayManualDialogParent::OnLeftDown ) ); - this->Disconnect( wxEVT_MOTION, wxMouseEventHandler( DisplayManualDialogParent::OnMotion ) ); - this->Disconnect( wxEVT_PAINT, wxPaintEventHandler( DisplayManualDialogParent::OnPaint ) ); - this->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( DisplayManualDialogParent::OnRightDown ) ); - minimum_text_ctrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DisplayManualDialogParent::OnLowChange ), NULL, this ); - maximum_text_ctrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DisplayManualDialogParent::OnHighChange ), NULL, this ); - histogram_checkbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DisplayManualDialogParent::OnHistogramCheck ), NULL, this ); - live_checkbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DisplayManualDialogParent::OnRealtimeCheck ), NULL, this ); - m_button94->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DisplayManualDialogParent::OnButtonOK ), NULL, this ); - m_button95->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DisplayManualDialogParent::OnButtonCancel ), NULL, this ); - +DisplayManualDialogParent::~DisplayManualDialogParent( ) { + // Disconnect Events + this->Disconnect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(DisplayManualDialogParent::OnClose)); + this->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(DisplayManualDialogParent::OnLeftDown)); + this->Disconnect(wxEVT_MOTION, wxMouseEventHandler(DisplayManualDialogParent::OnMotion)); + this->Disconnect(wxEVT_PAINT, wxPaintEventHandler(DisplayManualDialogParent::OnPaint)); + this->Disconnect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(DisplayManualDialogParent::OnRightDown)); + minimum_text_ctrl->Disconnect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(DisplayManualDialogParent::OnLowChange), NULL, this); + maximum_text_ctrl->Disconnect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(DisplayManualDialogParent::OnHighChange), NULL, this); + histogram_checkbox->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(DisplayManualDialogParent::OnHistogramCheck), NULL, this); + live_checkbox->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(DisplayManualDialogParent::OnRealtimeCheck), NULL, this); + m_button94->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(DisplayManualDialogParent::OnButtonOK), NULL, this); + m_button95->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(DisplayManualDialogParent::OnButtonCancel), NULL, this); } diff --git a/src/programs/cisTEM_display/display_gui.h b/src/programs/cisTEM_display/display_gui.h index cffc20797..183c84bc6 100644 --- a/src/programs/cisTEM_display/display_gui.h +++ b/src/programs/cisTEM_display/display_gui.h @@ -36,136 +36,165 @@ class DisplayPanel; /////////////////////////////////////////////////////////////////////////////// /// Class DisplayPanelParent /////////////////////////////////////////////////////////////////////////////// -class DisplayPanelParent : public wxPanel -{ - private: +class DisplayPanelParent : public wxPanel { + private: - protected: - wxBoxSizer* MainSizer; - wxToolBar* Toolbar; + protected: + wxBoxSizer* MainSizer; + wxToolBar* Toolbar; - // Virtual event handlers, override them in your derived class - virtual void OnMiddleUp( wxMouseEvent& event ) { event.Skip(); } + // Virtual event handlers, override them in your derived class + virtual void OnMiddleUp(wxMouseEvent& event) { event.Skip( ); } + public: + DisplayPanelParent(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500, 300), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString); - public: - - DisplayPanelParent( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); - - ~DisplayPanelParent(); - + ~DisplayPanelParent( ); }; /////////////////////////////////////////////////////////////////////////////// /// Class DisplayFrameParent /////////////////////////////////////////////////////////////////////////////// -class DisplayFrameParent : public wxFrame -{ - private: - - protected: - wxMenuBar* m_menubar2; - wxMenu* DisplayFileMenu; - wxMenuItem* DisplayFileOpen; - wxMenuItem* DisplayCloseTab; - wxMenuItem* SelectOpenTxt; - wxMenuItem* SelectSaveTxt; - wxMenuItem* SelectSaveTxtAs; - wxMenuItem* DisplayExit; - wxMenu* DisplayLabelMenu; - wxMenuItem* LabelLocationNumber; - wxMenu* DisplaySelectMenu; - wxMenuItem* SelectImageSelectionMode; - wxMenuItem* SelectCoordsSelectionMode; - wxMenuItem* SelectInvertSelection; - wxMenuItem* SelectClearSelection; - wxMenu* DisplayOptionsMenu; - wxMenu* OptionsSetPointSize; - wxMenuItem* CoordSize3; - wxMenuItem* CoordSize5; - wxMenuItem* CoordSize7; - wxMenuItem* CoordSize10; - wxMenuItem* OptionsSingleImageMode; - wxMenuItem* OptionsShowSelectionDistances; - wxMenuItem* OptionsShowResolution; - wxMenu* DisplayHelpMenu; - wxMenuItem* HelpAbout; - - // Virtual event handlers, override them in your derived class - virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } - virtual void OnFileOpenClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnCloseTabClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnOpenTxtClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSaveTxtClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSaveTxtAsClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnExitClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnLocationNumberClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnImageSelectionModeClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnCoordsSelectionModeClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnInvertSelectionClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnClearSelectionClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSize3( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSize5( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSize7( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSize10( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSingleImageModeClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnShowSelectionDistancesClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnShowResolution( wxCommandEvent& event ) { event.Skip(); } - virtual void OnDocumentationClick( wxCommandEvent& event ) { event.Skip(); } - - - public: - wxBoxSizer* bSizer631; - DisplayPanel* cisTEMDisplayPanel; - - DisplayFrameParent( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("cisTEM Display"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL ); - - ~DisplayFrameParent(); +class DisplayFrameParent : public wxFrame { + private: + + protected: + wxMenuBar* m_menubar2; + wxMenu* DisplayFileMenu; + wxMenuItem* DisplayFileOpen; + wxMenuItem* DisplayCloseTab; + wxMenuItem* SaveDisplayedImages; + wxMenuItem* SaveDisplayedImagesWithLegend; + wxMenuItem* SelectOpenTxt; + wxMenuItem* SelectSaveTxt; + wxMenuItem* SelectSaveTxtAs; + wxMenuItem* DisplayExit; + wxMenu* DisplayLabelMenu; + wxMenuItem* LabelLocationNumber; + wxMenuItem* LabelScaleBar; + wxMenu* DisplaySelectMenu; + wxMenuItem* SelectImageSelectionMode; + wxMenuItem* SelectCoordsSelectionMode; + wxMenuItem* SelectInvertSelection; + wxMenuItem* SelectClearSelection; + wxMenu* DisplayOptionsMenu; + wxMenu* OptionsSetPointSize; + wxMenuItem* CoordSize3; + wxMenuItem* CoordSize5; + wxMenuItem* CoordSize7; + wxMenuItem* CoordSize10; + wxMenuItem* OptionsSingleImageMode; + wxMenuItem* OptionsShowSelectionDistances; + wxMenuItem* OptionsShowResolution; + wxMenu* DisplayHelpMenu; + wxMenuItem* HelpDisplayControls; + wxMenuItem* HelpAbout; + + // Virtual event handlers, override them in your derived class + virtual void OnUpdateUI(wxUpdateUIEvent& event) { event.Skip( ); } + + virtual void OnFileOpenClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnCloseTabClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnSaveDisplayedImagesClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnSaveDisplayedImagesWithLegendClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnOpenTxtClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnSaveTxtClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnSaveTxtAsClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnExitClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnLocationNumberClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnLabelScaleBarClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnImageSelectionModeClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnCoordsSelectionModeClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnInvertSelectionClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnClearSelectionClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnSize3(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnSize5(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnSize7(wxCommandEvent& event) { event.Skip( ); } + virtual void OnSize10(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnSingleImageModeClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnShowSelectionDistancesClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnShowResolution(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnDisplayControlsClick(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnDocumentationClick(wxCommandEvent& event) { event.Skip( ); } + + public: + wxBoxSizer* bSizer631; + DisplayPanel* cisTEMDisplayPanel; + + DisplayFrameParent(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("cisTEM Display"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500, 300), long style = wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL); + + ~DisplayFrameParent( ); }; /////////////////////////////////////////////////////////////////////////////// /// Class DisplayManualDialogParent /////////////////////////////////////////////////////////////////////////////// -class DisplayManualDialogParent : public wxDialog -{ - private: - - protected: - wxBoxSizer* MainSizer; - wxStaticLine* m_staticline58; - wxStaticText* m_staticText315; - wxTextCtrl* minimum_text_ctrl; - wxStaticText* m_staticText316; - wxTextCtrl* maximum_text_ctrl; - wxStaticText* m_staticText317; - wxToolBar* Toolbar; - wxStaticLine* m_staticline61; - wxCheckBox* histogram_checkbox; - wxCheckBox* live_checkbox; - wxStaticLine* m_staticline63; - wxButton* m_button94; - wxButton* m_button95; - - // Virtual event handlers, override them in your derived class - virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } - virtual void OnLeftDown( wxMouseEvent& event ) { event.Skip(); } - virtual void OnMotion( wxMouseEvent& event ) { event.Skip(); } - virtual void OnPaint( wxPaintEvent& event ) { event.Skip(); } - virtual void OnRightDown( wxMouseEvent& event ) { event.Skip(); } - virtual void OnLowChange( wxCommandEvent& event ) { event.Skip(); } - virtual void OnHighChange( wxCommandEvent& event ) { event.Skip(); } - virtual void OnHistogramCheck( wxCommandEvent& event ) { event.Skip(); } - virtual void OnRealtimeCheck( wxCommandEvent& event ) { event.Skip(); } - virtual void OnButtonOK( wxCommandEvent& event ) { event.Skip(); } - virtual void OnButtonCancel( wxCommandEvent& event ) { event.Skip(); } - - - public: - - DisplayManualDialogParent( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Manual Grey Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); - - ~DisplayManualDialogParent(); +class DisplayManualDialogParent : public wxDialog { + private: -}; + protected: + wxBoxSizer* MainSizer; + wxStaticLine* m_staticline58; + wxStaticText* m_staticText315; + wxTextCtrl* minimum_text_ctrl; + wxStaticText* m_staticText316; + wxTextCtrl* maximum_text_ctrl; + wxStaticText* m_staticText317; + wxToolBar* Toolbar; + wxStaticLine* m_staticline61; + wxCheckBox* histogram_checkbox; + wxCheckBox* live_checkbox; + wxStaticLine* m_staticline63; + wxButton* m_button94; + wxButton* m_button95; + + // Virtual event handlers, override them in your derived class + virtual void OnClose(wxCloseEvent& event) { event.Skip( ); } + + virtual void OnLeftDown(wxMouseEvent& event) { event.Skip( ); } + virtual void OnMotion(wxMouseEvent& event) { event.Skip( ); } + + virtual void OnPaint(wxPaintEvent& event) { event.Skip( ); } + + virtual void OnRightDown(wxMouseEvent& event) { event.Skip( ); } + + virtual void OnLowChange(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnHighChange(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnHistogramCheck(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnRealtimeCheck(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnButtonOK(wxCommandEvent& event) { event.Skip( ); } + + virtual void OnButtonCancel(wxCommandEvent& event) { event.Skip( ); } + + public: + DisplayManualDialogParent(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Manual Grey Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE); + + ~DisplayManualDialogParent( ); +}; diff --git a/src/programs/measure_template_bias/measure_template_bias.cpp b/src/programs/measure_template_bias/measure_template_bias.cpp index 0dcbeec31..bc839103b 100644 --- a/src/programs/measure_template_bias/measure_template_bias.cpp +++ b/src/programs/measure_template_bias/measure_template_bias.cpp @@ -20,15 +20,16 @@ void MeasureTemplateBiasApp::DoInteractiveUserInput( ) { wxString input_diff_template; wxString input_full_template; wxString input_omit_template; - bool input_diff_map; + bool input_diff_map; UserInput* my_input = new UserInput("MeasureTemplateBias", 1.0); input_diff_map = my_input->GetYesNoFromUser("Input template diff map?", "If No, the difference map will be calculated from the full and omit templates", "No"); if ( input_diff_map == true ) { - input_diff_template = my_input->GetFilenameFromUser("Input diff template", "The difference map, full - omit template", "diff_template.mrc", true); - } else{ + input_diff_template = my_input->GetFilenameFromUser("Input diff template", "The difference map, full - omit template", "diff_template.mrc", true); + } + else { input_full_template = my_input->GetFilenameFromUser("Input full template", "The 3D map of the full template", "full_template.mrc", true); input_omit_template = my_input->GetFilenameFromUser("Input omit template", "The 3D map of the omit template", "omit_template.mrc", true); } @@ -37,12 +38,12 @@ void MeasureTemplateBiasApp::DoInteractiveUserInput( ) { delete my_input; my_current_job.ManualSetArguments("bttttt", - input_diff_map, - input_diff_template.ToUTF8( ).data( ), - input_full_template.ToUTF8( ).data( ), - input_omit_template.ToUTF8( ).data( ), - input_reconstruction_full_template.ToUTF8( ).data( ), - input_reconstruction_omit_template.ToUTF8( ).data( )); + input_diff_map, + input_diff_template.ToUTF8( ).data( ), + input_full_template.ToUTF8( ).data( ), + input_omit_template.ToUTF8( ).data( ), + input_reconstruction_full_template.ToUTF8( ).data( ), + input_reconstruction_omit_template.ToUTF8( ).data( )); } // override the do calculation method which will be what is actually run.. @@ -52,25 +53,25 @@ bool MeasureTemplateBiasApp::DoCalculation( ) { long count1 = 0; float correlation_3ds; float correlation_templates; -// float sigma_diff_template; -// float sigma_full_template; -// float sigma_omit_template; - float sum_3d_full = 0.0f; - float sum_3d_omit = 0.0f; + // float sigma_diff_template; + // float sigma_full_template; + // float sigma_omit_template; + float sum_3d_full = 0.0f; + float sum_3d_omit = 0.0f; float sum_difference = 0.0f; -// float mask_radius; + // float mask_radius; float max_value; Image input_3d_full; - Image input_3d_omit; - Image input_diff; - Image input_full; - Image input_omit; -// Image mask_3d; - - bool input_diff_map = my_current_job.arguments[0].ReturnBoolArgument( ); - wxString input_diff_template = my_current_job.arguments[1].ReturnStringArgument( ); - wxString input_full_template = my_current_job.arguments[2].ReturnStringArgument( ); - wxString input_omit_template = my_current_job.arguments[3].ReturnStringArgument( ); + Image input_3d_omit; + Image input_diff; + Image input_full; + Image input_omit; + // Image mask_3d; + + bool input_diff_map = my_current_job.arguments[0].ReturnBoolArgument( ); + wxString input_diff_template = my_current_job.arguments[1].ReturnStringArgument( ); + wxString input_full_template = my_current_job.arguments[2].ReturnStringArgument( ); + wxString input_omit_template = my_current_job.arguments[3].ReturnStringArgument( ); wxString input_reconstruction_full_template = my_current_job.arguments[4].ReturnStringArgument( ); wxString input_reconstruction_omit_template = my_current_job.arguments[5].ReturnStringArgument( ); @@ -78,7 +79,7 @@ bool MeasureTemplateBiasApp::DoCalculation( ) { MRCFile input_file_3d_omit(input_reconstruction_omit_template.ToStdString( ), false); if ( input_diff_map == true ) { MRCFile input_file_diff(input_diff_template.ToStdString( ), false); - if ( (input_file_3d_full.ReturnXSize( ) != input_file_diff.ReturnXSize( )) || (input_file_3d_full.ReturnYSize( ) != input_file_diff.ReturnYSize( )) || (input_file_3d_full.ReturnZSize( ) != input_file_diff.ReturnZSize( )) ) { + if ( (input_file_3d_full.ReturnXSize( ) != input_file_diff.ReturnXSize( )) || (input_file_3d_full.ReturnYSize( ) != input_file_diff.ReturnYSize( )) || (input_file_3d_full.ReturnZSize( ) != input_file_diff.ReturnZSize( )) ) { MyPrintWithDetails("Error: Input maps do not have the same dimensions\n"); DEBUG_ABORT; } @@ -86,14 +87,15 @@ bool MeasureTemplateBiasApp::DoCalculation( ) { // Making sure that the memory reserved for FFTs is also set to zero input_diff.SetToConstant(0.0f); input_diff.ReadSlices(&input_file_diff, 1, input_file_diff.ReturnZSize( )); - } else { + } + else { MRCFile input_file_full(input_full_template.ToStdString( ), false); MRCFile input_file_omit(input_omit_template.ToStdString( ), false); - if ( (input_file_3d_full.ReturnXSize( ) != input_file_full.ReturnXSize( )) || (input_file_3d_full.ReturnYSize( ) != input_file_full.ReturnYSize( )) || (input_file_3d_full.ReturnZSize( ) != input_file_full.ReturnZSize( )) ) { + if ( (input_file_3d_full.ReturnXSize( ) != input_file_full.ReturnXSize( )) || (input_file_3d_full.ReturnYSize( ) != input_file_full.ReturnYSize( )) || (input_file_3d_full.ReturnZSize( ) != input_file_full.ReturnZSize( )) ) { MyPrintWithDetails("Error: Input maps do not have the same dimensions\n"); DEBUG_ABORT; } - if ( (input_file_3d_full.ReturnXSize( ) != input_file_omit.ReturnXSize( )) || (input_file_3d_full.ReturnYSize( ) != input_file_omit.ReturnYSize( )) || (input_file_3d_full.ReturnZSize( ) != input_file_omit.ReturnZSize( )) ) { + if ( (input_file_3d_full.ReturnXSize( ) != input_file_omit.ReturnXSize( )) || (input_file_3d_full.ReturnYSize( ) != input_file_omit.ReturnYSize( )) || (input_file_3d_full.ReturnZSize( ) != input_file_omit.ReturnZSize( )) ) { MyPrintWithDetails("Error: Input maps do not have the same dimensions\n"); DEBUG_ABORT; } @@ -106,50 +108,51 @@ bool MeasureTemplateBiasApp::DoCalculation( ) { input_omit.ReadSlices(&input_file_omit, 1, input_file_omit.ReturnZSize( )); } - if ( (input_file_3d_full.ReturnXSize( ) != input_file_3d_omit.ReturnXSize( )) || (input_file_3d_full.ReturnYSize( ) != input_file_3d_omit.ReturnYSize( )) || (input_file_3d_full.ReturnZSize( ) != input_file_3d_omit.ReturnZSize( )) ) { + if ( (input_file_3d_full.ReturnXSize( ) != input_file_3d_omit.ReturnXSize( )) || (input_file_3d_full.ReturnYSize( ) != input_file_3d_omit.ReturnYSize( )) || (input_file_3d_full.ReturnZSize( ) != input_file_3d_omit.ReturnZSize( )) ) { MyPrintWithDetails("Error: Input maps do not have the same dimensions\n"); DEBUG_ABORT; } input_3d_full.Allocate(input_file_3d_full.ReturnXSize( ), input_file_3d_full.ReturnYSize( ), input_file_3d_full.ReturnZSize( ), true); input_3d_omit.Allocate(input_file_3d_omit.ReturnXSize( ), input_file_3d_omit.ReturnYSize( ), input_file_3d_omit.ReturnZSize( ), true); -// mask_3d.Allocate(input_file_3d_full.ReturnXSize( ), input_file_3d_full.ReturnYSize( ), input_file_3d_full.ReturnZSize( ), true); + // mask_3d.Allocate(input_file_3d_full.ReturnXSize( ), input_file_3d_full.ReturnYSize( ), input_file_3d_full.ReturnZSize( ), true); // Making sure that the memory reserved for FFTs is also set to zero input_3d_full.SetToConstant(0.0f); input_3d_omit.SetToConstant(0.0f); -// mask_3d.SetToConstant(0.0f); + // mask_3d.SetToConstant(0.0f); input_3d_full.ReadSlices(&input_file_3d_full, 1, input_file_3d_full.ReturnZSize( )); input_3d_omit.ReadSlices(&input_file_3d_omit, 1, input_file_3d_omit.ReturnZSize( )); -// mask_radius = std::min(std::min(float(input_file_3d_full.ReturnXSize( )), float(input_file_3d_full.ReturnYSize( ))), float(input_file_3d_full.ReturnZSize( ))); + // mask_radius = std::min(std::min(float(input_file_3d_full.ReturnXSize( )), float(input_file_3d_full.ReturnYSize( ))), float(input_file_3d_full.ReturnZSize( ))); wxPrintf("\nStarting calculation...\n"); if ( input_diff_map == true ) { -// sigma_diff_template = sqrtf(input_diff.ReturnVarianceOfRealValues(mask_radius/2.0f, 0.0f, 0.0f, 0.0f, true)); + // sigma_diff_template = sqrtf(input_diff.ReturnVarianceOfRealValues(mask_radius/2.0f, 0.0f, 0.0f, 0.0f, true)); max_value = input_diff.ReturnAverageOfMaxN(100); for ( long address = 0; address < input_diff.real_memory_allocated; address++ ) { - if ( input_diff.real_values[address] > max_value / 10.0f) { - sum_3d_full += input_3d_full.real_values[address]; - sum_3d_omit += input_3d_omit.real_values[address]; - sum_difference += input_3d_full.real_values[address] - input_3d_omit.real_values[address]; -// mask_3d.real_values[address] = 1.0f; - count1++; + if ( input_diff.real_values[address] > max_value / 10.0f ) { + sum_3d_full += input_3d_full.real_values[address]; + sum_3d_omit += input_3d_omit.real_values[address]; + sum_difference += input_3d_full.real_values[address] - input_3d_omit.real_values[address]; + // mask_3d.real_values[address] = 1.0f; + count1++; } } - } else { -// sigma_full_template = sqrtf(input_full.ReturnVarianceOfRealValues( )); -// sigma_omit_template = sqrtf(input_omit.ReturnVarianceOfRealValues( )); -// max_value = 0.0f; + } + else { + // sigma_full_template = sqrtf(input_full.ReturnVarianceOfRealValues( )); + // sigma_omit_template = sqrtf(input_omit.ReturnVarianceOfRealValues( )); + // max_value = 0.0f; for ( long address = 0; address < input_full.real_memory_allocated; address++ ) { - input_full.real_values[address] -= input_omit.real_values[address]; -// max_value = std::max(max_value, input_full.real_values[address] - input_omit.real_values[address]); + input_full.real_values[address] -= input_omit.real_values[address]; + // max_value = std::max(max_value, input_full.real_values[address] - input_omit.real_values[address]); } max_value = input_full.ReturnAverageOfMaxN(100); -// wxPrintf("\nSigma full template = %g\n", sigma_full_template); -// wxPrintf("\nSigma omit template = %g\n", sigma_omit_template); -/* for ( long address = 0; address < input_full.real_memory_allocated; address++ ) { + // wxPrintf("\nSigma full template = %g\n", sigma_full_template); + // wxPrintf("\nSigma omit template = %g\n", sigma_omit_template); + /* for ( long address = 0; address < input_full.real_memory_allocated; address++ ) { if ( input_full.real_values[address] < sigma_full_template / 10.0f ) { input_3d_full.real_values[address] = 0.0f; input_3d_omit.real_values[address] = 0.0f; @@ -159,24 +162,24 @@ bool MeasureTemplateBiasApp::DoCalculation( ) { } */ for ( long address = 0; address < input_full.real_memory_allocated; address++ ) { - if ( input_full.real_values[address] > max_value / 10.0f) { -// if ( input_full.real_values[address] > sigma_full_template) { -// if ( input_omit.real_values[address] / input_full.real_values[address] < 0.5f ) { - sum_3d_full += input_3d_full.real_values[address]; - sum_3d_omit += input_3d_omit.real_values[address]; -// wxPrintf("\nAddress, value1, value 2 = %li, %g, %g\n", address, input_full.real_values[address], input_omit.real_values[address]); - sum_difference += input_3d_full.real_values[address] - input_3d_omit.real_values[address]; -// mask_3d.real_values[address] = 1.0f; - count1++; -// } else { -// input_3d_full.real_values[address] = 0.0f; -// input_3d_omit.real_values[address] = 0.0f; -// } + if ( input_full.real_values[address] > max_value / 10.0f ) { + // if ( input_full.real_values[address] > sigma_full_template) { + // if ( input_omit.real_values[address] / input_full.real_values[address] < 0.5f ) { + sum_3d_full += input_3d_full.real_values[address]; + sum_3d_omit += input_3d_omit.real_values[address]; + // wxPrintf("\nAddress, value1, value 2 = %li, %g, %g\n", address, input_full.real_values[address], input_omit.real_values[address]); + sum_difference += input_3d_full.real_values[address] - input_3d_omit.real_values[address]; + // mask_3d.real_values[address] = 1.0f; + count1++; + // } else { + // input_3d_full.real_values[address] = 0.0f; + // input_3d_omit.real_values[address] = 0.0f; + // } } } } -/* wxPrintf("\nWriting out map 1...\n"); + /* wxPrintf("\nWriting out map 1...\n"); input_3d_full.QuickAndDirtyWriteSlices("diff_full.mrc", 1, input_3d_full.logical_z_dimension); wxPrintf("\nWriting out map 2...\n"); input_3d_omit.QuickAndDirtyWriteSlices("diff_omit.mrc", 1, input_3d_omit.logical_z_dimension); @@ -185,12 +188,12 @@ bool MeasureTemplateBiasApp::DoCalculation( ) { wxPrintf("\nWriting out map 4...\n"); input_omit.QuickAndDirtyWriteSlices("omit.mrc", 1, input_omit.logical_z_dimension); */ -// wxPrintf("\nWriting out mask... Number of voxels set: %li\n", count1); -// mask_3d.QuickAndDirtyWriteSlices("mask.mrc", 1, mask_3d.logical_z_dimension); + // wxPrintf("\nWriting out mask... Number of voxels set: %li\n", count1); + // mask_3d.QuickAndDirtyWriteSlices("mask.mrc", 1, mask_3d.logical_z_dimension); - correlation_3ds = input_3d_full.ReturnCorrelationCoefficientUnnormalized(input_3d_omit, 0.0f)/sqrtf(input_3d_full.ReturnVarianceOfRealValues( ))/sqrtf(input_3d_omit.ReturnVarianceOfRealValues( )); + correlation_3ds = input_3d_full.ReturnCorrelationCoefficientUnnormalized(input_3d_omit, 0.0f) / sqrtf(input_3d_full.ReturnVarianceOfRealValues( )) / sqrtf(input_3d_omit.ReturnVarianceOfRealValues( )); if ( input_diff_map == false ) { - correlation_templates = input_full.ReturnCorrelationCoefficientUnnormalized(input_omit, 0.0f)/sqrtf(input_full.ReturnVarianceOfRealValues( ))/sqrtf(input_omit.ReturnVarianceOfRealValues( )); + correlation_templates = input_full.ReturnCorrelationCoefficientUnnormalized(input_omit, 0.0f) / sqrtf(input_full.ReturnVarianceOfRealValues( )) / sqrtf(input_omit.ReturnVarianceOfRealValues( )); } wxPrintf("\nAverage of densities of full reconstruction = %g\n", sum_3d_full / count1); @@ -198,8 +201,8 @@ bool MeasureTemplateBiasApp::DoCalculation( ) { wxPrintf("\nAverage of difference densities = %g\n", sum_difference / count1); wxPrintf("\nCorrelation coefficient of reconstructions = %g\n", correlation_3ds); if ( input_diff_map == false ) { - wxPrintf("\nCorrelation coefficient of templates = %g\n", correlation_templates); - wxPrintf("\nRatio of correlation coefficients = %g\n", correlation_3ds/correlation_templates); + wxPrintf("\nCorrelation coefficient of templates = %g\n", correlation_templates); + wxPrintf("\nRatio of correlation coefficients = %g\n", correlation_3ds / correlation_templates); } wxPrintf("\n\nDegree of bias = %g\n\n", ((sum_3d_full - sum_3d_omit) / sum_3d_full)); diff --git a/src/programs/sum_all_eer_files/sum_all_eer_files.cpp b/src/programs/sum_all_eer_files/sum_all_eer_files.cpp index ae8e94edc..72d0ff66c 100644 --- a/src/programs/sum_all_eer_files/sum_all_eer_files.cpp +++ b/src/programs/sum_all_eer_files/sum_all_eer_files.cpp @@ -20,8 +20,8 @@ void SumAllEer::DoInteractiveUserInput( ) { int max_threads; std::string output_dark_filename; std::string output_gain_filename; - int eer_super_res_factor; - int eer_frames_per_image; + int eer_super_res_factor; + int eer_frames_per_image; UserInput* my_input = new UserInput("SumAllEerfiles", 1.0); @@ -34,20 +34,20 @@ void SumAllEer::DoInteractiveUserInput( ) { output_gain_filename = my_input->GetFilenameFromUser("Output gain file name", "Filename of output gain image", "gain_image.mrc", false); } - max_threads = my_input->GetIntFromUser("Max number of threads to use", "maximum number of threads to use for processing.", "1", 1); - eer_super_res_factor = my_input-> GetIntFromUser("EER super resolution factor", "super resolution factor for pixels.", "1", 1); + max_threads = my_input->GetIntFromUser("Max number of threads to use", "maximum number of threads to use for processing.", "1", 1); + eer_super_res_factor = my_input->GetIntFromUser("EER super resolution factor", "super resolution factor for pixels.", "1", 1); eer_frames_per_image = my_input->GetIntFromUser("EER frames per image", "frames per image in eer file type", "0", 0); delete my_input; my_current_job.Reset(7); my_current_job.ManualSetArguments("tbttiii", output_filename.c_str( ), - make_dark_and_gain, - output_dark_filename.c_str( ), - output_gain_filename.c_str( ), - max_threads, - eer_super_res_factor, - eer_frames_per_image); + make_dark_and_gain, + output_dark_filename.c_str( ), + output_gain_filename.c_str( ), + max_threads, + eer_super_res_factor, + eer_frames_per_image); } // override the do calculation method which will be what is actually run.. @@ -67,8 +67,8 @@ bool SumAllEer::DoCalculation( ) { std::string output_dark_filename = my_current_job.arguments[2].ReturnStringArgument( ); std::string output_gain_filename = my_current_job.arguments[3].ReturnStringArgument( ); int max_threads = my_current_job.arguments[4].ReturnIntegerArgument( ); - int eer_super_res_factor = my_current_job.arguments[5].ReturnIntegerArgument( ); - int eer_frames_per_image = my_current_job.arguments[6].ReturnIntegerArgument( ); + int eer_super_res_factor = my_current_job.arguments[5].ReturnIntegerArgument( ); + int eer_frames_per_image = my_current_job.arguments[6].ReturnIntegerArgument( ); wxArrayString all_files; wxDir::GetAllFiles(".", &all_files, "*.eer", wxDIR_FILES); @@ -92,7 +92,7 @@ bool SumAllEer::DoCalculation( ) { wxPrintf("\nThere are %li eer files in this directory.\n", all_files.GetCount( )); - current_input_file = new EerFile(); + current_input_file = new EerFile( ); current_input_file->OpenFile(all_files.Item(0).ToStdString( ), false, false, false, eer_super_res_factor, eer_frames_per_image); file_x_size = current_input_file->ReturnXSize( ); @@ -141,9 +141,9 @@ bool SumAllEer::DoCalculation( ) { #pragma omp for for ( file_counter = 0; file_counter < all_files.GetCount( ); file_counter++ ) { //wxPrintf("Summing file %s...\n", all_files.Item(file_counter)); - //wxPrintf("Summing File %ld\n", file_counter); - current_input_file = new EerFile(); - current_input_file->OpenFile(all_files.Item(file_counter).ToStdString( ), false, false, false, eer_super_res_factor, eer_frames_per_image); + //wxPrintf("Summing File %ld\n", file_counter); + current_input_file = new EerFile( ); + current_input_file->OpenFile(all_files.Item(file_counter).ToStdString( ), false, false, false, eer_super_res_factor, eer_frames_per_image); for ( frame_counter = 0; frame_counter < current_input_file->ReturnNumberOfSlices( ); frame_counter++ ) { buffer_image.ReadSlice(current_input_file, frame_counter + 1);