#pragma once #include "EmberFile.h" #include "DoubleSpinBox.h" #include "GLEmberController.h" /// /// FractoriumEmberControllerBase and FractoriumEmberController classes. /// /// /// An enum representing the type of edit being done. /// enum eEditUndoState : unsigned int { REGULAR_EDIT = 0, UNDO_REDO = 1, EDIT_UNDO = 2 }; /// /// FractoriumEmberController and Fractorium need each other, but each can't include the other. /// So Fractorium includes this file, and Fractorium is declared as a forward declaration here. /// class Fractorium; #define PREVIEW_SIZE 256 #define UNDO_SIZE 128 /// /// FractoriumEmberControllerBase serves as a non-templated base class with virtual /// functions which will be overridden in a derived class that takes a template parameter. /// The controller serves as a way to access both the Fractorium GUI and the underlying ember /// objects through an interface that doesn't require template argument, but does allow /// templated objects to be used underneath. /// Note that there are a few functions which access a templated object, so for those both /// versions for float and double must be provided, then overridden in the templated derived /// class. It's definitely a design flaw, but C++ doesn't offer any alternative since /// templated virtual functions are not supported. /// The functions not implemented in this file can be found in the GUI files which use them. /// class FractoriumEmberControllerBase : public RenderCallback { public: FractoriumEmberControllerBase(Fractorium* fractorium); virtual ~FractoriumEmberControllerBase(); //Embers. virtual void SetEmber(const Ember& ember, bool verbatim = false) { } virtual void CopyEmber(Ember& ember) { } virtual void SetEmberFile(const EmberFile& emberFile) { } virtual void CopyEmberFile(EmberFile& emberFile) { } virtual void SetTempPalette(const Palette& palette) { } virtual void CopyTempPalette(Palette& palette) { } #ifdef DO_DOUBLE virtual void SetEmber(const Ember& ember, bool verbatim = false) { } virtual void CopyEmber(Ember& ember) { } virtual void SetEmberFile(const EmberFile& emberFile) { } virtual void CopyEmberFile(EmberFile& emberFile) { } virtual void SetTempPalette(const Palette& palette) { } virtual void CopyTempPalette(Palette& palette) { } #endif virtual void SetEmber(size_t index) { } virtual void Clear() { } virtual void AddXform() { } virtual void DuplicateXform() { } virtual void ClearCurrentXform() { } virtual void DeleteCurrentXform() { } virtual void AddFinalXform() { } virtual bool UseFinalXform() { return false; } virtual size_t XformCount() { return 0; } virtual size_t TotalXformCount() { return 0; } virtual string Name() { return ""; } virtual void Name(string s) { } virtual unsigned int FinalRasW() { return 0; } virtual void FinalRasW(unsigned int w) { } virtual unsigned int FinalRasH() { return 0; } virtual void FinalRasH(unsigned int h) { } virtual void AddSymmetry(int sym, QTIsaac& rand) { } virtual void CalcNormalizedWeights() { } //Menu. virtual void NewFlock(unsigned int count) { }//File. virtual void NewEmptyFlameInCurrentFile() { } virtual void NewRandomFlameInCurrentFile() { } virtual void CopyFlameInCurrentFile() { } virtual void OpenAndPrepFiles(QStringList filenames, bool append) { } virtual void SaveCurrentAsXml() { } virtual void SaveEntireFileAsXml() { } virtual void SaveCurrentToOpenedFile() { } virtual void Undo() { }//Edit. virtual void Redo() { } virtual void CopyXml() { } virtual void CopyAllXml() { } virtual void PasteXmlAppend() { } virtual void PasteXmlOver() { } virtual void AddReflectiveSymmetry() { }//Tools. virtual void AddRotationalSymmetry() { } virtual void AddBothSymmetry() { } virtual void Flatten() { } virtual void Unflatten() { } virtual void ClearFlame() { } //Toolbar. //Params. virtual void SetCenter(double x, double y) { } virtual void FillParamTablesAndPalette() { } virtual void BrightnessChanged(double d) { } virtual void GammaChanged(double d) { } virtual void GammaThresholdChanged(double d) { } virtual void VibrancyChanged(double d) { } virtual void HighlightPowerChanged(double d) { } virtual void PaletteModeChanged(unsigned int i) { } virtual void CenterXChanged(double d) { } virtual void CenterYChanged(double d) { } virtual void ScaleChanged(double d) { } virtual void ZoomChanged(double d) { } virtual void RotateChanged(double d) { } virtual void ZPosChanged(double d) { } virtual void PerspectiveChanged(double d) { } virtual void PitchChanged(double d) { } virtual void YawChanged(double d) { } virtual void DepthBlurChanged(double d) { } virtual void SpatialFilterWidthChanged(double d) { } virtual void SpatialFilterTypeChanged(const QString& text) { } virtual void TemporalFilterWidthChanged(double d) { } virtual void TemporalFilterTypeChanged(const QString& text) { } virtual void DEFilterMinRadiusWidthChanged(double d) { } virtual void DEFilterMaxRadiusWidthChanged(double d) { } virtual void DEFilterCurveWidthChanged(double d) { } virtual void PassesChanged(int i) { } virtual void TemporalSamplesChanged(int d) { } virtual void QualityChanged(double d) { } virtual void SupersampleChanged(int d) { } virtual void AffineInterpTypeChanged(int i) { } virtual void InterpTypeChanged(int i) { } virtual void BackgroundChanged(const QColor& color) { } //Xforms. virtual void CurrentXformComboChanged(int index) { } virtual void XformWeightChanged(double d) { } virtual void EqualizeWeights() { } virtual void XformNameChanged(int row, int col) { } //Xforms Affine. virtual void AffineSetHelper(double d, int index, bool pre) { } virtual void FlipCurrentXform(bool horizontal, bool vertical, bool pre) { } virtual void RotateCurrentXformByAngle(double angle, bool pre) { } virtual void MoveCurrentXform(double x, double y, bool pre) { } virtual void ScaleCurrentXform(double scale, bool pre) { } virtual void ResetCurrentXformAffine(bool pre) { } //Xforms Color. virtual void XformColorIndexChanged(double d, bool updateRender) { } virtual void XformScrollColorIndexChanged(int d) { } virtual void XformColorSpeedChanged(double d) { } virtual void XformOpacityChanged(double d) { } virtual void XformDirectColorChanged(double d) { } void SetPaletteRefTable(QPixmap* pixmap); //Xforms Variations. virtual void SetupVariationTree() { } virtual void ClearVariationsTree() { } virtual void VariationSpinBoxValueChanged(double d) { } //Xforms Xaos. virtual void FillXaosWithCurrentXform() { } virtual QString MakeXaosNameString(unsigned int i) { return ""; } virtual void XaosChanged(DoubleSpinBox* sender) { } virtual void ClearXaos() { } //Palette. virtual bool InitPaletteTable(string s) { return false; } virtual void ApplyPaletteToEmber() { } virtual void PaletteAdjust() { } virtual QRgb GetQRgbFromPaletteIndex(unsigned int i) { return QRgb(); } virtual void PaletteCellClicked(int row, int col) { } //Library. virtual void SyncNames() { } virtual void FillLibraryTree(int selectIndex = -1) { } virtual void UpdateLibraryTree() { } virtual void EmberTreeItemChanged(QTreeWidgetItem* item, int col) { } virtual void EmberTreeItemDoubleClicked(QTreeWidgetItem* item, int col) { } virtual void RenderPreviews(unsigned int start = UINT_MAX, unsigned int end = UINT_MAX) { } virtual void StopPreviewRender() { } //Info. //Rendering/progress. virtual bool Render() { return false; } virtual bool CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared = true) { return false; } virtual unsigned int SizeOfT() { return 0; } virtual void ClearUndo() { } virtual GLEmberControllerBase* GLController() { return NULL; } bool RenderTimerRunning(); void StartRenderTimer(); void DelayedStartRenderTimer(); void StopRenderTimer(bool wait); void Shutdown(); void UpdateRender(eProcessAction action = FULL_RENDER); void DeleteRenderer(); void SaveCurrentRender(QString filename); RendererBase* Renderer() { return m_Renderer.get(); } vector* FinalImage() { return &m_FinalImage; } vector* PreviewFinalImage() { return &m_PreviewFinalImage; } protected: //Rendering/progress. void AddProcessAction(eProcessAction action); eProcessAction CondenseAndClearProcessActions(); eProcessState ProcessState() { return m_Renderer.get() ? m_Renderer->ProcessState() : NONE; } //Non-templated members. bool m_Rendering; bool m_Shared; bool m_LastEditWasUndoRedo; unsigned int m_Platform; unsigned int m_Device; unsigned int m_SubBatchCount; unsigned int m_FailedRenders; unsigned int m_UndoIndex; eRendererType m_RenderType; eEditUndoState m_EditState; GLuint m_OutputTexID; Timing m_RenderElapsedTimer; QImage m_FinalPaletteImage; QString m_LastSaveAll; QString m_LastSaveCurrent; CriticalSection m_Cs; vector m_FinalImage; vector m_PreviewFinalImage; vector m_ProcessActions; auto_ptr m_Renderer; QTIsaac m_Rand; Fractorium* m_Fractorium; QTimer* m_RenderTimer; QTimer* m_RenderRestartTimer; }; /// /// Templated derived class which implements all interaction functionality between the embers /// of a specific template type and the GUI. /// Switching between template arguments requires complete re-creation of the controller and the /// underlying renderer. Switching between CPU and OpenCL only requires re-creation of the renderer. /// template class FractoriumEmberController : public FractoriumEmberControllerBase { public: FractoriumEmberController(Fractorium* fractorium); virtual ~FractoriumEmberController(); //Embers. virtual void SetEmber(const Ember& ember, bool verbatim = false); virtual void CopyEmber(Ember& ember); virtual void SetEmberFile(const EmberFile& emberFile); virtual void CopyEmberFile(EmberFile& emberFile); virtual void SetTempPalette(const Palette& palette); virtual void CopyTempPalette(Palette& palette); #ifdef DO_DOUBLE virtual void SetEmber(const Ember& ember, bool verbatim = false); virtual void CopyEmber(Ember& ember); virtual void SetEmberFile(const EmberFile& emberFile); virtual void CopyEmberFile(EmberFile& emberFile); virtual void SetTempPalette(const Palette& palette); virtual void CopyTempPalette(Palette& palette); #endif virtual void SetEmber(size_t index); virtual void Clear() { } virtual void AddXform(); virtual void DuplicateXform(); virtual void ClearCurrentXform(); virtual void DeleteCurrentXform(); virtual void AddFinalXform(); virtual bool UseFinalXform() { return m_Ember.UseFinalXform(); } //virtual bool IsFinal(unsigned int i) { return false; } virtual size_t XformCount() { return m_Ember.XformCount(); } virtual size_t TotalXformCount() { return m_Ember.TotalXformCount(); } virtual string Name() { return m_Ember.m_Name; } virtual void Name(string s) { m_Ember.m_Name = s; } virtual unsigned int FinalRasW() { return m_Ember.m_FinalRasW; } virtual void FinalRasW(unsigned int w) { m_Ember.m_FinalRasW = w; } virtual unsigned int FinalRasH() { return m_Ember.m_FinalRasH; } virtual void FinalRasH(unsigned int h) { m_Ember.m_FinalRasH = h; } virtual void AddSymmetry(int sym, QTIsaac& rand) { m_Ember.AddSymmetry(sym, rand); } virtual void CalcNormalizedWeights() { m_Ember.CalcNormalizedWeights(m_NormalizedWeights); } Ember* CurrentEmber(); //Menu. virtual void NewFlock(unsigned int count); virtual void NewEmptyFlameInCurrentFile(); virtual void NewRandomFlameInCurrentFile(); virtual void CopyFlameInCurrentFile(); virtual void OpenAndPrepFiles(QStringList filenames, bool append); virtual void SaveCurrentAsXml(); virtual void SaveEntireFileAsXml(); virtual void SaveCurrentToOpenedFile(); virtual void Undo(); virtual void Redo(); virtual void CopyXml(); virtual void CopyAllXml(); virtual void PasteXmlAppend(); virtual void PasteXmlOver(); virtual void AddReflectiveSymmetry(); virtual void AddRotationalSymmetry(); virtual void AddBothSymmetry(); virtual void Flatten(); virtual void Unflatten(); virtual void ClearFlame(); //Toolbar. //Params. virtual void SetCenter(double x, double y); virtual void FillParamTablesAndPalette(); virtual void BrightnessChanged(double d); virtual void GammaChanged(double d); virtual void GammaThresholdChanged(double d); virtual void VibrancyChanged(double d); virtual void HighlightPowerChanged(double d); virtual void PaletteModeChanged(unsigned int i); virtual void CenterXChanged(double d); virtual void CenterYChanged(double d); virtual void ScaleChanged(double d); virtual void ZoomChanged(double d); virtual void RotateChanged(double d); virtual void ZPosChanged(double d); virtual void PerspectiveChanged(double d); virtual void PitchChanged(double d); virtual void YawChanged(double d); virtual void DepthBlurChanged(double d); virtual void SpatialFilterWidthChanged(double d); virtual void SpatialFilterTypeChanged(const QString& text); virtual void TemporalFilterWidthChanged(double d); virtual void TemporalFilterTypeChanged(const QString& text); virtual void DEFilterMinRadiusWidthChanged(double d); virtual void DEFilterMaxRadiusWidthChanged(double d); virtual void DEFilterCurveWidthChanged(double d); virtual void PassesChanged(int d); virtual void TemporalSamplesChanged(int d); virtual void QualityChanged(double d); virtual void SupersampleChanged(int d); virtual void AffineInterpTypeChanged(int index); virtual void InterpTypeChanged(int index); virtual void BackgroundChanged(const QColor& col); //Xforms. virtual void CurrentXformComboChanged(int index); virtual void XformWeightChanged(double d); virtual void EqualizeWeights(); virtual void XformNameChanged(int row, int col); void FillWithXform(Xform* xform); Xform* CurrentXform(); //Xforms Affine. virtual void AffineSetHelper(double d, int index, bool pre); virtual void FlipCurrentXform(bool horizontal, bool vertical, bool pre); virtual void RotateCurrentXformByAngle(double angle, bool pre); virtual void MoveCurrentXform(double x, double y, bool pre); virtual void ScaleCurrentXform(double scale, bool pre); virtual void ResetCurrentXformAffine(bool pre); void FillAffineWithXform(Xform* xform, bool pre); //Xforms Color. virtual void XformColorIndexChanged(double d, bool updateRender); virtual void XformScrollColorIndexChanged(int d); virtual void XformColorSpeedChanged(double d); virtual void XformOpacityChanged(double d); virtual void XformDirectColorChanged(double d); void FillColorWithXform(Xform* xform); //Xforms Variations. virtual void SetupVariationTree(); virtual void ClearVariationsTree(); virtual void VariationSpinBoxValueChanged(double d); void FillVariationTreeWithXform(Xform* xform); //Xforms Xaos. virtual void FillXaosWithCurrentXform(); virtual QString MakeXaosNameString(unsigned int i); virtual void XaosChanged(DoubleSpinBox* sender); virtual void ClearXaos(); //Palette. virtual bool InitPaletteTable(string s); virtual void ApplyPaletteToEmber(); virtual void PaletteAdjust(); virtual QRgb GetQRgbFromPaletteIndex(unsigned int i) { return QRgb(); } virtual void PaletteCellClicked(int row, int col); //Library. virtual void SyncNames(); virtual void FillLibraryTree(int selectIndex = -1); virtual void UpdateLibraryTree(); virtual void EmberTreeItemChanged(QTreeWidgetItem* item, int col); virtual void EmberTreeItemDoubleClicked(QTreeWidgetItem* item, int col); virtual void RenderPreviews(unsigned int start = UINT_MAX, unsigned int end = UINT_MAX); virtual void StopPreviewRender(); //Info. //Rendering/progress. virtual bool Render(); virtual bool CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared = true); virtual unsigned int SizeOfT() { return sizeof(T); } virtual int ProgressFunc(Ember& ember, void* foo, double fraction, int stage, double etaMs); virtual void ClearUndo(); virtual GLEmberControllerBase* GLController() { return m_GLController.get(); } private: //Embers. void ApplyXmlSavingTemplate(Ember& ember); template void SetEmberPrivate(const Ember& ember, bool verbatim); //Params. void ParamsToEmber(Ember& ember); //Xforms. void SetNormalizedWeightText(Xform* xform); bool IsFinal(Xform* xform); //Xforms Color. void SetCurrentXformColorIndex(double d); //Palette. void UpdateAdjustedPaletteGUI(Palette& palette); //Rendering/progress. void Update(std::function func, bool updateRender = true, eProcessAction action = FULL_RENDER); void UpdateCurrentXform(std::function*)> func, bool updateRender = true, eProcessAction action = FULL_RENDER); //Templated members. bool m_PreviewRun; bool m_PreviewRunning; vector m_TempOpacities; vector m_NormalizedWeights; Ember m_Ember; EmberFile m_EmberFile; deque> m_UndoList; Palette m_TempPalette; PaletteList m_PaletteList; VariationList m_VariationList; auto_ptr> m_SheepTools; auto_ptr> m_GLController; auto_ptr> m_PreviewRenderer; QFuture m_PreviewResult; std::function m_PreviewRenderFunc; }; template class FractoriumEmberController; #ifdef DO_DOUBLE template class FractoriumEmberController; #endif