-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntegralHistogram.h
95 lines (83 loc) · 2.39 KB
/
IntegralHistogram.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef _INTEGRALHISTOGRAM_H_
#define _INTEGRALHISTOGRAM_H_
#include <vector>
using namespace std;
#include "Histogram.h"
class IntegralHistogram
{
public:
//constructor: construct a empty IH
IntegralHistogram()
{
m_hists.clear();
}
//deconstructor
~IntegralHistogram()
{
for( int i=0; i<m_hists.size(); i++ ){
delete m_hists[i];
}
m_hists.clear();
}
//pushHistogram: given a histogram and add it into this IH
//it means the new location for this histogram in this IH
//is this histogram+previous_integralHistogram
void pushHistogram( Histogram *a)
{
Histogram* h = new Histogram(a);
if( m_hists.size() != 0 )
Histogram::addHistogram( h, h, m_hists[m_hists.size()-1] );
m_hists.push_back( h );
}
int getbins(){
return m_hists[0]->getBinNum();
}
//getHistogram: get histogram between s and t(include s and t )
//hist: return histogram
void getHistogram( Histogram* hist, int s, int t )
{
if( s == 0 )
Histogram::assign( hist, m_hists[t] );
else
Histogram::subHistogram( hist, m_hists[t], m_hists[s-1] );
}
//getSubBinHistogram: the same as getHistogram but only calculate bin between binS and binT
//hist: return histogram: bin number should be binT-binS+1
//sliceS, sliceT: get histogram between sliceS and sliceT (include S and T )
//binS and binT: calculate bin between binS and binT (include binS and binT)
void getSubBinHistogram( Histogram* hist, int sliceS, int sliceT, int binS, int binT )
{
if( sliceS == 0 ){
float* f = (float*) malloc( sizeof(float) * (binT-binS+1) );
m_hists[sliceT]->getBins( f, binS, binT );
hist->setBins( binS, binT, f );
free(f);
}else{
Histogram::subSubHistogram( hist, m_hists[sliceT], m_hists[sliceS-1], binS, binT );
}
}
//printIntegralHistogram: print this integral histogram
void printIntegralHistogram()
{
for( int i=0; i<m_hists.size(); i++ ){
printf( "%02d : ",i );
m_hists[i]->printHistogram();
}
}
//write integral histogram to file(not do any substraction)
void writeToFile(FILE* fp)
{
for( int i=0; i<m_hists.size(); i++ ){
m_hists[i]->writeToFile(fp);
}
}
//getSize: return number of histogram in this integral histogram
int getSize()
{
return (int)(m_hists.size());
}
private:
vector<Histogram*> m_hists;
//histograms: every histogram is integraled( m_hists[i]-m_hist[i-1] can get raw histogram at i location)
};
#endif