From 618eeb6371993a0b6185a10a4786196ad37e020f Mon Sep 17 00:00:00 2001 From: Pascal Pieper Date: Mon, 11 Apr 2022 16:12:55 +0200 Subject: [PATCH 1/2] using just one point for bottom center --- src/create_mesh.jl | 119 ++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 76 deletions(-) diff --git a/src/create_mesh.jl b/src/create_mesh.jl index ad6c5b6..dcd0701 100644 --- a/src/create_mesh.jl +++ b/src/create_mesh.jl @@ -555,17 +555,15 @@ $(SIGNATURES) """ function solidify(inputMesh, offset=100) width = inputMesh.width - height = inputMesh.height + height = inputMesh.height #here, height is depth (y) totalNodes = width * height * 2 nodeList = Vector{Point3D}(undef, totalNodes) - nodeArrayTop = Matrix{Point3D}(undef, width, height) - nodeArrayBottom = Matrix{Point3D}(undef, width, height) # imagine a 4x4 image. 4 * 2 + 2 * 2 = 12 numEdgeNodes = width * 2 + (height - 2) * 2 numTrianglesTop = (width - 1) * (height - 1) * 2 - numTrianglesBottom = numTrianglesTop + numTrianglesBottom = numEdgeNodes numTrianglesEdges = numEdgeNodes * 2 totalTriangles = numTrianglesBottom + numTrianglesTop + numTrianglesEdges @@ -576,13 +574,14 @@ function solidify(inputMesh, offset=100) count = 1 for y = 1:height for x = 1:width + # most of them are not used, but just the centerpoint for bottom newPoint = Point3D(x, y, -offset, x, y) nodeList[count] = newPoint - nodeArrayBottom[x, y] = newPoint count += 1 end end + # Copy in the top surface for y = 1:height for x = 1:width @@ -596,7 +595,6 @@ function solidify(inputMesh, offset=100) end nodeList[count] = copiedPoint - nodeArrayTop[x, y] = copiedPoint count += 1 end end @@ -604,37 +602,16 @@ function solidify(inputMesh, offset=100) println("We now have $(count - 1) valid nodes") triangles = Vector{Triangle}(undef, totalTriangles) - # Build the triangles for the bottom surface count = 1 - for y = 1:(height - 1) - for x = 1:(width - 1) - # here x and y establish the column of squares we're in - index_ul = (y - 1) * width + x - index_ur = index_ul + 1 - - index_ll = y * width + x - index_lr = index_ll + 1 - - triangles[count] = Triangle(index_ul, index_ll, index_ur) - count += 1 - triangles[count] = Triangle(index_lr, index_ur, index_ll) - count += 1 - end - end - - println("We've filled up $(count - 1) triangles") - if count != numTrianglesBottom + 1 - println("Hmm aren't count and triangles bottom equal? $(count) vs $(numTrianglesBottom + 1)") - end # Build the triangles for the top surface for y = 1:(height - 1) for x = 1:(width - 1) # here x and y establish the column of squares we're in - index_ul = (y - 1) * width + x + totalNodes / 2 + index_ul = (y - 1) * width + x + (width*height) index_ur = index_ul + 1 - index_ll = y * width + x + totalNodes / 2 + index_ll = y * width + x + (width*height) index_lr = index_ll + 1 triangles[count] = Triangle(index_ul, index_ur, index_ll) @@ -645,57 +622,47 @@ function solidify(inputMesh, offset=100) end println("We've filled up $(count - 1) triangles") - - # Build the triangles to close the mesh - x = 1 - for y = 1:(height - 1) - ll = (y - 1) * width + x - ul = ll + totalNodes / 2 - lr = y * width + x - ur = lr + totalNodes / 2 - triangles[count] = Triangle(ll, ul, ur) - count += 1 - triangles[count] = Triangle(ur, lr, ll) - count += 1 - end - - x = width - for y = 1:(height - 1) - ll = (y - 1) * width + x - ul = ll + totalNodes / 2 - lr = y * width + x - ur = lr + totalNodes / 2 - triangles[count] = Triangle(ll, ur, ul) - count += 1 - triangles[count] = Triangle(ur, ll, lr) - count += 1 + + centerpoint_idx = (height/2)*width + width/2 + # Build the Side triangles to close the mesh + for x = [1, width] + for y = 1:(height - 1) + ll = (y - 1) * width + x + ul = ll + (width * height) + lr = y * width + x + ur = lr + (width * height) + triangles[count] = Triangle(ll, ul, ur) + count += 1 + triangles[count] = Triangle(ur, lr, ll) + count += 1 + triangles[count] = Triangle(lr, ll, centerpoint_idx) + count += 1 + end end - y = 1 - for x = 2:width - ll = (y - 1) * width + x - ul = ll + totalNodes / 2 - lr = (y - 1) * width + (x - 1) - ur = lr + totalNodes / 2 - triangles[count] = Triangle(ll, ul, ur) - count += 1 - triangles[count] = Triangle(ur, lr, ll) - count += 1 + for y = [1, height] + for x = 2:width + ll = (y - 1) * width + x + ul = ll + (width * height) + lr = (y - 1) * width + (x - 1) + ur = lr + (width * height) + triangles[count] = Triangle(ll, ul, ur) + count += 1 + triangles[count] = Triangle(ur, lr, ll) + count += 1 + triangles[count] = Triangle(lr, ll, centerpoint_idx) + count += 1 + end end - - y = height - for x = 2:width - ll = (y - 1) * width + x - ul = ll + totalNodes / 2 - lr = (y - 1) * width + (x - 1) - ur = lr + totalNodes / 2 - triangles[count] = Triangle(ll, ur, ul) - count += 1 - triangles[count] = Triangle(ur, ll, lr) - count += 1 + + println("We've filled up $(count - 1) triangles") + if count != numTrianglesBottom + 1 + println("Hmm aren't count and triangles bottom equal? $(count) vs $(numTrianglesBottom + 1)") end - -Mesh(nodeList, nodeArrayBottom, triangles, width, height) + + # Array not actually used by calling functions here + sumArray = Matrix{Point3D}(undef, width, height) + Mesh(nodeList, sumArray, triangles, width, height) end From bb29132e8998144f2001ac5dc97629d866dee7b4 Mon Sep 17 00:00:00 2001 From: Pascal Pieper Date: Tue, 12 Apr 2022 18:24:38 +0200 Subject: [PATCH 2/2] renamed height to depth. Using better centerpoint calculation. --- src/create_mesh.jl | 56 +++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/create_mesh.jl b/src/create_mesh.jl index dcd0701..76c0565 100644 --- a/src/create_mesh.jl +++ b/src/create_mesh.jl @@ -555,35 +555,39 @@ $(SIGNATURES) """ function solidify(inputMesh, offset=100) width = inputMesh.width - height = inputMesh.height #here, height is depth (y) - totalNodes = width * height * 2 + depth = inputMesh.height + totalNodes = width * depth * 2 nodeList = Vector{Point3D}(undef, totalNodes) # imagine a 4x4 image. 4 * 2 + 2 * 2 = 12 - numEdgeNodes = width * 2 + (height - 2) * 2 + numEdgeNodes = width * 2 + (depth - 2) * 2 - numTrianglesTop = (width - 1) * (height - 1) * 2 + numTrianglesTop = (width - 1) * (depth - 1) * 2 numTrianglesBottom = numEdgeNodes numTrianglesEdges = numEdgeNodes * 2 totalTriangles = numTrianglesBottom + numTrianglesTop + numTrianglesEdges - println("Specs: $(width) $(height) $(totalNodes) $(numEdgeNodes) $(numTrianglesBottom) $(totalTriangles)") + println("Specs: $(width)x$(depth). $(totalNodes) nodes, $(numEdgeNodes) edges, $(numTrianglesBottom), faces on bottom, $(totalTriangles) faces total") + centerpoint_idx = 0 # Build the bottom surface count = 1 - for y = 1:height + for y = 1:depth for x = 1:width # most of them are not used, but just the centerpoint for bottom - newPoint = Point3D(x, y, -offset, x, y) - nodeList[count] = newPoint + nodeList[count] = Point3D(x, y, -offset, x, y) + if y == floor(depth/2) && x == floor(width/2) + centerpoint_idx = count + end count += 1 end end - + + println("Found a centerpoint at ($(nodeList[centerpoint_idx].x), $(nodeList[centerpoint_idx].y))") # Copy in the top surface - for y = 1:height + for y = 1:depth for x = 1:width node = inputMesh.nodeArray[x, y] copiedPoint = Point3D(node.x, node.y, node.z, node.ix, node.iy) @@ -605,13 +609,13 @@ function solidify(inputMesh, offset=100) count = 1 # Build the triangles for the top surface - for y = 1:(height - 1) + for y = 1:(depth - 1) for x = 1:(width - 1) # here x and y establish the column of squares we're in - index_ul = (y - 1) * width + x + (width*height) + index_ul = (y - 1) * width + x + (width*depth) index_ur = index_ul + 1 - index_ll = y * width + x + (width*height) + index_ll = y * width + x + (width*depth) index_lr = index_ll + 1 triangles[count] = Triangle(index_ul, index_ur, index_ll) @@ -621,16 +625,15 @@ function solidify(inputMesh, offset=100) end end - println("We've filled up $(count - 1) triangles") + println("We've filled up $(count - 1) top triangles") - centerpoint_idx = (height/2)*width + width/2 # Build the Side triangles to close the mesh for x = [1, width] - for y = 1:(height - 1) + for y = 1:(depth - 1) ll = (y - 1) * width + x - ul = ll + (width * height) + ul = ll + (width * depth) lr = y * width + x - ur = lr + (width * height) + ur = lr + (width * depth) triangles[count] = Triangle(ll, ul, ur) count += 1 triangles[count] = Triangle(ur, lr, ll) @@ -640,12 +643,12 @@ function solidify(inputMesh, offset=100) end end - for y = [1, height] + for y = [1, depth] for x = 2:width ll = (y - 1) * width + x - ul = ll + (width * height) + ul = ll + (width * depth) lr = (y - 1) * width + (x - 1) - ur = lr + (width * height) + ur = lr + (width * depth) triangles[count] = Triangle(ll, ul, ur) count += 1 triangles[count] = Triangle(ur, lr, ll) @@ -655,14 +658,15 @@ function solidify(inputMesh, offset=100) end end - println("We've filled up $(count - 1) triangles") - if count != numTrianglesBottom + 1 - println("Hmm aren't count and triangles bottom equal? $(count) vs $(numTrianglesBottom + 1)") + println("We've filled up $(count - 1) triangles, including bottom") + + if count-1 != totalTriangles + println("Hmm aren't count and triangles bottom equal? $(count-1) vs $(totalTriangles)") end # Array not actually used by calling functions here - sumArray = Matrix{Point3D}(undef, width, height) - Mesh(nodeList, sumArray, triangles, width, height) + sumArray = Matrix{Point3D}(undef, width, depth) + Mesh(nodeList, sumArray, triangles, width, depth) end