// =========================== // // Implementation for Image class #include #include "Image.h" //------------- // Constructor Image::Image( int date, std::vector pixels ) { m_date = date ; m_pixels = pixels ; } //--------------- // Simple accessor to get size of image int Image::size() { return m_pixels.size(); } //--------------- // Simple accessor to give data at which image recorded int Image::date() { return m_date; } //--------------- // simple accessor to get intensity at a given position int Image::intensity( int position ) { if( (position < 0) || (position >= m_pixels.size()) ) return 0 ; return m_pixels[position]; } //------------------------- // Find position of pixel with maximum intensity int Image::peakPosition( ) { int posMax = 0 ; int valMax = 0 ; for(int ind=0; ind < m_pixels.size(); ++ind ) { if( this->intensity(ind) > valMax ) { valMax = this->intensity(ind) ; posMax = ind ; } } return posMax ; } //------------------------- // retrun value of intensity of pixel with maximum intensity. int Image::peakValue( ) { return this->intensity(this->peakPosition()) ; } //------------------------ // Operator overload. Image& Image::operator+=( Image& rhs ) { // Dumb test that sizes are the same // Should probably print an error or throw an exception. if( this->size() != rhs.size() ) return *this ; // Add pixels together. // Note: we use the virtual self methods in case they have been overridden // in a sub class which re-defines intensity. for( int ind=0; ind < this->size() ; ++ind ) { m_pixels[ind] = this->intensity(ind) + rhs.intensity(ind) ; } // Cant do anything sensible with the date m_date = 0 ; return *this ; } //------------------------ // Print out void Image::print() { std::cout << std::endl << "Image: " ; for( int ind=0; ind < this->size() ; ++ind ) { std::cout << " " << this->intensity(ind) ; } std::cout << std::endl; }