#include "StdAfx.h" #include "SphereInput.h" #include "DistanceTransform.h" // ---------------------------------------------------------- // Disables user interface inputs before run // ---------------------------------------------------------- void disable_inputs(SphereDialog* SphereDlg) { //common inputs disabled in dialog class SphereDlg->check_save_diameter_map_gray.EnableWindow(FALSE); SphereDlg->check_save_diameter_map_rgb.EnableWindow(FALSE); SphereDlg->check_save_sphere_map_gray.EnableWindow(FALSE); SphereDlg->check_save_sphere_map_rgb.EnableWindow(FALSE); SphereDlg->check_use_dist_xfrm.EnableWindow(FALSE); SphereDlg->check_calc_even_diam.EnableWindow(FALSE); SphereDlg->check_conserve_memory.EnableWindow(FALSE); SphereDlg->check_boundary_is_solid.EnableWindow(FALSE); SphereDlg->combo_stop_after_point.EnableWindow(FALSE); SphereDlg->field_xfrm_face_cntrl.EnableWindow(FALSE); SphereDlg->field_xfrm_edge_cntrl.EnableWindow(FALSE); SphereDlg->field_xfrm_corner_cntrl.EnableWindow(FALSE); SphereDlg->check_pad_distribution.EnableWindow(FALSE); } // ---------------------------------------------------------- // Enables user interface inputs after run // ---------------------------------------------------------- void enable_inputs(SphereDialog* SphereDlg) { //enable the common inputs SphereDlg->EnableCommonInputs(); SphereDlg->check_save_diameter_map_gray.EnableWindow(TRUE); SphereDlg->check_save_diameter_map_rgb.EnableWindow(TRUE); SphereDlg->check_save_sphere_map_gray.EnableWindow(TRUE); SphereDlg->check_save_sphere_map_rgb.EnableWindow(TRUE); SphereDlg->check_use_dist_xfrm.EnableWindow(TRUE); SphereDlg->check_calc_even_diam.EnableWindow(TRUE); SphereDlg->check_conserve_memory.EnableWindow(TRUE); SphereDlg->check_boundary_is_solid.EnableWindow(TRUE); SphereDlg->combo_stop_after_point.EnableWindow(TRUE); // If distance transform method is used, make F-E-C values available to edit if ( SphereDlg->check_use_dist_xfrm.GetCheck() ) { SphereDlg->field_xfrm_face_cntrl.EnableWindow(TRUE); SphereDlg->field_xfrm_edge_cntrl.EnableWindow(TRUE); SphereDlg->field_xfrm_corner_cntrl.EnableWindow(TRUE); } // If calc even diameters option is set, no sense in padding distribution if ( !SphereDlg->check_calc_even_diam.GetCheck() ) { SphereDlg->check_pad_distribution.EnableWindow(TRUE); } //flash for 3 seconds to alert user that we are done SphereDlg->FlashWindowEx(FLASHW_TRAY, 3, 0); } // ---------------------------------------------------------- // Start of Sphere work thread, sets up sphere object using // dialog object options and starts running algorithm // ---------------------------------------------------------- UINT SphereSetup(LPVOID pParam) { char sphere_directory[512], data_out_prefix[512]; SphereDialog *SphereDlg = (SphereDialog*) pParam; sg_options sphere_options = 0; dist_xfrm_vals dt_params; sg_status ret_status; // Disable dialog inputs disable_inputs(SphereDlg); // Create a new sphere result directory if needed sprintf(sphere_directory, "%sSphereGrowth", SphereDlg->field_directory_work_str); if ( !CreateDirectory(sphere_directory, NULL) ) { write_to_log("SphereGrowth: 'SphereGrowth' directory already exists, new one will not be created."); } sprintf(data_out_prefix, "%s\\%s", sphere_directory, SphereDlg->field_name_output_str); // Convert input to DS_1b_cube DS_1b_cube * ds_cube = SphereDlg->Dlg_Input_to_cDS(); if ( !ds_cube ) { // Some kind of error doing input read enable_inputs(SphereDlg); return 1; } // Setup options for Sphere growth sphere_options |= ( SphereDlg->check_calc_even_diam.GetCheck() ) ? (0) : (SG_ODD_DIAMETER_ONLY); sphere_options |= ( SphereDlg->check_boundary_is_solid.GetCheck() ) ? (SG_BOUNDARY_IS_SOLID) : (0); sphere_options |= ( SphereDlg->check_conserve_memory.GetCheck() ) ? (SG_CONSERVE_MEMORY) : (0); if ( SphereDlg->check_use_dist_xfrm.GetCheck() ) { sphere_options |= SG_QUICK_DIST_XFRM; dt_params.face = (sg_xfrm_type) SphereDlg->field_xfrm_face_float; dt_params.edge = (sg_xfrm_type) SphereDlg->field_xfrm_edge_float; dt_params.corner = (sg_xfrm_type) SphereDlg->field_xfrm_corner_float; } // Saving options sphere_options |= ( SphereDlg->check_save_diameter_map_gray.GetCheck() ) ? (SG_SAVE_DIST_GRAY) : (0); sphere_options |= ( SphereDlg->check_save_diameter_map_rgb.GetCheck() ) ? (SG_SAVE_DIST_RGB) : (0); sphere_options |= ( SphereDlg->check_save_sphere_map_gray.GetCheck() ) ? (SG_SAVE_GROWN_GRAY) : (0); sphere_options |= ( SphereDlg->check_save_sphere_map_rgb.GetCheck() ) ? (SG_SAVE_GROWN_RGB) : (0); sphere_options |= ( SphereDlg->check_pad_distribution.GetCheck() ) ? (SG_PAD_ODD_DISTRIBUTION) : (0); // Early stop point sphere_options |= ( SphereDlg->combo_stop_after_point.GetCurSel() == 0 ) ? (SG_STOP_AFTER_DISTANCE) : (0); sphere_options |= ( SphereDlg->combo_stop_after_point.GetCurSel() == 1 ) ? (SG_STOP_AFTER_SPHERE) : (0); // User disconnected options //sphere_options |= SG_SAVE_STAGE_CUBE_RGB; // Specify to save a 'snap shot' of each growth stage // ======END OF OPTIONS SETUP====== // Create sphere run object. SphereGrowth* SphereGrow = new SphereGrowth(ds_cube, &SphereDlg->txt_field_progress, &SphereDlg->pbar_simulation_progress); // Run distance transform and sphere growth ret_status = SphereGrow->RunSphereGrowth( sphere_options, data_out_prefix, \ ( SphereDlg->check_use_dist_xfrm.GetCheck() ) ? (&dt_params) : (NULL) ); if ( ret_status != SG_NO_ERROR ) { // Error was encountered delete ds_cube; delete SphereGrow; return 1; } // Do common header sprintf( sphere_directory, "%s_Sphere_Analysis.csv", data_out_prefix); SphereDlg->Write_Result_Header(sphere_directory); // Perform analysis SphereGrow->RunAnalysis(SphereDlg->field_pixel_size_float, SG_APPEND_RESULTS, 50, sphere_directory); // Clean up delete ds_cube; delete SphereGrow; // Re-enable user inputs enable_inputs(SphereDlg); SphereDlg->txt_field_progress.SetWindowText("Run is complete!"); return 0; }