#include "stdafx.h" #include "PoroMediaDialogShare.h" ////////////////////////////////////////////////////////////////////////////////////////////////// // // Methods dealing with file selection, and directory selection // ////////////////////////////////////////////////////////////////////////////////////////////////// // The following method deals with the user specified input file, and autofills whatever possible void PoroMediaDialogShare::ClickedInputDirectory() { //open up the file browser window, and wait for return input_info* input = FileBrowser(); //caution: this will attack '[' and ']' if mult file input //if FileBrowser returns a valid input_info struct if (input != NULL) { if (input->input_type == INPUT_IS_UNKNOWN) {//assume to be .stack.raw, but turn off autocalc, tell so to the user check_auto_calc_params.SetCheck(false); AfxMessageBox("Warning: Unknown file extension, assuming to be .STACK.RAW type."); input->input_type = INPUT_IS_RAW_STACK; } else check_auto_calc_params.SetCheck(true); CString outdirectory; //these are CString types, so no need to strcpy input_file_ext = input->input_type; input_file_name = input->filename; input_directory_name = input->directory; //check if image directory is a predefined RAW_XY or BIN_XY, if so backup one directory for output default outdirectory = input_directory_name; if (strcmp( outdirectory.GetBuffer() + outdirectory.GetLength() - 7, "RAW_XY\\") == 0) outdirectory = outdirectory.GetBufferSetLength(outdirectory.GetLength() - 7); else if (strcmp( outdirectory.GetBuffer() + outdirectory.GetLength() - 7, "BIN_XY\\") == 0) outdirectory = outdirectory.GetBufferSetLength(outdirectory.GetLength() - 7); //fill in directory + input file field UpdateDirFileField(); //fill in default work dir and default output prefix field_directory_work_cntrl.SetWindowText(outdirectory); /////////////////////////////////////////////////////////////// //update global values if not a stack input /////////////////////////////////////////////////////////////// if (!( (input_file_ext == INPUT_IS_RAW_STACK) || (input_file_ext == INPUT_IS_BIN_STACK) || (input_file_ext == INPUT_IS_CBIN_STACK)) ) { field_name_output_cntrl.SetWindowText(input->basename); //set globals that keep track of '[' left_bracket_indx = input->left_bracket_indx; first_slice_indx = input->attached_number; max_dig_cnt = input->max_dig_cnt; cur_dig_cnt = input->attached_number_dig_cnt; //convert to text and place in 'start slice' box SetIntValField(&field_start_slice_cntrl, input->attached_number); //attempt to find the last valid slice file CString temp_name = input_file_name; temp_name.Delete(left_bracket_indx, temp_name.GetLength() ); //delete entire valid file number for (int i = cur_dig_cnt; i < max_dig_cnt; i++) temp_name.Delete(left_bracket_indx - (i-cur_dig_cnt+1), 1); int indx = first_slice_indx + 1; ifstream test; while (1) { //create full file name char* full_name = AppendDigitsAndExtension(temp_name.GetBuffer(), indx, max_dig_cnt, input_file_ext); temp_name.ReleaseBuffer(); //try to open the file, if it fails, we have reached max number test.open(full_name); if (!test) { free(full_name); break; } //increase to next file num indx++; test.close(); free(full_name); } SetIntValField(&field_end_slice_cntrl, indx-1); //read header info if BMP, to autofill dimensions if (input_file_ext == INPUT_IS_BMP) { int xsize, ysize, psize, biBitCount; FILE* bmp_file = fopen(input->full_path_name, "r"); //incase it's a huge file, or computer slow, inform user that a file is being read, hense the delay txt_field_progress.SetWindowText("Reading dimensions of selected BMP image..."); if(bmp_read_header (bmp_file,&xsize,&ysize,&psize,&biBitCount)) { AfxMessageBox("Error: Could not read specified BMP file header."); } else { SetIntValField(&field_start_X_cntrl, 1); SetIntValField(&field_end_X_cntrl, xsize); SetIntValField(&field_start_Y_cntrl, 1); SetIntValField(&field_end_Y_cntrl, ysize); max_X_size = xsize; max_Y_size = ysize; } fclose(bmp_file); txt_field_progress.SetWindowText("Enter desired parameters and push \"OK\""); field_start_X_cntrl.EnableWindow(TRUE); field_end_X_cntrl.EnableWindow(TRUE); field_start_Y_cntrl.EnableWindow(TRUE); field_end_Y_cntrl.EnableWindow(TRUE); } //else its a BIN or RAW, so disable start/end x/y else{ SetIntValField(&field_start_X_cntrl, 1); field_start_X_cntrl.EnableWindow(FALSE); field_end_X_cntrl.EnableWindow(FALSE); SetIntValField(&field_start_Y_cntrl, 1); field_start_Y_cntrl.EnableWindow(FALSE); field_end_Y_cntrl.EnableWindow(FALSE); } //enable end/start slice field_start_slice_cntrl.EnableWindow(TRUE); field_end_slice_cntrl.EnableWindow(TRUE); } /////////////////////////////////////////////////////////////// //input is a stack type /////////////////////////////////////////////////////////////// else { //for stack inputs, set starts to '1', disable start/end fields SetIntValField(&field_start_slice_cntrl, 1); field_start_slice_cntrl.EnableWindow(FALSE); field_end_slice_cntrl.EnableWindow(FALSE); SetIntValField(&field_start_X_cntrl, 1); field_start_X_cntrl.EnableWindow(FALSE); field_end_X_cntrl.EnableWindow(FALSE); SetIntValField(&field_start_Y_cntrl, 1); field_start_Y_cntrl.EnableWindow(FALSE); field_end_Y_cntrl.EnableWindow(FALSE); /////////////////////////////////////////////////////////////// //check for (x_y_z) for autofill potential /////////////////////////////////////////////////////////////// if (check_auto_calc_params.GetCheck()) { int offset; char num_str[MAX_DIG_LIMIT+1]; offset = (int) strlen( input->basename ) - 1; //check for ')' right before extension to signify autofill should be valid if (input_file_name.GetAt(offset) == ')') { char lastchar; char temp_buf[MAX_DIG_LIMIT+1]; char out_name_buf[512]; int i = 0; //get Z num num_str[0] = '\0'; temp_buf[0] = '\0'; offset--; while ( (lastchar = input_file_name.GetAt(offset)) != '_') { sprintf(temp_buf, "%c%s", lastchar, num_str); strcpy(num_str, temp_buf); offset--; i++; if (i == MAX_DIG_LIMIT) break; } SetIntValField(&field_width_slices_cntrl, atoi(num_str)); //get Y num num_str[0] = '\0'; temp_buf[0] = '\0'; i = 0; offset--; while ( (lastchar = input_file_name.GetAt(offset)) != '_') { sprintf(temp_buf, "%c%s", lastchar, num_str); strcpy(num_str, temp_buf); offset--; i++; if (i == MAX_DIG_LIMIT) break; } SetIntValField(&field_width_Y_cntrl, atoi(num_str)); //get X num num_str[0] = '\0'; temp_buf[0] = '\0'; i = 0; offset--; while ( (lastchar = input_file_name.GetAt(offset)) != '(') { sprintf(temp_buf, "%c%s", lastchar, num_str); strcpy(num_str, temp_buf); offset--; i++; if (i == MAX_DIG_LIMIT) break; } SetIntValField(&field_width_X_cntrl, atoi(num_str)); strcpy(out_name_buf, input_file_name); out_name_buf[offset] = '\0'; field_name_output_cntrl.SetWindowText(out_name_buf); } else field_name_output_cntrl.SetWindowText(input->basename); } } /////////////////////////////////////////////////////////////// // Enabling and disabling options based on type of input /////////////////////////////////////////////////////////////// if ( input_file_ext == INPUT_IS_BMP ) {//if BMP, enable both save options, binerization, all filters if ( is_control_enabled(FILESAVE_CONTROLS) ) { check_save_raw_stack.EnableWindow(TRUE); check_save_cbin_stack.EnableWindow(TRUE); } if ( is_control_enabled(FILTER_CONTROLS) ) { check_filter_contrast_enable.EnableWindow(TRUE); check_filter_convolve_enable.EnableWindow(TRUE); check_filter_aniso_enable.EnableWindow(TRUE); check_filter_voxrem_enable.EnableWindow(TRUE); check_filter_close_enable.EnableWindow(TRUE); } if ( is_control_enabled(BINARIZE_CONTROLS) ) { check_image_is_inverted.EnableWindow(TRUE); combo_threshold_method.EnableWindow(TRUE); field_manual_threshold.EnableWindow(TRUE); } } else if ( (input_file_ext == INPUT_IS_RAW) || (input_file_ext == INPUT_IS_RAW_STACK) ) {// if RAW, only enable BIN savin, binerization, all filters if ( is_control_enabled(FILESAVE_CONTROLS) ) { check_save_raw_stack.EnableWindow(FALSE); check_save_cbin_stack.EnableWindow(TRUE); } if ( is_control_enabled(FILTER_CONTROLS) ) { check_filter_contrast_enable.EnableWindow(TRUE); check_filter_convolve_enable.EnableWindow(TRUE); check_filter_aniso_enable.EnableWindow(TRUE); check_filter_voxrem_enable.EnableWindow(TRUE); check_filter_close_enable.EnableWindow(TRUE); } if ( is_control_enabled(BINARIZE_CONTROLS) ) { check_image_is_inverted.EnableWindow(TRUE); combo_threshold_method.EnableWindow(TRUE); field_manual_threshold.EnableWindow(TRUE); } } else if( (input_file_ext == INPUT_IS_BIN) || (input_file_ext == INPUT_IS_BIN_STACK) || (input_file_ext == INPUT_IS_CBIN_STACK) || (input_file_ext == INPUT_IS_CBIN) ) {//if a binary input, disable saving except cbin, binarization, and any RAW filters if ( is_control_enabled(FILESAVE_CONTROLS) ) { check_save_raw_stack.EnableWindow(FALSE); check_save_cbin_stack.EnableWindow(TRUE); } if ( is_control_enabled(FILTER_CONTROLS) ) { check_filter_contrast_enable.EnableWindow(FALSE); check_filter_convolve_enable.EnableWindow(FALSE); check_filter_aniso_enable.EnableWindow(FALSE); check_filter_voxrem_enable.EnableWindow(TRUE); check_filter_close_enable.EnableWindow(TRUE); } if ( is_control_enabled(BINARIZE_CONTROLS) ) { check_image_is_inverted.EnableWindow(FALSE); combo_threshold_method.EnableWindow(FALSE); field_manual_threshold.EnableWindow(FALSE); } } //TODO: else invalid type, dont do anything? //enable slice width field field_width_slices_cntrl.EnableWindow(TRUE); field_width_X_cntrl.EnableWindow(TRUE); field_width_Y_cntrl.EnableWindow(TRUE); free(input->basename); free(input->directory); free(input->full_path_name); free(input->filename); free(input); } } // void PoroMediaDialogShare::ClickedInputDirectory_auto( char *directory_name_str, char *file_name_str ) { //get all the parameter values from the dialog //RW_Dialog* dlg = (RW_Dialog*) dlg_share; //open up the file browser window, and wait for return input_info* input = FileBrowser_auto( directory_name_str, file_name_str ); //caution: this will attack '[' and ']' if mult file input //if FileBrowser returns a valid input_info struct if (input != NULL) { if (input->input_type == INPUT_IS_UNKNOWN) {//assume to be .stack.raw, but turn off autocalc, tell so to the user check_auto_calc_params.SetCheck(false); AfxMessageBox("Warning: Unknown file extension, assuming to be .STACK.RAW type."); input->input_type = INPUT_IS_RAW_STACK; } else check_auto_calc_params.SetCheck(true); CString outdirectory; //these are CString types, so no need to strcpy input_file_ext = input->input_type; input_file_name = input->filename; input_directory_name = input->directory; //check if image directory is a predefined RAW_XY or BIN_XY, if so backup one directory for output default outdirectory = input_directory_name; if (strcmp( outdirectory.GetBuffer() + outdirectory.GetLength() - 7, "RAW_XY\\") == 0) outdirectory = outdirectory.GetBufferSetLength(outdirectory.GetLength() - 7); else if (strcmp( outdirectory.GetBuffer() + outdirectory.GetLength() - 7, "BIN_XY\\") == 0) outdirectory = outdirectory.GetBufferSetLength(outdirectory.GetLength() - 7); //fill in directory + input file field UpdateDirFileField(); //fill in default work dir and default output prefix field_directory_work_cntrl.SetWindowText(outdirectory); /////////////////////////////////////////////////////////////// //update global values if not a stack input /////////////////////////////////////////////////////////////// if (!( (input_file_ext == INPUT_IS_RAW_STACK) || (input_file_ext == INPUT_IS_BIN_STACK) || (input_file_ext == INPUT_IS_CBIN_STACK)) ) { field_name_output_cntrl.SetWindowText(input->basename); //set globals that keep track of '[' left_bracket_indx = input->left_bracket_indx; first_slice_indx = input->attached_number; max_dig_cnt = input->max_dig_cnt; cur_dig_cnt = input->attached_number_dig_cnt; //convert to text and place in 'start slice' box SetIntValField(&field_start_slice_cntrl, input->attached_number); //attempt to find the last valid slice file CString temp_name = input_file_name; temp_name.Delete(left_bracket_indx, temp_name.GetLength() ); //delete entire valid file number for (int i = cur_dig_cnt; i < max_dig_cnt; i++) temp_name.Delete(left_bracket_indx - (i-cur_dig_cnt+1), 1); int indx = first_slice_indx + 1; ifstream test; while (1) { //create full file name char* full_name = AppendDigitsAndExtension(temp_name.GetBuffer(), indx, max_dig_cnt, input_file_ext); temp_name.ReleaseBuffer(); //try to open the file, if it fails, we have reached max number test.open(full_name); if (!test) { free(full_name); break; } //increase to next file num indx++; test.close(); free(full_name); } SetIntValField(&field_end_slice_cntrl, indx-1); //read header info if BMP, to autofill dimensions if (input_file_ext == INPUT_IS_BMP) { int xsize, ysize, psize, biBitCount; FILE* bmp_file = fopen(input->full_path_name, "r"); //incase it's a huge file, or computer slow, inform user that a file is being read, hense the delay txt_field_progress.SetWindowText("Reading dimensions of selected BMP image..."); if(bmp_read_header (bmp_file,&xsize,&ysize,&psize,&biBitCount)) { AfxMessageBox("Error: Could not read specified BMP file header."); } else { SetIntValField(&field_start_X_cntrl, 1); SetIntValField(&field_end_X_cntrl, xsize); SetIntValField(&field_start_Y_cntrl, 1); SetIntValField(&field_end_Y_cntrl, ysize); max_X_size = xsize; max_Y_size = ysize; } fclose(bmp_file); txt_field_progress.SetWindowText("Enter desired parameters and push \"OK\""); field_start_X_cntrl.EnableWindow(TRUE); field_end_X_cntrl.EnableWindow(TRUE); field_start_Y_cntrl.EnableWindow(TRUE); field_end_Y_cntrl.EnableWindow(TRUE); } //else its a BIN or RAW, so disable start/end x/y else{ SetIntValField(&field_start_X_cntrl, 1); field_start_X_cntrl.EnableWindow(FALSE); field_end_X_cntrl.EnableWindow(FALSE); SetIntValField(&field_start_Y_cntrl, 1); field_start_Y_cntrl.EnableWindow(FALSE); field_end_Y_cntrl.EnableWindow(FALSE); } //enable end/start slice field_start_slice_cntrl.EnableWindow(TRUE); field_end_slice_cntrl.EnableWindow(TRUE); } /////////////////////////////////////////////////////////////// //input is a stack type /////////////////////////////////////////////////////////////// else { //for stack inputs, set starts to '1', disable start/end fields SetIntValField(&field_start_slice_cntrl, 1); field_start_slice_cntrl.EnableWindow(FALSE); field_end_slice_cntrl.EnableWindow(FALSE); SetIntValField(&field_start_X_cntrl, 1); field_start_X_cntrl.EnableWindow(FALSE); field_end_X_cntrl.EnableWindow(FALSE); SetIntValField(&field_start_Y_cntrl, 1); field_start_Y_cntrl.EnableWindow(FALSE); field_end_Y_cntrl.EnableWindow(FALSE); /////////////////////////////////////////////////////////////// //check for (x_y_z) for autofill potential /////////////////////////////////////////////////////////////// if (check_auto_calc_params.GetCheck()) { int offset; char num_str[MAX_DIG_LIMIT+1]; offset = (int) strlen( input->basename ) - 1; //check for ')' right before extension to signify autofill should be valid if (input_file_name.GetAt(offset) == ')') { char lastchar; char temp_buf[MAX_DIG_LIMIT+1]; char out_name_buf[512]; int i = 0; //get Z num num_str[0] = '\0'; temp_buf[0] = '\0'; offset--; while ( (lastchar = input_file_name.GetAt(offset)) != '_') { sprintf(temp_buf, "%c%s", lastchar, num_str); strcpy(num_str, temp_buf); offset--; i++; if (i == MAX_DIG_LIMIT) break; } SetIntValField(&field_width_slices_cntrl, atoi(num_str)); field_width_slices_int = atoi(num_str); //get Y num num_str[0] = '\0'; temp_buf[0] = '\0'; i = 0; offset--; while ( (lastchar = input_file_name.GetAt(offset)) != '_') { sprintf(temp_buf, "%c%s", lastchar, num_str); strcpy(num_str, temp_buf); offset--; i++; if (i == MAX_DIG_LIMIT) break; } SetIntValField(&field_width_Y_cntrl, atoi(num_str)); field_width_Y_int = atoi(num_str); //get X num num_str[0] = '\0'; temp_buf[0] = '\0'; i = 0; offset--; while ( (lastchar = input_file_name.GetAt(offset)) != '(') { sprintf(temp_buf, "%c%s", lastchar, num_str); strcpy(num_str, temp_buf); offset--; i++; if (i == MAX_DIG_LIMIT) break; } SetIntValField(&field_width_X_cntrl, atoi(num_str)); field_width_X_int = atoi(num_str); strcpy(out_name_buf, input_file_name); out_name_buf[offset] = '\0'; field_name_output_cntrl.SetWindowText(out_name_buf); } else field_name_output_cntrl.SetWindowText(input->basename); } } /////////////////////////////////////////////////////////////// // Enabling and disabling options based on type of input /////////////////////////////////////////////////////////////// if ( input_file_ext == INPUT_IS_BMP ) {//if BMP, enable both save options, binerization, all filters if ( is_control_enabled(FILESAVE_CONTROLS) ) { check_save_raw_stack.EnableWindow(TRUE); check_save_cbin_stack.EnableWindow(TRUE); } if ( is_control_enabled(FILTER_CONTROLS) ) { check_filter_contrast_enable.EnableWindow(TRUE); check_filter_convolve_enable.EnableWindow(TRUE); check_filter_aniso_enable.EnableWindow(TRUE); check_filter_voxrem_enable.EnableWindow(TRUE); check_filter_close_enable.EnableWindow(TRUE); } if ( is_control_enabled(BINARIZE_CONTROLS) ) { check_image_is_inverted.EnableWindow(TRUE); combo_threshold_method.EnableWindow(TRUE); field_manual_threshold.EnableWindow(TRUE); } } else if ( (input_file_ext == INPUT_IS_RAW) || (input_file_ext == INPUT_IS_RAW_STACK) ) {// if RAW, only enable BIN savin, binerization, all filters if ( is_control_enabled(FILESAVE_CONTROLS) ) { check_save_raw_stack.EnableWindow(FALSE); check_save_cbin_stack.EnableWindow(TRUE); } if ( is_control_enabled(FILTER_CONTROLS) ) { check_filter_contrast_enable.EnableWindow(TRUE); check_filter_convolve_enable.EnableWindow(TRUE); check_filter_aniso_enable.EnableWindow(TRUE); check_filter_voxrem_enable.EnableWindow(TRUE); check_filter_close_enable.EnableWindow(TRUE); } if ( is_control_enabled(BINARIZE_CONTROLS) ) { check_image_is_inverted.EnableWindow(TRUE); combo_threshold_method.EnableWindow(TRUE); field_manual_threshold.EnableWindow(TRUE); } } else if( (input_file_ext == INPUT_IS_BIN) || (input_file_ext == INPUT_IS_BIN_STACK) || (input_file_ext == INPUT_IS_CBIN_STACK) || (input_file_ext == INPUT_IS_CBIN) ) {//if a binary input, disable saving except cbin, binarization, and any RAW filters if ( is_control_enabled(FILESAVE_CONTROLS) ) { check_save_raw_stack.EnableWindow(FALSE); check_save_cbin_stack.EnableWindow(TRUE); } if ( is_control_enabled(FILTER_CONTROLS) ) { check_filter_contrast_enable.EnableWindow(FALSE); check_filter_convolve_enable.EnableWindow(FALSE); check_filter_aniso_enable.EnableWindow(FALSE); check_filter_voxrem_enable.EnableWindow(TRUE); check_filter_close_enable.EnableWindow(TRUE); } if ( is_control_enabled(BINARIZE_CONTROLS) ) { check_image_is_inverted.EnableWindow(FALSE); combo_threshold_method.EnableWindow(FALSE); field_manual_threshold.EnableWindow(FALSE); } } //TODO: else invalid type, dont do anything? //enable slice width field field_width_slices_cntrl.EnableWindow(TRUE); field_width_X_cntrl.EnableWindow(TRUE); field_width_Y_cntrl.EnableWindow(TRUE); free(input->basename); free(input->directory); free(input->full_path_name); free(input->filename); free(input); } } //lets user select a work directory void PoroMediaDialogShare::ClickedWorkDirectory() { program_generated = true; input_info* input = DirectoryBrowser(); field_directory_work_cntrl.SetWindowText(input->directory); free(input->directory); free(input); program_generated = false; }