Mercurial > hg > multitrack-audio-matcher
view annotationCalculatorSrc/Histogram.cpp @ 47:689704aa55d5
Added square and better scrolling through the matrix, better loading of files
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 09 May 2012 12:38:00 +0100 |
parents | ba36a1721538 |
children | 5359e2c0b0fb |
line wrap: on
line source
/* * Histogram.cpp * annotationResultCalculator * * Created by Andrew on 08/05/2012. * Copyright 2012 QMUL. All rights reserved. * */ #include "Histogram.h" Histogram::Histogram(){ screenHeight = ofGetHeight(); } void Histogram::createHistogram(const int& binWidthIn, const int& numberofBinsIn){ numberofBins = numberofBinsIn; binWidth = binWidthIn; minimumBinValue = -1.0 * binWidth * ((double)numberofBins/2); histogram.clear(); histogram.assign(numberofBins, 0); maximum = 0; numberOutsideRange = 0; setBinPoints(); } void Histogram::setBinPoints(){ binPoints.clear(); binPoints.push_back(minimumBinValue); while (binPoints.size() < numberofBins){ binPoints.push_back(binPoints[binPoints.size()-1] + binWidth); } maximumBinValue = binPoints[binPoints.size()-1]+binWidth; for (int k = 0; k < binPoints.size();k++){ printf("Bin pts [%i] : %f\n", k, binPoints[k]); } } void Histogram::processDataIntoHistogram(const DoubleVector& data){ double binPoint; int bin = 0; numberOutsideRange = 0; for (int i = 0;i < data.size();i++){ //find which bin it falls into. //5 bins, width is 10 //then we start around zero for the 5+1/2 th, i.e. 3rd bin //zero is the 5/2 th pt bin = 0; binPoint = binPoints[0];//i.e. minimumBinValue; if (data[i] >= binPoint){//i.e. falls inside // while (data[i] > (binPoint + binWidth) && bin < numberofBins) { while (bin < numberofBins && data[i] > binPoints[bin+1]) { //printf("data pt %f bin %i binPt %.1f\n", data[i], bin, binPoint); bin++; binPoint = binPoints[bin]; // binPoint += binWidth; // bin++; } // printf("data pt %f bin %i binPt %.1f\n", data[i], bin, binPoint); if (data[i] <= maximumBinValue){//in case outside range histogram[bin]++; } else{ //then it's greater than maximum numberOutsideRange++; } } else{ //then it's less than minimum numberOutsideRange++; } } for (int k = 0; k < histogram.size();k++){ if (histogram[k] > maximum) maximum = histogram[k]; printf("HISTO[%i] = %i\n", k, histogram[k]); } printf("Number outside %i\n", numberOutsideRange); } void Histogram::plotHistogram(){ plotHistogram(maximum); } void Histogram::plotHistogram(const double& maxHeight){ double width = ofGetWidth(); double height = ofGetHeight(); screenHeight = ofGetHeight(); if (numberofBins > 0 && maxHeight > 0){ width /= numberofBins; height /= maxHeight; for (int i = 0;i < numberofBins;i++){ ofRect(i * width, getY(histogram[i]*height), width, histogram[i]*height); } } } int Histogram::getY(const int& y){ return screenHeight - y; }