#include ".\slidingwindow.h" #include using namespace std; SlidingWindow::SlidingWindow(int L) { pixelOffset = 5; length = L; lastTopIndex = 0; lastBotIndex = pixelOffset; pixelIndex = pixelOffset+1; sizeTop = L-pixelOffset+1; numSatBot = 0; numSatTop = 0; colored = new int[L]; SlidingWindow::Reset(); } SlidingWindow::~SlidingWindow(void) { delete [] colored; } // Adds a pixel to the array void SlidingWindow::AddPixel(int is_Color) { numSatBot -= colored[lastBotIndex]; // the bottom lost this numSatTop -= colored[lastTopIndex]; // top lost this colored[lastTopIndex] = is_Color; // new data numSatBot += colored[lastTopIndex]; numSatTop += colored[lastBotIndex]; updateIndex(&lastTopIndex); updateIndex(&lastBotIndex); updateIndex(&pixelIndex); } // Resets the array void SlidingWindow::Reset() { for ( int i = 0; i< length; i++ ) { colored[i] = 0; } numSatBot = 0; numSatTop = 0; } // Checks for the correct number of 'white' // above and the corret number of 'non-white' pixels below // the middle of the array int SlidingWindow::ok() { if (numSatTop >= sizeTop && numSatBot <= 0) return 1; else return 0; } // same as ok() but is used for debugging purposes... int SlidingWindow::pok() { cout << "top: " << numSatTop << " " << "bottom: " << numSatBot <= sizeTop && numSatBot <= 0) return 1; else return 0; }