Commit 6bb375ae authored by Stefan Pfeifer's avatar Stefan Pfeifer

Implement bow format conversion from 0.4 to 0.5

Closes #97
parent f8b5ec06
{
"layers": [
{
"E": 15000000000.0,
"height": [
[
0.0,
0.015
],
[
1.0,
0.01
]
],
"name": "unnamed",
"rho": 600.0
}
],
"masses": {
"limb_tip": 0.005,
"string_center": 0.005,
"string_tip": 0.005
},
"meta": {
"comments": "",
"version": "0.5"
},
"operation": {
"arrow_mass": 0.025,
"brace_height": 0.2,
"draw_length": 0.7
},
"profile": {
"angle": 0.0,
"segments": [
[
0.85,
0.0
]
],
"x_pos": 0.0,
"y_pos": 0.0
},
"settings": {
"n_draw_steps": 150,
"n_limb_elements": 40,
"n_string_elements": 45,
"sampling_rate": 10000.0,
"time_span_factor": 1.5,
"time_step_factor": 0.5
},
"string": {
"n_strands": 12,
"strand_density": 0.0005,
"strand_stiffness": 3500.0
},
"width": [
[
0.0,
0.035
],
[
1.0,
0.008
]
]
}
......@@ -5,31 +5,31 @@ using nlohmann::json;
static void convert_0_1_0_to_0_2_0(json& obj)
{
obj.at("meta").at("version") = "0.2";
obj["meta"]["version"] = "0.2";
}
static void convert_0_2_0_to_0_3_0(json& obj)
{
json obj2;
obj2.at("meta").at("version") = "0.3";
obj2.at("meta").at("comments") = obj.at("meta").at("comments");
obj2.at("profile").at("segments") = obj.at("profile").at("segments");
obj2.at("profile").at("x0") = obj.at("profile").at("offset_x");
obj2.at("profile").at("y0") = obj.at("profile").at("offset_y");
obj2.at("profile").at("phi0") = obj.at("profile").at("angle");
obj2.at("width") = obj.at("sections").at("width");
obj2.at("height") = obj.at("sections").at("height");
obj2.at("material").at("rho") = obj.at("sections").at("rho");
obj2.at("material").at("E") = obj.at("sections").at("E");
obj2.at("string") = obj.at("string");
obj2.at("masses") = obj.at("masses");
obj2.at("operation") = obj.at("operation");
obj2.at("settings").at("n_limb_elements") = obj.at("settings").at("n_limb_elements");
obj2.at("settings").at("n_string_elements") = obj.at("settings").at("n_string_elements");
obj2.at("settings").at("n_draw_steps") = obj.at("settings").at("n_draw_steps");
obj2.at("settings").at("time_span_factor") = obj.at("settings").at("time_span_factor");
obj2.at("settings").at("time_step_factor") = obj.at("settings").at("time_step_factor");
obj2.at("settings").at("sampling_rate") = 1.0/double(obj.at("settings").at("sampling_time"));
obj2["meta"]["version"] = "0.3";
obj2["meta"]["comments"] = obj.at("meta").at("comments");
obj2["profile"]["segments"] = obj.at("profile").at("segments");
obj2["profile"]["x0"] = obj.at("profile").at("offset_x");
obj2["profile"]["y0"] = obj.at("profile").at("offset_y");
obj2["profile"]["phi0"] = obj.at("profile").at("angle");
obj2["width"] = obj.at("sections").at("width");
obj2["height"] = obj.at("sections").at("height");
obj2["material"]["rho"] = obj.at("sections").at("rho");
obj2["material"]["E"] = obj.at("sections").at("E");
obj2["string"] = obj.at("string");
obj2["masses"] = obj.at("masses");
obj2["operation"] = obj.at("operation");
obj2["settings"]["n_limb_elements"] = obj.at("settings").at("n_limb_elements");
obj2["settings"]["n_string_elements"] = obj.at("settings").at("n_string_elements");
obj2["settings"]["n_draw_steps"] = obj.at("settings").at("n_draw_steps");
obj2["settings"]["time_span_factor"] = obj.at("settings").at("time_span_factor");
obj2["settings"]["time_step_factor"] = obj.at("settings").at("time_step_factor");
obj2["settings"]["sampling_rate"] = 1.0/double(obj.at("settings").at("sampling_time"));
obj = obj2;
}
......@@ -37,38 +37,81 @@ static void convert_0_2_0_to_0_3_0(json& obj)
static void convert_0_3_0_to_0_4_0(json& obj)
{
json obj2;
obj2.at("meta").at("version") = "0.4";
obj2.at("meta").at("comments") = obj.at("meta").at("comments");
obj2["meta"]["version"] = "0.4";
obj2["meta"]["comments"] = obj.at("meta").at("comments");
// Reverse curvatures
std::vector<double> curvatures;
for(double kappa: obj.at("profile").at("segments").at("vals"))
curvatures.push_back(-kappa);
obj2.at("profile").at("segments").at("args") = obj.at("profile").at("segments").at("args");
obj2.at("profile").at("segments").at("vals") = curvatures;
obj2.at("profile").at("x0") = obj.at("profile").at("x0");
obj2.at("profile").at("y0") = -double(obj.at("profile").at("y0")); // Reverse y-Offset
obj2.at("profile").at("phi0") = -double(obj.at("profile").at("phi0")); // Reverse angular offset
obj2.at("width") = obj.at("width");
obj2.at("height") = obj.at("height");
obj2.at("material").at("rho") = obj.at("material").at("rho");
obj2.at("material").at("E") = obj.at("material").at("E");
obj2.at("string").at("strand_stiffness") = obj.at("string").at("strand_stiffness");
obj2.at("string").at("strand_density") = obj.at("string").at("strand_density");
obj2.at("string").at("n_strands") = obj.at("string").at("n_strands");
obj2.at("masses").at("string_center") = obj.at("masses").at("string_center");
obj2.at("masses").at("string_tip") = obj.at("masses").at("string_tip");
obj2.at("masses").at("limb_tip") = obj.at("masses").at("limb_tip");
obj2.at("operation").at("brace_height") = obj.at("operation").at("brace_height");
obj2.at("operation").at("draw_length") = obj.at("operation").at("draw_length");
obj2.at("operation").at("arrow_mass") = obj.at("operation").at("arrow_mass");
obj2.at("settings").at("n_limb_elements") = obj.at("settings").at("n_limb_elements");
obj2.at("settings").at("n_string_elements") = obj.at("settings").at("n_string_elements");
obj2.at("settings").at("n_draw_steps") = obj.at("settings").at("n_draw_steps");
obj2.at("settings").at("time_span_factor") = obj.at("settings").at("time_span_factor");
obj2.at("settings").at("time_step_factor") = obj.at("settings").at("time_step_factor");
obj2.at("settings").at("sampling_rate") = obj.at("settings").at("sampling_rate");
obj2["profile"]["segments"]["args"] = obj.at("profile").at("segments").at("args");
obj2["profile"]["segments"]["vals"] = curvatures;
obj2["profile"]["x0"] = obj.at("profile").at("x0");
obj2["profile"]["y0"] = -double(obj.at("profile").at("y0")); // Reverse y-Offset
obj2["profile"]["phi0"] = -double(obj.at("profile").at("phi0")); // Reverse angular offset
obj2["width"] = obj.at("width");
obj2["height"] = obj.at("height");
obj2["material"]["rho"] = obj.at("material").at("rho");
obj2["material"]["E"] = obj.at("material").at("E");
obj2["string"]["strand_stiffness"] = obj.at("string").at("strand_stiffness");
obj2["string"]["strand_density"] = obj.at("string").at("strand_density");
obj2["string"]["n_strands"] = obj.at("string").at("n_strands");
obj2["masses"]["string_center"] = obj.at("masses").at("string_center");
obj2["masses"]["string_tip"] = obj.at("masses").at("string_tip");
obj2["masses"]["limb_tip"] = obj.at("masses").at("limb_tip");
obj2["operation"]["brace_height"] = obj.at("operation").at("brace_height");
obj2["operation"]["draw_length"] = obj.at("operation").at("draw_length");
obj2["operation"]["arrow_mass"] = obj.at("operation").at("arrow_mass");
obj2["settings"]["n_limb_elements"] = obj.at("settings").at("n_limb_elements");
obj2["settings"]["n_string_elements"] = obj.at("settings").at("n_string_elements");
obj2["settings"]["n_draw_steps"] = obj.at("settings").at("n_draw_steps");
obj2["settings"]["time_span_factor"] = obj.at("settings").at("time_span_factor");
obj2["settings"]["time_step_factor"] = obj.at("settings").at("time_step_factor");
obj2["settings"]["sampling_rate"] = obj.at("settings").at("sampling_rate");
obj = obj2;
}
static void convert_0_4_0_to_0_5_0(json& obj)
{
auto series_to_array = [](const json& input)
{
json output;
for(size_t i = 0; i < input.at("args").size(); ++i)
{
output.push_back(json::array());
output[i].push_back(input.at("args").at(i));
output[i].push_back(input.at("vals").at(i));
}
return output;
};
json obj2;
obj2["meta"]["version"] = "0.5";
obj2["meta"]["comments"] = obj.at("meta").at("comments");
obj2["settings"]["n_draw_steps"] = obj.at("settings").at("n_draw_steps");
obj2["settings"]["n_limb_elements"] = obj.at("settings").at("n_elements_limb");
obj2["settings"]["n_string_elements"] = obj.at("settings").at("n_elements_string");
obj2["settings"]["sampling_rate"] = obj.at("settings").at("sampling_rate");
obj2["settings"]["time_span_factor"] = obj.at("settings").at("time_span_factor");
obj2["settings"]["time_step_factor"] = obj.at("settings").at("time_step_factor");
obj2["profile"]["segments"] = series_to_array(obj.at("profile").at("segments"));
obj2["profile"]["angle"] = obj.at("profile").at("phi0");
obj2["profile"]["x_pos"] = obj.at("profile").at("x0");
obj2["profile"]["y_pos"] = obj.at("profile").at("y0");
obj2["width"] = series_to_array(obj.at("width"));
obj2["layers"].push_back(json());
obj2["layers"][0]["name"] = "unnamed";
obj2["layers"][0]["height"] = series_to_array(obj.at("height"));
obj2["layers"][0]["rho"] = obj.at("material").at("rho");
obj2["layers"][0]["E"] = obj.at("material").at("E");
obj2["string"] = obj.at("string");
obj2["masses"] = obj.at("masses");
obj2["operation"]["arrow_mass"] = obj.at("operation").at("mass_arrow");
obj2["operation"]["brace_height"] = obj.at("operation").at("brace_height");
obj2["operation"]["draw_length"] = obj.at("operation").at("draw_length");
obj = obj2;
}
......@@ -85,5 +128,10 @@ static void convert_to_current(json& obj)
convert_0_3_0_to_0_4_0(obj);
if(obj.at("meta").at("version") == "0.4" || obj.at("meta").at("version") == "0.4.0")
convert_0_4_0_to_0_5_0(obj);
if(obj.at("meta").at("version") == "0.5" || obj.at("meta").at("version") == "0.5.0")
return;
throw std::runtime_error("Version not recognized.");
}
......@@ -9,12 +9,7 @@ QColor getLayerColor(const Layer& layer)
{
std::mt19937 rng(unsigned(layer.rho)*unsigned(layer.E));
std::uniform_real_distribution<qreal> uni(0.0, 1.0);
qreal h = uni(rng);
qInfo() << "h = " << h;
return QColor::fromHsvF(h, 0.8, 1.0);
return QColor::fromHsvF(uni(rng), 0.8, 1.0);
}
/*
......
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