Skip to content

Commit

Permalink
Beginning to refactor, split JuliaThread and MandelThread into sepera…
Browse files Browse the repository at this point in the history
…te files.
  • Loading branch information
ecordell committed Aug 17, 2009
1 parent d222bc1 commit db75b85
Show file tree
Hide file tree
Showing 20 changed files with 467 additions and 325 deletions.
Binary file added bin/Release/BuildLog.htm
Binary file not shown.
Binary file added bin/Release/ChaosTools.exe
Binary file not shown.
15 changes: 15 additions & 0 deletions bin/Release/ChaosTools.exe.intermediate.manifest
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*' />
</dependentAssembly>
</dependency>
</assembly>
Binary file added bin/Release/ChaosToolsApp.obj
Binary file not shown.
Binary file added bin/Release/ChaosToolsFrm.obj
Binary file not shown.
Binary file added bin/Release/JuliaThread.obj
Binary file not shown.
Binary file added bin/Release/MandelThread.obj
Binary file not shown.
Binary file added bin/Release/gradient.obj
Binary file not shown.
Binary file added bin/Release/gradientdlg.obj
Binary file not shown.
1 change: 1 addition & 0 deletions bin/Release/mt.dep
@@ -0,0 +1 @@
Manifest resource last updated at 0:49:24.44 on Mon 08/17/2009
Binary file added bin/Release/vc90.idb
Binary file not shown.
Binary file added bin/Release/vc90.pdb
Binary file not shown.
Binary file modified build/ChaosTools.suo
Binary file not shown.
16 changes: 16 additions & 0 deletions build/ChaosTools.vcproj
Expand Up @@ -192,6 +192,14 @@
RelativePath="..\src\gradientdlg.cpp" RelativePath="..\src\gradientdlg.cpp"
> >
</File> </File>
<File
RelativePath="..\src\JuliaThread.cpp"
>
</File>
<File
RelativePath="..\src\MandelThread.cpp"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Header Files" Name="Header Files"
Expand All @@ -214,6 +222,14 @@
RelativePath="..\src\gradientdlg.h" RelativePath="..\src\gradientdlg.h"
> >
</File> </File>
<File
RelativePath="..\src\JuliaThread.h"
>
</File>
<File
RelativePath="..\src\MandelThread.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"
Expand Down
228 changes: 0 additions & 228 deletions src/ChaosToolsFrm.cpp
Expand Up @@ -22,9 +22,6 @@
*/ */
#include "ChaosToolsFrm.h" #include "ChaosToolsFrm.h"


DEFINE_EVENT_TYPE(wxEVT_MTHREAD)
DEFINE_EVENT_TYPE(wxEVT_JTHREAD)

BEGIN_EVENT_TABLE(ChaosToolsFrm,wxFrame) BEGIN_EVENT_TABLE(ChaosToolsFrm,wxFrame)
EVT_COMMAND(wxID_ANY, wxEVT_MTHREAD, ChaosToolsFrm::OnMandelThread) EVT_COMMAND(wxID_ANY, wxEVT_MTHREAD, ChaosToolsFrm::OnMandelThread)
EVT_COMMAND(wxID_ANY, wxEVT_JTHREAD, ChaosToolsFrm::OnJuliaThread) EVT_COMMAND(wxID_ANY, wxEVT_JTHREAD, ChaosToolsFrm::OnJuliaThread)
Expand Down Expand Up @@ -1318,231 +1315,6 @@ wxColour ChaosToolsFrm::getColour(double iter)
B *= 255.0F; B *= 255.0F;
return wxColour((int)R,(int)G,(int)B); return wxColour((int)R,(int)G,(int)B);
} }

MandelThread::MandelThread(wxEvtHandler* pParent, int row, double &xmint, double &xmaxt, double &ymint, double &ymaxt, int &widtht, int &heightt, int &max) : wxThread(wxTHREAD_DETACHED), m_pParent(pParent)
{
width = widtht;
height = heightt;
xmin = xmint;
xmax = xmaxt;
ymin = ymint;
ymax = ymaxt;
dx = (xmax-xmin)/(width);
dy = (ymax-ymin)/(height);
maxiter = max;
r = row;
}
void* MandelThread::Entry()
{
wxCommandEvent evt(wxEVT_MTHREAD, GetId());
evt.SetInt(r);
evt.SetClientData(DrawMandelRow());
wxPostEvent(m_pParent, evt);
return 0;
}
unsigned char* MandelThread::DrawMandelRow()
{
int i, iter=0;
double x, y, x0, y0, xtemp;
unsigned char* rgbdata = new unsigned char[width*3];
y0 = ymax - r*dy;
for (i=0; i<width; i++) //columns: x
{
y = y0;
x = x0 = xmin + i*dx;
iter = 0;
while (x*x+y*y < 4 && iter<maxiter)
{
xtemp = x*x - y*y + x0;
y = x*y + x*y + y0;
x = xtemp;
iter++;
}

if(iter==maxiter)
{
rgbdata[i*3] = (unsigned char)0;
rgbdata[i*3+1] = (unsigned char)0;
rgbdata[i*3+2] = (unsigned char)0;
}
else
{
unsigned char* temp = getColour(4*(iter - (log(log(x*x+y*y)))/log(2.0)));
rgbdata[i*3] = temp[0];
rgbdata[i*3+1] = temp[1];
rgbdata[i*3+2] = temp[2];
delete[] temp;
}
}
return rgbdata;
}
unsigned char* MandelThread::getColour(double iter)
{
double R = 1, G = 0, B = 0;
double H, S, V;
H = iter;
S = 1;
V = 1;
int hi = (int)floor(H / 60.0)%6;
double f = H/60 - floor(H/60);
double pv = V * ( 1 - S );
double qv = V * ( 1 - S * f );
double tv = V * ( 1 - S * ( 1 - f ) );
switch(hi)
{
case 0:
R = V;
G = tv;
B = pv;
break;
case 1:
R = qv;
G = V;
B = pv;
break;
case 2:
R = pv;
G = V;
B = tv;
break;
case 3:
R = pv;
G = qv;
B = V;
break;
case 4:
R = tv;
G = pv;
B = V;
break;
case 5:
R = V;
G = pv;
B = qv;
break;
default:
break;
}
unsigned char* res = new unsigned char[3];
res[0] = (unsigned char)(int)(R*255.0F);
res[1] = (unsigned char)(int)(G*255.0F);
res[2] = (unsigned char)(int)(B*255.0F);
return res;
}

JuliaThread::JuliaThread(wxEvtHandler* pParent, int row, double &cxt, double &cyt, double &xmint, double &xmaxt, double &ymint, double &ymaxt, int &widtht, int &heightt, int &max) : wxThread(wxTHREAD_DETACHED), m_pParent(pParent)
{
width = widtht;
height = heightt;
xmin = xmint;
xmax = xmaxt;
ymin = ymint;
ymax = ymaxt;
dx = (xmax-xmin)/(width);
dy = (ymax-ymin)/(height);
maxiter = max;
cx = cxt;
cy = cyt;
r = row;
}
void* JuliaThread::Entry()
{
wxCommandEvent evt(wxEVT_JTHREAD, GetId());
evt.SetInt(r);
evt.SetClientData(DrawJuliaRow());
wxPostEvent(m_pParent, evt);
return 0;
}
unsigned char* JuliaThread::DrawJuliaRow()
{
int i, iter=0;
double x, y, xtemp;
unsigned char* rgbdata = new unsigned char[width*3];
for (i=0; i<width; i++) //columns: x
{
y = ymax - r*dy;
x = xmin + i*dx;
iter = 0;
while (x*x+y*y < 4 && iter<maxiter)
{
xtemp = x*x - y*y + cx;
y = x*y + x*y + cy;
x = xtemp;
iter++;
}

if(iter==maxiter)
{
rgbdata[i*3] = (unsigned char)0;
rgbdata[i*3+1] = (unsigned char)0;
rgbdata[i*3+2] = (unsigned char)0;
}
else
{
unsigned char* temp = getColour((4*(iter - (log(log(x*x+y*y)))/log(2.0))));
rgbdata[i*3] = temp[0];
rgbdata[i*3+1] = temp[1];
rgbdata[i*3+2] = temp[2];
delete[] temp;
}
}
return rgbdata;
}
unsigned char* JuliaThread::getColour(double iter)
{
double R = 1, G = 0, B = 0;
double H, S, V;
H = iter;
S = 1;
V = 1;
int hi = (int)floor(H / 60.0)%6;
double f = H/60 - floor(H/60);
double pv = V * ( 1 - S );
double qv = V * ( 1 - S * f );
double tv = V * ( 1 - S * ( 1 - f ) );
switch(hi)
{
case 0:
R = V;
G = tv;
B = pv;
break;
case 1:
R = qv;
G = V;
B = pv;
break;
case 2:
R = pv;
G = V;
B = tv;
break;
case 3:
R = pv;
G = qv;
B = V;
break;
case 4:
R = tv;
G = pv;
B = V;
break;
case 5:
R = V;
G = pv;
B = qv;
break;
default:
break;
}
unsigned char* res = new unsigned char[3];
res[0] = (unsigned char)(int)(R*255.0F);
res[1] = (unsigned char)(int)(G*255.0F);
res[2] = (unsigned char)(int)(B*255.0F);
return res;
}


void ChaosToolsFrm::iterBookPageChanged(wxNotebookEvent& event) void ChaosToolsFrm::iterBookPageChanged(wxNotebookEvent& event)
{ {
} }
Expand Down

0 comments on commit db75b85

Please sign in to comment.