mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
reorganizing repo
git-svn-id: svn://ultimatepp.org/upp/trunk@9206 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
7d17505cfe
commit
e3e8d627f5
3840 changed files with 0 additions and 1161578 deletions
|
|
@ -1,460 +0,0 @@
|
|||
/***********************************************************************************************
|
||||
|
||||
Ultimate++ Multi Threading example
|
||||
|
||||
Copyright (c) 2007, Artur Bac
|
||||
______ ____ _____ __ _
|
||||
| ____| _ \ /\ / ____| / _| |
|
||||
| |__ | |_) | / \ | (___ ___ | |_| |_
|
||||
| __| | _ < / /\ \ \___ \ / _ \| _| __|
|
||||
| |____| |_) / ____ \ ____) | (_) | | | |_
|
||||
|______|____/_/ \_\_____/ \___/|_| \__|
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the EBASoft nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
***********************************************************************************************/
|
||||
|
||||
#include "Threads.h"
|
||||
#include <cmath>
|
||||
#define TFILE <Threads/Threads.t>
|
||||
#include <Core/t.h>
|
||||
|
||||
Threads::Threads()
|
||||
: threads(0)
|
||||
, area(-2.0,-1.1, 0.60, 1.1)
|
||||
, densityR (1)
|
||||
, densityC (1)
|
||||
, rows (1)
|
||||
, cols (1)
|
||||
, julia_c(Complex(-0.4,0.6))
|
||||
, posOnClick(0,0)
|
||||
, moveShift(0,0)
|
||||
, moving(false)
|
||||
{
|
||||
SetLanguage(SetLNGCharset(GetSystemLNG(), CHARSET_UTF8));
|
||||
CtrlLayout(*this, t_("Threads"));
|
||||
inp_col.SetData(4);
|
||||
inp_row.SetData(3);
|
||||
inp_iter.SetData(500);
|
||||
inp_threads.SetData(3);
|
||||
edb_re.SetData(-0.4);
|
||||
edb_im.SetData(0.6);
|
||||
AddFrame(statusBar);
|
||||
|
||||
statusBar.AddFrame(time.Right(140));
|
||||
|
||||
BackPaint();
|
||||
Zoomable().Sizeable();
|
||||
picbox.onPaint = callback(this, &Threads::picbox_Paint);
|
||||
picbox.onLeftDown = callback(this, &Threads::picbox_LeftDown);
|
||||
picbox.onLeftUp = callback(this, &Threads::picbox_LeftUp);
|
||||
picbox.onMouseMove= callback(this, &Threads::picbox_MouseMove);
|
||||
|
||||
cbx_fractal_set.Add( t_("Mandelbrot"));
|
||||
cbx_fractal_set.Add( t_("Qubic Mandelbrot"));
|
||||
cbx_fractal_set.Add( t_("Quadric Mandelbrot"));
|
||||
cbx_fractal_set.Add( t_("Julia Set"));
|
||||
cbx_fractal_set.Add( t_("Qubic Julia Set"));
|
||||
cbx_fractal_set.Add( t_("Quadric Julia Set"));
|
||||
cbx_fractal_set.Add( t_("Phoenix Set"));
|
||||
cbx_fractal_set.Add( t_("BacPhoenix Set"));
|
||||
cbx_fractal_set.Add( t_("Bać Set - my own :) discovered by mistake..."));
|
||||
|
||||
cbx_fractal_set.WhenAction = THISBACK(SetSelected);
|
||||
btn_recalculate.WhenAction = THISBACK(DoJob);
|
||||
cbx_fractal_set.SetIndex(0);
|
||||
}
|
||||
|
||||
void Threads::picbox_Paint(Upp::Draw & g )
|
||||
{
|
||||
int i,r,c,w,h;
|
||||
|
||||
if (picbox.GetSize().cx == 0 || picbox.GetSize().cy == 0)
|
||||
return;
|
||||
|
||||
DrawingDraw d(cols,rows);
|
||||
d.DrawRect(0,0,rows,cols, White);
|
||||
|
||||
INTERLOCKED_(job_lock) {
|
||||
for (i=0; i< active.GetCount(); i++)
|
||||
{
|
||||
r = active.GetKey(i) / cols;
|
||||
c = active.GetKey(i) % cols;
|
||||
d.DrawRect(c,r,1,1,Color(255,255,0));
|
||||
}
|
||||
}
|
||||
g.Offset(moveShift);
|
||||
g.DrawDrawing(0,0,densityC * cols, densityR * rows,d);
|
||||
|
||||
INTERLOCKED_(image_lock) {
|
||||
for (i=0; i < rendered.GetCount(); i++)
|
||||
{
|
||||
r = rendered.GetKey(i) / cols;
|
||||
c = rendered.GetKey(i) % cols;
|
||||
w = picbox.GetSize().cx / cols;
|
||||
h = picbox.GetSize().cy / rows;
|
||||
g.DrawImage(c * w, r *h, w, h, rendered[i]);
|
||||
}
|
||||
}
|
||||
DrawAxis(g);
|
||||
g.End();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Threads::ThreadRenderJob(int r, int c, const FractalJobHandeler & job, int)
|
||||
{
|
||||
if (densityR == 0 || densityC==0) return;
|
||||
|
||||
double UNITC = area.Width() / (densityC * cols);
|
||||
double UNITR = area.Height() / (densityR * rows);
|
||||
int iter, y0, x0;
|
||||
RGBA *l;
|
||||
|
||||
ImageBuffer ib(densityC, densityR);
|
||||
|
||||
for (y0 = 0; y0< densityR; y0++)
|
||||
{
|
||||
l = ib[y0];
|
||||
for (x0 = 0; x0< densityC; x0++)
|
||||
{
|
||||
Complex tmp(area.left + UNITC *( c*densityC + x0), area.top + UNITR*( y0 + r*densityR));
|
||||
job(tmp, &iter);
|
||||
|
||||
l->a = 0xFF;
|
||||
l->r = ( iter == maxIter ) ? 0 : 255 - (int)(250 * log10((double)iter) / logmax);//255 - iter * 120 / maxIter ;
|
||||
l->g = ( iter == maxIter ) ? 0 : 20 ;//iter * 125 / maxIter;
|
||||
l->b = ( iter == maxIter ) ? 0 : 40 + (int)(205 * log10((double)iter) / logmax) ;//120 + iter * 125 / maxIter ;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
|
||||
AtomicDec(threads);
|
||||
INTERLOCKED_(job_lock)
|
||||
active.RemoveKey(r * cols + c);
|
||||
INTERLOCKED_(image_lock)
|
||||
rendered.Add(r * cols + c, ib);
|
||||
waitforfinish.Release();
|
||||
}
|
||||
|
||||
void Threads::DrawAxis(Upp::Draw & g)
|
||||
{
|
||||
const int DENS = 1000;
|
||||
double re_step = area.Width() * 0.05;
|
||||
double im_step = area.Height() * 0.05;
|
||||
int side = 1;
|
||||
Complex re_value(area.left, area.top + area.Height()*0.5);
|
||||
Complex im_value(area.left + area.Width()*0.5, area.top);
|
||||
|
||||
DrawingDraw axis(DENS<<1,DENS<<1);
|
||||
axis.DrawLine(0,DENS,DENS<<1,DENS,1,White);
|
||||
axis.DrawLine(DENS,0,DENS,DENS<<1,1,White);
|
||||
|
||||
for (int i=0; i< (DENS<<1); i += DENS/10)
|
||||
{
|
||||
side *= -1;
|
||||
re_value.SetRe(re_value.Re() + re_step );
|
||||
im_value.SetIm(im_value.Im() + im_step );
|
||||
axis.DrawLine(i,DENS - DENS/50,i,DENS+DENS/50,1,White);
|
||||
axis.DrawLine(DENS - DENS/50,i,DENS+DENS/50,i,1,White);
|
||||
axis.DrawText(i,DENS + side * DENS/30, - side *900,ToString(re_value),Arial(12*(DENS<<1)/ picbox.GetSize().cy),White);
|
||||
axis.DrawText(DENS + DENS/30,i,ToString(im_value),Arial(12*(DENS<<1)/ picbox.GetSize().cx),White);
|
||||
|
||||
for (int j=DENS/100; j< (DENS/10); j += DENS/100){
|
||||
axis.DrawLine(i + j,DENS - DENS/120,i +j,DENS+DENS/120,1,Color(0xAA,0xAA,0xAA));
|
||||
axis.DrawLine(DENS - DENS/120,i + j,DENS+DENS/120,i +j,1,Color(0xAA,0xAA,0xAA));
|
||||
}
|
||||
}
|
||||
g.DrawDrawing(0,0,picbox.GetSize().cx, picbox.GetSize().cy,axis);
|
||||
}
|
||||
|
||||
String FormatTS (int ms) { return Format("Render time %d:%02.2d.%03d",(ms/1000/60), (ms / 1000) % 60, ms % 1000 );}
|
||||
|
||||
void Threads::Process(const FractalJobHandeler & job)
|
||||
{
|
||||
ProgressInfo statTotal(statusBar);
|
||||
|
||||
rows = inp_row.GetData();
|
||||
cols = inp_col.GetData();
|
||||
densityR = picbox.GetSize().cy / rows;
|
||||
densityC = picbox.GetSize().cx / cols;
|
||||
maxIter = inp_iter.GetData();
|
||||
logmax= log10((double)maxIter);
|
||||
max_threads = inp_threads.GetData();
|
||||
|
||||
statTotal.Set(0,rows*cols);
|
||||
|
||||
TimeStop startTime;
|
||||
|
||||
for (int r = 0; r < rows; r++){
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
while(threads >= max_threads)
|
||||
waitforfinish.Wait();
|
||||
|
||||
AtomicInc(threads);
|
||||
Thread().Run(callback4(this, &Threads::ThreadRenderJob, r, c, job, 0));
|
||||
|
||||
INTERLOCKED_(job_lock)
|
||||
active.Add((r * cols + c), 0);
|
||||
|
||||
statTotal.Text(Format("Invoking calculations for sector R:%02d C:%02d",r,c));
|
||||
time.Set(FormatTS(startTime.Elapsed()));
|
||||
picbox.Refresh();
|
||||
statTotal.Set(r * cols + c,rows*cols);
|
||||
ProcessEvents();
|
||||
}
|
||||
}
|
||||
|
||||
while(threads > 0)
|
||||
waitforfinish.Wait();
|
||||
|
||||
time.Set(FormatTS(startTime.Elapsed()));
|
||||
picbox.Refresh();
|
||||
}
|
||||
|
||||
void Threads::SetSelected()
|
||||
{
|
||||
switch (cbx_fractal_set.GetIndex())
|
||||
{
|
||||
case 0:
|
||||
area = Rect_<double>(-2.0,-1.1, 0.60, 1.1);
|
||||
break;
|
||||
case 1:
|
||||
area = Rect_<double>(-1.3,-1.3, 1.3, 1.3);
|
||||
break;
|
||||
case 2:
|
||||
area = Rect_<double>(-1.5,-1.0, 1.5, 1.0);
|
||||
break;
|
||||
case 3:
|
||||
area = Rect_<double>(-1.5,-1.0, 1.5, 1.0);
|
||||
edb_re.SetData(-0.4);
|
||||
edb_im.SetData(0.6);
|
||||
break;
|
||||
case 4:
|
||||
area = Rect_<double>(-1.5,-1.0, 1.5, 1.0);
|
||||
break;
|
||||
case 5:
|
||||
area = Rect_<double>(-1.5,-1.0, 1.5, 1.0);
|
||||
break;
|
||||
case 6:
|
||||
area = Rect_<double>(-1.5,-1.0, 1.5, 1.0);
|
||||
edb_re.SetData(-0.4);
|
||||
edb_im.SetData(0.6);
|
||||
break;
|
||||
case 7:
|
||||
area = Rect_<double>(-1.5,-1.0, 1.5, 1.0);
|
||||
break;
|
||||
case 8:
|
||||
area = Rect_<double>(-1.25,-1.2, 1.75, 1.2);
|
||||
edb_re.SetData(-0.4);
|
||||
edb_im.SetData(0.5);
|
||||
break;
|
||||
}
|
||||
DoJob();
|
||||
}
|
||||
|
||||
|
||||
void Threads::DoJob()
|
||||
{
|
||||
rendered.Clear();
|
||||
FractalJobHandeler job;
|
||||
|
||||
switch (cbx_fractal_set.GetIndex())
|
||||
{
|
||||
case 0:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnMandelbrot));
|
||||
break;
|
||||
case 1:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnQubicMandelbrot));
|
||||
break;
|
||||
case 2:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnQuadricMandelbrot));
|
||||
break;
|
||||
case 3:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnJulia));
|
||||
julia_c = Complex(~edb_re, ~edb_im);
|
||||
break;
|
||||
case 4:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnQubicJulia));
|
||||
julia_c = Complex(~edb_re, ~edb_im);
|
||||
break;
|
||||
case 5:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnQuadricJulia));
|
||||
julia_c = Complex(~edb_re, ~edb_im);
|
||||
break;
|
||||
case 6:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnPhoenix));
|
||||
break;
|
||||
case 7:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnBacPhoenix));
|
||||
julia_c = Complex(~edb_re, ~edb_im);
|
||||
break;
|
||||
case 8:
|
||||
job = FractalJobHandeler(callback(this,&Threads::FnBac));
|
||||
julia_c = Complex(~edb_re, ~edb_im);
|
||||
break;
|
||||
}
|
||||
Process(job);
|
||||
}
|
||||
|
||||
void Threads::FnMandelbrot(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmp(cpx);
|
||||
for (iter = 0; tmp.Abs2() < 4 && iter < maxIter ;iter++)
|
||||
tmp = tmp * tmp + cpx;
|
||||
*res = iter;
|
||||
}
|
||||
void Threads::FnQubicMandelbrot(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmp(cpx);
|
||||
for (iter = 0; tmp.Abs2() < 4 && iter < maxIter ;iter++)
|
||||
tmp = tmp * tmp * tmp + cpx;
|
||||
*res = iter;
|
||||
}
|
||||
void Threads::FnQuadricMandelbrot(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmp(cpx);
|
||||
for (iter = 0; tmp.Abs2() < 4 && iter < maxIter ;iter++)
|
||||
tmp = tmp * tmp * tmp * tmp + cpx;
|
||||
*res = iter;
|
||||
}
|
||||
void Threads::FnJulia(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmp(cpx);
|
||||
for (iter = 0; tmp.Abs2() < 4 && iter < maxIter ;iter++)
|
||||
tmp = tmp * tmp + julia_c;
|
||||
*res = iter;
|
||||
}
|
||||
void Threads::FnQubicJulia(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmp(cpx);
|
||||
for (iter = 0; tmp.Abs2() < 4 && iter < maxIter ;iter++)
|
||||
tmp = tmp * tmp * tmp + julia_c;
|
||||
*res = iter;
|
||||
}
|
||||
void Threads::FnQuadricJulia(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmp(cpx);
|
||||
for (iter = 0; tmp.Abs2() < 4 && iter < maxIter ;iter++)
|
||||
tmp = tmp * tmp * tmp * tmp + julia_c;
|
||||
*res = iter;
|
||||
}
|
||||
void Threads::FnPhoenix(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmpp;
|
||||
Complex tmp;
|
||||
Complex tmpn(cpx);
|
||||
for (iter = 0; tmpn.Abs2() < 4 && iter < maxIter ;iter++){
|
||||
tmp = tmpn;
|
||||
tmpn = tmp * tmp + julia_c.Re() + Complex(0,julia_c.Im()) * tmpp;
|
||||
tmpp = tmp;
|
||||
}
|
||||
*res = iter;
|
||||
}
|
||||
//My Own Sets made by mistake
|
||||
void Threads::FnBacPhoenix(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmpp;
|
||||
Complex tmp;
|
||||
Complex tmpn(cpx);
|
||||
for (iter = 0; tmpn.Abs2() < 4 && iter < maxIter ;iter++){
|
||||
tmp = tmpn;
|
||||
tmpn = tmp * tmp + julia_c.Re() + julia_c.Im() + tmpp;
|
||||
tmpp = tmp;
|
||||
}
|
||||
*res = iter;
|
||||
}
|
||||
|
||||
void Threads::FnBac(const Complex & cpx, int *res) const
|
||||
{
|
||||
int iter =0;
|
||||
Complex tmpp;
|
||||
Complex tmp;
|
||||
Complex tmpn(cpx);
|
||||
for (iter = 0; tmpn.Abs2() < 4 && iter < maxIter ;iter++){
|
||||
tmp = tmpn;
|
||||
tmpn = tmp * tmp + tmpp.Re() + tmpp.Im() + julia_c;
|
||||
tmpp = tmp;
|
||||
}
|
||||
*res = iter;
|
||||
}
|
||||
void Threads::picbox_LeftDown(Point p, dword keyflags )
|
||||
{
|
||||
if (keyflags & K_CTRL)
|
||||
{
|
||||
RectTracker tr(picbox);
|
||||
Rect s_xy = RectC(p.x, p.y, 0, 0);
|
||||
tr.Solid().Animation();
|
||||
s_xy = tr.Track(s_xy, ALIGN_RIGHT, ALIGN_BOTTOM);
|
||||
area = Rect_<double>( area.left + (double)s_xy.left * area.Width() / picbox.GetSize().cx
|
||||
, area.top + (double)s_xy.top * area.Height() / picbox.GetSize().cy
|
||||
, area.left + (double)s_xy.right * area.Width() / picbox.GetSize().cx
|
||||
, area.top + (double)s_xy.bottom * area.Height() / picbox.GetSize().cy );
|
||||
DoJob();
|
||||
}
|
||||
else
|
||||
moving = true;
|
||||
|
||||
posOnClick = p;
|
||||
}
|
||||
|
||||
|
||||
void Threads::picbox_LeftUp(Point p, dword keyflags )
|
||||
{
|
||||
if (moving)
|
||||
{
|
||||
moveShift = p - posOnClick;
|
||||
double dx = (moveShift.cx* 1.0 / picbox.GetSize().cx) *area.Width();
|
||||
double dy = (moveShift.cy* 1.0 / picbox.GetSize().cy) *area.Height();
|
||||
area = Rect_<double>(area.left - dx, area.top - dy, area.right - dx,area.bottom - dy);
|
||||
}
|
||||
moving = false;
|
||||
moveShift = Size(0, 0);
|
||||
DoJob();
|
||||
}
|
||||
|
||||
void Threads::picbox_MouseMove(Point p, dword keyflags )
|
||||
{
|
||||
if (moving)
|
||||
{
|
||||
moveShift = p - posOnClick;
|
||||
picbox.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
/***********************************************************************************************
|
||||
|
||||
Ultimate++ Multi Threading example
|
||||
|
||||
Copyright (c) 2007, Artur Bac
|
||||
______ ____ _____ __ _
|
||||
| ____| _ \ /\ / ____| / _| |
|
||||
| |__ | |_) | / \ | (___ ___ | |_| |_
|
||||
| __| | _ < / /\ \ \___ \ / _ \| _| __|
|
||||
| |____| |_) / ____ \ ____) | (_) | | | |_
|
||||
|______|____/_/ \_\_____/ \___/|_| \__|
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the EBASoft nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
***********************************************************************************************/
|
||||
|
||||
#ifndef _Threads_h
|
||||
#define _Threads_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
#include "paintbox.h"
|
||||
#include "complex.h"
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <Threads/Threads.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
class Threads : public WithThreadsLayout<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef Threads CLASSNAME;
|
||||
typedef Callback2<const Complex &, int *> FractalJobHandeler;
|
||||
|
||||
Threads();
|
||||
|
||||
void picbox_Paint( Upp::Draw & g ); //draw area paint rutine
|
||||
void picbox_LeftDown( Point p, dword keyflags );
|
||||
void picbox_LeftUp( Point p, dword keyflags );
|
||||
void picbox_MouseMove( Point p, dword keyflags );
|
||||
|
||||
private:
|
||||
StatusBar statusBar;
|
||||
InfoCtrl time;
|
||||
int densityR, densityC, maxIter;
|
||||
int rows, cols;
|
||||
int max_threads;
|
||||
ArrayMap<int, Image> rendered;
|
||||
VectorMap<int,int> active; //Active map
|
||||
volatile Atomic threads; //thread counter
|
||||
Mutex job_lock; //lock used for accesing active map
|
||||
Mutex image_lock; //lock used for accesing active map
|
||||
Semaphore waitforfinish; //semaphore for signaling thread finish
|
||||
Rect_<double> area;
|
||||
Complex julia_c;
|
||||
Point posOnClick;
|
||||
Size moveShift;
|
||||
bool moving;
|
||||
double logmax;
|
||||
|
||||
void Process(const FractalJobHandeler & job);
|
||||
void DoJob();
|
||||
void ThreadRenderJob(int r, int c, const FractalJobHandeler & job, int);
|
||||
void DrawAxis(Upp::Draw & g);
|
||||
void SetSelected();
|
||||
void Refresh() const;
|
||||
//Fractal jobs
|
||||
void FnMandelbrot(const Complex & cpx, int *res) const;
|
||||
void FnQubicMandelbrot(const Complex & cpx, int *res) const;
|
||||
void FnQuadricMandelbrot(const Complex & cpx, int *res) const;
|
||||
void FnJulia(const Complex & cpx, int *res) const;
|
||||
void FnQubicJulia(const Complex & cpx, int *res) const;
|
||||
void FnQuadricJulia(const Complex & cpx, int *res) const;
|
||||
void FnPhoenix(const Complex & cpx, int *res) const;
|
||||
void FnBacPhoenix(const Complex & cpx, int *res) const;
|
||||
void FnBac(const Complex & cpx, int *res) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
LAYOUT(ThreadsLayout, 656, 468)
|
||||
ITEM(PaintBox, picbox, SetFrame(InsetFrame()).HSizePosZ(136, 4).VSizePosZ(8, 4))
|
||||
ITEM(EditIntSpin, inp_row, Min(1).Max(100).NotNull(true).LeftPosZ(76, 48).TopPosZ(28, 19))
|
||||
ITEM(LabelBox, dv___2, SetLabel(t_("Julia Complex constant")).LeftPosZ(4, 124).TopPosZ(248, 48))
|
||||
ITEM(LabelBox, dv___3, SetLabel(t_("Threads")).LeftPosZ(4, 124).TopPosZ(152, 68))
|
||||
ITEM(LabelBox, dv___4, SetLabel(t_("Quality")).LeftPosZ(4, 124).TopPosZ(80, 68))
|
||||
ITEM(LabelBox, dv___5, SetLabel(t_("Area Split")).LeftPosZ(4, 124).TopPosZ(8, 68))
|
||||
ITEM(EditIntSpin, inp_col, Min(1).Max(100).NotNull(true).WantFocus(false).LeftPosZ(76, 48).TopPosZ(52, 19))
|
||||
ITEM(Label, dv___7, SetLabel(t_("Columns")).SetAlign(ALIGN_RIGHT).LeftPosZ(12, 56).TopPosZ(52, 20))
|
||||
ITEM(Label, dv___8, SetLabel(t_("Concurent threads")).LeftPosZ(12, 108).TopPosZ(168, 20))
|
||||
ITEM(Label, dv___9, SetLabel(t_("Maximal iterations")).LeftPosZ(12, 108).TopPosZ(96, 20))
|
||||
ITEM(Label, dv___10, SetLabel(t_("Rows")).SetAlign(ALIGN_RIGHT).LeftPosZ(12, 56).TopPosZ(28, 20))
|
||||
ITEM(EditIntSpin, inp_threads, Min(1).Max(100).NotNull(true).LeftPosZ(72, 48).TopPosZ(192, 19))
|
||||
ITEM(EditIntSpin, inp_iter, Min(10).Max(100000).NotNull(true).LeftPosZ(72, 48).TopPosZ(120, 19))
|
||||
ITEM(Label, dv___13, SetLabel(t_("Hold left to move fractal\nHold left & CTRL to select \nrecantangle to zoom")).LeftPosZ(4, 128).BottomPosZ(84, 80))
|
||||
ITEM(DropList, cbx_fractal_set, LeftPosZ(4, 124).TopPosZ(224, 19))
|
||||
ITEM(Button, btn_recalculate, SetLabel(t_("Recalculate")).LeftPosZ(4, 70).BottomPosZ(4, 24))
|
||||
ITEM(EditDoubleNotNull, edb_re, LeftPosZ(12, 48).TopPosZ(268, 19))
|
||||
ITEM(EditDouble, edb_im, LeftPosZ(68, 48).TopPosZ(268, 19))
|
||||
END_LAYOUT
|
||||
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma setlocale("C")
|
||||
#endif
|
||||
// Threads.cpp
|
||||
|
||||
T_("Threads")
|
||||
plPL("Wątki")
|
||||
|
||||
T_("Mandelbrot")
|
||||
plPL("")
|
||||
|
||||
T_("Qubic Mandelbrot")
|
||||
plPL("")
|
||||
|
||||
T_("Quadric Mandelbrot")
|
||||
plPL("")
|
||||
|
||||
T_("Julia Set")
|
||||
plPL("")
|
||||
|
||||
T_("Qubic Julia Set")
|
||||
plPL("")
|
||||
|
||||
T_("Quadric Julia Set")
|
||||
plPL("")
|
||||
|
||||
T_("Phoenix Set")
|
||||
plPL("")
|
||||
|
||||
T_("BacPhoenix Set")
|
||||
plPL("")
|
||||
|
||||
T_("Bać Set - my own :) discovered by mistake...")
|
||||
plPL("")
|
||||
|
||||
|
||||
// Threads.lay
|
||||
|
||||
T_("Julia Complex constant")
|
||||
plPL("Stała zespolona do Julii")
|
||||
|
||||
T_("Quality")
|
||||
plPL("Jakość")
|
||||
|
||||
T_("Area Split")
|
||||
plPL("Podział obszaru")
|
||||
|
||||
T_("Columns")
|
||||
plPL("Kolumny")
|
||||
|
||||
T_("Concurent threads")
|
||||
plPL("Współbierzne wątki")
|
||||
|
||||
T_("Maximal iterations")
|
||||
plPL("Maksymalna ilość iteracji")
|
||||
|
||||
T_("Rows")
|
||||
plPL("Wierszy")
|
||||
|
||||
T_("Hold left to move fractal\nHold left & CTRL to select \nrecantangle to "
|
||||
"zoom")
|
||||
plPL("Przytrzymaj lewy przycisk\nmyszy aby przesunąć fraktal\nPrzytrzymaja lewy & CTRL\n aby powiększyć")
|
||||
|
||||
T_("Recalculate")
|
||||
plPL("Przelicz")
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
description "Using paralelization with limited number of threads";
|
||||
|
||||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
complex.h,
|
||||
Threads.cpp,
|
||||
Threads.t,
|
||||
Threads.h,
|
||||
main.cpp,
|
||||
paintbox.cpp,
|
||||
paintbox.h,
|
||||
Threads.lay;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI MT";
|
||||
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
#ifndef _Threads_complex_h_
|
||||
#define _Threads_complex_h_
|
||||
|
||||
#include <Core/Core.h>
|
||||
|
||||
template<typename T>
|
||||
class Complex_
|
||||
{
|
||||
public:
|
||||
|
||||
T Re(void) const { return re; }
|
||||
void SetRe(T value ) { re = value; }
|
||||
T Im(void) const { return im; }
|
||||
void SetIm(T value ) { im = value; }
|
||||
|
||||
explicit Complex_ (void) : re(0), im(0) {}
|
||||
explicit Complex_ (T re) : re(re), im(0) {}
|
||||
Complex_ (T re, T im) : re(re), im(im) {}
|
||||
|
||||
Complex_ operator + (const Complex_ & other) const { return Complex_(re + other.re, im + other.im ); }
|
||||
Complex_ operator - (const Complex_ & other) const { return Complex_(re - other.re, im - other.im ); }
|
||||
Complex_ operator * (const Complex_ & other) const { return Complex_(re * other.re - im * other.im, re * other.im + im * other.re ); }
|
||||
|
||||
T Abs2() const { return re*re+im*im; }
|
||||
private:
|
||||
|
||||
T re;
|
||||
T im;
|
||||
};
|
||||
|
||||
|
||||
typedef Complex_<double> Complex;
|
||||
|
||||
String ToString(const Complex & c);
|
||||
|
||||
template<typename T, typename U>
|
||||
Complex_<T> operator + (const Complex_<T> & a, U b) { return Complex_<T>(a.Re() + b, a.Im() ); }
|
||||
template<typename T, typename U>
|
||||
Complex_<T> operator + (U b, const Complex_<T> & a) { return Complex_<T>(a.Re() + b, a.Im() ); }
|
||||
|
||||
template<typename T, typename U>
|
||||
Complex_<T> operator - (const Complex_<T> & a, U b) { return Complex_<T>(a.Re() - b, a.Im() ); }
|
||||
template<typename T, typename U>
|
||||
Complex_<T> operator - (U b, const Complex_<T> & a) { return Complex_<T>(a.Re() - b, a.Im() ); }
|
||||
|
||||
template<typename T, typename U>
|
||||
Complex_<T> operator * (const Complex_<T> & a, U b) { return Complex_<T>(a.Re() * b, a.Im() * b ); }
|
||||
template<typename T, typename U>
|
||||
Complex_<T> operator * (U b, const Complex_<T> & a) { return Complex_<T>(a.Re() * b, a.Im() * b ); }
|
||||
|
||||
#endif
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#include "Threads.h"
|
||||
|
||||
String ToString(const Complex & c) { return Format("%g+%g i",c.Re(), c.Im());}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
Threads().Run();
|
||||
}
|
||||
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#include "paintbox.h"
|
||||
|
||||
|
||||
PaintBox::PaintBox( void ) : Ctrl()
|
||||
{
|
||||
}
|
||||
|
||||
void PaintBox::Paint( Draw &w )
|
||||
{
|
||||
|
||||
/*ImageDraw dw(GetSize());
|
||||
onPaint(dw);
|
||||
w.DrawImage(0, 0, dw); */
|
||||
w.DrawRect(0,0,this->GetSize().cx,this->GetSize().cy, White);
|
||||
onPaint(w);
|
||||
}
|
||||
void PaintBox::MouseMove( Point p, dword keyflags )
|
||||
{
|
||||
onMouseMove(p, keyflags);
|
||||
}
|
||||
void PaintBox::LeftUp( Point p, dword keyflags )
|
||||
{
|
||||
onLeftUp(p, keyflags );
|
||||
}
|
||||
void PaintBox::LeftDown(Point p, dword keyflags)
|
||||
{
|
||||
onLeftDown(p, keyflags);
|
||||
}
|
||||
void PaintBox::MouseWheel(Point p, int zdelta, dword keyflags)
|
||||
{
|
||||
onMouseWheel(p,zdelta, keyflags);
|
||||
}
|
||||
bool PaintBox::Key( dword key, int count )
|
||||
{
|
||||
onKeyPress(key);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef _paintbox_h_
|
||||
#define _paintbox_h_
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct PaintBox : public Ctrl
|
||||
{
|
||||
public:
|
||||
|
||||
Callback1< Draw & > onPaint;
|
||||
Callback2< Point , dword > onLeftDown;
|
||||
Callback2< Point , dword > onLeftUp;
|
||||
Callback2< Point , dword > onMouseMove;
|
||||
Callback3< Point , int , dword > onMouseWheel;
|
||||
Callback1< dword > onKeyPress;
|
||||
|
||||
PaintBox( void );
|
||||
|
||||
virtual void Paint( Draw & w );
|
||||
virtual void MouseMove( Point p, dword keyflags );
|
||||
virtual void LeftUp( Point p, dword keyflags );
|
||||
virtual void LeftDown( Point p, dword keyflags );
|
||||
virtual void MouseWheel( Point p, int zdelta, dword keyflags );
|
||||
virtual bool Key( dword key, int count );
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Reference in a new issue