00001 /* 00002 * Copyright (C) 2006, Jose Renato Santos. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 */ 00017 00018 /////////////////////////////////////////////////////////////////////////////// 00019 // Histogram.cpp: Implementation of the CHistogram class (histogram) 00020 /////////////////////////////////////////////////////////////////////////////// 00021 00022 #include "Histogram.h" 00023 00024 #ifdef __Rio_Win 00025 // Windows implementation 00026 // This was included to use in Visual Studio 6.0 00027 #include "stdafx.h" 00028 #else 00029 // Linux implementation 00030 #endif 00031 00032 /* ------------------------ */ 00033 00034 ////////////////////////////////////////////////////////////////////// 00035 CHistogram::CHistogram (const double First, 00036 const double Interval, 00037 const int nPoints) 00038 { 00039 m_n = nPoints; 00040 m_First = First; 00041 m_Interval = Interval; 00042 m_Vector = new unsigned int[nPoints]; 00043 for(int i=0; i<nPoints; i++) 00044 { 00045 m_Vector[i] = 0; 00046 } 00047 } 00048 00049 ////////////////////////////////////////////////////////////////////// 00050 CHistogram::~CHistogram () 00051 { 00052 delete[] m_Vector; 00053 } 00054 00055 ////////////////////////////////////////////////////////////////////// 00056 void CHistogram::Update(const double Val) 00057 { 00058 int ind; 00059 00060 if(Val <= m_First) 00061 ind = 0; 00062 else 00063 ind = (int) (( (Val - m_First)/m_Interval ) + 0.5 ); 00064 00065 if(ind >= m_n) 00066 ind = m_n-1; 00067 00068 m_Vector[ind]++; 00069 } 00070 00071 ////////////////////////////////////////////////////////////////////// 00072 void CHistogram::Print(ofstream* out, const char* Str) 00073 { 00074 if(Str != 0) 00075 *out << Str; 00076 00077 *out << m_n << endl; 00078 for(int i=0; i<m_n; i++) 00079 { 00080 if(Str != 0) 00081 *out << Str; 00082 *out << m_First + i * m_Interval << " " << m_Vector[i] << endl; 00083 } 00084 00085 }