less exits, more exceptions
This commit is contained in:
parent
6d3cf83dc0
commit
5dc3e48bf8
6 changed files with 30 additions and 54 deletions
|
@ -7,10 +7,7 @@
|
||||||
#include "AttractorKernel.hpp"
|
#include "AttractorKernel.hpp"
|
||||||
#include "Projector.hpp"
|
#include "Projector.hpp"
|
||||||
|
|
||||||
Attractor::Attractor()
|
void Attractor::generate_random(){
|
||||||
: projector(0)
|
|
||||||
, kernel(0)
|
|
||||||
{
|
|
||||||
stfu::node kernel_node;
|
stfu::node kernel_node;
|
||||||
switch(rand()%2+1){
|
switch(rand()%2+1){
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -14,24 +14,24 @@ public:
|
||||||
// should be private really
|
// should be private really
|
||||||
Projector* projector;
|
Projector* projector;
|
||||||
|
|
||||||
Attractor(const std::string& filename)
|
Attractor(const std::string& filename = "")
|
||||||
: projector(0)
|
: projector(0)
|
||||||
, kernel(0)
|
, kernel(0)
|
||||||
{
|
{
|
||||||
LogInfo("Reading file '%s'...\n", filename.c_str());
|
if (filename == "") {
|
||||||
|
LogInfo("Making random attractor\n");
|
||||||
|
generate_random();
|
||||||
|
} else {
|
||||||
|
LogInfo("Reading file '%s'\n", filename.c_str());
|
||||||
|
|
||||||
stfu::node system;
|
stfu::node system;
|
||||||
if(!system.read(filename.c_str())){
|
if(!system.read(filename.c_str())) throw std::runtime_error(filename + " could not be opened");
|
||||||
std::cerr << "Couldn't open file (" << filename << ") for reading\n";
|
|
||||||
exit(-1);
|
kernel = AttractorKernel::createAttractorKernel(system.getChild("AttractorKernel"));
|
||||||
|
projector = Projector::createProjector(system.getChild(system.getValue("Projector")), kernel->getDimension());
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel = AttractorKernel::createAttractorKernel(system.getChild("AttractorKernel"));
|
|
||||||
projector = Projector::createProjector(system.getChild(system.getValue("Projector")), kernel->getDimension());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Attractor();
|
|
||||||
|
|
||||||
~Attractor() {
|
~Attractor() {
|
||||||
delete kernel;
|
delete kernel;
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,8 @@ public:
|
||||||
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void generate_random();
|
||||||
|
|
||||||
AttractorKernel* kernel;
|
AttractorKernel* kernel;
|
||||||
|
|
||||||
Attractor(Attractor const &);
|
Attractor(Attractor const &);
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
427057A81475637B00CBE978 /* ImageFormatBMP.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatBMP.hpp; sourceTree = "<group>"; };
|
427057A81475637B00CBE978 /* ImageFormatBMP.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatBMP.hpp; sourceTree = "<group>"; };
|
||||||
427057A91475637B00CBE978 /* ImageFormatPNG.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatPNG.hpp; sourceTree = "<group>"; };
|
427057A91475637B00CBE978 /* ImageFormatPNG.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatPNG.hpp; sourceTree = "<group>"; };
|
||||||
427057AB1475637B00CBE978 /* Tonemapper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Tonemapper.hpp; sourceTree = "<group>"; };
|
427057AB1475637B00CBE978 /* Tonemapper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Tonemapper.hpp; sourceTree = "<group>"; };
|
||||||
427057AC1475654E00CBE978 /* array.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = array.hpp; sourceTree = "<group>"; };
|
427057AC1475654E00CBE978 /* array.hpp */ = {isa = PBXFileReference; fileEncoding = 4; path = array.hpp; sourceTree = "<group>"; };
|
||||||
427057AD147571FC00CBE978 /* libboost_program_options.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libboost_program_options.a; path = ../../../../../usr/local/lib/libboost_program_options.a; sourceTree = "<group>"; };
|
427057AD147571FC00CBE978 /* libboost_program_options.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libboost_program_options.a; path = ../../../../../usr/local/lib/libboost_program_options.a; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
@ -235,7 +235,6 @@
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
||||||
GCC_AUTO_VECTORIZATION = YES;
|
GCC_AUTO_VECTORIZATION = YES;
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
|
||||||
GCC_DEBUGGING_SYMBOLS = full;
|
GCC_DEBUGGING_SYMBOLS = full;
|
||||||
GCC_FAST_MATH = YES;
|
GCC_FAST_MATH = YES;
|
||||||
GCC_OPTIMIZATION_LEVEL = 3;
|
GCC_OPTIMIZATION_LEVEL = 3;
|
||||||
|
@ -283,7 +282,6 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
HEADER_SEARCH_PATHS = /usr/local/include;
|
HEADER_SEARCH_PATHS = /usr/local/include;
|
||||||
LIBRARY_SEARCH_PATHS = "/usr/local/lib//**";
|
LIBRARY_SEARCH_PATHS = "/usr/local/lib//**";
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
#else
|
#else
|
||||||
#include <tr1/array>
|
#include <tr1/array>
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
2
batch.sh
2
batch.sh
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
while true; do ./build/Debug/AwesomeAttract0r -P ./render/ -R -I 50 -W 1280 -H 800 -f attractors/emptyUnravel3D.stf; done
|
while true; do ./build/Debug/AwesomeAttract0r -P ./render/ -I 50 -W 1280 -H 800 -f attractors/emptyUnravel3D.stf; done
|
||||||
|
|
48
main.cpp
48
main.cpp
|
@ -40,14 +40,12 @@ void render(Attractor & myAttractor, Canvas2D & canvas, unsigned int iterations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) try {
|
||||||
std::string attractorFile;
|
std::string attractorFile, output_path;
|
||||||
std::string output_path;
|
|
||||||
bool generate_random = false;
|
|
||||||
unsigned int iterations, width, height;
|
unsigned int iterations, width, height;
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
|
|
||||||
po::options_description desc("Usage");
|
po::options_description desc("Options");
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("help,h", "produce help message")
|
("help,h", "produce help message")
|
||||||
("iterations,I", po::value<unsigned int>(&iterations)->default_value(DEFAULT_ITERATIONS), "set number of iterations (in milions)")
|
("iterations,I", po::value<unsigned int>(&iterations)->default_value(DEFAULT_ITERATIONS), "set number of iterations (in milions)")
|
||||||
|
@ -55,55 +53,33 @@ int main(int argc, char* argv[]) {
|
||||||
("height,H", po::value<unsigned int>(&height)->default_value(DEFAULT_HEIGHT), "height of output image")
|
("height,H", po::value<unsigned int>(&height)->default_value(DEFAULT_HEIGHT), "height of output image")
|
||||||
("input-file,f", po::value<std::string>(&attractorFile)->default_value(""), "attractor file to read")
|
("input-file,f", po::value<std::string>(&attractorFile)->default_value(""), "attractor file to read")
|
||||||
("output-path,P", po::value<std::string>(&output_path)->default_value("render/"), "path to output image")
|
("output-path,P", po::value<std::string>(&output_path)->default_value("render/"), "path to output image")
|
||||||
("random,R", "use random parameters")
|
|
||||||
;
|
;
|
||||||
|
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
try {
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
po::notify(vm);
|
||||||
po::notify(vm);
|
|
||||||
} catch(std::exception & e) {
|
|
||||||
std::cout << "Failed to read commandline: " << e.what() << std::endl;
|
|
||||||
std::cout << desc << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.count("help") || argc <= 1) {
|
if (vm.count("help") || argc <= 1) {
|
||||||
std::cout << desc << std::endl;
|
std::cout << desc << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vm.count("random")) generate_random = true;
|
|
||||||
|
|
||||||
std::string filename = output_path + generate_filename();
|
std::string filename = output_path + generate_filename();
|
||||||
|
|
||||||
Logger logger(LOG_VERBOSE, std::cout);
|
Logger logger(LOG_VERBOSE, std::cout);
|
||||||
Canvas2D canvas(width, height);
|
Canvas2D canvas(width, height);
|
||||||
{
|
{
|
||||||
Attractor* my_attractor_ptr = 0;
|
Attractor my_attractor(attractorFile);
|
||||||
if(attractorFile != "")
|
|
||||||
my_attractor_ptr = new Attractor(attractorFile);
|
|
||||||
else if(generate_random)
|
|
||||||
my_attractor_ptr = new Attractor();
|
|
||||||
|
|
||||||
if(my_attractor_ptr == 0){
|
my_attractor.init_range();
|
||||||
LogError("Nothing todo\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
my_attractor_ptr->init_range();
|
|
||||||
|
|
||||||
logger.start("rendering");
|
logger.start("rendering");
|
||||||
render(*my_attractor_ptr, canvas, iterations);
|
render(my_attractor, canvas, iterations);
|
||||||
logger.stop();
|
logger.stop();
|
||||||
|
|
||||||
{
|
std::string path(filename + ".stf");
|
||||||
std::string path(filename + ".stf");
|
std::ofstream file(path.c_str());
|
||||||
std::ofstream file(path.c_str());
|
file << my_attractor.stf_output() << std::endl;
|
||||||
file << my_attractor_ptr->stf_output() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete my_attractor_ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -115,6 +91,8 @@ int main(int argc, char* argv[]) {
|
||||||
tonemapper.process(canvas, image);
|
tonemapper.process(canvas, image);
|
||||||
logger.stop();
|
logger.stop();
|
||||||
}
|
}
|
||||||
|
} catch (std::exception & e) {
|
||||||
|
std::cout << "Terminated because of: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue