From fe3593ac00d4c0690b1aefa4d0f25d43961ce68d Mon Sep 17 00:00:00 2001 From: mlin865 Date: Fri, 18 Aug 2023 09:42:09 +1200 Subject: [PATCH 1/4] Handle d1 scaling when using inward and update unit test for bladder --- src/scaffoldmaker/utils/tubemesh.py | 7 +++++-- tests/test_bladder.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/scaffoldmaker/utils/tubemesh.py b/src/scaffoldmaker/utils/tubemesh.py index d39749a1..07fedaff 100644 --- a/src/scaffoldmaker/utils/tubemesh.py +++ b/src/scaffoldmaker/utils/tubemesh.py @@ -336,13 +336,16 @@ def extrudeSurfaceCoordinates(xSurf, d1Surf, d2Surf, d3Surf, xList.append(x) # dx_ds1 - factor = 1.0 + wallThickness * xi3 * curvatureAroundSurf[n] + distance = vector.magnitude([x[i] - xSurf[n][i] for i in range(3)]) + if outward: + factor = 1.0 + distance * curvatureAroundSurf[n] + else: + factor = 1.0 - distance * curvatureAroundSurf[n] d1 = [factor*c for c in d1Surf[n]] d1List.append(d1) # dx_ds2 curvature = curvatureAlong[n] - distance = vector.magnitude([x[i] - xSurf[n][i] for i in range(3)]) if outward: factor = 1.0 - curvature * distance else: diff --git a/tests/test_bladder.py b/tests/test_bladder.py index 0fd430b3..cae6823d 100644 --- a/tests/test_bladder.py +++ b/tests/test_bladder.py @@ -75,10 +75,10 @@ def test_bladder1(self): fieldcache = fieldmodule.createFieldcache() result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(surfaceArea, 3.6740101958977296, delta=1.0E-8) + self.assertAlmostEqual(surfaceArea, 3.6692194413389085, delta=1.0E-8) result, volume = volumeField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(volume, 0.02543636759208289, delta=1.0E-8) + self.assertAlmostEqual(volume, 0.025405251791144414, delta=1.0E-8) # result, flatSurfaceArea = flatSurfaceAreaField.evaluateReal(fieldcache, 1) # self.assertEqual(result, RESULT_OK) # self.assertAlmostEqual(flatSurfaceArea, 32905.65612644931, delta=1.0E-3) From 7c9d4ed5d9afeff5ec6f934fbe658f966f2c095b Mon Sep 17 00:00:00 2001 From: mlin865 Date: Fri, 18 Aug 2023 13:15:57 +1200 Subject: [PATCH 2/4] Standardise calculation of d1 and d2 --- src/scaffoldmaker/utils/tubemesh.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/scaffoldmaker/utils/tubemesh.py b/src/scaffoldmaker/utils/tubemesh.py index 07fedaff..577eee88 100644 --- a/src/scaffoldmaker/utils/tubemesh.py +++ b/src/scaffoldmaker/utils/tubemesh.py @@ -292,8 +292,10 @@ def extrudeSurfaceCoordinates(xSurf, d1Surf, d2Surf, d3Surf, # Calculate curvature along elements around prevIdx = n - 1 if (n1 != 0) else (n2 + 1)*elementsCountAround - 1 nextIdx = n + 1 if (n1 < elementsCountAround - 1) else n2*elementsCountAround - kappam = interp.getCubicHermiteCurvatureSimple(xSurf[prevIdx], d1Surf[prevIdx], xSurf[n], d1Surf[n], 1.0) - kappap = interp.getCubicHermiteCurvatureSimple(xSurf[n], d1Surf[n], xSurf[nextIdx], d1Surf[nextIdx], 0.0) + kappam = interp.getCubicHermiteCurvature(xSurf[prevIdx], d1Surf[prevIdx], xSurf[n], d1Surf[n], + vector.normalise(d3Surf[n]), 1.0) + kappap = interp.getCubicHermiteCurvature(xSurf[n], d1Surf[n], xSurf[nextIdx], d1Surf[nextIdx], + vector.normalise(d3Surf[n]), 0.0) if not transitElementList[n1] and not transitElementList[(n1-1)%elementsCountAround]: curvatureAround = 0.5*(kappam + kappap) elif transitElementList[n1]: @@ -336,23 +338,15 @@ def extrudeSurfaceCoordinates(xSurf, d1Surf, d2Surf, d3Surf, xList.append(x) # dx_ds1 - distance = vector.magnitude([x[i] - xSurf[n][i] for i in range(3)]) - if outward: - factor = 1.0 + distance * curvatureAroundSurf[n] - else: - factor = 1.0 - distance * curvatureAroundSurf[n] + factor = 1.0 - wallOutwardDisplacement * (xi3 if outward else (1.0 - xi3)) * curvatureAroundSurf[n] d1 = [factor*c for c in d1Surf[n]] d1List.append(d1) # dx_ds2 - curvature = curvatureAlong[n] - if outward: - factor = 1.0 - curvature * distance - else: - factor = 1.0 + curvature * distance - d2 = [factor*c for c in d2Surf[n]] + factor = 1.0 - wallOutwardDisplacement * (xi3 if outward else (1.0 - xi3)) * curvatureAlong[n] + d2 = [factor * c for c in d2Surf[n]] d2List.append(d2) - curvatureList.append(curvature) + curvatureList.append(curvatureAlong[n]) # dx_ds3 d3 = [c * wallThickness * (relativeThicknessList[n3] if relativeThicknessList else 1.0/elementsCountThroughWall) for c in norm] From dd9e603fb92a1d2ce2b2927fd5e0b52e5a48f59c Mon Sep 17 00:00:00 2001 From: mlin865 Date: Fri, 18 Aug 2023 13:18:06 +1200 Subject: [PATCH 3/4] Update comment to refer to node wall thickness --- src/scaffoldmaker/utils/tubemesh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scaffoldmaker/utils/tubemesh.py b/src/scaffoldmaker/utils/tubemesh.py index 577eee88..b1c4c493 100644 --- a/src/scaffoldmaker/utils/tubemesh.py +++ b/src/scaffoldmaker/utils/tubemesh.py @@ -252,7 +252,7 @@ def extrudeSurfaceCoordinates(xSurf, d1Surf, d2Surf, d3Surf, :param d1Surf: Derivatives on surface around tube :param d2Surf: Derivatives on surface along tube :param d3Surf: Derivatives on surface through wall - :param wallThicknessList: Wall thickness for each element along tube + :param wallThicknessList: Wall thickness for each node along tube :param relativeThicknessList: Relative wall thickness for each element through wall :param elementsCountAround: Number of elements around tube :param elementsCountAlong: Number of elements along tube From 5d5e3de286385bcf1c37f61d852dc9ee0aa205d9 Mon Sep 17 00:00:00 2001 From: mlin865 Date: Fri, 18 Aug 2023 13:29:13 +1200 Subject: [PATCH 4/4] Update unit tests --- tests/test_bladder.py | 2 +- tests/test_bladderurethra.py | 4 ++-- tests/test_cecum.py | 6 +++--- tests/test_colon.py | 4 ++-- tests/test_colonsegment.py | 4 ++-- tests/test_esophagus.py | 4 ++-- tests/test_smallintestine.py | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test_bladder.py b/tests/test_bladder.py index cae6823d..4c57569f 100644 --- a/tests/test_bladder.py +++ b/tests/test_bladder.py @@ -78,7 +78,7 @@ def test_bladder1(self): self.assertAlmostEqual(surfaceArea, 3.6692194413389085, delta=1.0E-8) result, volume = volumeField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(volume, 0.025405251791144414, delta=1.0E-8) + self.assertAlmostEqual(volume, 0.025324264242304235, delta=1.0E-8) # result, flatSurfaceArea = flatSurfaceAreaField.evaluateReal(fieldcache, 1) # self.assertEqual(result, RESULT_OK) # self.assertAlmostEqual(flatSurfaceArea, 32905.65612644931, delta=1.0E-3) diff --git a/tests/test_bladderurethra.py b/tests/test_bladderurethra.py index 3fa50269..c67ce708 100644 --- a/tests/test_bladderurethra.py +++ b/tests/test_bladderurethra.py @@ -88,10 +88,10 @@ def test_bladderurethra1(self): fieldcache = fieldmodule.createFieldcache() result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(surfaceArea, 4564.851396969593, delta=1.0E-6) + self.assertAlmostEqual(surfaceArea, 4564.518506192725, delta=1.0E-6) result, volume = volumeField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(volume, 2221.1973927759996, delta=1.0E-6) + self.assertAlmostEqual(volume, 2218.8526070746825, delta=1.0E-6) result, flatSurfaceArea = flatSurfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) self.assertAlmostEqual(flatSurfaceArea, 4087.7670057497376, delta=1.0E-3) diff --git a/tests/test_cecum.py b/tests/test_cecum.py index 527ea9b2..fa7812a4 100644 --- a/tests/test_cecum.py +++ b/tests/test_cecum.py @@ -70,7 +70,7 @@ def test_cecum1(self): self.assertTrue(coordinates.isValid()) minimums, maximums = evaluateFieldNodesetRange(coordinates, nodes) assertAlmostEqualList(self, minimums, [-49.01658984455258, -46.89686037622053, -2.343256155753525], 1.0E-6) - assertAlmostEqualList(self, maximums, [42.18085849205387, 54.902119877312636, 180.0], 1.0E-6) + assertAlmostEqualList(self, maximums, [42.18085849205387, 54.90211871346987, 180.0], 1.0E-6) with ChangeManager(fieldmodule): one = fieldmodule.createFieldConstant(1.0) @@ -82,10 +82,10 @@ def test_cecum1(self): fieldcache = fieldmodule.createFieldcache() result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(surfaceArea, 65960.86557108756, delta=1.0E-6) + self.assertAlmostEqual(surfaceArea, 65905.04907630144, delta=1.0E-6) result, volume = volumeField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(volume, 127907.08806524028, delta=1.0E-6) + self.assertAlmostEqual(volume, 127866.92887366761, delta=1.0E-6) if __name__ == "__main__": diff --git a/tests/test_colon.py b/tests/test_colon.py index 969a4d03..7640c071 100644 --- a/tests/test_colon.py +++ b/tests/test_colon.py @@ -164,10 +164,10 @@ def test_colon1(self): fieldcache = fieldmodule.createFieldcache() result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(surfaceArea, 174848.22676409548, delta=1.0E-6) + self.assertAlmostEqual(surfaceArea, 174749.05868939584, delta=1.0E-6) result, volume = volumeField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(volume, 313689.5754456567, delta=1.0E-6) + self.assertAlmostEqual(volume, 314670.65237072564, delta=1.0E-6) def test_mousecolon1(self): """ diff --git a/tests/test_colonsegment.py b/tests/test_colonsegment.py index 8f85ed7c..55f58781 100644 --- a/tests/test_colonsegment.py +++ b/tests/test_colonsegment.py @@ -78,10 +78,10 @@ def test_humancolonsegment1(self): fieldcache = fieldmodule.createFieldcache() result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(surfaceArea, 21035.8818469729, delta=1.0E-6) + self.assertAlmostEqual(surfaceArea, 21032.6788157990, delta=1.0E-6) result, volume = volumeField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(volume, 39781.704358310606, delta=1.0E-6) + self.assertAlmostEqual(volume, 39836.60239335828, delta=1.0E-6) def test_mousecolonsegment1(self): """ diff --git a/tests/test_esophagus.py b/tests/test_esophagus.py index 0aacaccc..b3d43748 100644 --- a/tests/test_esophagus.py +++ b/tests/test_esophagus.py @@ -82,10 +82,10 @@ def test_esophagus1(self): fieldcache = fieldmodule.createFieldcache() result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(surfaceArea, 13994.064785386161, delta=1.0E-6) + self.assertAlmostEqual(surfaceArea, 13952.301236699395, delta=1.0E-6) result, volume = volumeField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(volume, 35763.04473815047, delta=1.0E-6) + self.assertAlmostEqual(volume, 35523.4403218177, delta=1.0E-6) # check some annotationGroups: expectedSizes3d = { diff --git a/tests/test_smallintestine.py b/tests/test_smallintestine.py index 9320fe22..0eee9d40 100644 --- a/tests/test_smallintestine.py +++ b/tests/test_smallintestine.py @@ -142,10 +142,10 @@ def test_smallintestine1(self): fieldcache = fieldmodule.createFieldcache() result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(surfaceArea, 143.8506801217898, delta=1.0E-6) + self.assertAlmostEqual(surfaceArea, 143.8501823770281, delta=1.0E-6) result, volume = volumeField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) - self.assertAlmostEqual(volume, 13.608918623618687, delta=1.0E-6) + self.assertAlmostEqual(volume, 13.608455265457282, delta=1.0E-6) result, flatSurfaceArea = flatSurfaceAreaField.evaluateReal(fieldcache, 1) self.assertEqual(result, RESULT_OK) self.assertAlmostEqual(flatSurfaceArea, 144.42091907104523, delta=1.0E-3)