Skip to content
Browse files

Beginning to refactor, split JuliaThread and MandelThread into sepera…

…te files.
  • Loading branch information...
1 parent d222bc1 commit db75b855325e6b49a79a1a584191891748c865b4 @ecordell committed Aug 17, 2009
View
BIN bin/Release/BuildLog.htm
Binary file not shown.
View
BIN bin/Release/ChaosTools.exe
Binary file not shown.
View
15 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>
View
BIN bin/Release/ChaosToolsApp.obj
Binary file not shown.
View
BIN bin/Release/ChaosToolsFrm.obj
Binary file not shown.
View
BIN bin/Release/JuliaThread.obj
Binary file not shown.
View
BIN bin/Release/MandelThread.obj
Binary file not shown.
View
BIN bin/Release/gradient.obj
Binary file not shown.
View
BIN bin/Release/gradientdlg.obj
Binary file not shown.
View
1 bin/Release/mt.dep
@@ -0,0 +1 @@
+Manifest resource last updated at 0:49:24.44 on Mon 08/17/2009
View
BIN bin/Release/vc90.idb
Binary file not shown.
View
BIN bin/Release/vc90.pdb
Binary file not shown.
View
BIN build/ChaosTools.suo
Binary file not shown.
View
16 build/ChaosTools.vcproj
@@ -192,6 +192,14 @@
RelativePath="..\src\gradientdlg.cpp"
>
</File>
+ <File
+ RelativePath="..\src\JuliaThread.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\src\MandelThread.cpp"
+ >
+ </File>
</Filter>
<Filter
Name="Header Files"
@@ -214,6 +222,14 @@
RelativePath="..\src\gradientdlg.h"
>
</File>
+ <File
+ RelativePath="..\src\JuliaThread.h"
+ >
+ </File>
+ <File
+ RelativePath="..\src\MandelThread.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
View
228 src/ChaosToolsFrm.cpp
@@ -22,9 +22,6 @@
*/
#include "ChaosToolsFrm.h"
-DEFINE_EVENT_TYPE(wxEVT_MTHREAD)
-DEFINE_EVENT_TYPE(wxEVT_JTHREAD)
-
BEGIN_EVENT_TABLE(ChaosToolsFrm,wxFrame)
EVT_COMMAND(wxID_ANY, wxEVT_MTHREAD, ChaosToolsFrm::OnMandelThread)
EVT_COMMAND(wxID_ANY, wxEVT_JTHREAD, ChaosToolsFrm::OnJuliaThread)
@@ -1318,231 +1315,6 @@ wxColour ChaosToolsFrm::getColour(double iter)
B *= 255.0F;
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)
{
}
View
101 src/ChaosToolsFrm.h
@@ -51,18 +51,17 @@
#include <wx/aboutdlg.h>
#include <cstdlib>
+//thread classes
+#include "MandelThread.h"
+#include "JuliaThread.h"
+
//Image includes
#include "Images/cos.xpm"
#include "Images/sin.xpm"
#include "Images/logistic.xpm"
#include "Images/quadratic.xpm"
#include "Images/tent.xpm"
-BEGIN_DECLARE_EVENT_TYPES()
- DECLARE_EVENT_TYPE(wxEVT_MTHREAD, -1)
- DECLARE_EVENT_TYPE(wxEVT_JTHREAD, -1)
-END_DECLARE_EVENT_TYPES()
-
#undef ChaosToolsFrm_STYLE
#define ChaosToolsFrm_STYLE wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX
@@ -658,96 +657,4 @@ class ChaosToolsFrm : public wxFrame
*/
wxColour getColour(double iter);
};
-
-//! MandelThread class
-/*!
- Handles the calculation of a single row of the mandelbrot set.
-*/
-class MandelThread : public wxThread
-{
-public:
- //! MandelThread Constructor
- /*!
- \param pParent A pointer to the parent object that will handle the events produced by this thread.
- \param row The row index of the row to be rendered.
- \param xmint The minimum mathematical x-value of the viewing window.
- \param xmaxt The maximum mathematical x-value of the viewing window.
- \param ymint The minimum mathematical y-value of the viewing window.
- \param ymaxt The maximum mathematical y-value of the viewing window.
- \param widtht The width, in pixels, of the viewing window.
- \param heightt The height, in pixels, of the viewing window.
- \param max The maximum number of iterations per pixel.
-
- Transfers necessary information to the thread for calculating a row.
- */
- MandelThread(wxEvtHandler* pParent, int row, double &xmint, double &xmaxt, double &ymint, double &ymaxt, int &widtht, int &heightt, int &max);
-private:
- double xmin, xmax, ymin, ymax, dx, dy;
- int width, height, maxiter, r;
- //! Called when the thread's path of execution is entered.
- /*!
- Creates a wxCommandEvent of type wxEVT_MTHREAD, calls functions to calculate the row, and passes that data back through the event system.
- */
- void* Entry();
- //! Calculates a single row of the Mandelbrot Set
- /*!
- \return An array of unsigned char values representing RGB pixel data
- */
- unsigned char* DrawMandelRow();
- //! Generates the necessary color for a pixel based on iteration count.
- /*!
- \return A 3 unsigned char long array of pixel data representing an RGB color.
- Consider replacing with wxWidgets code if benchmarks prove it more efficient.
- */
- unsigned char* getColour(double iter);
-protected:
- wxEvtHandler* m_pParent;
-};
-
-//! JuliaThread class
-/*!
- Handles the calculation of a single row of a julia set.
-*/
-class JuliaThread: public wxThread
-{
-public:
- //! JuliaThread Constructor
- /*!
- \param pParent A pointer to the parent object that will handle the events produced by this thread.
- \param row The row index of the row to be rendered.
- \param cxt The real component of the parameter.
- \param cyt The imaginary component of the parameter.
- \param xmint The minimum mathematical x-value of the viewing window.
- \param xmaxt The maximum mathematical x-value of the viewing window.
- \param ymint The minimum mathematical y-value of the viewing window.
- \param ymaxt The maximum mathematical y-value of the viewing window.
- \param widtht The width, in pixels, of the viewing window.
- \param heightt The height, in pixels, of the viewing window.
- \param max The maximum number of iterations per pixel.
-
- Transfers necessary information to the thread for calculating a row.
- */
- JuliaThread(wxEvtHandler* pParent, int row, double &cxt, double &cyt, double &xmint, double &xmaxt, double &ymint, double &ymaxt, int &widtht, int &heightt, int &max);
-private:
- double xmin, xmax, ymin, ymax, dx, dy, cx, cy;
- int width, height, maxiter, r;
- //! Called when the thread's path of execution is entered.
- /*!
- Creates a wxCommandEvent of type wxEVT_JTHREAD, calls functions to calculate the row, and passes that data back through the event system.
- */
- void* Entry();
- //! Calculates a single row of a Julia Set
- /*!
- \return An array of unsigned char values representing RGB pixel data
- */
- unsigned char* DrawJuliaRow();
- //! Generates the necessary color for a pixel based on iteration count.
- /*!
- \return A 3 unsigned char long array of pixel data representing an RGB color.
- Consider replacing with wxWidgets code if benchmarks prove it more efficient.
- */
- unsigned char* getColour(double iter);
-protected:
- wxEvtHandler* m_pParent;
-};
#endif
View
137 src/JuliaThread.cpp
@@ -0,0 +1,137 @@
+/*!! \file JuliaThread.cpp
+ \brief JuliaThread class implementation
+
+ Author: Evan Cordell
+
+ Copyright 2009 Evan Cordell
+
+ This file is part of ChaosTools.
+
+ ChaosTools is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ ChaosTools is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ChaosTools. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "JuliaThread.h"
+
+DEFINE_EVENT_TYPE(wxEVT_JTHREAD)
+
+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;
+}
View
80 src/JuliaThread.h
@@ -0,0 +1,80 @@
+/*!! \file JuliaThread.h
+ \brief JuliaThread class declaration
+
+ Author: Evan Cordell
+
+ Copyright 2009 Evan Cordell
+
+ This file is part of ChaosTools.
+
+ ChaosTools is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ ChaosTools is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ChaosTools. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef JULIATHREAD_H
+#define JULIATHREAD_H
+
+#include <wx/thread.h>
+#include <wx/event.h>
+
+BEGIN_DECLARE_EVENT_TYPES()
+ DECLARE_EVENT_TYPE(wxEVT_JTHREAD, -1)
+END_DECLARE_EVENT_TYPES()
+
+//! JuliaThread class
+/*!
+ Handles the calculation of a single row of a julia set.
+*/
+class JuliaThread: public wxThread
+{
+public:
+ //! JuliaThread Constructor
+ /*!
+ \param pParent A pointer to the parent object that will handle the events produced by this thread.
+ \param row The row index of the row to be rendered.
+ \param cxt The real component of the parameter.
+ \param cyt The imaginary component of the parameter.
+ \param xmint The minimum mathematical x-value of the viewing window.
+ \param xmaxt The maximum mathematical x-value of the viewing window.
+ \param ymint The minimum mathematical y-value of the viewing window.
+ \param ymaxt The maximum mathematical y-value of the viewing window.
+ \param widtht The width, in pixels, of the viewing window.
+ \param heightt The height, in pixels, of the viewing window.
+ \param max The maximum number of iterations per pixel.
+
+ Transfers necessary information to the thread for calculating a row.
+ */
+ JuliaThread(wxEvtHandler* pParent, int row, double &cxt, double &cyt, double &xmint, double &xmaxt, double &ymint, double &ymaxt, int &widtht, int &heightt, int &max);
+private:
+ double xmin, xmax, ymin, ymax, dx, dy, cx, cy;
+ int width, height, maxiter, r;
+ //! Called when the thread's path of execution is entered.
+ /*!
+ Creates a wxCommandEvent of type wxEVT_JTHREAD, calls functions to calculate the row, and passes that data back through the event system.
+ */
+ void* Entry();
+ //! Calculates a single row of a Julia Set
+ /*!
+ \return An array of unsigned char values representing RGB pixel data
+ */
+ unsigned char* DrawJuliaRow();
+ //! Generates the necessary color for a pixel based on iteration count.
+ /*!
+ \return A 3 unsigned char long array of pixel data representing an RGB color.
+ Consider replacing with wxWidgets code if benchmarks prove it more efficient.
+ */
+ unsigned char* getColour(double iter);
+protected:
+ wxEvtHandler* m_pParent;
+};
+#endif
View
136 src/MandelThread.cpp
@@ -0,0 +1,136 @@
+/*!! \file MandelThread.cpp
+ \brief MandelThread class implementation
+
+ Author: Evan Cordell
+
+ Copyright 2009 Evan Cordell
+
+ This file is part of ChaosTools.
+
+ ChaosTools is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ ChaosTools is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ChaosTools. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "MandelThread.h"
+
+DEFINE_EVENT_TYPE(wxEVT_MTHREAD)
+
+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;
+}
View
78 src/MandelThread.h
@@ -0,0 +1,78 @@
+/*!! \file MandelThread.h
+ \brief MandelThread class declaration
+
+ Author: Evan Cordell
+
+ Copyright 2009 Evan Cordell
+
+ This file is part of ChaosTools.
+
+ ChaosTools is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ ChaosTools is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ChaosTools. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef MANDELTHREAD_H
+#define MANDELTHREAD_H
+
+#include <wx/thread.h>
+#include <wx/event.h>
+
+BEGIN_DECLARE_EVENT_TYPES()
+DECLARE_EVENT_TYPE(wxEVT_MTHREAD, -1)
+END_DECLARE_EVENT_TYPES()
+
+//! MandelThread class
+/*!
+ Handles the calculation of a single row of the mandelbrot set.
+*/
+class MandelThread : public wxThread
+{
+public:
+ //! MandelThread Constructor
+ /*!
+ \param pParent A pointer to the parent object that will handle the events produced by this thread.
+ \param row The row index of the row to be rendered.
+ \param xmint The minimum mathematical x-value of the viewing window.
+ \param xmaxt The maximum mathematical x-value of the viewing window.
+ \param ymint The minimum mathematical y-value of the viewing window.
+ \param ymaxt The maximum mathematical y-value of the viewing window.
+ \param widtht The width, in pixels, of the viewing window.
+ \param heightt The height, in pixels, of the viewing window.
+ \param max The maximum number of iterations per pixel.
+
+ Transfers necessary information to the thread for calculating a row.
+ */
+ MandelThread(wxEvtHandler* pParent, int row, double &xmint, double &xmaxt, double &ymint, double &ymaxt, int &widtht, int &heightt, int &max);
+private:
+ double xmin, xmax, ymin, ymax, dx, dy;
+ int width, height, maxiter, r;
+ //! Called when the thread's path of execution is entered.
+ /*!
+ Creates a wxCommandEvent of type wxEVT_MTHREAD, calls functions to calculate the row, and passes that data back through the event system.
+ */
+ void* Entry();
+ //! Calculates a single row of the Mandelbrot Set
+ /*!
+ \return An array of unsigned char values representing RGB pixel data
+ */
+ unsigned char* DrawMandelRow();
+ //! Generates the necessary color for a pixel based on iteration count.
+ /*!
+ \return A 3 unsigned char long array of pixel data representing an RGB color.
+ Consider replacing with wxWidgets code if benchmarks prove it more efficient.
+ */
+ unsigned char* getColour(double iter);
+protected:
+ wxEvtHandler* m_pParent;
+};
+#endif

0 comments on commit db75b85

Please sign in to comment.
Something went wrong with that request. Please try again.