www.pudn.com > colortracker.rar > MPGridScan.h
/* * MPGridScan.h * * * Created by Josh Susskind 2003. * Copyright (c) 2003 Machine Perception Laboratory * University of California San Diego. * Please read the disclaimer and notes about redistribution * at the end of this file. * * Authors: Josh Susskind */ #ifndef __MPGRIDSCAN_H__ #define __MPGRIDSCAN_H__ #include "preprocessor.h" /* ================================================================ */ //templateclass MPGridScan { private: int m_downsample; int m_gridScanX; int m_gridScanY; int m_maxSamplePoints; int m_scanX; int m_scanY; int m_scanLength; int m_scanHeight; int m_imgWidth; int m_imgHeight; double m_dh; double m_dw; public: MPGridScan() { m_downsample = 1;//DOWNSAMPLE; m_scanX = 0; m_scanY = 0; } inline void UpdateVars(const int & imgWidth, const int & imgHeight, const int & downsample) { m_downsample = downsample; m_imgWidth = imgWidth; m_imgHeight = imgHeight; m_gridScanX = m_imgWidth / m_downsample; m_gridScanY = m_imgHeight / m_downsample; m_maxSamplePoints = m_gridScanX*m_gridScanY; m_scanLength = m_imgWidth; m_scanHeight = m_imgHeight; m_dh = m_downsample; // (double) m_scanHeight/m_gridScanY; m_dw = m_downsample; // (double) m_scanLength/m_gridScanX; } inline int get_gridScanX() { return m_gridScanX; } inline int get_gridScanY() { return m_gridScanY; } inline int next(int &gridX, int &gridY, int &incr) { static int iPixel = 0; if (iPixel == m_maxSamplePoints) { iPixel = 0; return (0); } static const float oneoverdiv = 1.0/m_gridScanX; gridY = (int)( iPixel * oneoverdiv ); gridX = (int)( iPixel % m_gridScanX ); int yCoord = m_scanY + m_dh*gridY; int xCoord = m_scanX + m_dw*gridX; incr = m_imgWidth * yCoord + xCoord; iPixel++; return (1); } }; /* ================================================================ */ #endif __MPGRIDSCAN_H__ /* * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */