Kaynağa Gözat

implementing headless mandelbrot renderer

Nicolas Winkler 4 yıl önce
ebeveyn
işleme
e02af9bc18
4 değiştirilmiş dosya ile 87 ekleme ve 28 silme
  1. 4 2
      mandelvid/CMakeLists.txt
  2. 11 0
      mandelvid/include/run.h
  3. 38 26
      mandelvid/src/main.cpp
  4. 34 0
      mandelvid/src/run.cpp

+ 4 - 2
mandelvid/CMakeLists.txt

@@ -7,12 +7,14 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../CMakeModules)
 add_subdirectory(../libalmond ./libalmond)
 
 set(CMAKE_CXX_STANDARD 17)
-
+set(Boost_USE_STATIC_LIBS ON)
+find_package(Boost 1.65 REQUIRED COMPONENTS program_options)
 
 FILE(GLOB mvidsources src/*.cpp)
 FILE(GLOB mvidheaders include/*.h)
 
 add_executable(mvg ${mvidsources})
-#target_include_directories(mvg PUBLIC "include")
+target_include_directories(mvg PUBLIC "include")
 target_link_libraries(mvg PUBLIC libalmond)
+target_link_libraries(mvg PUBLIC Boost::program_options)
 

+ 11 - 0
mandelvid/include/run.h

@@ -0,0 +1,11 @@
+#pragma once
+#ifndef MANDELVID_RUN_H
+#define MANDELVID_RUN_H
+
+#include <string>
+
+
+void renderImage(const std::string& xmlPath, const std::string& outPath);
+
+
+#endif // MANDELVID_RUN_H

+ 38 - 26
mandelvid/src/main.cpp

@@ -1,23 +1,48 @@
-#include "MandelVideoGenerator.h"
-#include "ImageExport.h"
-#include "Gradient.h"
-#include "Mandel.h"
-#include "Fixed.h"
+#include "run.h"
+#include <iostream>
 
+#include <boost/program_options.hpp>
 
-int main() {
+namespace progOpts = boost::program_options;
+
+int main(int argc, char** argv)
+{
+    progOpts::options_description desc("Available options");
+    desc.add_options()
+        ("help", "display this help message")
+        ("render-image,i", "render a mandelbrot view")
+        ("file,f", progOpts::value<std::string>(), "specifies a file to load")
+        ("output,o", progOpts::value<std::string>(), "file to output")
+    ;
+    progOpts::positional_options_description p;
+    p.add("file", 1);
+    progOpts::variables_map vm;
+    progOpts::store(progOpts::command_line_parser(argc, argv)
+                .options(desc).positional(p).run(), vm);
+    progOpts::notify(vm);
+
+    if (vm.count("help")) {
+        std::cout << desc << "\n";
+        return 0;
+    }
+
+    std::string out = vm["output"].as<std::string>();
+
+    if (vm.count("render-image")) {
+        std::string inPath = vm["file"].as<std::string>();
+        std::cout << "rendering image " << inPath << std::endl;
+        renderImage(inPath, out);
+    } else {
+        std::cout << "No files specified" << std::endl;
+    }
+
+/*
     mnd::MandelContext mndCtxt = mnd::initializeContext();
 
 
     ExportVideoInfo evi;
     
     evi.start = mnd::MandelViewport::standardView();
-    /*evi.end = mnd::MandelViewport {
-        mnd::Real("-1.5016327722130767973008541252724123393337183519056236025189105693015282429244791506194548898968185999262221668435271537932672968559900159142085320685031"),
-        mnd::Real("9.1949171527697821768939276268368163504538591789778359909730511642378316080598664365235178721745031546786105261407973733873085119833457073054327967448264e-06"),
-        mnd::Real("1.6236294899543021550377844129369984149698872979955210084321757728274664401182171658849308001321609757279087031477100527629814577654596624031152718524352e-10"),
-        mnd::Real("1.2246019034401093377903721086780361028058704962292211685926779200766324399350798858672587301860274703389823933260119617558370004128301410779021141722617e-10")
-    };*/
     evi.end = mnd::MandelViewport {
         mnd::Real("-1.0"),
         mnd::Real("-1.0"),
@@ -27,20 +52,6 @@ int main() {
     //evi.end.zoomCenter(1.0e+27);
     evi.gradient = Gradient::defaultGradient();
 
-    /*evi.mi.bWidth = 1280;
-    evi.mi.bHeight = 720;
-    evi.mi.maxIter = 1000;
-    evi.fps = 60;
-    evi.zoomSpeed = 1.0;
-    evi.path = "video.avi";
-    evi.bitrate = 1500;
-    evi.preset = "veryfast";
-
-    evi.start.adjustAspectRatio(evi.mi.bWidth, evi.mi.bHeight);
-
-    MandelVideoGenerator mvg(evi);
-
-    mvg.generate(mndCtxt.getDefaultGenerator());*/
     
 
     mnd::MandelContext mc = mnd::initializeContext();
@@ -64,6 +75,7 @@ int main() {
     }
 
     return 0;
+    */
 }
 
 

+ 34 - 0
mandelvid/src/run.cpp

@@ -0,0 +1,34 @@
+#include "run.h"
+
+#include "Mandel.h"
+
+#include "Serialize.h"
+#include "ImageExport.h"
+
+#include <fstream>
+#include <iostream>
+
+std::string readFile(const std::string& path)
+{
+    std::ifstream inFile(path.c_str());
+    return std::string{ std::istreambuf_iterator<char>(inFile),
+        std::istreambuf_iterator<char>() };
+}
+
+
+void renderImage(const std::string& xmlPath, const std::string& outPath)
+{
+    mnd::MandelContext mndCtxt = mnd::initializeContext();
+    std::string xml = readFile(xmlPath);
+    alm::ImageView iv = alm::fromXml<alm::ImageView>(xml);
+
+    alm::ImageExportInfo iei;
+    iei.drawInfo = iv.view;
+    iei.generator = &mndCtxt.getDefaultGenerator();
+    iei.gradient = iv.gradient;
+    iei.path = outPath;
+
+    exportImage(iei, [] (float progress) {
+        std::cout << progress << "% completed" << std::endl;
+    });
+}