![]() |
The Machine Perception Toolbox |
|
00001 /* 00002 * MPGridScan.h 00003 * 00004 * 00005 * Created by Josh Susskind 2003. 00006 * Copyright (c) 2003 Machine Perception Laboratory 00007 * University of California San Diego. 00008 * Please read the disclaimer and notes about redistribution 00009 * at the end of this file. 00010 * 00011 * Authors: Josh Susskind 00012 */ 00013 #ifndef __MPGRIDSCAN_H__ 00014 #define __MPGRIDSCAN_H__ 00015 00016 #include "preprocessor.h" 00017 00018 /* ================================================================ */ 00019 00020 //template<class T, int DOWNSAMPLE> 00021 class MPGridScan { 00022 private: 00023 int m_downsample; 00024 int m_gridScanX; 00025 int m_gridScanY; 00026 int m_maxSamplePoints; 00027 int m_scanX; 00028 int m_scanY; 00029 int m_scanLength; 00030 int m_scanHeight; 00031 int m_imgWidth; 00032 int m_imgHeight; 00033 double m_dh; 00034 double m_dw; 00035 00036 public: 00037 MPGridScan() { 00038 m_downsample = 1;//DOWNSAMPLE; 00039 m_scanX = 0; 00040 m_scanY = 0; 00041 } 00042 00043 inline void UpdateVars(const int & imgWidth, const int & imgHeight, const int & downsample) { 00044 m_downsample = downsample; 00045 m_imgWidth = imgWidth; 00046 m_imgHeight = imgHeight; 00047 m_gridScanX = m_imgWidth / m_downsample; 00048 m_gridScanY = m_imgHeight / m_downsample; 00049 m_maxSamplePoints = m_gridScanX*m_gridScanY; 00050 m_scanLength = m_imgWidth; 00051 m_scanHeight = m_imgHeight; 00052 m_dh = m_downsample; // (double) m_scanHeight/m_gridScanY; 00053 m_dw = m_downsample; // (double) m_scanLength/m_gridScanX; 00054 } 00055 00056 inline int get_gridScanX() { 00057 return m_gridScanX; 00058 } 00059 00060 inline int get_gridScanY() { 00061 return m_gridScanY; 00062 } 00063 00064 inline int next(int &gridX, int &gridY, int &incr) { 00065 static int iPixel = 0; 00066 if (iPixel == m_maxSamplePoints) { 00067 iPixel = 0; 00068 return (0); 00069 } 00070 static const float oneoverdiv = 1.0/m_gridScanX; 00071 gridY = (int)( iPixel * oneoverdiv ); 00072 gridX = (int)( iPixel % m_gridScanX ); 00073 int yCoord = m_scanY + m_dh*gridY; 00074 int xCoord = m_scanX + m_dw*gridX; 00075 incr = m_imgWidth * yCoord + xCoord; 00076 iPixel++; 00077 return (1); 00078 } 00079 }; 00080 00081 /* ================================================================ */ 00082 00083 #endif __MPGRIDSCAN_H__ 00084 00085 00086 /* 00087 * 00088 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 00089 * 00090 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00091 * 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. 00092 * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. 00093 * 00094 * 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. 00095 * 00096 */