next up previous contents
Next: object.h Up: CHO Data Previous: cell.h

object.cpp

 

//////////////////////////////////////////////////////////////////////////
//
//
//                             object.cpp
//
//
//                           Michael Boland
//                          2 September 1995
//
//    02Jan96:  Added capability for multi-color images. -M. Boland
//    28Feb96:  Changed functions for external calculation of features
//               -M. Boland
//
//////////////////////////////////////////////////////////////////////////


#include 
#include 
#include 
#include 

#include "object.h"

//
// Member functions for class Object
//

Object::Object()
{
	for(int i = 1; i <= MAX_COLORS; i++)
	{
		obj_intensity[i] = 0.0 ;
	}
	obj_num_colors = 1 ;
	obj_num_pixels = 0 ;

}

Object::Object(int num_colors)
{
	for(int i = 1; i <= MAX_COLORS; i++)
	{
		obj_intensity[i] = 0.0 ;
	}
	obj_num_colors = num_colors ;
	obj_num_pixels = 0 ;

}


Object::~Object() { } ;


int Object::object_add_pixel(int x, int y, int z, int pixel_intensity[]) 
{
	Pixel* new_pixel = new Pixel ;

	new_pixel->x = x ;
	new_pixel->y = y ;
	new_pixel->z = z ;
	for(int i = 1; i <= obj_num_colors; i++)
		new_pixel->intensity[i] = pixel_intensity[i] ;

	if (! pixels.list_add(new_pixel))
	{
		cerr << "object.cpp: cannot add new pixel \n" ;
		return(0) ;
	}

	for(int j = 1; j <= obj_num_colors; j++)
	{
		obj_intensity[j] += pixel_intensity[j] ;
	}

	obj_num_pixels++ ;

	return(1) ;
}


Pixel* Object::object_pixel_array()
{
	Pixel* pixel_ptr ;
	Pixel* pixel_array = new Pixel[obj_num_pixels] ;
	long pixel_index = 0 ;
	int color_index ;

	if (!(pixel_ptr = pixels.list_top()))
	{
		cerr << "object_pixel_array(): No pixels.\n" ;
		return(0) ;
	}

	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 = pixels.list_next()) ;

	return(pixel_array) ;
}
	
 



Copyright ©1999 Michael V. Boland
1999-09-18