From ac29687ff4409317eff4230f05c8d0aa89a285b6 Mon Sep 17 00:00:00 2001 From: Patrizia Kaye Date: Sat, 16 Nov 2024 00:18:34 +0100 Subject: [PATCH 1/2] Fix autoscaling of structures. In rescaleToUnit, the transformation is computed as a vector with three components, each 1/lengthScale. However, when computing the determinant of this, it results in a scaling of 1/lengthScale^3. Therefore compute the inverse scale as 1/std::cbrt(lengthScale). --- src/structure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structure.cpp b/src/structure.cpp index ba1aa1c0..428602bc 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -215,7 +215,7 @@ void Structure::centerBoundingBox() { void Structure::rescaleToUnit() { double currScale = lengthScale(); - float s = static_cast(1.0 / currScale); + float s = static_cast(1.0 / std::cbrt(currScale)); glm::mat4x4 newTrans = glm::scale(glm::mat4x4(1.0), glm::vec3{s, s, s}); objectTransform = newTrans * objectTransform.get(); updateStructureExtents(); From 35e056da4659a9e53f677d84ff063c50ac58b49b Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Sat, 28 Dec 2024 14:51:46 -0500 Subject: [PATCH 2/2] move cbrt to length scale computation --- src/structure.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/structure.cpp b/src/structure.cpp index 428602bc..99fb4166 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -21,7 +21,7 @@ Structure::Structure(std::string name_, std::string subtypeName) validateName(name); } -Structure::~Structure(){}; +Structure::~Structure() {}; Structure* Structure::setEnabled(bool newEnabled) { if (newEnabled == isEnabled()) return this; @@ -173,7 +173,7 @@ std::tuple Structure::boundingBox() { float Structure::lengthScale() { // compute the scaling caused by the object transform const glm::mat4x4& T = objectTransform.get(); - float transScale = std::abs(glm::determinant(glm::mat3x3(T))) / T[3][3]; + float transScale = std::cbrt(std::abs(glm::determinant(glm::mat3x3(T)))) / T[3][3]; return transScale * objectSpaceLengthScale; } @@ -215,7 +215,7 @@ void Structure::centerBoundingBox() { void Structure::rescaleToUnit() { double currScale = lengthScale(); - float s = static_cast(1.0 / std::cbrt(currScale)); + float s = static_cast(1.0 / currScale); glm::mat4x4 newTrans = glm::scale(glm::mat4x4(1.0), glm::vec3{s, s, s}); objectTransform = newTrans * objectTransform.get(); updateStructureExtents();