From 0ba744dc921e5d51ffcea73802516de81aabaa1c Mon Sep 17 00:00:00 2001 From: Joachim Wuttke <j.wuttke@fz-juelich.de> Date: Tue, 24 Oct 2023 18:30:37 +0200 Subject: [PATCH 1/7] expand auto --- Img3D/View/Canvas.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Img3D/View/Canvas.cpp b/Img3D/View/Canvas.cpp index 0f81765368e..7bdc4002130 100644 --- a/Img3D/View/Canvas.cpp +++ b/Img3D/View/Canvas.cpp @@ -153,14 +153,14 @@ void Canvas::paintGL() m_shader->setAxis(false); // opaque objects - for (auto* o : m_model->objects()) + for (const PlottableBody* o : m_model->objects()) drawBody(*o); // transparent objects glEnable(GL_BLEND); glDepthMask(false); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - for (auto* o : m_model->transparentObjects()) + for (const PlottableBody* o : m_model->transparentObjects()) drawBody(*o); glDisable(GL_BLEND); glDepthMask(true); @@ -274,7 +274,7 @@ void Canvas::releaseBuffer(Geometry const* g) void Canvas::releaseBuffers() { - for (auto* b : m_buffers.values()) + for (BodyPlotter* b : m_buffers.values()) delete b; m_buffers.clear(); } -- GitLab From 14bff16904b2ad2c53f66322f8188668b3a4ca10 Mon Sep 17 00:00:00 2001 From: Joachim Wuttke <j.wuttke@fz-juelich.de> Date: Tue, 24 Oct 2023 18:31:42 +0200 Subject: [PATCH 2/7] Img3D Model expand auto --- Img3D/Model/Model.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Img3D/Model/Model.cpp b/Img3D/Model/Model.cpp index 1fde1b309ab..719406e5838 100644 --- a/Img3D/Model/Model.cpp +++ b/Img3D/Model/Model.cpp @@ -125,9 +125,9 @@ void Model::emplaceTransparentBody(PlottableBody* o) void Model::releaseGeometries() { - for (auto* o : m_objects) + for (PlottableBody* o : m_objects) o->releaseGeometry(); - for (auto* o : m_transparentObjects) + for (PlottableBody* o : m_transparentObjects) o->releaseGeometry(); } -- GitLab From 1b12f1191021858a8451d1713ec4290782a47df9 Mon Sep 17 00:00:00 2001 From: Joachim Wuttke <j.wuttke@fz-juelich.de> Date: Tue, 24 Oct 2023 18:36:13 +0200 Subject: [PATCH 3/7] Img3D BodyPlotter expand auto --- Img3D/Plot/BodyPlotter.cpp | 2 +- Img3D/View/Shader.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Img3D/Plot/BodyPlotter.cpp b/Img3D/Plot/BodyPlotter.cpp index 00d0da40184..f6cff7fd82b 100644 --- a/Img3D/Plot/BodyPlotter.cpp +++ b/Img3D/Plot/BodyPlotter.cpp @@ -21,7 +21,7 @@ BodyPlotter::BodyPlotter(Geometry const& geometry) { initializeOpenGLFunctions(); - const auto& mesh = geometry.mesh(); + const QVector<Geometry::VertexAndNormal>& mesh = geometry.mesh(); m_vertexCount = mesh.count(); QOpenGLVertexArrayObject::Binder dummy(&m_vao); diff --git a/Img3D/View/Shader.cpp b/Img3D/View/Shader.cpp index 204da2c5ff4..2b53affedb0 100644 --- a/Img3D/View/Shader.cpp +++ b/Img3D/View/Shader.cpp @@ -43,7 +43,7 @@ void Shader::init() return; doInit = false; - auto ok = addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/vertex_shader.vert"); + bool ok = addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/vertex_shader.vert"); ASSERT(ok); ok = addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/fragment_shader.frag"); -- GitLab From 3ed7825b3b69628f256ed177ac40127a4d7d3931 Mon Sep 17 00:00:00 2001 From: Joachim Wuttke <j.wuttke@fz-juelich.de> Date: Tue, 24 Oct 2023 18:37:37 +0200 Subject: [PATCH 4/7] Img3D Geometry expand auto --- Img3D/Model/Geometry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Img3D/Model/Geometry.cpp b/Img3D/Model/Geometry.cpp index ac32eabb0b8..db0ceba8412 100644 --- a/Img3D/Model/Geometry.cpp +++ b/Img3D/Model/Geometry.cpp @@ -58,7 +58,7 @@ void Geometry::Vertices::addStrip(const Vertices& vs, const Indices& is) void Geometry::Vertices::addFan(const Vertices& vs, const Indices& is) { ASSERT(is.size() >= 3); // at least one triangle - const auto& ctr = vs.at(is.at(0)); + const F3& ctr = vs.at(is.at(0)); for (size_t i = 0; i + 2 < is.size(); ++i) addTriangle(ctr, vs.at(is.at(1 + i)), vs.at(is.at(2 + i))); } -- GitLab From a875d203ba51c6b2037e9f9531210b7301ac56b4 Mon Sep 17 00:00:00 2001 From: Joachim Wuttke <j.wuttke@fz-juelich.de> Date: Tue, 24 Oct 2023 18:40:29 +0200 Subject: [PATCH 5/7] Img3D PlottableBody expand auto, + const, if -> ternary --- Img3D/Model/PlottableBody.cpp | 43 ++++++++++++++++------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/Img3D/Model/PlottableBody.cpp b/Img3D/Model/PlottableBody.cpp index 6646d42d59a..3a38e0191fc 100644 --- a/Img3D/Model/PlottableBody.cpp +++ b/Img3D/Model/PlottableBody.cpp @@ -21,16 +21,16 @@ namespace { QQuaternion EulerToQuaternion(const Img3D::F3& euler) { - float cpsi2 = std::cos(euler.x() / 2.0f); - float spsi2 = std::sin(euler.x() / 2.0f); - float cth2 = std::cos(euler.y() / 2.0f); - float sth2 = std::sin(euler.y() / 2.0f); - float cphi2 = std::cos(euler.z() / 2.0f); - float sphi2 = std::sin(euler.z() / 2.0f); - auto a = cphi2 * cth2 * cpsi2 - sphi2 * cth2 * spsi2; - auto b = cphi2 * cpsi2 * sth2 + sphi2 * sth2 * spsi2; - auto c = cphi2 * sth2 * spsi2 - sphi2 * cpsi2 * sth2; - auto d = cphi2 * cth2 * spsi2 + cth2 * cpsi2 * sphi2; + const float cpsi2 = std::cos(euler.x() / 2.0f); + const float spsi2 = std::sin(euler.x() / 2.0f); + const float cth2 = std::cos(euler.y() / 2.0f); + const float sth2 = std::sin(euler.y() / 2.0f); + const float cphi2 = std::cos(euler.z() / 2.0f); + const float sphi2 = std::sin(euler.z() / 2.0f); + const float a = cphi2 * cth2 * cpsi2 - sphi2 * cth2 * spsi2; + const float b = cphi2 * cpsi2 * sth2 + sphi2 * sth2 * spsi2; + const float c = cphi2 * sth2 * spsi2 - sphi2 * cpsi2 * sth2; + const float d = cphi2 * cth2 * spsi2 + cth2 * cpsi2 * sphi2; return QQuaternion{a, b, c, d}; } @@ -38,22 +38,17 @@ Img3D::F3 QuaternionToEuler(const QQuaternion& q) { auto qvec = q.toVector4D(); - float a = qvec.w(); // scalar part of quaternion - float b = qvec.x(); - float c = qvec.y(); - float d = qvec.z(); + const float a = qvec.w(); // scalar part of quaternion + const float b = qvec.x(); + const float c = qvec.y(); + const float d = qvec.z(); - float term1 = std::atan(d / a); - float term2 = 0; + const float term1 = std::atan(d / a); + const float term2 = b == 0 ? static_cast<float>((pi / 2)) : std::atan(c / b); - if (b == 0) - term2 = static_cast<float>((pi / 2)); - else - term2 = std::atan(c / b); - - float x = term1 + term2; - float y = 2 * std::atan(std::sqrt((b * b + c * c) / (a * a + d * d))); - float z = term1 - term2; + const float x = term1 + term2; + const float y = 2 * std::atan(std::sqrt((b * b + c * c) / (a * a + d * d))); + const float z = term1 - term2; return Img3D::F3(x, y, z); } -- GitLab From 7adea8e79ad39f6f39f6f0ffdbb4add4c1b6c14c Mon Sep 17 00:00:00 2001 From: Joachim Wuttke <j.wuttke@fz-juelich.de> Date: Tue, 24 Oct 2023 18:43:21 +0200 Subject: [PATCH 6/7] Img3D PositionBuilder - auto + const --- Img3D/Build/PositionBuilders.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Img3D/Build/PositionBuilders.cpp b/Img3D/Build/PositionBuilders.cpp index a56d571428b..d1dc74e404e 100644 --- a/Img3D/Build/PositionBuilders.cpp +++ b/Img3D/Build/PositionBuilders.cpp @@ -69,7 +69,7 @@ std::vector<std::vector<double>> IPositionBuilder::generatePositions(double laye std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd() std::normal_distribution<double> dis(0.0, std::sqrt(pos_var)); for (auto& position : positions) { - for (auto& coordinate : position) + for (double& coordinate : position) coordinate += dis(gen); } } @@ -182,16 +182,16 @@ Lattice2DPositionBuilder::~Lattice2DPositionBuilder() = default; std::vector<std::vector<double>> Lattice2DPositionBuilder::generatePositionsImpl(double layer_size, double) const { - const auto& lattice = m_iff->lattice(); - double l1 = lattice.length1(); - double l2 = lattice.length2(); - double alpha = lattice.latticeAngle(); - double xi = lattice.rotationAngle(); + const Lattice2D& lattice = m_iff->lattice(); + const double l1 = lattice.length1(); + const double l2 = lattice.length2(); + const double alpha = lattice.latticeAngle(); + const double xi = lattice.rotationAngle(); // Estimate the limits n1 and n2 of the maximum integer multiples of the lattice vectors // required for populating particles correctly within the 3D model's boundaries unsigned n1, n2; - double sina = std::abs(std::sin(alpha)); + const double sina = std::abs(std::sin(alpha)); if (sina <= 1e-4) { n1 = l1 == 0.0 ? 2 : static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l1); n2 = l2 == 0.0 ? 2 : static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l2); -- GitLab From 651909e2060991855a494403ec94b4b6b809c5fa Mon Sep 17 00:00:00 2001 From: Joachim Wuttke <j.wuttke@fz-juelich.de> Date: Tue, 24 Oct 2023 18:47:17 +0200 Subject: [PATCH 7/7] Img3D PositionBuilder + const, simplify return --- Img3D/Build/PositionBuilders.cpp | 33 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Img3D/Build/PositionBuilders.cpp b/Img3D/Build/PositionBuilders.cpp index d1dc74e404e..d1e9b33ab6a 100644 --- a/Img3D/Build/PositionBuilders.cpp +++ b/Img3D/Build/PositionBuilders.cpp @@ -26,12 +26,12 @@ std::vector<std::vector<double>> Generate2DLatticePoints(double l1, double l2, d std::vector<std::vector<double>> lattice_positions; std::vector<double> position; - unsigned nn1 = std::max(1u, n1); - unsigned nn2 = std::max(1u, n2); - int n1m = -static_cast<int>((nn1 - 1) / 2); - int n1M = static_cast<int>(nn1 / 2); - int n2m = -static_cast<int>((nn2 - 1) / 2); - int n2M = static_cast<int>(nn2 / 2); + const unsigned nn1 = std::max(1u, n1); + const unsigned nn2 = std::max(1u, n2); + const int n1m = -static_cast<int>((nn1 - 1) / 2); + const int n1M = static_cast<int>(nn1 / 2); + const int n2m = -static_cast<int>((nn2 - 1) / 2); + const int n2M = static_cast<int>(nn2 / 2); for (int i = n1m; i <= n1M; ++i) { for (int j = n2m; j <= n2M; ++j) { @@ -62,7 +62,7 @@ std::vector<std::vector<double>> IPositionBuilder::generatePositions(double laye double density) const { std::vector<std::vector<double>> positions = generatePositionsImpl(layer_size, density); - double pos_var = positionVariance(); + const double pos_var = positionVariance(); if (pos_var > 0.0) { // random generator and distribution std::random_device rd; // Will be used to obtain a seed for the random number engine @@ -87,8 +87,7 @@ DefaultPositionBuilder::~DefaultPositionBuilder() = default; std::vector<std::vector<double>> DefaultPositionBuilder::generatePositionsImpl(double, double) const { - std::vector<double> origin = {0.0, 0.0}; - return {origin}; + return {{0., 0.}}; } double DefaultPositionBuilder::positionVariance() const @@ -247,13 +246,13 @@ std::vector<std::vector<double>> Finite2DLatticePositionBuilder::generatePositionsImpl(double layer_size, double) const { const auto& lattice = m_iff->lattice(); - double l1 = lattice.length1(); - double l2 = lattice.length2(); - double alpha = lattice.latticeAngle(); - double xi = lattice.rotationAngle(); + const double l1 = lattice.length1(); + const double l2 = lattice.length2(); + const double alpha = lattice.latticeAngle(); + const double xi = lattice.rotationAngle(); unsigned n1, n2; - double sina = std::abs(std::sin(alpha)); + const double sina = std::abs(std::sin(alpha)); if (sina <= 1e-4) { n1 = l1 == 0.0 ? 2 : static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l1); n2 = l2 == 0.0 ? 2 : static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l2); @@ -290,11 +289,11 @@ RadialParacrystalPositionBuilder::generatePositionsImpl(double layer_size, doubl { std::vector<std::vector<double>> lattice_positions; - double distance = m_iff->peakDistance(); + const double distance = m_iff->peakDistance(); // Estimate the limit n of the integer multiple i of the peakDistance required // for populating particles correctly within the 3D model's boundaries - int n = distance <= 0.0 ? 1 : static_cast<int>(layer_size * std::sqrt(2.0) / distance); + const int n = distance <= 0.0 ? 1 : static_cast<int>(layer_size * std::sqrt(2.0) / distance); lattice_positions.resize(2 * n + 1); for (auto& it : lattice_positions) @@ -305,7 +304,7 @@ RadialParacrystalPositionBuilder::generatePositionsImpl(double layer_size, doubl for (int i = 1; i <= n; ++i) { // positions of particles located along +x (store at odd index) - unsigned i_left = static_cast<unsigned>(std::max(0, 2 * i - 3)); + const unsigned i_left = static_cast<unsigned>(std::max(0, 2 * i - 3)); double offset = m_iff->randomSample(); lattice_positions[2 * i - 1][0] = lattice_positions[i_left][0] + distance + offset; -- GitLab