Nicolas Winkler 5 anni fa
parent
commit
8758203bf2
7 ha cambiato i file con 111 aggiunte e 13 eliminazioni
  1. 1 1
      Almond.cpp
  2. 2 0
      Almond.h
  3. 48 0
      Almond.ui
  4. 17 9
      choosegenerators.cpp
  5. 18 3
      choosegenerators.h
  6. 12 0
      libmandel/include/IterationCompiler.h
  7. 13 0
      libmandel/src/IterationCompiler.cpp

+ 1 - 1
Almond.cpp

@@ -164,7 +164,7 @@ void Almond::on_displayInfo_stateChanged(int checked)
 void Almond::on_chooseGenerator_clicked()
 {
     if (!generatorsDialog)
-        generatorsDialog = std::make_unique<ChooseGenerators>(mandelContext, this);
+        generatorsDialog = std::make_unique<ChooseGenerators>(mandelContext, *this);
     generatorsDialog->exec();
 
     if (generatorsDialog->getChosenGenerator()) {

+ 2 - 0
Almond.h

@@ -37,6 +37,8 @@ private:
     std::unique_ptr<ChooseGenerators> generatorsDialog;
     GradientChooseDialog gcd;
 
+    std::vector<std::unique_ptr<mnd::MandelGenerator>> compiledGenerators;
+
     ViewType currentView;
     mnd::MandelViewport mandelViewSave;
     mnd::MandelGenerator* mandelGeneratorSave;

+ 48 - 0
Almond.ui

@@ -177,6 +177,54 @@
         </widget>
        </item>
        <item>
+        <widget class="QGroupBox" name="groupBox">
+         <property name="title">
+          <string>GroupBox</string>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout">
+          <item>
+           <widget class="QRadioButton" name="wMandel">
+            <property name="text">
+             <string>Mandelbrot Set</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QRadioButton" name="radioButton">
+            <property name="text">
+             <string>Quadratic Julia Set</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <layout class="QHBoxLayout" name="horizontalLayout_2">
+            <item>
+             <widget class="QRadioButton" name="radioButton_2">
+              <property name="text">
+               <string>RadioButton</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QComboBox" name="comboBox">
+              <item>
+               <property name="text">
+                <string>a</string>
+               </property>
+              </item>
+              <item>
+               <property name="text">
+                <string>b</string>
+               </property>
+              </item>
+             </widget>
+            </item>
+           </layout>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
         <spacer name="verticalSpacer_2">
          <property name="orientation">
           <enum>Qt::Vertical</enum>

+ 17 - 9
choosegenerators.cpp

@@ -1,6 +1,8 @@
 #include "choosegenerators.h"
 #include "ui_choosegenerators.h"
 
+#include "Almond.h"
+
 #include <Hardware.h>
 #include <IterationCompiler.h>
 
@@ -122,8 +124,9 @@ void Benchmarker::run(void)
 }
 
 
-ChooseGenerators::ChooseGenerators(mnd::MandelContext& mndCtxt, QWidget *parent) :
-    QDialog{ parent },
+ChooseGenerators::ChooseGenerators(mnd::MandelContext& mndCtxt, Almond& owner) :
+    QDialog{ &owner },
+    owner{ owner },
     ui{ std::make_unique<Ui::ChooseGenerators>() },
     mndCtxt{ mndCtxt },
     tableContent{}
@@ -310,13 +313,12 @@ void ChooseGenerators::on_compile_clicked()
     //zi.optimize();
     //z0.optimize();
 
-    mnd::MandelDevice& dev = mndCtxt.getDevices()[0];
-    //auto cls = mnd::compileOpenCl(dev, z0, itf);
-    std::vector<std::unique_ptr<mnd::MandelGenerator>> cpuGenerators;
+    mnd::GeneratorCollection cr;
+
     try {
         //std::cout << mnd::toString(*z0.expr) << std::endl;
         //std::cout << mnd::toString(*zi.expr) << std::endl;
-        cpuGenerators = mnd::compileOpenCl(dev, z0, zi);
+        cr = mnd::compileFormula(mndCtxt, z0, zi);
     }
     catch(const mnd::ParseError& pe) {
         printf("Parse error: %s\n", pe.what());
@@ -331,8 +333,14 @@ void ChooseGenerators::on_compile_clicked()
         return;
     }*/
     fflush(stdout);
-    chosenGenerator = std::move(cpuGenerators[0]);
-
+    fractalDefs.push_back(FractalDef {
+                "name",
+                z0formula,
+                formula,
+                std::move(cr)
+    });
+    //chosenGenerator = std::move(cpuGenerators[0]);
+    chosenGenerator = fractalDefs[fractalDefs.size() - 1].gc.clGenerators[0].get();
     return;
 
     std::string expr = mnd::toString(*zi.expr);
@@ -351,7 +359,7 @@ void ChooseGenerators::on_compile_clicked()
     /*QMessageBox msgBox(nullptr);
     msgBox.setText(QString::fromStdString(asmCode));
     msgBox.exec();*/
-    chosenGenerator = std::move(cg);
+    //chosenGenerator = std::move(cg);
     try {
         //chosenGenerator = mnd::compileCl(irform, dev);
     }

+ 18 - 3
choosegenerators.h

@@ -3,6 +3,7 @@
 #include "ui_choosegenerators.h"
 
 #include <Mandel.h>
+#include <IterationCompiler.h>
 
 #include "Bitmap.h"
 
@@ -16,6 +17,8 @@
 #include <memory>
 #include <map>
 
+class Almond;
+
 namespace Ui
 {
     class ChooseGenerators;
@@ -54,10 +57,19 @@ signals:
 };
 
 
+struct FractalDef
+{
+    QString name;
+    QString z0;
+    QString zi;
+    mnd::GeneratorCollection gc;
+};
+
 class ChooseGenerators : public QDialog
 {
     Q_OBJECT
 private:
+    Almond& owner;
     Ui::ChooseGenerators* sadfgsdfg;
     std::unique_ptr<Ui::ChooseGenerators> ui;
     mnd::MandelContext& mndCtxt;
@@ -65,14 +77,17 @@ private:
     std::vector<std::pair<QLineEdit*, QComboBox*>> tableContent;
     std::unique_ptr<QValidator> floatValidator;
     //std::unique_ptr<mnd::AdaptiveGenerator> createdGenerator;
-    std::unique_ptr<mnd::MandelGenerator> chosenGenerator;
+    mnd::MandelGenerator* chosenGenerator;
     std::vector<mnd::MandelGenerator*> actualGenerators;
+
+    std::vector<FractalDef> fractalDefs;
+
     QThreadPool benchmarker;
 public:
-    ChooseGenerators(mnd::MandelContext& mndCtxt, QWidget* parent = nullptr);
+    ChooseGenerators(mnd::MandelContext& mndCtxt, Almond& owner);
     ~ChooseGenerators();
 
-    inline mnd::MandelGenerator* getChosenGenerator(void) { return chosenGenerator.get(); }
+    inline mnd::MandelGenerator* getChosenGenerator(void) { return chosenGenerator; }
 
 private:
     QComboBox* createComboBox(void);

+ 12 - 0
libmandel/include/IterationCompiler.h

@@ -18,6 +18,8 @@ namespace mnd
 
     enum class GeneratorType : int;
 
+    struct GeneratorCollection;
+
     //mnd::ExecData compile(mnd::MandelContext& mndCtxt);
 
     std::vector<std::unique_ptr<mnd::MandelGenerator>> compileCpu(mnd::MandelContext& mndCtxt,
@@ -27,10 +29,20 @@ namespace mnd
     std::vector<std::unique_ptr<mnd::MandelGenerator>> compileOpenCl(mnd::MandelDevice& dev,
         const IterationFormula& z0,
         const IterationFormula& zi);
+
+    GeneratorCollection compileFormula(mnd::MandelContext& mndCtxt,
+        const IterationFormula& z0,
+        const IterationFormula& zi);
 }
 //void squareTest();
 
 
+struct mnd::GeneratorCollection
+{
+    std::vector<std::unique_ptr<mnd::MandelGenerator>> cpuGenerators;
+    std::vector<std::unique_ptr<mnd::MandelGenerator>> clGenerators;
+};
+
 
 namespace mnd
 {

+ 13 - 0
libmandel/src/IterationCompiler.cpp

@@ -469,6 +469,19 @@ namespace mnd
         vec.push_back(std::move(fl));
         return vec;// { { mnd::GeneratorType::FLOAT, std::move(fl) } };
     }
+
+    GeneratorCollection compileFormula(mnd::MandelContext& mndCtxt, const IterationFormula& z0,
+        const IterationFormula& zi)
+    {
+        GeneratorCollection cr;
+        cr.cpuGenerators = compileCpu(mndCtxt, z0, zi);
+        for (mnd::MandelDevice& dev : mndCtxt.getDevices()) {
+            auto gens = compileOpenCl(dev, z0, zi);
+            std::move(gens.begin(), gens.end(), std::back_inserter(cr.clGenerators));
+        }
+
+        return cr;
+    }
 }