Skip to content

Commit

Permalink
Symbol fix (#66)
Browse files Browse the repository at this point in the history
* symbol_triangle.cpp

* symbol_triangle.h

* Update base.h

* symbol_base.cpp

* Update stylefactory.h

* Update stylefactory.cpp

* Update CMakeLists.txt

* Update mainwindow.ui

* Add material storage for symbol entity in base DataEntity.

* Always add symbol renderer to Data1DEntity.

* Add option to have no symbols (since we always have a renderer).

* Remove additional vector argument from SymbolRenderer constructor.

* Final fixup, and don't forget to add the material to the symbol renderer!

* Update mainwindow_funcs.cpp

* Update mainwindow.ui

* Update mainwindow.h

* Update examples/errors/mainwindow.h

Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>

* Update examples/errors/mainwindow_funcs.cpp

Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>

* Update src/renderers/1d/symbol_triangle.cpp

Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>

* Update examples/errors/mainwindow_funcs.cpp

Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>

* Update examples/errors/mainwindow_funcs.cpp

Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>

* Update examples/errors/mainwindow_funcs.cpp

Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>

* Update mainwindow.h

* Update mainwindow.ui

* Update mainwindow_funcs.cpp

* Update base.h

* Update stylefactory.h

* Update symbol_triangle.cpp

* Update symbol_triangle.h

* Update symbol_triangle.h

---------

Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
  • Loading branch information
Pranavya-Vivek and trisyoungs authored Jul 17, 2023
1 parent ce666a3 commit b2a402a
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 8 deletions.
6 changes: 6 additions & 0 deletions examples/errors/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@ class MainWindow : public QMainWindow
void on_UniformErrorRadio_clicked(bool checked);
void on_RandomErrorRadio_clicked(bool checked);
void on_ShowErrorBarsCheck_toggled(bool checked);
void on_ShowSymbolsCheck_selected(bool checked);
void on_StyleCombo_currentIndexChanged(int index);
void on_SymbolStyleCombo_currentShapeIndexChanged(int shapeindex);

public slots:
// Set error size
void setErrorBarSize(double size);

// Set symbol size
void setSymbolSize(double size);

private:
// Main form declaration
Ui::MainWindow ui_;
// Display group
Mildred::Data1DEntity *dataEntity_{nullptr};
// Style
Mildred::StyleFactory1D::ErrorBarStyle style_{Mildred::StyleFactory1D::ErrorBarStyle::Stick};
Mildred::StyleFactory1D::SymbolStyle shapeStyle_{Mildred::StyleFactory1D::SymbolStyle::Triangle};
/*
* Data
*/
Expand Down
49 changes: 48 additions & 1 deletion examples/errors/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Erorr Bars</string>
<string>Error Bars</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
Expand Down Expand Up @@ -140,6 +140,53 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Symbol</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Style</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="SymbolCombo"/>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="ShowSymbolsCheck">
<property name="text">
<string>Show</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="SymbolSizeSpin"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
27 changes: 25 additions & 2 deletions examples/errors/mainwindow_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ MainWindow::MainWindow() : QMainWindow()

dataEntity_ = ui_.TestingWidget->addData1D("Sin");
dataEntity_->setData(xValues_, yValues_, uniformErrors_);
dataEntity_->setSymbolStyle(Mildred::StyleFactory1D::SymbolStyle::Triangle);

ui_.StyleCombo->addItem(QString("Stick"));
ui_.StyleCombo->addItem(QString("T-Bar Stick"));

ui_.SymbolCombo->addItem(QString("Triangle"));
ui_.WidthSpin->setValue(10.0);
ui_.SymbolSizeSpin->setValue(12.0);

connect(ui_.WidthSpin, SIGNAL(valueChanged(double)), this, SLOT(setErrorBarSize(double)));
connect(ui_.SymbolSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setSymbolSize(double)));
};

// UI For Errors
void MainWindow::on_UniformErrorRadio_clicked(bool checked)
{
if (checked)
Expand Down Expand Up @@ -74,4 +78,23 @@ void MainWindow::on_StyleCombo_currentIndexChanged(int index)
}
}

void MainWindow::setErrorBarSize(double size) { dataEntity_->setErrorBarMetric(size); }
void MainWindow::setErrorBarSize(double size) { dataEntity_->setErrorBarMetric(size); }

// UI For Symbols
void MainWindow::on_ShowSymbolsCheck_selected(bool checked)
{
dataEntity_->setSymbolStyle(checked ? shapeStyle_ : Mildred::StyleFactory1D::SymbolStyle::None);
dataEntity_->setSymbolMetric(ui_.SymbolSizeSpin->value());
}

void MainWindow::on_SymbolStyleCombo_currentShapeIndexChanged(int shapeindex)
{
shapeStyle_ = shapeindex == 0 ? Mildred::StyleFactory1D::SymbolStyle::Triangle : Mildred::StyleFactory1D::SymbolStyle::None;
if (ui_.ShowSymbolsCheck->isChecked())
{
dataEntity_->setSymbolStyle(shapeStyle_);
dataEntity_->setSymbolMetric(ui_.SymbolSizeSpin->value());
}
}

void MainWindow::setSymbolSize(double size) { dataEntity_->setSymbolMetric(size); }
23 changes: 23 additions & 0 deletions src/entities/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ Qt3DRender::QMaterial *DataEntity::dataMaterial() { return dataEntityMaterial_;

Qt3DRender::QMaterial *DataEntity::errorMaterial() { return errorEntityMaterial_; }

void DataEntity::setSymbolMaterial(Qt3DRender::QMaterial *material)
{
// Remove existing material if one exists
if (symbolEntityMaterial_)
foreach (auto *node, symbolEntity_->childNodes())
{
auto *entity = dynamic_cast<Qt3DCore::QEntity *>(node);
if (entity)
entity->removeComponent(symbolEntityMaterial_);
}

symbolEntityMaterial_ = material;
if (symbolEntityMaterial_)
foreach (auto *node, symbolEntity_->childNodes())
{
auto *entity = dynamic_cast<Qt3DCore::QEntity *>(node);
if (entity)
entity->addComponent(symbolEntityMaterial_);
}
}

Qt3DRender::QMaterial *DataEntity::symbolMaterial() { return symbolEntityMaterial_; }

/*
* Rendering
*/
Expand Down
6 changes: 6 additions & 0 deletions src/entities/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class DataEntity : public Qt3DCore::QEntity
Qt3DRender::QMaterial *dataEntityMaterial_{nullptr};
// Material for error entity
Qt3DRender::QMaterial *errorEntityMaterial_{nullptr};
// Material for symbol entity
Qt3DRender::QMaterial *symbolEntityMaterial_{nullptr};

protected:
// Local colour definition for entity
Expand Down Expand Up @@ -94,6 +96,10 @@ class DataEntity : public Qt3DCore::QEntity
void setErrorMaterial(Qt3DRender::QMaterial *material);
// Get the error entity material
Qt3DRender::QMaterial *errorMaterial();
// Set symbol entity material
void setSymbolMaterial(Qt3DRender::QMaterial *material);
// Get the symbol entity material
Qt3DRender::QMaterial *symbolMaterial();

/*
* Rendering
Expand Down
25 changes: 24 additions & 1 deletion src/entities/data1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Data1DEntity::Data1DEntity(const AxisEntity *xAxis, const AxisEntity *valueAxis,
{
dataRenderer_ = StyleFactory1D::createDataRenderer(style_, dataEntity_);
errorRenderer_ = StyleFactory1D::createErrorRenderer(errorStyle_, errorEntity_);
symbolRenderer_ = StyleFactory1D::createSymbolRenderer(symbolStyle_, symbolEntity_);
}

/*
Expand Down Expand Up @@ -83,6 +84,8 @@ void Data1DEntity::create()
dataRenderer_->create(colourDefinition(), x_, xAxis_, values_, valueAxis_);
assert(errorRenderer_);
errorRenderer_->create(colourDefinition(), x_, xAxis_, values_, errors_, valueAxis_);
assert(symbolRenderer_);
symbolRenderer_->create(colourDefinition(), x_, xAxis_, values_, valueAxis_);
}

//! Set the line style
Expand Down Expand Up @@ -113,4 +116,24 @@ void Data1DEntity::setErrorBarMetric(double metric)
}

//! Get error size
double Data1DEntity::errorBarMetric() const { return errorRenderer_->errorBarMetric(); }
double Data1DEntity::errorBarMetric() const { return errorRenderer_->errorBarMetric(); }

//! Set the symbol style
void Data1DEntity::setSymbolStyle(StyleFactory1D::SymbolStyle style)
{
symbolStyle_ = style;
symbolRenderer_ = StyleFactory1D::createSymbolRenderer(symbolStyle_, symbolEntity_);
if (symbolMaterial())
setSymbolMaterial(symbolMaterial());
create();
}

//! Set symbol size
void Data1DEntity::setSymbolMetric(double metric)
{
symbolRenderer_->setSymbolMetric(metric);
create();
}

//! Get symbol size
double Data1DEntity::symbolMetric() const { return symbolRenderer_->symbolMetric(); }
10 changes: 10 additions & 0 deletions src/entities/data1d.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class Data1DEntity : public DataEntity
StyleFactory1D::ErrorBarStyle errorStyle_;
// Error Renderer
std::shared_ptr<ErrorRenderer1D> errorRenderer_{nullptr};
// Symbol style
StyleFactory1D::SymbolStyle symbolStyle_{StyleFactory1D::SymbolStyle::None};
// Symbol Renderer
std::shared_ptr<SymbolRenderer1D> symbolRenderer_{nullptr};
// Orientation
AxisEntity::AxisType abscissa_{AxisEntity::AxisType::Horizontal}, ordinate_{AxisEntity::AxisType::Vertical};

Expand All @@ -66,6 +70,12 @@ class Data1DEntity : public DataEntity
void setErrorBarMetric(double metric);
// Get error size
double errorBarMetric() const;
// Set symbol style
void setSymbolStyle(StyleFactory1D::SymbolStyle style);
// Set symbol size
void setSymbolMetric(double metric);
// Get symbol size
double symbolMetric() const;

protected:
// Create renderables from current data
Expand Down
6 changes: 5 additions & 1 deletion src/renderers/1d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ add_library(
error_stick.cpp
error_tee.cpp
stylefactory.cpp
symbol_base.cpp
symbol_triangle.cpp
base.h
line.h
none.h
error_stick.h
error_tee.h
error_none.h
stylefactory.h)
stylefactory.h
symbol_none.h
symbol_triangle.h)

target_include_directories(
renderers1d
Expand Down
39 changes: 38 additions & 1 deletion src/renderers/1d/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,41 @@ class ErrorRenderer1D
void setErrorBarMetric(double errorBarMetric);
};

} // namespace Mildred
//! SymbolRenderer1DBase is the base class for all 1-dimensional symbol renderers.
/*!
* SymbolRenderer1DBase provides a base class for all 1-dimensional symbol rendering styles.
*/
class SymbolRenderer1D
{
public:
SymbolRenderer1D(Qt3DCore::QEntity *rootEntity) : rootEntity_(rootEntity){};
virtual ~SymbolRenderer1D() = default;

/*
* Entities
*/
protected:
// Root Entity
Qt3DCore::QEntity *rootEntity_{nullptr};

/*
* Rendering
*/
protected:
// Colour definition
ColourDefinition colour_;

// Symbol metrics
double symbolMetric_{6.0};

public:
// Create entities from the supplied axes and data
virtual void create(const ColourDefinition &colour, const std::vector<double> &x, const AxisEntity *xAxis,
const std::vector<double> &values, const AxisEntity *valueAxis) = 0;
// Get symbol metric.
double symbolMetric() const;
// Set symbol metric.
void setSymbolMetric(double symbolMetric);
};

} // namespace Mildred
13 changes: 12 additions & 1 deletion src/renderers/1d/stylefactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "renderers/1d/error_tee.h"
#include "renderers/1d/line.h"
#include "renderers/1d/none.h"
#include "renderers/1d/symbol_none.h"
#include "renderers/1d/symbol_triangle.h"
#include <stdexcept>

namespace Mildred
Expand Down Expand Up @@ -31,5 +33,14 @@ std::shared_ptr<ErrorRenderer1D> createErrorRenderer(ErrorBarStyle style, Qt3DCo

throw(std::runtime_error("DataRenderer1D::createErrorRenderer() - Style not accounted for.\n"));
}
std::shared_ptr<SymbolRenderer1D> createSymbolRenderer(SymbolStyle style, Qt3DCore::QEntity *rootEntity)
{
if (style == SymbolStyle::None)
return std::make_shared<NoSymbolRenderer1D>(rootEntity);
if (style == SymbolStyle::Triangle)
return std::make_shared<TriangleSymbolRenderer1D>(rootEntity);

throw(std::runtime_error("DataRenderer1D::createSymbolRenderer() - Style not accounted for.\n"));
}
} // namespace StyleFactory1D
} // namespace Mildred
} // namespace Mildred
13 changes: 12 additions & 1 deletion src/renderers/1d/stylefactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@ enum class ErrorBarStyle
Tee
};

enum class SymbolStyle
{
None,
Circle,
Square,
Triangle
};

// Produce renderer for the specified style
std::shared_ptr<DataRenderer1D> createDataRenderer(Style style, Qt3DCore::QEntity *rootEntity);

// Produce error renderer for the specified style
std::shared_ptr<ErrorRenderer1D> createErrorRenderer(ErrorBarStyle style, Qt3DCore::QEntity *rootEntity);

// Produce symbol renderer for the specified style
std::shared_ptr<SymbolRenderer1D> createSymbolRenderer(SymbolStyle style, Qt3DCore::QEntity *rootEntity);

} // namespace StyleFactory1D
} // namespace Mildred
} // namespace Mildred
9 changes: 9 additions & 0 deletions src/renderers/1d/symbol_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "base.h"

using namespace Mildred;

// Returns the symbol metric.
double SymbolRenderer1D::symbolMetric() const { return symbolMetric_; }

// Sets the symbol metric.
void SymbolRenderer1D::setSymbolMetric(double symbolMetric) { symbolMetric_ = symbolMetric; }
20 changes: 20 additions & 0 deletions src/renderers/1d/symbol_none.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "renderers/1d/base.h"

namespace Mildred
{
//! NoSymbolRenderer1D renders no symbols.
/*!
* NoSymbolRenderer1D is a dummy class to represent valid, but 'None' symbols.
*/
class NoSymbolRenderer1D : public SymbolRenderer1D
{
public:
NoSymbolRenderer1D(Qt3DCore::QEntity *rootEntity) : SymbolRenderer1D(rootEntity) {}
~NoSymbolRenderer1D(){};

void create(const ColourDefinition &colour, const std::vector<double> &x, const AxisEntity *xAxis,
const std::vector<double> &values, const AxisEntity *valueAxis) override{};
};
} // namespace Mildred
Loading

0 comments on commit b2a402a

Please sign in to comment.