Python Forum
Surface thickening VTK
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Surface thickening VTK
#1
Good morning,

I am very new at Python and my skills are pretty limited. I am asking here for advices/libraries/functions to look at that may help me to achieve my goal.
I am trying to code a program that generates a scaffold based on a particular minimal surface named "gyroid". My final goal is to create an .obj file (that I will afterwards modify with other softwares) in order to 3D print it and proceed to mechanical tests. To visualize it better, you can look at page 3 of this publication : http://core.ac.uk/download/pdf/82090411.pdf

I already achieved to generate a gyroid surface using VTK (see below, my code is probably not well constructed). This code duplicates the surface of a gyroid unit cell (U) to build a rectangular beam (2*2*8 U)

import numpy as np
import vtk  # VTK version 7.0
from mayavi import mlab  # mayavi version 4.4.4
from mayavi.api import Engine, OffScreenEngine
from tvtk.api import tvtk

cos = np.cos
sin = np.sin
pi  = np.pi

def gyroid(x,y,z):
        return cos(x)*sin(y) + cos(y)*sin(z) + cos(z)*sin(x)

[nx, ny, nz] = [2, 2, 8]  # amount of unit cells
# Meshgrid
x, y, z = np.mgrid[0:nx*2*pi:100j,0:ny*2*pi:100j,0:nz*2*pi:100j]

#engine = Engine()
engine = OffScreenEngine()  # do not start mayavi GUI
engine.start()

# create a Source : TPMS surface using mayavi.mlab
fig = mlab.figure(figure=None, engine=engine)
contour3d = mlab.contour3d(x, y, z, gyroid(x, y, z), figure=fig)

scene = engine.scenes[0]
actor = contour3d.actor.actors[0]
iso_surface = scene.children[0].children[0].children[0]
iso_surface.contour.minimum_contour = 0 # Minimum contour : 0 sheet / 1 skeletal
iso_surface.contour.number_of_contours = 1
iso_surface.compute_normals = False
iso_surface.contour.auto_update_range = False

mlab.draw(fig)
# mlab.show()  # enable if you want to see the mayavi GUI

polydata = tvtk.to_vtk(actor.mapper.input)  # convert tvtkPolyData to vtkPolyData

# Move object to the coordinate center to make clipping easier later on.
center_coords = np.array(polydata.GetCenter())
center = vtk.vtkTransform()
center.Translate(-center_coords[0], -center_coords[1], -center_coords[2])
centerFilter = vtk.vtkTransformPolyDataFilter()
centerFilter.SetTransform(center)
centerFilter.SetInputData(polydata)
centerFilter.Update()

# Render the result
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(centerFilter.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderer.AddActor(actor)
renderWindow.Render()
renderWindowInteractor.Start()
Now I wish to:
(1) Thicken this surface and keeping it in the 2*2*8 U beam. I couldn't find any function that thicken a surface as lines can be thicken for instance.
(2) This thickness must be non-linear for mechanical reasons : small thickness around the middle of the beam and bigger thickness near the beam extreme edges.
(3) Add 2 cubes of 2*2*2 U, one at each extreme edge (for the clamping claws)

Many thanks!

Marie
Reply
#2
A good place to look for libraries (packages) is https://pypi.org/
There are 163,577 projects to choose from.
A quick search for gyroid brings up: https://pypi.org/project/gyroid/
You can do a better search as you are more familiar with the terminology.
Reply
#3
Thank you Larz60+ for your reply.
I tried to use the gyroid.py package as you suggested but I get a error message. Plus, this package generates a gyroid surface and I wish to thicken this surface to create a solid, I am not sure this package is relevant for my work.
I keep searching!
Reply
#4
Quote:but I get a error message
A bit more detail would be appreciated.
I only pointed to that package as an example of what's available, it was not a recommendation as I have never used it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tips on surface plot HW question Cwcox 1 2,311 Nov-14-2018, 11:45 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020