I've been making a parametric design using NURBS implementation geomdl in python. the problem is that it is hollow and cannot be processed with cgal
or 3dprinted. I am looking for a way to make it watertight by closing the top and the bottom. I already tried to use trimesh.covex.convex_hull
function from the trimesh
library but it messed up the design.
Example code:
import os
from geomdl import NURBS
from geomdl import construct
from geomdl import exchange
from geomdl.visualization import VisMPL as vis
from geomdl import knotvector
os.chdir(os.path.dirname(os.path.realpath(__file__)))
# Create a NURBS surface instance
surf = NURBS.Surface()
# Set degrees
surf.degree_u = 2
surf.degree_v = 2
# Set control points from a template file
surf.set_ctrlpts(*exchange.import_txt("ctrlpts.cptw", two_dimensional=True, jinja2=True))
# Set knot vectors
surf.knotvector_u = knotvector.generate(surf.degree_u, surf.ctrlpts_size_u)
surf.knotvector_v = knotvector.generate(surf.degree_v, surf.ctrlpts_size_v)#[0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]
# Set evaluation delta
surf.delta = 0.05
exchange.export_stl(surf, "test2.stl")
os.system('fstl ./test2.stl')
and the control points:
4.00,0.00,0.00,1.00;2.83,2.83,0.00,1.00;0.00,4.00,0.00,1.00;-2.83,2.83,0.00,1.00;-4.00,0.00,0.00,1.00;-2.83,-2.83,0.00,1.00;0.00,-4.00,0.00,1.00;2.83,-2.83,0.00,1.00;4.00,0.00,0.00,1.00
4.00,0.00,10.00,1.00;2.83,2.83,10.00,1.00;0.00,4.00,10.00,1.00;-2.83,2.83,10.00,1.00;-4.00,0.00,10.00,1.00;-2.83,-2.83,10.00,1.00;0.00,-4.00,10.00,1.00;2.83,-2.83,10.00,1.00;4.00,0.00,10.00,1.00
4.00,0.00,20.00,1.00;2.83,2.83,20.00,1.00;0.00,4.00,20.00,1.00;-2.83,2.83,20.00,1.00;-4.00,0.00,20.00,1.00;-2.83,-2.83,20.00,1.00;0.00,-4.00,20.00,1.00;2.83,-2.83,20.00,1.00;4.00,0.00,20.00,1.00
4.00,0.00,30.00,1.00;2.83,2.83,30.00,1.00;0.00,4.00,30.00,1.00;-2.83,2.83,30.00,1.00;-4.00,0.00,30.00,1.00;-2.83,-2.83,30.00,1.00;0.00,-4.00,30.00,1.00;2.83,-2.83,30.00,1.00;4.00,0.00,30.00,1.00
4.00,0.00,40.00,1.00;2.83,2.83,40.00,1.00;0.00,4.00,40.00,1.00;-2.83,2.83,40.00,1.00;-4.00,0.00,40.00,1.00;-2.83,-2.83,40.00,1.00;0.00,-4.00,40.00,1.00;2.83,-2.83,40.00,1.00;4.00,0.00,40.00,1.00
4.30,0.00,50.00,1.00;3.04,3.04,50.00,1.00;0.00,4.30,50.00,1.00;-3.04,3.04,50.00,1.00;-4.30,0.00,50.00,1.00;-3.04,-3.04,50.00,1.00;0.00,-4.30,50.00,1.00;3.04,-3.04,50.00,1.00;4.30,0.00,50.00,1.00
4.60,0.00,60.00,1.00;3.25,3.25,60.00,1.00;0.00,4.60,60.00,1.00;-3.25,3.25,60.00,1.00;-4.60,0.00,60.00,1.00;-3.25,-3.25,60.00,1.00;0.00,-4.60,60.00,1.00;3.25,-3.25,60.00,1.00;4.60,0.00,60.00,1.00
0.30,0.00,70.00,1.00;-0.96,3.04,70.00,1.00;-4.00,4.30,70.00,1.00;-7.04,3.04,70.00,1.00;-8.30,0.00,70.00,1.00;-7.04,-3.04,70.00,1.00;-4.00,-4.30,70.00,1.00;-0.96,-3.04,70.00,1.00;0.30,0.00,70.00,1.00
-3.70,0.00,80.00,1.00;-4.96,3.04,80.00,1.00;-8.00,4.30,80.00,1.00;-11.04,3.04,80.00,1.00;-12.30,0.00,80.00,1.00;-11.04,-3.04,80.00,1.00;-8.00,-4.30,80.00,1.00;-4.96,-3.04,80.00,1.00;-3.70,0.00,80.00,1.00
-7.70,0.00,90.00,1.00;-8.96,3.04,90.00,1.00;-12.00,4.30,90.00,1.00;-15.04,3.04,90.00,1.00;-16.30,0.00,90.00,1.00;-15.04,-3.04,90.00,1.00;-12.00,-4.30,90.00,1.00;-8.96,-3.04,90.00,1.00;-7.70,0.00,90.00,1.00
-11.70,0.00,100.00,1.00;-12.96,3.04,100.00,1.00;-16.00,4.30,100.00,1.00;-19.04,3.04,100.00,1.00;-20.30,0.00,100.00,1.00;-19.04,-3.04,100.00,1.00;-16.00,-4.30,100.00,1.00;-12.96,-3.04,100.00,1.00;-11.70,0.00,100.00,1.00
-15.70,0.00,110.00,1.00;-16.96,3.04,110.00,1.00;-20.00,4.30,110.00,1.00;-23.04,3.04,110.00,1.00;-24.30,0.00,110.00,1.00;-23.04,-3.04,110.00,1.00;-20.00,-4.30,110.00,1.00;-16.96,-3.04,110.00,1.00;-15.70,0.00,110.00,1.00
A simple and easy way for you is to use the 3D alpha-shape (also known as concave hull). You can sample your NURBS surface (possibly adding additional points on the "caps", but from the figure in your question I believe in your context even this won't be necessary) and then construct the 3D alpha-shape surface, which should give you the water-tight mesh you're looking for.
See my previous answer for example python code of a call to construct (and plot) the alpha-shape on a set of 3D points and for further explanation. The answer is based on the 3D alpha-shape code found in this nice answer.
If you don't want to use the alpha-shape, you can probably construct a water-tight surface mesh yourself by sampling uniformly the uv-domain of the NURBS surface and get the connectivity information for creating triangles from the sample indices (for example, the sample point from
(u[i],v[j])
will create a triangle with(u[i+1], v[j+1])
and(u[i], v[j+1])
and similarly for other neighbors). To close the "caps" you can add an additional point at the middle of the tube end (for example at the mean point of the points at(u[0], v[:])
and similarly for the mean point on the other end at(u[-1], v[:])
). And add triangles from this additional point to the points on the boundary circles of the tube surface.