diff --git a/Img3D/Build/PositionBuilders.cpp b/Img3D/Build/PositionBuilders.cpp index a56d571428b984aa91c48640be6733a9652c18ec..d1e9b33ab6a008c4ca2ca66560482d4e70504b19 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,14 +62,14 @@ 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 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); } } @@ -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 @@ -182,16 +181,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); @@ -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; diff --git a/Img3D/Model/Geometry.cpp b/Img3D/Model/Geometry.cpp index ac32eabb0b8430b79e960314c945cdf9796ad369..db0ceba84129d02b6ec499b98ec15fdd655529c4 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))); } diff --git a/Img3D/Model/Model.cpp b/Img3D/Model/Model.cpp index 1fde1b309abe4aab527507f37feb2e2734b5e9f3..719406e5838861469b740154e97d089e118b55a8 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(); } diff --git a/Img3D/Model/PlottableBody.cpp b/Img3D/Model/PlottableBody.cpp index 6646d42d59a44b262e9535da2390dd7000eafa32..3a38e0191fcefc1edbff69a9566366086a2a7162 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); } diff --git a/Img3D/Plot/BodyPlotter.cpp b/Img3D/Plot/BodyPlotter.cpp index 00d0da401848c9773a6b0edb30bab3fc4808abd9..f6cff7fd82b5fd7ee19e673a5688df26ea080f89 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/Canvas.cpp b/Img3D/View/Canvas.cpp index 0f81765368e42530bb7ff05add76f4d339868695..7bdc40021305226bece7981e2f42b9b1892fdc99 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(); } diff --git a/Img3D/View/Shader.cpp b/Img3D/View/Shader.cpp index 204da2c5ff4e5639a6328050527371d1a96bc48f..2b53affedb09ee517364036cc1c4bb5333d67879 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");