-
Notifications
You must be signed in to change notification settings - Fork 1
/
gaussian_random_number.cpp
47 lines (40 loc) · 1.12 KB
/
gaussian_random_number.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
#include <array>
#include <ctime>
#include "vtkChartXY.h"
#include "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkFloatArray.h"
#include "vtkIntArray.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkPlot.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkTable.h"
auto main(int argc, char** argv) -> int {
vtkMath::RandomSeed(time(nullptr));
vtkNew<vtkTable> table;
vtkNew<vtkIntArray> x;
x->SetName("X Axis");
table->AddColumn(x);
vtkNew<vtkFloatArray> y;
y->SetName("Y axis");
table->AddColumn(y);
const auto num = 1000;
table->SetNumberOfRows(num);
for (auto i = 0; i < num; ++i) {
table->SetValue(i, 0, i);
table->SetValue(i, 1, vtkMath::Gaussian(0.0, 2.0));
}
vtkNew<vtkChartXY> chart;
auto line = chart->AddPlot(vtkChart::LINE);
line->SetWidth(2);
line->SetInputData(table, 0, 1);
vtkNew<vtkContextView> view;
view->GetScene()->AddItem(chart);
view->GetRenderer()->SetBackground(255, 255, 255);
view->GetRenderWindow()->Render();
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
}