////////////////////////////////////////////////////////////////////////// // // // cell.cpp // // // Michael Boland // 2 September 1995 // // // Revisions: // 13Oct95: Added normalization of intensity feature to cell_moments // M. Boland // 21Dec95: Added cell_obj_moments(). -M. Boland // 02Jan96: Added capabiliity for multi-color images -M. Boland // 07Jan96: Changed normalization of pixels to total cell intensity // instead of avg. intensity. -M. Boland // 13Jan96: Added test code for use in determining z=1 for Zernike // calculations. -M. Boland // 19Jan96: Moved cell_moments(), cell_object_moments(), and // cell_zernike() to separate files. -M.Boland // ////////////////////////////////////////////////////////////////////////// #include #include #include #include #include "cell.h" Cell::Cell() { for(int i = 1; i <= MAX_COLORS; i++) { cell_intensity[i] = 0.0 ; } cell_num_objects = 0 ; cell_num_pixels = 0 ; cell_num_colors = 0 ; } Cell::Cell(ifstream& infile) { for(int i = 1; i <= MAX_COLORS; i++) { cell_intensity[i] = 0.0 ; } cell_num_objects = 0 ; cell_num_pixels = 0 ; cell_num_colors = 0 ; if (!infile) { cerr << "cell.cpp: invalid infile. \n" ; return ; } Object* new_object ; int size = 0 ; int label = 0 ; int x, y, z, intensity[MAX_COLORS] ; char ch ; while(!infile.eof()) { if (!(infile >> size) || !(infile >> label)) { cerr << "cell.cpp: 1:Invalid input file. \n" ; return ; } new_object = new Object ; for (int index = 0; index < size ; index++) { cell_num_colors = 1 ; if (!(infile >> x) || !(infile >> y) || !(infile >> z) || !(infile >> intensity[1])) { cerr << "cell.cpp: 2:Invalid input file. \n" ; return ; } do { ch = infile.get() ; if (!(isspace(ch))) { infile.putback(ch) ; cell_num_colors++ ; if (!(infile >> intensity[cell_num_colors])) { cerr << "cell.cpp: 3:Invalid input file. \n" ; return ; } } } while (ch != '\n') ; if (!(new_object->object_set_num_colors(cell_num_colors))) { cerr << "cell.cpp: Unable to set number of colors.\n" ; return ; } if (!(new_object->object_add_pixel(x, y, z, intensity))) { cerr << "cell.cpp: Unable to add pixel to object.\n" ; return ; } cell_num_pixels++ ; } // endfor if (!cell_add_object(new_object)) { cerr << "cell.cpp: Unable to add new object. \n" ; return ; } // // Needed to check for CR in last line of file // do { ch = infile.get() ; } while(isspace(ch)) ; infile.putback(ch) ; } // endwhile infile.close() ; } Cell::~Cell() { } ; int Cell::cell_add_object(Object* new_object) { if (!objects.list_add(new_object)) { cerr << "cell.cpp: Unable to create new Object \n" ; return(0) ; } cell_num_objects++ ; for(int color = 1; color <= cell_num_colors ; color++) { cell_intensity[color] += new_object->object_color_intensity(color) ; } return(1) ; } double Cell::cell_color_intensity(int color) { if (color <= cell_num_colors) return(cell_intensity[color]) ; else return(0.0) ; } Pixel* Cell::cell_pixel_array() { Object* obj_ptr ; Pixel* pixel_ptr ; // // allocate space for pixels // Pixel* pixel_array = new Pixel[cell_num_pixels] ; long pixel_index = 0 ; int color_index ; if (!(obj_ptr=objects.list_top())) { cerr << "cell_pixel_array(): No objects.\n" ; return(0) ; } do { if (pixel_ptr = obj_ptr->pixels.list_top()) do { pixel_array[pixel_index].x = pixel_ptr->x ; pixel_array[pixel_index].y = pixel_ptr->y ; pixel_array[pixel_index].z = pixel_ptr->z ; for (color_index=1; color_index <= MAX_COLORS; color_index++) pixel_array[pixel_index].intensity[color_index] = pixel_ptr->intensity[color_index] ; pixel_index++ ; } while (pixel_ptr = obj_ptr->pixels.list_next()) ; } while (obj_ptr = objects.list_next()) ; return(pixel_array) ; }