-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create symbol_square.cpp * Create symbol_square.h * Update stylefactory.h * Update stylefactory.cpp * Update CMakeLists.txt * Update mainwindow_funcs.cpp * Update base.h * Update mainwindow.h * Update mainwindow.ui * Update src/renderers/1d/symbol_square.cpp Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk> --------- Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
- Loading branch information
1 parent
b2a402a
commit 09d4029
Showing
6 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "renderers/1d/symbol_square.h" | ||
|
||
using namespace Mildred; | ||
|
||
SquareSymbolRenderer1D::SquareSymbolRenderer1D(Qt3DCore::QEntity *rootEntity) : SymbolRenderer1D(rootEntity) | ||
{ | ||
symbols_ = new LineEntity(rootEntity_); | ||
} | ||
|
||
SquareSymbolRenderer1D::~SquareSymbolRenderer1D() | ||
{ | ||
if (symbols_) | ||
symbols_->setParent(static_cast<Qt3DCore::QNode *>(nullptr)); | ||
}; | ||
|
||
/* | ||
* Rendering | ||
*/ | ||
|
||
// Create entities from the supplied metrics and data | ||
void SquareSymbolRenderer1D::create(const ColourDefinition &colour, const std::vector<double> &x, const AxisEntity *xAxis, | ||
const std::vector<double> &values, const AxisEntity *valueAxis) | ||
{ | ||
assert(symbols_); | ||
symbols_->clear(); | ||
|
||
colour_ = colour; | ||
|
||
// Check array sizes | ||
if (x.size() != values.size()) | ||
{ | ||
printf("Irregular vector sizes provided (%zu (x) vs %zu (y)) so can't create entities.\n", x.size(), values.size()); | ||
symbols_->finalise(); | ||
return; | ||
} | ||
|
||
// Loop over data and add vertices | ||
auto xit = x.cbegin(), vit = values.cbegin(); | ||
auto i = 0; | ||
auto w = symbolMetric_ / 2.0; | ||
while (xit != x.end()) | ||
{ | ||
// Get datapoint value in scaled coordinates | ||
auto centre = xAxis->toScaled(*xit) + valueAxis->toScaled(*vit); | ||
|
||
// Square Vertices | ||
symbols_->addVertex(centre + QVector3D(-w, w, 0.0), colour_.colour(*vit)); | ||
symbols_->addIndex(i++); | ||
symbols_->addVertex(centre + QVector3D(-w, -w, 0.0), colour_.colour(*vit)); | ||
symbols_->addIndex(i++); | ||
|
||
symbols_->addVertex(centre + QVector3D(w, -w, 0.0), colour_.colour(*vit)); | ||
symbols_->addIndex(i++); | ||
symbols_->addVertex(centre + QVector3D(w, w, 0.0), colour_.colour(*vit)); | ||
symbols_->addIndex(i++); | ||
|
||
// Close the square! | ||
symbols_->addIndex(i - 4); | ||
|
||
// Add restart index, to cause line break. | ||
symbols_->addIndex(-1); | ||
++xit; | ||
++vit; | ||
} | ||
|
||
// Finalise the entity | ||
symbols_->finalise(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "entities/line.h" | ||
#include "renderers/1d/base.h" | ||
|
||
namespace Mildred | ||
{ | ||
//! SquareSymbolRenderer1D renders 1D data symbols as a square. | ||
/*! | ||
* SquareSymbolRenderer1D manages the creation of entities for displaying 1D data as a simple square. | ||
*/ | ||
class SquareSymbolRenderer1D : public SymbolRenderer1D | ||
{ | ||
public: | ||
SquareSymbolRenderer1D(Qt3DCore::QEntity *rootEntity); | ||
~SquareSymbolRenderer1D(); | ||
|
||
/* | ||
* Rendering | ||
*/ | ||
private: | ||
// Line entity | ||
LineEntity *symbols_{nullptr}; | ||
|
||
public: | ||
// Create entities from the supplied metrics and data | ||
void create(const ColourDefinition &colour, const std::vector<double> &x, const AxisEntity *xAxis, | ||
const std::vector<double> &values, const AxisEntity *valueAxis) override; | ||
}; | ||
|
||
} // namespace Mildred |