// source\SphereDialog.cpp : implementation file // #include "stdafx.h" #include "SphereDialog.h" // SphereDialog dialog IMPLEMENT_DYNAMIC(SphereDialog, CDialog) SphereDialog::SphereDialog(CWnd* pParent /*=NULL*/) : CDialog(SphereDialog::IDD, pParent) { field_xfrm_corner_float = 5.0f; field_xfrm_edge_float = 4.0f; field_xfrm_face_float = 3.0f; } SphereDialog::~SphereDialog() { } void SphereDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); /* SHARED (can copy and paste between dialogs) */ BindCommonInputFields(pDX); /////////////////////////////// //sphere specific DDX_Control(pDX, IDC_CHECK_CALC_EVEN, check_calc_even_diam); DDX_Control(pDX, IDC_CHECK_BOUNDARY_IS_SOLID, check_boundary_is_solid); DDX_Control(pDX, IDC_CHECK_CONSERVE_MEMORY, check_conserve_memory); DDX_Control(pDX, IDC_CHECK_USE_DIST_XFRM, check_use_dist_xfrm); DDX_Control(pDX, IDC_CHECK_SAVE_SPHERE_MAP_GRAY, check_save_sphere_map_gray); DDX_Control(pDX, IDC_CHECK_SAVE_SPHERE_MAP_RGB, check_save_sphere_map_rgb); DDX_Control(pDX, IDC_CHECK_SAVE_DIAMETER_MAP_GRAY, check_save_diameter_map_gray); DDX_Control(pDX, IDC_CHECK_SAVE_DIAMETER_MAP_RGB, check_save_diameter_map_rgb ); DDX_Control(pDX, IDC_CHECK_PAD_DISTRIBUTION, check_pad_distribution ); DDX_Control(pDX, IDC_COMBO_STOP_AFTER_POINT, combo_stop_after_point); DDX_Control(pDX, IDC_EDIT_XFRM_CORNER, field_xfrm_corner_cntrl); DDX_Text(pDX, IDC_EDIT_XFRM_CORNER, field_xfrm_corner_float); DDX_Control(pDX, IDC_EDIT_XFRM_EDGE, field_xfrm_edge_cntrl); DDX_Text(pDX, IDC_EDIT_XFRM_EDGE, field_xfrm_edge_float); DDX_Control(pDX, IDC_EDIT_XFRM_FACE, field_xfrm_face_cntrl); DDX_Text(pDX, IDC_EDIT_XFRM_FACE, field_xfrm_face_float); } BEGIN_MESSAGE_MAP(SphereDialog, CDialog) //messages similar to all dialogs (copy and paste) ON_BN_CLICKED(IDC_BUTTON_INPUT_DIRECTORY, OnBnClickedButtonInputDirectory) ON_BN_CLICKED(IDC_BUTTON_WORK_DIRECTORY, OnBnClickedButtonWorkDirectory) ON_CBN_SELCHANGE(IDC_COMBO_THRESHOLDING_METHOD, OnCbnSelchangeComboThresholdingMethod) ON_EN_CHANGE(IDC_EDIT_MANUAL_THRESHOLD, OnEnChangeEditManualThreshold) ON_BN_CLICKED(IDSTOP, OnBnClickedStop) ON_EN_CHANGE(IDC_EDIT_WIDTH_SLICES, OnEnChangeEditWidthSlices) ON_EN_CHANGE(IDC_EDIT_END_SLICE, OnEnChangeEditEndSlice) ON_EN_CHANGE(IDC_EDIT_WIDTHX, OnEnChangeEditWidthx) ON_EN_CHANGE(IDC_EDIT_ENDX, OnEnChangeEditEndx) ON_EN_CHANGE(IDC_EDIT_WIDTHY, OnEnChangeEditWidthy) ON_EN_CHANGE(IDC_EDIT_ENDY, OnEnChangeEditEndy) ON_EN_CHANGE(IDC_EDIT_START_SLICE, OnEnChangeEditStartSlice) ON_EN_CHANGE(IDC_EDIT_STARTX, OnEnChangeEditStartx) ON_EN_CHANGE(IDC_EDIT_STARTY, OnEnChangeEditStarty) ////////////////////////////////////// ON_BN_CLICKED(IDC_BUTTON_TOGGLE_ALL_SAVE, &SphereDialog::OnBnClickedButtonToggleAllSave) ON_BN_CLICKED(IDC_CHECK_CALC_EVEN, &SphereDialog::OnBnClickedCheckCalcEven) ON_BN_CLICKED(IDC_CHECK_CONSERVE_MEMORY, &SphereDialog::OnBnClickedCheckConserveMemory) ON_BN_CLICKED(IDC_CHECK_USE_DIST_XFRM, &SphereDialog::OnBnClickedCheckUseDistXfrm) END_MESSAGE_MAP() // SphereDialog message handlers void SphereDialog::OnOK() { // TODO: Add extra validation here bool is_dataright=true; CString m_error; // have windows auto check the parameters, and fill out variables if (!UpdateData(TRUE)) return; /* no need to check: input directory, file need to check (in this order): valid output directory valid output file prefix at least one type of run is selected either number of runs specified (> 0), or 'run all' check box marked (for all 3 run types) end depth is <= appropriate planes depth distribution res >= 1 the rest is auto checked by UpdateData(TRUE) */ if ( field_directory_work_str.IsEmpty() ){ //make sure there is an output directory is_dataright=false; m_error = "You must select a valid output directory."; } else if ( field_name_output_str.IsEmpty() ){ //make sure there is a output file prefix is_dataright=false; m_error = "You must select a valid output file prefix."; } if(is_dataright) { //delete '[' and everything after it input_file_name_cut = input_file_name; if (left_bracket_indx > 0) input_file_name_cut.Delete(left_bracket_indx, input_file_name.GetLength() ); DisableCommonInputs(); pbar_simulation_progress.SetPos(0); //create a sphere work thread, which will also disable the restof the GUI, except for STOP button AfxBeginThread(SphereSetup, this); } else AfxMessageBox(m_error); } void SphereDialog::OnCancel() { if(!DestroyWindow()) AfxMessageBox("Could not destroy this window!!!"); delete this; } BOOL SphereDialog::OnInitDialog() { program_generated = true; CDialog::OnInitDialog(); InitCommonInputFields(); program_generated = false; // Init dialog specific stuff check_save_diameter_map_gray.SetCheck(true); check_save_diameter_map_rgb.SetCheck(true); check_save_sphere_map_gray.SetCheck(true); check_save_sphere_map_rgb.SetCheck(true); check_use_dist_xfrm.SetCheck(false); check_calc_even_diam.SetCheck(true); check_conserve_memory.SetCheck(false); check_boundary_is_solid.SetCheck(false); check_pad_distribution.SetCheck(true); // Set pad option as enabled/disabled based on even diam default if ( check_calc_even_diam.GetCheck() ) check_pad_distribution.EnableWindow(FALSE); else check_pad_distribution.EnableWindow(TRUE); // Set F-E-C input enable/disable based on distance xfrm default if ( check_use_dist_xfrm.GetCheck() ) { field_xfrm_face_cntrl.EnableWindow(TRUE); field_xfrm_edge_cntrl.EnableWindow(TRUE); field_xfrm_corner_cntrl.EnableWindow(TRUE); } else { // Otherwise disable field_xfrm_face_cntrl.EnableWindow(FALSE); field_xfrm_edge_cntrl.EnableWindow(FALSE); field_xfrm_corner_cntrl.EnableWindow(FALSE); } // Init combo box for thresholding type combo_stop_after_point.AddString("Diameter Map/Distance Xfrm"); combo_stop_after_point.AddString("Sphere Map Generation"); combo_stop_after_point.AddString("Analysis Complete"); combo_stop_after_point.SetCurSel(2); // Initialize memory estimate if ( check_conserve_memory.GetCheck() ) { // If conserve memory is set, peak amount will larger of: // 1) 1x (bytes in sg_sphr_type) + (3/wZ)x (bytes in sg_xfrm_type) // 2) 1x (bytes in sg_xfrm_type) req_mem_byte_multiplier = 0.03f*sizeof(sg_xfrm_type) + sizeof(sg_sphr_type); //wZ is unknown, assume 100 for an estimate if ( req_mem_byte_multiplier < sizeof(sg_xfrm_type) ) { req_mem_byte_multiplier = sizeof(sg_xfrm_type); } } else { // Otherwise memory will just be sum of both cubes req_mem_byte_multiplier = sizeof(sg_xfrm_type) + sizeof(sg_sphr_type); } // One additional 1 bit cube req_mem_byte_multiplier += 0.125; // If calculate even diameters option is set, need an additional 2-bit cube if ( check_calc_even_diam.GetCheck() ) { req_mem_byte_multiplier += 0.25; } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void SphereDialog::OnBnClickedButtonToggleAllSave() { // Flip all save options check_save_diameter_map_gray.SetCheck( !check_save_diameter_map_gray.GetCheck() ); check_save_diameter_map_rgb.SetCheck( !check_save_diameter_map_rgb.GetCheck() ); check_save_sphere_map_gray.SetCheck( !check_save_sphere_map_gray.GetCheck() ); check_save_sphere_map_rgb.SetCheck( !check_save_sphere_map_rgb.GetCheck() ); } void SphereDialog::OnBnClickedCheckCalcEven() { // If Even spheres are to be calculated, need another 2bit cube so update mem req if ( check_calc_even_diam.GetCheck() ) { req_mem_byte_multiplier += 0.250; // 2-bit = .250 bytes } else { req_mem_byte_multiplier -= 0.250; } // Force interface update EditWidthx(); // If calc even diameters option is set, no sense in padding distribution if ( check_calc_even_diam.GetCheck() ) { check_pad_distribution.EnableWindow(FALSE); } else { check_pad_distribution.EnableWindow(TRUE); } } void SphereDialog::OnBnClickedCheckConserveMemory() { if ( check_conserve_memory.GetCheck() && (max_XY_depth > 0) ) { // If conserve memory is set, peak amount will larger of: // 1) 1x (bytes in sg_sphr_type) + (3/wZ)x (bytes in sg_xfrm_type) // 2) 1x (bytes in sg_xfrm_type) req_mem_byte_multiplier = 3.0f*sizeof(sg_xfrm_type)/max_XY_depth + sizeof(sg_sphr_type); //wZ is unknown, assume 100 for an estimate if ( req_mem_byte_multiplier < sizeof(sg_xfrm_type) ) { req_mem_byte_multiplier = sizeof(sg_xfrm_type); } } else { // Otherwise memory will just be sum of both cubes req_mem_byte_multiplier = sizeof(sg_xfrm_type) + sizeof(sg_sphr_type); } // One additional 1 bit cube req_mem_byte_multiplier += 0.125; // If Even spheres are to be calculated, need another 2bit cube so update mem req if ( check_calc_even_diam.GetCheck() ) { req_mem_byte_multiplier += 0.250; // 2-bit = .250 bytes } // Force interface update EditWidthx(); } void SphereDialog::OnBnClickedCheckUseDistXfrm() { // If distance transform method is used, make F-E-C values available to edit if ( check_use_dist_xfrm.GetCheck() ) { field_xfrm_face_cntrl.EnableWindow(TRUE); field_xfrm_edge_cntrl.EnableWindow(TRUE); field_xfrm_corner_cntrl.EnableWindow(TRUE); } else { // Otherwise disable field_xfrm_face_cntrl.EnableWindow(FALSE); field_xfrm_edge_cntrl.EnableWindow(FALSE); field_xfrm_corner_cntrl.EnableWindow(FALSE); } } //--------------------------------------------------------------------------------------- // The following are messages that are dealt in similar matter for all PoroMedia dialogs //--------------------------------------------------------------------------------------- //when the stop button is pushed, initialize stop procedure void SphereDialog::OnBnClickedStop() { StopRequest(); } //when input directory button is pushed void SphereDialog::OnBnClickedButtonInputDirectory() { //grab file, do inits common to all poromedia dialogs ClickedInputDirectory(); } //when work directory button is pushed void SphereDialog::OnBnClickedButtonWorkDirectory() { ClickedWorkDirectory(); } //threshold stuff void SphereDialog::OnCbnSelchangeComboThresholdingMethod() { ChangeComboThresholding(); } void SphereDialog::OnEnChangeEditManualThreshold() { EditManualThreshold(); } //the rest deals with start/width/end field autocalcs void SphereDialog::OnEnChangeEditStartSlice() { EditStartSlice(); } void SphereDialog::OnEnChangeEditWidthSlices() { EditWidthSlices(); } void SphereDialog::OnEnChangeEditEndSlice() { EditEndSlice(); } void SphereDialog::OnEnChangeEditStartx() { EditStartx(); } void SphereDialog::OnEnChangeEditWidthx() { EditWidthx(); } void SphereDialog::OnEnChangeEditEndx() { EditEndx(); } void SphereDialog::OnEnChangeEditStarty() { EditStarty(); } void SphereDialog::OnEnChangeEditWidthy() { EditWidthy(); } void SphereDialog::OnEnChangeEditEndy() { EditEndy(); }