#pragma once #include "afxwin.h" #include "DistanceTransform.h" #include "DS_cube.h" #include "DS_1b_cube.h" #include "DS_2b_cube.h" #include "useful_inlined_functions.h" using namespace std; //%%%%%%%%%%IMPORTANT%%%%%%%%%%%%%// // This will be type of cube used for xfrm and growth typedef unsigned char sg_xfrm_type; typedef unsigned char sg_sphr_type; // This is amount of BYTES reserved for precomputed SQRT table #define SG_SQRT_TABLE_BYTES 1000000 //%%%%%%%%END IMPORTANT%%%%%%%%%%%// // Structure for holding Face/Edge/Corner values in a DistanceXfrm typedef struct dist_xfrm_vals { sg_xfrm_type face, edge, corner; } dist_xfrm_vals; /////////////////////////////////// //options available to sphere growth typedef unsigned int sg_options; #define SG_QUICK_DIST_XFRM 0x0001 // Uses distance xfrm rather than growing a sphere at each pixel #define SG_BOUNDARY_IS_SOLID 0x0002 // Cube boundary is a wall rather than internal mirror #define SG_ODD_DIAMETER_ONLY 0x0004 // All spheres will have an odd diameter, but perfect one pixel centers #define SG_CONSERVE_MEMORY 0x0008 // In Growth stage, distance xfrm cube will be stored on disk, only 3 slices in RAM // Output cube options #define SG_SAVE_DIST_GRAY 0x0010 #define SG_SAVE_DIST_RGB 0x0020 #define SG_SAVE_GROWN_GRAY 0x0040 #define SG_SAVE_GROWN_RGB 0x0080 #define SG_SAVE_STAGE_CUBE_GREY 0x4000 // Outputs a cube with each slice representing growth stage #define SG_SAVE_STAGE_CUBE_RGB 0x8000 // Outputs a cube with each slice representing growth stage // Early stop options #define SG_STOP_AFTER_DISTANCE 0x1000 #define SG_STOP_AFTER_SPHERE 0x2000 // Options for RunAnalysis() #define SG_APPEND_RESULTS 0x0100 // Output results will be appended to specified file #define SG_DO_NOT_ADD_HEADER 0x0200 // Only analysis results will be output, no sample information #define SG_PAD_ODD_DISTRIBUTION 0x0400 // Only analysis results will be output, no sample information //////////////////////////////////// //state sphere growth is currently in typedef unsigned int sg_current_states; #define SG_STATE_XFRM_DONE 0x0001 #define SG_STATE_GROWTH_DONE 0x0002 //////////////////////////////////// //return values typedef unsigned int sg_status; #define SG_NO_ERROR 0x0000 #define SG_ERR_MEMORY_ALLOC 0x0001 #define SG_ERR_FILE_IO 0x0002 #define SG_ERR_XFRM_CREATION 0x0004 #define SG_ERR_SPHERE_CREATION 0x0008 #define SG_ERR_INVALID_STATE 0x4000 #define SG_ERR_ABORT_RECEIVED 0x8000 #define SG_FIBER_HIT 0x0100 class SphereGrowth { public: // SG_Setup SphereGrowth(DS_1b_cube* ds_cube_ptr, CEdit *prog_text=NULL, CProgressCtrl *prog_bar=NULL); ~SphereGrowth(); // PUBLIC functions sg_status RunSphereGrowth(sg_options options, char *outfile_prefix, dist_xfrm_vals *dt_params = NULL); sg_status RunAnalysis(float pixel_size, sg_options options, int dist_offset = 0, char *outfile = NULL); private: // PRIVATE functions sg_status PrepareMemoryForRun(); sg_status OutputSphereHeader(ofstream &file_ptr); // SG_DistanceXfrm sg_status GetDiameterMap(); sg_status ValidateOuterSphereLayer(unsigned short z, unsigned short y, unsigned short x, sg_xfrm_type inn_diam, sg_xfrm_type out_diam); sg_xfrm_type GetExactDiameter(unsigned short z, unsigned short y, unsigned short x); // SG_GrowSpheres sg_status GrowAllFromMinToMaxDiameter(unsigned short slice_to_snap=0); void GrowSingleSphere(unsigned short z, unsigned short y, unsigned short x, sg_sphr_type inn_diam, sg_sphr_type out_diam); // Uses precomputed table to get square root, unless entry is larger than table inline unsigned short GetSqrt(unsigned int value) { if (value > sqrt_table_last_precomputed) return ( (unsigned short)sqrt( (float)value ) ); else return ( sqrt_table[value] ); }; // External pointers DS_1b_cube *ds_cube; char *output_prefix; // Prefix of all output files // Progress bar and text CEdit *progress_txt; CProgressCtrl *progress_bar; bool *stop_request; // Internal structures DSt_cube<sg_xfrm_type> *distance_xfrm; DSt_cube<sg_sphr_type> *sphere_map; sg_xfrm_type inf_radius; // Settings and tracking variables sg_sphr_type max_diameter; unsigned short *sqrt_table; unsigned int sqrt_table_last_precomputed; char file_prefix[512]; sg_options cur_setting; dist_xfrm_vals cur_FEC; sg_current_states cur_state; };