Skip to content

Commit

Permalink
More improvements of the output data and the result viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnp committed Aug 29, 2024
1 parent cceea9c commit 12a0abd
Show file tree
Hide file tree
Showing 26 changed files with 222 additions and 268 deletions.
12 changes: 6 additions & 6 deletions gui/source/post/CurvaturePlot.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "CurvaturePlot.hpp"
#include "pre/viewmodel/units/UnitSystem.hpp"

CurvaturePlot::CurvaturePlot(const LimbSetup& limb, const States& states)
: limb(limb),
CurvaturePlot::CurvaturePlot(const Common& common, const States& states)
: common(common),
states(states),
index(0),
quantity_length(Quantities::length),
Expand Down Expand Up @@ -31,9 +31,9 @@ void CurvaturePlot::updatePlot() {

void CurvaturePlot::updateCurvature() {
this->graph(0)->data()->clear();
for(size_t i = 0; i < limb.length.size(); ++i) {
for(size_t i = 0; i < common.limb.length.size(); ++i) {
this->graph(0)->addData(
quantity_length.getUnit().fromBase(limb.length[i]),
quantity_length.getUnit().fromBase(common.limb.length[i]),
quantity_curvature.getUnit().fromBase(states.limb_strain[index][i][0])
);
}
Expand All @@ -44,8 +44,8 @@ void CurvaturePlot::updateAxes() {
this->yAxis->setLabel("Curvature " + quantity_curvature.getUnit().getLabel());

QCPRange x_range(
quantity_length.getUnit().fromBase(limb.length.front()),
quantity_length.getUnit().fromBase(limb.length.back())
quantity_length.getUnit().fromBase(common.limb.length.front()),
quantity_length.getUnit().fromBase(common.limb.length.back())
);

QCPRange y_range(
Expand Down
4 changes: 2 additions & 2 deletions gui/source/post/CurvaturePlot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

class CurvaturePlot: public PlotWidget {
public:
CurvaturePlot(const LimbSetup& limb, const States& states);
CurvaturePlot(const Common& common, const States& states);
void setStateIndex(int i);

private:
const LimbSetup& limb;
const Common& common;
const States& states;
int index;

Expand Down
98 changes: 48 additions & 50 deletions gui/source/post/OutputWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,33 @@ StaticOutputWidget::StaticOutputWidget(const OutputData& data)
numbers->addColumn();
numbers->addGroup("Performance");
numbers->addValue("Final draw force", data.statics->final_draw_force, Quantities::force);
numbers->addValue("Drawing work", data.statics->drawing_work, Quantities::energy);
numbers->addValue("Drawing work", data.statics->final_drawing_work, Quantities::energy);
numbers->addValue("Energy storage factor", data.statics->storage_factor, Quantities::ratio);
numbers->addGroup("Properties");
numbers->addValue("Limb mass", data.setup.limb_mass, Quantities::mass);
numbers->addValue("String mass", data.setup.string_mass, Quantities::mass);
numbers->addValue("String length", data.setup.string_length, Quantities::length);
numbers->addValue("Limb mass", data.common.limb_mass, Quantities::mass);
numbers->addValue("String mass", data.common.string_mass, Quantities::mass);
numbers->addValue("String length", data.common.string_length, Quantities::length);

numbers->addColumn();
numbers->addGroup("Minimum stress by layer");
for(size_t i = 0; i < data.statics->min_layer_stresses.size(); ++i) {
numbers->addValue(QString::fromStdString("TODO"), std::get<0>(data.statics->min_layer_stresses[i]), Quantities::stress);
for(size_t i = 0; i < data.common.layers.size(); ++i) {
numbers->addValue(QString::fromStdString(data.common.layers[i].name), std::get<0>(data.statics->min_layer_stresses.at(i)), Quantities::stress);
}
numbers->addGroup("Maximum stress by layer");
for(size_t i = 0; i < data.statics->max_layer_stresses.size(); ++i) {
numbers->addValue(QString::fromStdString("TODO"), std::get<0>(data.statics->max_layer_stresses[i]), Quantities::stress);
for(size_t i = 0; i < data.common.layers.size(); ++i) {
numbers->addValue(QString::fromStdString(data.common.layers[i].name), std::get<0>(data.statics->max_layer_stresses.at(i)), Quantities::stress);
}

numbers->addColumn();
numbers->addGroup("Maximum absolute forces");
numbers->addValue("Draw force", std::get<0>(data.statics->max_draw_force), Quantities::force);
numbers->addValue("Grip force", std::get<0>(data.statics->max_grip_force), Quantities::force);
numbers->addValue("String force (total)", std::get<0>(data.statics->max_string_force), Quantities::force);
numbers->addValue("String force (strand)", 0.0, Quantities::force);
numbers->addValue("String force (strand)", std::get<0>(data.statics->max_strand_force), Quantities::force);

auto plot_shapes = new ShapePlot(data.setup.limb, data.statics->states, 4);
auto plot_stress = new StressPlot(data.setup.limb, data.statics->states);
auto plot_curvature = new CurvaturePlot(data.setup.limb, data.statics->states);
auto plot_shapes = new ShapePlot(data.common, data.statics->states, 4);
auto plot_stress = new StressPlot(data.common, data.statics->states);
auto plot_curvature = new CurvaturePlot(data.common, data.statics->states);
auto plot_energy = new EnergyPlot(data.statics->states, data.statics->states.draw_length, "Draw length", Quantities::length, Quantities::energy);
auto plot_combo = new ComboPlot();
plot_combo->addData("Draw length", data.statics->states.draw_length, Quantities::length);
Expand Down Expand Up @@ -163,50 +163,49 @@ StaticOutputWidget::~StaticOutputWidget() {
DynamicOutputWidget::DynamicOutputWidget(const OutputData& data)
: tabs(new QTabWidget())
{
/*
auto numbers = new NumberGrid();
numbers->addColumn();
numbers->addGroup("Performance");
numbers->addValue("Final arrow velocity", data.dynamics.final_vel_arrow, Quantities::velocity);
numbers->addValue("Degree of efficiency", data.dynamics.efficiency, Quantities::ratio);
numbers->addValue("Final arrow velocity", data.dynamics->final_arrow_vel, Quantities::velocity);
numbers->addValue("Degree of efficiency", data.dynamics->energy_efficiency, Quantities::ratio);
numbers->addGroup("Energy at arrow departure");
numbers->addValue("Kinetic energy arrow", data.dynamics.final_e_kin_arrow, Quantities::energy);
numbers->addValue("Kinetic energy limbs", data.dynamics.final_e_kin_limbs, Quantities::energy);
numbers->addValue("Kinetic energy string", data.dynamics.final_e_kin_string, Quantities::energy);
numbers->addValue("Kinetic energy arrow", data.dynamics->final_e_kin_arrow, Quantities::energy);
numbers->addValue("Kinetic energy limbs", data.dynamics->final_e_kin_limbs, Quantities::energy);
numbers->addValue("Kinetic energy string", data.dynamics->final_e_kin_string, Quantities::energy);

numbers->addColumn();
numbers->addGroup("Minimum stress by layer");
for(size_t i = 0; i < data.statics.min_stress_index.size(); ++i) {
numbers->addValue(QString::fromStdString(data.setup.limb_properties.layers[i].name), data.dynamics.min_stress_value[i], Quantities::stress);
for(size_t i = 0; i < data.common.layers.size(); ++i) {
numbers->addValue(QString::fromStdString(data.common.layers[i].name), std::get<0>(data.dynamics->min_layer_stresses.at(i)), Quantities::stress);
}
numbers->addGroup("Maximum stress by layer");
for(size_t i = 0; i < data.statics.max_stress_index.size(); ++i) {
numbers->addValue(QString::fromStdString(data.setup.limb_properties.layers[i].name), data.dynamics.max_stress_value[i], Quantities::stress);
for(size_t i = 0; i < data.common.layers.size(); ++i) {
numbers->addValue(QString::fromStdString(data.common.layers[i].name), std::get<0>(data.dynamics->max_layer_stresses.at(i)), Quantities::stress);
}

numbers->addColumn();
numbers->addGroup("Maximum absolute forces");
numbers->addValue("String force (total)", data.dynamics.states.string_force[data.dynamics.max_string_force_index], Quantities::force);
numbers->addValue("String force (strand)", data.dynamics.states.strand_force[data.dynamics.max_string_force_index], Quantities::force);
numbers->addValue("Grip force", data.dynamics.states.grip_force[data.dynamics.max_grip_force_index], Quantities::force);
auto plot_shapes = new ShapePlot(data.setup.limb_properties, data.dynamics.states, 0);
auto plot_stress = new StressPlot(data.setup.limb_properties, data.dynamics.states);
auto plot_curvature = new CurvaturePlot(data.setup.limb_properties, data.dynamics.states);
auto plot_energy = new EnergyPlot(data.dynamics.states, data.dynamics.states.time, "Time", Quantities::time, Quantities::energy);
numbers->addValue("Grip force", std::get<0>(data.dynamics->max_grip_force), Quantities::force);
numbers->addValue("String force (total)", std::get<0>(data.dynamics->max_string_force), Quantities::force);
numbers->addValue("String force (strand)", std::get<0>(data.dynamics->max_strand_force), Quantities::force);

auto plot_shapes = new ShapePlot(data.common, data.dynamics->states, 0);
auto plot_stress = new StressPlot(data.common, data.dynamics->states);
auto plot_curvature = new CurvaturePlot(data.common, data.dynamics->states);
auto plot_energy = new EnergyPlot(data.dynamics->states, data.dynamics->states.time, "Time", Quantities::time, Quantities::energy);
auto plot_combo = new ComboPlot();
plot_combo->addData("Time", data.dynamics.states.time, Quantities::time);
plot_combo->addData("Arrow position", data.dynamics.states.pos_arrow, Quantities::position);
plot_combo->addData("Arrow velocity", data.dynamics.states.vel_arrow, Quantities::velocity);
plot_combo->addData("Arrow acceleration", data.dynamics.states.acc_arrow, Quantities::acceleration);
plot_combo->addData("String force (total)", data.dynamics.states.string_force, Quantities::force);
plot_combo->addData("String force (strand)", data.dynamics.states.strand_force, Quantities::force);
plot_combo->addData("Grip force", data.dynamics.states.grip_force, Quantities::force);
plot_combo->addData("Pot. energy limbs", data.dynamics.states.e_pot_limbs, Quantities::energy);
plot_combo->addData("Kin. energy limbs", data.dynamics.states.e_kin_limbs, Quantities::energy);
plot_combo->addData("Pot. energy string", data.dynamics.states.e_pot_string, Quantities::energy);
plot_combo->addData("Kin. energy string", data.dynamics.states.e_kin_string, Quantities::energy);
plot_combo->addData("Kin. energy arrow", data.dynamics.states.e_kin_arrow, Quantities::energy);
plot_combo->addData("Time", data.dynamics->states.time, Quantities::time);
plot_combo->addData("Arrow position", data.dynamics->states.arrow_pos, Quantities::position);
plot_combo->addData("Arrow velocity", data.dynamics->states.arrow_vel, Quantities::velocity);
plot_combo->addData("Arrow acceleration", data.dynamics->states.arrow_acc, Quantities::acceleration);
plot_combo->addData("String force (total)", data.dynamics->states.string_force, Quantities::force);
plot_combo->addData("String force (strand)", data.dynamics->states.strand_force, Quantities::force);
plot_combo->addData("Grip force", data.dynamics->states.grip_force, Quantities::force);
plot_combo->addData("Pot. energy limbs", data.dynamics->states.e_pot_limbs, Quantities::energy);
plot_combo->addData("Kin. energy limbs", data.dynamics->states.e_kin_limbs, Quantities::energy);
plot_combo->addData("Pot. energy string", data.dynamics->states.e_pot_string, Quantities::energy);
plot_combo->addData("Kin. energy string", data.dynamics->states.e_kin_string, Quantities::energy);
plot_combo->addData("Kin. energy arrow", data.dynamics->states.e_kin_arrow, Quantities::energy);
plot_combo->setCombination(0, 1);

tabs->addTab(scrollArea(numbers), "Characteristics");
Expand All @@ -216,13 +215,13 @@ DynamicOutputWidget::DynamicOutputWidget(const OutputData& data)
tabs->addTab(plot_energy, "Energy");
tabs->addTab(plot_combo, "Other Plots");

auto slider = new Slider(data.dynamics.states.time, "Time", Quantities::time);
slider->addJumpAction("Arrow departure", data.dynamics.arrow_departure_index);
slider->addJumpAction("Max. grip force", data.dynamics.max_grip_force_index);
slider->addJumpAction("Max. string force", data.dynamics.max_string_force_index);
for (size_t i = 0; i < data.dynamics.max_stress_index.size(); ++i) {
slider->addJumpAction(QString::fromStdString("Max. stress for layer: " + data.setup.limb_properties.layers[i].name), data.dynamics.max_stress_index[i].first);
}
auto slider = new Slider(data.dynamics->states.time, "Time", Quantities::time);
//slider->addJumpAction("Arrow departure", data.dynamics.arrow_departure_index);
//slider->addJumpAction("Max. grip force", data.dynamics.max_grip_force_index);
//slider->addJumpAction("Max. string force", data.dynamics.max_string_force_index);
//for (size_t i = 0; i < data.dynamics.max_stress_index.size(); ++i) {
// slider->addJumpAction(QString::fromStdString("Max. stress for layer: " + data.setup.limb_properties.layers[i].name), data.dynamics.max_stress_index[i].first);
//}

QObject::connect(slider, &Slider::indexChanged, plot_shapes, &ShapePlot::setStateIndex);
QObject::connect(slider, &Slider::indexChanged, plot_stress, &StressPlot::setStateIndex);
Expand All @@ -238,7 +237,6 @@ DynamicOutputWidget::DynamicOutputWidget(const OutputData& data)

UserSettings settings;
tabs->setCurrentIndex(settings.value("DynamicOutputWidget/selectedTab", tabs->currentIndex()).toInt());
*/
}

DynamicOutputWidget::~DynamicOutputWidget() {
Expand Down
12 changes: 6 additions & 6 deletions gui/source/post/ShapePlot.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ShapePlot.hpp"
#include "pre/viewmodel/units/UnitSystem.hpp"

ShapePlot::ShapePlot(const LimbSetup& limb, const States& states, int background_states)
: limb(limb),
ShapePlot::ShapePlot(const Common& common, const States& states, int background_states)
: common(common),
states(states),
quantity(Quantities::length),
background_states(background_states),
Expand Down Expand Up @@ -87,7 +87,7 @@ void ShapePlot::updateBackgroundStates() {

if(intermediate_states >= 0) {
// Unbraced state
plotLimbOutline(limb_left[intermediate_states], limb_right[intermediate_states], limb.position);
plotLimbOutline(limb_left[intermediate_states], limb_right[intermediate_states], common.limb.position);
}
}

Expand Down Expand Up @@ -120,7 +120,7 @@ void ShapePlot::updateAxes() {
}
};

expand3(limb.position);
expand3(common.limb.position);
for(size_t i = 0; i < states.time.size(); ++i) {
// Add 0.5*height as an estimated upper bound
//expand(states.x_pos_limb[i] + 0.5*limb.height, states.y_pos_limb[i] + 0.5*limb.height);
Expand Down Expand Up @@ -153,8 +153,8 @@ void ShapePlot::plotLimbOutline(QCPCurve* left, QCPCurve* right, const std::vect

// Iterate backward and plot belly
for(int i = position.size() - 1; i >= 0; --i) {
double xi = position[i][0] + limb.height[i]*sin(position[i][2]);
double yi = position[i][1] - limb.height[i]*cos(position[i][2]);
double xi = position[i][0] + common.limb.height[i]*sin(position[i][2]);
double yi = position[i][1] - common.limb.height[i]*cos(position[i][2]);

left->addData(
quantity.getUnit().fromBase(-xi),
Expand Down
4 changes: 2 additions & 2 deletions gui/source/post/ShapePlot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

class ShapePlot: public PlotWidget {
public:
ShapePlot(const LimbSetup& limb, const States& states, int background_states);
ShapePlot(const Common& common, const States& states, int background_states);
void setStateIndex(int i);

private:
const LimbSetup& limb;
const Common& common;
const States& states;
const Quantity& quantity;

Expand Down
22 changes: 11 additions & 11 deletions gui/source/post/StressPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ const QList<QColor> COLOR_PALETTE = {
QColor("#17becf")
};

StressPlot::StressPlot(const LimbSetup& limb, const States& states)
: limb(limb),
StressPlot::StressPlot(const Common& common, const States& states)
: common(common),
states(states),
index(0),
quantity_length(Quantities::length),
quantity_stress(Quantities::stress)
{
this->setupTopLegend();

for(size_t iLayer = 0; iLayer < limb.layers.size(); ++iLayer) {
QString name = QString::fromStdString("TODO" /*limb.layers[i].name*/);
QColor color = COLOR_PALETTE[iLayer % COLOR_PALETTE.size()]; // Wrap around when colors are exhausted
for(size_t iLayer = 0; iLayer < common.layers.size(); ++iLayer) {
QString name = QString::fromStdString(common.layers[iLayer].name);
QColor color = COLOR_PALETTE[iLayer % COLOR_PALETTE.size()]; // Wrap around when all colors have been used

this->addGraph();
this->graph(2*iLayer)->setName(name + " (back)");
Expand Down Expand Up @@ -56,17 +56,17 @@ void StressPlot::updatePlot() {
}

void StressPlot::updateStresses() {
for(size_t iLayer = 0; iLayer < limb.layers.size(); ++iLayer) {
for(size_t iLayer = 0; iLayer < common.layers.size(); ++iLayer) {
this->graph(2*iLayer)->data()->clear();
this->graph(2*iLayer+1)->data()->clear();

for(size_t iLength = 0; iLength < limb.layers[iLayer].length.size(); ++iLength) {
for(size_t iLength = 0; iLength < common.layers[iLayer].length.size(); ++iLength) {
this->graph(2*iLayer)->addData(
quantity_length.getUnit().fromBase(limb.layers[iLayer].length[iLength]),
quantity_length.getUnit().fromBase(common.layers[iLayer].length[iLength]),
quantity_stress.getUnit().fromBase(std::get<0>(states.layer_stress[index][iLayer][iLength]))
);
this->graph(2*iLayer+1)->addData(
quantity_length.getUnit().fromBase(limb.layers[iLayer].length[iLength]),
quantity_length.getUnit().fromBase(common.layers[iLayer].length[iLength]),
quantity_stress.getUnit().fromBase(std::get<1>(states.layer_stress[index][iLayer][iLength]))
);
}
Expand All @@ -78,8 +78,8 @@ void StressPlot::updateAxes() {
this->yAxis->setLabel("Stress " + quantity_stress.getUnit().getLabel());

QCPRange x_range(
quantity_length.getUnit().fromBase(limb.length.front()),
quantity_length.getUnit().fromBase(limb.length.back())
quantity_length.getUnit().fromBase(common.limb.length.front()),
quantity_length.getUnit().fromBase(common.limb.length.back())
);
QCPRange y_range(
0.0,
Expand Down
4 changes: 2 additions & 2 deletions gui/source/post/StressPlot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

class StressPlot: public PlotWidget {
public:
StressPlot(const LimbSetup& limb, const States& states);
StressPlot(const Common& common, const States& states);
void setStateIndex(int i);

private:
const LimbSetup& limb;
const Common& common;
const States& states;
int index;

Expand Down
Loading

0 comments on commit 12a0abd

Please sign in to comment.