#include "StdAfx.h" #include "ExtrasInput.h" void disable_inputs(ExtrasDialog* ExtrasDlg){ //common inputs disabled in dialog class ExtrasDlg->check_histogram.EnableWindow(FALSE); ExtrasDlg->check_run_resize_to.EnableWindow(FALSE); ExtrasDlg->check_debug.EnableWindow(FALSE); ExtrasDlg->check_run_edge.EnableWindow(FALSE); ExtrasDlg->check_run_drawing.EnableWindow(FALSE); ExtrasDlg->check_do_not_read_input.EnableWindow(FALSE); } /* re-enable the windows after an analysis run is done */ void enable_inputs(ExtrasDialog* ExtrasDlg){ //enable the common inputs ExtrasDlg->EnableCommonInputs(); ExtrasDlg->check_histogram.EnableWindow(TRUE); ExtrasDlg->check_run_resize_to.EnableWindow(TRUE); ExtrasDlg->check_debug.EnableWindow(TRUE); ExtrasDlg->check_run_edge.EnableWindow(TRUE); ExtrasDlg->check_run_drawing.EnableWindow(TRUE); ExtrasDlg->check_do_not_read_input.EnableWindow(TRUE); //flash for 3 seconds to alert user that we are done ExtrasDlg->FlashWindowEx(FLASHW_TRAY, 3, 0); } UINT ExtrasSetup(LPVOID pParam) { char output_name[512]; ExtrasDialog* ExtrasDlg = (ExtrasDialog*) pParam; char extras_directory[512], data_out_prefix[512]; //disable dialog inputs disable_inputs( ExtrasDlg ); // Create a new sphere result directory if needed sprintf( extras_directory, "%sExtrasOutput", ExtrasDlg->field_directory_work_str ); if ( !CreateDirectory(extras_directory, NULL) ) { write_to_log("ExtrasSetup: 'ExtrasOutput' directory already exists, new one will not be created."); } sprintf(data_out_prefix, "%s\\%s", extras_directory, ExtrasDlg->field_name_output_str); //edge - converts some solid block into edges only if (ExtrasDlg->check_run_edge.GetCheck()) { DS_cube * ds_cube = ExtrasDlg->Dlg_Input_to_DS(); unsigned short x, y, z; char dx, dy, dz; DS_cube * ds_cube_edge = new DS_cube(ds_cube->wZ, ds_cube->wY, ds_cube->wX); ExtrasDlg->pbar_simulation_progress.SetRange(0, ds_cube->wZ-1); ExtrasDlg->pbar_simulation_progress.SetPos(0); ExtrasDlg->pbar_simulation_progress.SetStep(1); ExtrasDlg->txt_field_progress.SetWindowText("Now running edge detect..."); for (z = 0; z < ds_cube->wZ; z++) { for (y = 0; y < ds_cube->wY; y++) for (x = 0; x < ds_cube->wX; x++) { if (ds_cube->data[z][y][x] == ExtrasDlg->field_edge_solid_val_int) {//count neighs for (dz = -1; dz <= 1; dz++) for (dy = -1; dy <= 1; dy++) for (dx = -1; dx <= 1; dx++) { //bounds check and fiber check if ( (((int)z +dz) < 0) || (((int)y +dy) < 0) || (((int)x +dx) < 0) || (((int)z +dz) >= ds_cube->wZ) || (((int)y +dy) >= ds_cube->wY) || (((int)x +dx) >= ds_cube->wX) || (ds_cube->data[z+dz][y+dy][x+dx] != ExtrasDlg->field_edge_solid_val_int) ) { ds_cube_edge->data[z][y][x] = (unsigned char)ExtrasDlg->field_edge_solid_val_int; goto skip_rest; } } //all neighs were fiber ds_cube_edge->data[z][y][x] = (unsigned char)ExtrasDlg->field_edge_background_int; } else ds_cube_edge->data[z][y][x] = ds_cube->data[z][y][x]; skip_rest:; } ExtrasDlg->pbar_simulation_progress.StepIt(); } ExtrasDlg->txt_field_progress.SetWindowText("Saving output..."); sprintf(output_name, "%s_edge(%d_%d_%d).stack.raw", data_out_prefix, ds_cube->wX, ds_cube->wY, ds_cube->wZ); ds_cube_edge->write_to_RAW_STACK(output_name); delete ds_cube_edge; delete ds_cube; } // Drawing if ( ExtrasDlg->check_run_drawing.GetCheck() ) { ExtrasSampleCreation( ExtrasDlg, data_out_prefix ); } // Cropping if ( ExtrasDlg->check_crop_enable.GetCheck() ) { DS_1b_cube *cropped_cube = new DS_1b_cube( (unsigned short)ExtrasDlg->field_crop_z_width_int, (unsigned short)ExtrasDlg->field_crop_y_width_int, (unsigned short)ExtrasDlg->field_crop_x_width_int ); Vect3usi cur_coord( (unsigned short)ExtrasDlg->field_crop_z_start_int, (unsigned short)ExtrasDlg->field_crop_y_start_int, (unsigned short)ExtrasDlg->field_crop_x_start_int ); Vect3usi cropped_coord(0, 0, 0); DS_1b_cube *input_cube = ExtrasDlg->Dlg_Input_to_cDS(); for ( ; cur_coord.z <= (unsigned short)ExtrasDlg->field_crop_z_end_int; cur_coord.z++ ) { for ( cur_coord.y = (unsigned short)ExtrasDlg->field_crop_y_start_int, cropped_coord.y = 0; cur_coord.y <= (unsigned short)ExtrasDlg->field_crop_y_end_int; cur_coord.y++ ) { for ( cur_coord.x = (unsigned short)ExtrasDlg->field_crop_x_start_int, cropped_coord.x = 0; cur_coord.x <= (unsigned short)ExtrasDlg->field_crop_x_end_int; cur_coord.x++ ) { if ( input_cube->get_spot(cur_coord) ) { cropped_cube->set_spot_1(cropped_coord); } else { cropped_cube->set_spot_0(cropped_coord); } ++ cropped_coord.x; } ++ cropped_coord.y; } ++ cropped_coord.z; } // Save cube cropped_cube->writeToFile( data_out_prefix, true ); } //done! ExtrasDlg->txt_field_progress.SetWindowText("Done."); enable_inputs(ExtrasDlg); return 1; }