Eigene Dateien/uni/visualisierung/vislu/bsp1/VisLu/VHistogram.cpp

Go to the documentation of this file.
00001 #include "VHistogram.h"
00002 #include <algorithm>
00003 #include <vector>
00004 #include <math.h>
00005 #include <GL/glew.h>
00006 #include <GL/glut.h>
00007 #include <iostream>
00008 
00009 using namespace std;
00010 
00011 VHistogram::VHistogram(int * hist,int length,int x,int y,int width,int height)
00012 {
00013         this->hist = hist;
00014         this->length = length;
00015         this->width = width;
00016         this->height = height;
00017         this->x = x;
00018         this->y = y;
00019         int k = (int)ceil((double)this->length/this->width);
00020         for(int i=1; i<this->length-k+1; i+=k) {//start on 1 to avoid outliers
00021                 int sum = 0;
00022                 for(int j=i; j<i+k; j++) {
00023                         sum+=this->hist[j];
00024                 }
00025                 this->clamped_hist.push_back(sum);
00026         }
00027         this->peak = *max_element(this->clamped_hist.begin(),this->clamped_hist.end());
00028         for(vector<int>::iterator it = this->clamped_hist.begin(); it!=this->clamped_hist.end(); it++) {
00029                 (*it) = (int)ceil(((double)(*it)*this->height/this->peak));
00030         }
00031 }
00032 
00033 void VHistogram::draw() {
00034         glBegin(GL_LINES);
00035                 int i = 0;
00036                 for(vector<int>::iterator it = this->clamped_hist.begin(); it!=this->clamped_hist.end(); it++) {
00037                         glVertex2f(x+i,y+this->height);
00038                         glVertex2f(x+i,y+this->height-(*it));
00039                         i++;
00040                 }
00041         glEnd();
00042 }
00043 
00044 VHistogram::~VHistogram(void)
00045 {
00046         delete this->hist;
00047         this->clamped_hist.clear();
00048 }

Generated on Wed Dec 6 11:07:59 2006 for VisLU by  doxygen 1.5.1-p1