-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogramChart.cpp
86 lines (71 loc) · 2.52 KB
/
histogramChart.cpp
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
/*
* =====================================================================================
*
* Filename: histogramChart.c
*
* Description:
*
* Version: 1.0
* Created: 10/15/2011 16:33:56
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Company:
*
* =====================================================================================
*/
#include "histogramChart.h"
Histogram::Histogram(string fl) : filename(fl), ignoreZero(0), numComponents(0), xmax(0), ymax(0) {
reader = vtkSmartPointer<vtkDICOMImageReader>::New() ;
reader->SetDirectoryName(filename.c_str()) ;
plot = vtkSmartPointer<vtkXYPlotActor>::New() ;
numComponents = reader->GetOutput()->GetNumberOfScalarComponents() ;
drawPlot() ;
renderer = vtkSmartPointer<vtkRenderer>::New() ;
renderer->AddActor(plot) ;
renderWindow = vtkSmartPointer<vtkRenderWindow>::New() ;
renderWindow->AddRenderer(renderer) ;
renderWindow->SetSize(600,480) ;
iren = new QVTKWidget ;
iren->SetRenderWindow(renderWindow) ;
//iren->Initialize() ;
//interactor->Start() ;
}
Histogram::~Histogram() {}
void Histogram::drawPlot() {
for(std::size_t i = 0; i < numComponents; i++ ) {
vtkSmartPointer<vtkImageExtractComponents> extract = vtkSmartPointer<vtkImageExtractComponents>::New() ;
extract->SetInputConnection(reader->GetOutputPort()) ;
extract->SetComponents(i) ;
extract->Update() ;
double range[2] ;
extract->GetOutput()->GetScalarRange(range) ;
histo = vtkSmartPointer<vtkImageAccumulate>::New() ;
histo->SetInputConnection(extract->GetOutputPort()) ;
histo->SetComponentExtent(0, static_cast<int>(range[1]) - static_cast<int>(range[0]) - 1, 0,0,0,0) ;
histo->SetComponentOrigin(range[0], 0, 0) ;
histo->SetComponentSpacing(1, 0, 0) ;
histo->SetIgnoreZero(ignoreZero) ;
histo->Update() ;
if( range[1] > xmax )
{
xmax = range[1];
}
if( histo->GetOutput()->GetScalarRange()[1] > ymax )
{
ymax = histo->GetOutput()->GetScalarRange()[1];
}
plot->SetXTitle("Value") ;
plot->SetYTitle("Frequency") ;
plot->SetLabelFormat("%g") ;
plot->AddInput( histo->GetOutput() );
/*
if( numComponents > 1 )
{
plot->SetPlotColor(i,colors[i]);
}*/
}
plot->SetXRange(0, xmax) ;
plot->SetYRange(0, ymax) ;
}