Browse Source

stf output, and possibly even more to header. (and a fix in stfu)

master
Joshua Moerman (joshua-desktop) 14 years ago
parent
commit
97a9b87354
  1. 9
      Attractor.hpp
  2. 19
      AttractorKernel.hpp
  3. 14
      canvae/PNG.cpp
  4. 2
      kernels/Logistic.hpp
  5. 2
      kernels/Lorenz3D.hpp
  6. 2
      kernels/Polynomial.hpp
  7. 2
      kernels/PolynomialA3D.hpp
  8. 2
      kernels/Unravel3D.hpp
  9. 6
      main.cpp
  10. 9
      stfu/stf.cpp
  11. 5
      stfu/stf.hpp

9
Attractor.hpp

@ -57,6 +57,15 @@ public:
LogMoreInfo("\n"); 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); friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
private: private:

19
AttractorKernel.hpp

@ -2,6 +2,7 @@
#define ATTRACTORKERNEL_HPP #define ATTRACTORKERNEL_HPP
#include "Logger.hpp" #include "Logger.hpp"
#include <string>
#include <algorithm> #include <algorithm>
#include <cstdlib> #include <cstdlib>
@ -55,6 +56,24 @@ public:
// iterate his formula, implemented by subclasses // iterate his formula, implemented by subclasses
virtual void operator()() = 0; 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 -
#pragma mark vector #pragma mark vector
double const* vector() const { double const* vector() const {

14
canvae/PNG.cpp

@ -44,7 +44,9 @@ void PNG::plot(const double* position) {
I/O functions 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]; unsigned int* max_int = new unsigned int[num_colors];
double* power = new double[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; 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->setcompressionlevel(9);
pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor"); 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[] max_int;
delete[] power; delete[] power;
LogInfo("Writing %s\n", filename); LogInfo("Writing %s\n", filename.c_str());
std::ofstream file(filename);
if(!file) {
LogError("Couldn't write to file");
}
pngFile->close(); pngFile->close();
LogMoreInfo("File written"); LogMoreInfo("File written");
} }

2
kernels/Logistic.hpp

@ -25,6 +25,8 @@ public:
init(); init();
} }
virtual std::string type() { return "logistic"; };
virtual void generate_random_parameters() { virtual void generate_random_parameters() {
for(unsigned int i = 0; i < numberOfParameters; ++i) { for(unsigned int i = 0; i < numberOfParameters; ++i) {
parameters[i] = rand() / double(RAND_MAX) + 3.0; parameters[i] = rand() / double(RAND_MAX) + 3.0;

2
kernels/Lorenz3D.hpp

@ -16,6 +16,8 @@ public:
init(); init();
} }
virtual std::string type() { return "lorenz"; };
virtual void generate_random_parameters() { virtual void generate_random_parameters() {
parameters[0] = rand() / double(RAND_MAX) * 0.02; parameters[0] = rand() / double(RAND_MAX) * 0.02;
parameters[1] = rand() / double(RAND_MAX) * 4.0 + 8.0; parameters[1] = rand() / double(RAND_MAX) * 4.0 + 8.0;

2
kernels/Polynomial.hpp

@ -38,6 +38,8 @@ public:
Polynomial(const unsigned int dimension, const unsigned int orde): Polynomial(const unsigned int dimension, const unsigned int orde):
AttractorKernel(dimension, calculateNumberOfParameters(dimension, orde)), orde(orde) {} AttractorKernel(dimension, calculateNumberOfParameters(dimension, orde)), orde(orde) {}
virtual std::string type() { return "polynomial"; };
virtual void operator()() { virtual void operator()() {
std::swap(vectorNew, vectorOld); std::swap(vectorNew, vectorOld);

2
kernels/PolynomialA3D.hpp

@ -8,6 +8,8 @@ public:
PolynomialA3D(): PolynomialA3D():
AttractorKernel(3, 3) {} AttractorKernel(3, 3) {}
virtual std::string type() { return "polynomial a"; };
virtual void operator()() { virtual void operator()() {
std::swap(vectorNew, vectorOld); std::swap(vectorNew, vectorOld);

2
kernels/Unravel3D.hpp

@ -10,6 +10,8 @@ public:
Unravel3D(): Unravel3D():
AttractorKernel(3, 7) {} AttractorKernel(3, 7) {}
virtual std::string type() { return "unravel"; };
virtual void operator()() { virtual void operator()() {
std::swap(vectorNew, vectorOld); std::swap(vectorNew, vectorOld);

6
main.cpp

@ -1,5 +1,6 @@
#include "Logger.hpp" #include "Logger.hpp"
#include <iostream> #include <iostream>
#include <fstream>
#include <ctime> #include <ctime>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
@ -112,7 +113,7 @@ int main(int argc, char* argv[]) {
time_t t = time(0); time_t t = time(0);
struct tm* lt = localtime(&t); struct tm* lt = localtime(&t);
int r = rand() % 10; 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(); start = clock();
myAttractor.projector->canvas->output_file(filename); 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); 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; delete my_attractor_ptr;
return 0; return 0;

9
stfu/stf.cpp

@ -48,12 +48,9 @@ bool operator<< (const char* filename, const node& root) {
return root.write(filename); return root.write(filename);
} }
bool operator<< (std::ofstream& out, const node& root) { std::istream& operator>> (std::istream& in, node& root) {
return root.write(out); root.read(in);
} return in;
bool operator>> (std::istream& in, node& root) {
return root.read(in);
} }
bool operator>> (const char* filename, node& root) { bool operator>> (const char* filename, node& root) {

5
stfu/stf.hpp

@ -56,14 +56,11 @@ class node {
/** Overloaded ostream's operator<< */ /** Overloaded ostream's operator<< */
friend std::ostream& operator<< (std::ostream& out, const node& root); 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 */ /** Acts like write(), but looks like this: "filename" << node */
friend bool operator<< (const char* filename, const node& root); friend bool operator<< (const char* filename, const node& root);
/** Overloaded istream's operator>> */ /** 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 */ /** Acts like read(), but looks like this: "filename" >> node */
friend bool operator>> (const char* filename, node& root); friend bool operator>> (const char* filename, node& root);