Mercurial > hg > multitrack-audio-matcher
view annotationCalculatorSrc/Histogram.cpp @ 46:ba36a1721538
Added abs median calculation, match forwards and backwards paths
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 08 May 2012 23:16:00 +0100 |
parents | d23685b9e766 |
children | 689704aa55d5 |
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, DoubleVector& data){ numberofBins = numberofBinsIn; binWidth = binWidthIn; histogram.clear(); histogram.assign(numberofBins, 0); maximum = 0; double binPoint; int bin = 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 = -1.0 * binWidth * ((double)numberofBins/2); if (data[i] >= binPoint){//i.e. falls inside while (data[i] > (binPoint + binWidth) && bin < numberofBins) { //printf("data pt %f bin %i binPt %.1f\n", data[i], bin, binPoint); binPoint += binWidth; bin++; } // printf("data pt %f bin %i binPt %.1f\n", data[i], bin, binPoint); if (data[i] <= binPoint + binWidth){//in case outside range histogram[bin]++; } } } for (int k = 0; k < histogram.size();k++){ if (histogram[k] > maximum) maximum = histogram[k]; printf("HISTO[%i] = %i\n", k, histogram[k]); } } 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; }