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 "Projector.hpp"
|
||||
|
||||
Attractor::Attractor()
|
||||
: projector(0)
|
||||
, kernel(0)
|
||||
{
|
||||
void Attractor::generate_random(){
|
||||
stfu::node kernel_node;
|
||||
switch(rand()%2+1){
|
||||
case 0:
|
||||
|
|
|
@ -14,24 +14,24 @@ public:
|
|||
// should be private really
|
||||
Projector* projector;
|
||||
|
||||
Attractor(const std::string& filename)
|
||||
Attractor(const std::string& filename = "")
|
||||
: projector(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;
|
||||
if(!system.read(filename.c_str())){
|
||||
std::cerr << "Couldn't open file (" << filename << ") for reading\n";
|
||||
exit(-1);
|
||||
stfu::node system;
|
||||
if(!system.read(filename.c_str())) throw std::runtime_error(filename + " could not be opened");
|
||||
|
||||
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() {
|
||||
delete kernel;
|
||||
}
|
||||
|
@ -79,6 +79,8 @@ public:
|
|||
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
||||
|
||||
private:
|
||||
void generate_random();
|
||||
|
||||
AttractorKernel* kernel;
|
||||
|
||||
Attractor(Attractor const &);
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
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>"; };
|
||||
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>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -235,7 +235,6 @@
|
|||
buildSettings = {
|
||||
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
||||
GCC_AUTO_VECTORIZATION = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DEBUGGING_SYMBOLS = full;
|
||||
GCC_FAST_MATH = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 3;
|
||||
|
@ -283,7 +282,6 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
HEADER_SEARCH_PATHS = /usr/local/include;
|
||||
LIBRARY_SEARCH_PATHS = "/usr/local/lib//**";
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#ifndef __APPLE__
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#else
|
||||
#include <tr1/array>
|
||||
namespace std {
|
||||
|
|
2
batch.sh
2
batch.sh
|
@ -1,2 +1,2 @@
|
|||
#!/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[]) {
|
||||
std::string attractorFile;
|
||||
std::string output_path;
|
||||
bool generate_random = false;
|
||||
int main(int argc, char* argv[]) try {
|
||||
std::string attractorFile, output_path;
|
||||
unsigned int iterations, width, height;
|
||||
srand(time(0));
|
||||
|
||||
po::options_description desc("Usage");
|
||||
po::options_description desc("Options");
|
||||
desc.add_options()
|
||||
("help,h", "produce help message")
|
||||
("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")
|
||||
("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")
|
||||
("random,R", "use random parameters")
|
||||
;
|
||||
|
||||
po::variables_map vm;
|
||||
try {
|
||||
po::store(po::parse_command_line(argc, argv, desc), 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;
|
||||
}
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::notify(vm);
|
||||
|
||||
if (vm.count("help") || argc <= 1) {
|
||||
std::cout << desc << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(vm.count("random")) generate_random = true;
|
||||
|
||||
std::string filename = output_path + generate_filename();
|
||||
|
||||
Logger logger(LOG_VERBOSE, std::cout);
|
||||
Canvas2D canvas(width, height);
|
||||
{
|
||||
Attractor* my_attractor_ptr = 0;
|
||||
if(attractorFile != "")
|
||||
my_attractor_ptr = new Attractor(attractorFile);
|
||||
else if(generate_random)
|
||||
my_attractor_ptr = new Attractor();
|
||||
|
||||
if(my_attractor_ptr == 0){
|
||||
LogError("Nothing todo\n");
|
||||
exit(0);
|
||||
}
|
||||
Attractor my_attractor(attractorFile);
|
||||
|
||||
my_attractor_ptr->init_range();
|
||||
my_attractor.init_range();
|
||||
|
||||
logger.start("rendering");
|
||||
render(*my_attractor_ptr, canvas, iterations);
|
||||
render(my_attractor, canvas, iterations);
|
||||
logger.stop();
|
||||
|
||||
{
|
||||
std::string path(filename + ".stf");
|
||||
std::ofstream file(path.c_str());
|
||||
file << my_attractor_ptr->stf_output() << std::endl;
|
||||
}
|
||||
|
||||
delete my_attractor_ptr;
|
||||
std::string path(filename + ".stf");
|
||||
std::ofstream file(path.c_str());
|
||||
file << my_attractor.stf_output() << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -115,6 +91,8 @@ int main(int argc, char* argv[]) {
|
|||
tonemapper.process(canvas, image);
|
||||
logger.stop();
|
||||
}
|
||||
} catch (std::exception & e) {
|
||||
std::cout << "Terminated because of: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
|
Reference in a new issue