Commit b26095be authored by bbguimaraes's avatar bbguimaraes
Browse files

sms: remove not-so-useful code to load from file

parent a446dc04
......@@ -10,8 +10,6 @@ class SpringMassSystem;
class SMSCreator {
public:
static void read_from_file(
SpringMassSystem * system, std::istream * input);
static void create_string(
SpringMassSystem * system,
Vector begin, Vector end,
......
#include <sstream>
#include <QApplication>
#include <QTimer>
......@@ -11,15 +9,14 @@
void init_sm_system0(SpringMassSystem * system);
void init_sm_system1(SpringMassSystem * system);
void init_sm_system2(SpringMassSystem * system);
void init_sm_system3(SpringMassSystem * system);
GLuint load_texture(const std::string & filename);
int main(int argc, char ** argv) {
const double UPDATE_RATE = 1.0f / 3000.0f;
QApplication app(argc, argv);
SpringMassSystem sms0, sms1;
init_sm_system3(&sms0);
init_sm_system2(&sms1);
init_sm_system2(&sms0);
init_sm_system1(&sms1);
Simulation simulations[2];
simulations[0].set_systems({&sms0});
simulations[1].set_systems({&sms1});
......@@ -54,22 +51,6 @@ int main(int argc, char ** argv) {
}
void init_sm_system0(SpringMassSystem * system) {
std::stringstream input(
"# begin\n"
"0.0 0.0 0.0\n"
"# end\n"
"10.0 0.0 0.0\n"
"# number of Masses\n"
"11\n"
"# total mass\n"
"0.1\n"
"# spring k constant\n"
"0.25\n");
SMSCreator::read_from_file(system, &input);
(*system->masses())[0].set_fixed(true);
}
void init_sm_system1(SpringMassSystem * system) {
SMSCreator::create_string(
system,
Vector(),
......@@ -78,7 +59,7 @@ void init_sm_system1(SpringMassSystem * system) {
(*system->masses())[0].set_fixed(true);
}
void init_sm_system2(SpringMassSystem * system) {
void init_sm_system1(SpringMassSystem * system) {
const unsigned int W = 10;
SMSCreator::create_flag(
system,
......@@ -89,7 +70,7 @@ void init_sm_system2(SpringMassSystem * system) {
(*system->masses())[W - 1].set_fixed(true);
}
void init_sm_system3(SpringMassSystem * system) {
void init_sm_system2(SpringMassSystem * system) {
const unsigned int W = 10;
SMSCreator::create_crossed_flag(
system,
......
......@@ -2,51 +2,11 @@
#include <cassert>
#include <cmath>
#include <fstream>
#include <sstream>
#include "sms/mass.h"
#include "sms/spring.h"
#include "sms/springmasssystem.h"
/**
* Reads a SpringMassSystem from a file. Example of file:
*
* # begin
* 5.0 4.0 0.0
* # end
* -5.0 4.0 0.0
* # number of Masses
* 51
* # total mass
* 1
* # spring k constant
* 1.0
*/
/*static*/
void SMSCreator::read_from_file(
SpringMassSystem * system, std::istream * input) {
auto next_line = [input]() -> std::string {
std::string line;
do {
getline(*input, line);
} while(line[0] == '#');
return line;
};
auto read_point = [next_line]() -> Vector {
auto ss = std::stringstream(next_line());
float x, y, z;
ss >> x >> y >> z;
return Vector(x, y, z);
};
auto p0 = read_point();
auto p1 = read_point();
auto n_masses = std::stoi(next_line());
auto total_mass = std::stof(next_line());
auto k = std::stof(next_line());
return SMSCreator::create_string(system, p0, p1, n_masses, total_mass, k);
}
/*static*/
void SMSCreator::create_string(
SpringMassSystem * system,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment