Mercurial > hg > multitrack-audio-matcher
view annotationCalculatorSrc/Histogram.cpp @ 48:5359e2c0b0fb
Added data from six tracks. Absolute histogram
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 09 May 2012 21:55:16 +0100 |
parents | 689704aa55d5 |
children | 8df911733fdc |
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){ //printf("create regular histo\n"); numberofBins = numberofBinsIn; binWidth = binWidthIn; minimumBinValue = -1.0 * binWidth * ((double)numberofBins/2); histogram.clear(); histogram.assign(numberofBins, 0); maximum = 0; numberOutsideRange = 0; setBinPoints(); } void Histogram::createAbsoluteHistogram(const int& binWidthIn, const int& numberofBinsIn){ printf("create abs histo\n"); minimumBinValue = 0; numberofBins = numberofBinsIn; binWidth = binWidthIn; 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 // printf("data[%i] %f\n", i, data[i]); bin = 0; binPoint = binPoints[0];//i.e. minimumBinValue; // printf("binpT%f\n", binPoint); if (data[i] >= binPoint){//i.e. falls inside // while (data[i] > (binPoint + binWidth) && bin < numberofBins) { while (bin < numberofBins && data[i] > binPoints[bin]) { //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] (%.1f - %.1f) = %i\n", k, binPoints[k], binPoints[k]+binWidth, 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; }