-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
92 lines (74 loc) · 2.56 KB
/
main.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
87
88
89
90
91
92
#include <iostream>
#include <random>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "FlameFunctions.h"
#include "Histogram.h"
#include "FlameCalculator.h"
#include <future>
using namespace flame;
const int WinWidth = 1024;
const int WinHeight = 1024;
const int SuperSampling = 2;
int main( int argc, char** argv )
{
const auto wndName = "Flames";
const auto bpp = 3;
cv::Mat mat = cv::Mat::zeros( WinWidth, WinHeight, CV_8UC3 );
cv::namedWindow( wndName );
FlameFunctionSet ffs;
ffs.AddFunction(
FlameFunction( { Variations::Linear }, { Coefficients::Build( 0.3f, 0, 0, 0, 0.3f, 0 ) }, { 1.f }, Color3_8( 138, 43, 226 ) ),
0.33f
);
ffs.AddFunction(
FlameFunction(
{ Variations::Heart, Variations::Sinusoidal },
{ Coefficients::Build( 0.3f, 0, 0, 0, 0.3f, 0.5f ), Coefficients::Build( 0.3f, 0.3f, 0.2f, 0.3f, 0.7f, 0.4f ) },
{ 0.8f, 0.2f }, Color3_8( 153, 50, 204 ) ),
0.33f
);
ffs.AddFunction(
FlameFunction( { Variations::Spherical }, { Coefficients::Build( 0.3f, 0, 0.5f, 0, 0.3f, 0 ) }, { 1.f }, Color3_8( 255, 105, 180 ) ),
0.33f
);
ffs.AddSymmetries( { Symmetry::Rotate72 } );
const auto Threads = 7;
std::vector<SimpleHistogram_t> snapshotHistograms;
std::vector<FlameCalculator::Ptr> calculators;
for ( auto idx = 0; idx < Threads; idx++ )
{
snapshotHistograms.emplace_back( WinWidth * SuperSampling, WinHeight * SuperSampling );
calculators.push_back(
std::make_unique<FlameCalculator>( ffs,
static_cast<size_t>( WinWidth ),
static_cast<size_t>( WinHeight ),
static_cast<size_t>( SuperSampling ) ) );
calculators[idx]->Start();
}
std::vector<Color3_8> colors;
colors.resize( WinWidth * WinHeight );
while ( true )
{
for ( auto t = 0; t < Threads; t++ )
{
calculators[t]->TakeSnapshot( snapshotHistograms[t] );
}
flame::MergeHistograms( snapshotHistograms );
snapshotHistograms[0].Resolve( colors.begin(), colors.end(), 2 );
auto matPtr = mat.data;
for ( auto y = 0; y < WinHeight; y++ )
{
for ( auto x = 0; x < WinWidth; x++ )
{
auto& col = colors[y * WinWidth + x];
col.CopyToInverse( matPtr );
matPtr += bpp;
}
}
cv::imshow( wndName, mat );
if ( cv::waitKey( 100 ) >= 0 ) break;
}
for ( auto& calc : calculators ) calc->Stop();
return 0;
}