stf output, and possibly even more to header. (and a fix in stfu)
This commit is contained in:
parent
1a00cc60dd
commit
97a9b87354
11 changed files with 52 additions and 20 deletions
|
@ -57,6 +57,15 @@ public:
|
|||
LogMoreInfo("\n");
|
||||
}
|
||||
|
||||
stfu::node stf_output(){
|
||||
stfu::node kernel_node = kernel-> stf_output();
|
||||
stfu::node projector_node;/* = projector->stf_output();*/
|
||||
stfu::node system;
|
||||
system.addChild("AttractorKernel", kernel_node);
|
||||
system.addChild("Projector", projector_node);
|
||||
return system;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
||||
|
||||
private:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define ATTRACTORKERNEL_HPP
|
||||
|
||||
#include "Logger.hpp"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
|
||||
|
@ -55,6 +56,24 @@ public:
|
|||
// iterate his formula, implemented by subclasses
|
||||
virtual void operator()() = 0;
|
||||
|
||||
stfu::node stf_output() {
|
||||
stfu::node output;
|
||||
output.value("type") = type();
|
||||
output.value("dimension") = std::to_string((long long unsigned)dimension);
|
||||
stf_other(output);
|
||||
|
||||
stfu::node parameters_node;
|
||||
for(unsigned int i = 0; i < numberOfParameters; ++i)
|
||||
parameters_node.value(i) = std::to_string((long double)parameters[i]);
|
||||
|
||||
output.addChild("parameters", parameters_node);
|
||||
return output;
|
||||
}
|
||||
|
||||
virtual std::string type() = 0;
|
||||
|
||||
virtual void stf_other(stfu::node&) {}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark vector
|
||||
double const* vector() const {
|
||||
|
|
|
@ -44,7 +44,9 @@ void PNG::plot(const double* position) {
|
|||
I/O functions
|
||||
*/
|
||||
|
||||
void PNG::output_file(const char* filename) const {
|
||||
void PNG::output_file(const char* filename_in) const {
|
||||
std::string filename = filename_in;
|
||||
filename += ".png";
|
||||
unsigned int* max_int = new unsigned int[num_colors];
|
||||
double* power = new double[num_colors];
|
||||
|
||||
|
@ -88,7 +90,7 @@ void PNG::output_file(const char* filename) const {
|
|||
power[i] = vibrancy*power[i] + (1.0 - vibrancy)*averagePower;
|
||||
}
|
||||
|
||||
pngwriter* pngFile = new pngwriter(width, height, 0.0, filename);
|
||||
pngwriter* pngFile = new pngwriter(width, height, 0.0, filename.c_str());
|
||||
pngFile->setcompressionlevel(9);
|
||||
pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor");
|
||||
|
||||
|
@ -125,14 +127,8 @@ void PNG::output_file(const char* filename) const {
|
|||
delete[] max_int;
|
||||
delete[] power;
|
||||
|
||||
LogInfo("Writing %s\n", filename);
|
||||
|
||||
std::ofstream file(filename);
|
||||
if(!file) {
|
||||
LogError("Couldn't write to file");
|
||||
}
|
||||
LogInfo("Writing %s\n", filename.c_str());
|
||||
pngFile->close();
|
||||
|
||||
LogMoreInfo("File written");
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
init();
|
||||
}
|
||||
|
||||
virtual std::string type() { return "logistic"; };
|
||||
|
||||
virtual void generate_random_parameters() {
|
||||
for(unsigned int i = 0; i < numberOfParameters; ++i) {
|
||||
parameters[i] = rand() / double(RAND_MAX) + 3.0;
|
||||
|
|
|
@ -16,6 +16,8 @@ public:
|
|||
init();
|
||||
}
|
||||
|
||||
virtual std::string type() { return "lorenz"; };
|
||||
|
||||
virtual void generate_random_parameters() {
|
||||
parameters[0] = rand() / double(RAND_MAX) * 0.02;
|
||||
parameters[1] = rand() / double(RAND_MAX) * 4.0 + 8.0;
|
||||
|
|
|
@ -38,6 +38,8 @@ public:
|
|||
Polynomial(const unsigned int dimension, const unsigned int orde):
|
||||
AttractorKernel(dimension, calculateNumberOfParameters(dimension, orde)), orde(orde) {}
|
||||
|
||||
virtual std::string type() { return "polynomial"; };
|
||||
|
||||
virtual void operator()() {
|
||||
std::swap(vectorNew, vectorOld);
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ public:
|
|||
PolynomialA3D():
|
||||
AttractorKernel(3, 3) {}
|
||||
|
||||
virtual std::string type() { return "polynomial a"; };
|
||||
|
||||
virtual void operator()() {
|
||||
std::swap(vectorNew, vectorOld);
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ public:
|
|||
Unravel3D():
|
||||
AttractorKernel(3, 7) {}
|
||||
|
||||
virtual std::string type() { return "unravel"; };
|
||||
|
||||
virtual void operator()() {
|
||||
std::swap(vectorNew, vectorOld);
|
||||
|
||||
|
|
6
main.cpp
6
main.cpp
|
@ -1,5 +1,6 @@
|
|||
#include "Logger.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
@ -112,7 +113,7 @@ int main(int argc, char* argv[]) {
|
|||
time_t t = time(0);
|
||||
struct tm* lt = localtime(&t);
|
||||
int r = rand() % 10;
|
||||
sprintf(filename, "render/attractor_%04d-%02d-%02d_%02d-%02d-%02d-%01d.png", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r);
|
||||
sprintf(filename, "render/attractor_%04d-%02d-%02d_%02d-%02d-%02d-%01d", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r);
|
||||
|
||||
start = clock();
|
||||
myAttractor.projector->canvas->output_file(filename);
|
||||
|
@ -122,6 +123,9 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
LogInfo("Total clock time for writing png: %f\n", totalTime);
|
||||
|
||||
std::ofstream file(std::string(filename)+".stf");
|
||||
file << myAttractor.stf_output() << std::endl;
|
||||
|
||||
|
||||
delete my_attractor_ptr;
|
||||
return 0;
|
||||
|
|
|
@ -48,12 +48,9 @@ bool operator<< (const char* filename, const node& root) {
|
|||
return root.write(filename);
|
||||
}
|
||||
|
||||
bool operator<< (std::ofstream& out, const node& root) {
|
||||
return root.write(out);
|
||||
}
|
||||
|
||||
bool operator>> (std::istream& in, node& root) {
|
||||
return root.read(in);
|
||||
std::istream& operator>> (std::istream& in, node& root) {
|
||||
root.read(in);
|
||||
return in;
|
||||
}
|
||||
|
||||
bool operator>> (const char* filename, node& root) {
|
||||
|
|
|
@ -56,14 +56,11 @@ class node {
|
|||
/** Overloaded ostream's operator<< */
|
||||
friend std::ostream& operator<< (std::ostream& out, const node& root);
|
||||
|
||||
/** Returns whether it was succesful or not*/
|
||||
friend bool operator<< (std::ofstream& out, const node& root);
|
||||
|
||||
/** Acts like write(), but looks like this: "filename" << node */
|
||||
friend bool operator<< (const char* filename, const node& root);
|
||||
|
||||
/** Overloaded istream's operator>> */
|
||||
friend bool operator>> (std::istream& in, node& root);
|
||||
friend std::istream& operator>> (std::istream& in, node& root);
|
||||
|
||||
/** Acts like read(), but looks like this: "filename" >> node */
|
||||
friend bool operator>> (const char* filename, node& root);
|
||||
|
|
Reference in a new issue