3D operations
Repeating unit geometry
from pathlib import Path
import cadquery as cq
from microgen import Rve, repeatShape
rve = Rve(dim=1)
step_file = str(Path(__file__).parent / "octettruss.step")
unit_geom = cq.importers.importStep(step_file)
unit_geom = cq.Shape(unit_geom.val().wrapped)
shape = repeatShape(unit_geom, rve, grid=(5, 5, 5))
stl_file = str(Path(__file__).parent / "repeated_shape.stl")
cq.exporters.export(shape, stl_file)
Raster Ellipsoid
from pathlib import Path
import cadquery as cq
from microgen import Ellipsoid, Phase, Rve, mesh, rasterPhase
rve = Rve(dim=1)
elem = Ellipsoid(radii=(0.15, 0.31, 0.4))
elli = elem.generate()
raster = rasterPhase(phase=Phase(shape=elli), rve=rve, grid=[5, 5, 5])
compound = cq.Compound.makeCompound(
[solid for phase in raster for solid in phase.solids]
)
step_file = str(Path(__file__).parent / "compound.step")
cq.exporters.export(compound, step_file)
vtk_file = str(Path(__file__).parent / "rasterEllipsoid.vtk")
mesh(
mesh_file=step_file,
listPhases=raster,
size=0.03,
order=1,
output_file=vtk_file,
)
Voronoi
from pathlib import Path
import cadquery as cq
from microgen import Neper, Phase, mesh
# # We import the Polyhedra from Neper tessellation file
# listPolyhedra, seed, vertices, edges, faces, polys = parseNeper("test1")
# Revel = Rve(dim=1)
# phases = []
# for polyhedron in listPolyhedra:
# elem = Polyhedron(
# center=(
# polyhedron["original"][0],
# polyhedron["original"][1],
# polyhedron["original"][2],
# ),
# dic=polyhedron,
# )
# phases.append(Phase(shape=elem.generate()))
# compound = cq.Compound.makeCompound([phase.shape for phase in phases])
# cq.exporters.export(compound, "compound.step")
# mesh(
# mesh_file="compound.step",
# listPhases=phases,
# size=0.05,
# order=1,
# output_file="Voronoi.vtk",
# )
tess_file = str(Path(__file__).parent / "test1.tess")
polyhedra = Neper.generateVoronoiFromTessFile(tess_file)
shapes = [poly.generate() for poly in polyhedra]
compound = cq.Compound.makeCompound(shapes)
step_file = str(Path(__file__).parent / "compound.step")
cq.exporters.export(compound, step_file)
phases = [Phase(shape=shape) for shape in shapes]
vtk_file = str(Path(__file__).parent / "Voronoi.vtk")
mesh(
mesh_file=step_file,
listPhases=phases,
size=0.05,
order=1,
output_file=vtk_file,
)
Voronoi gyroid
from pathlib import Path
import cadquery as cq
from microgen import Neper, Phase, Tpms, mesh
from microgen.shape import surface_functions
# We import the Polyhedra from Neper tessellation file
tess_file = str(Path(__file__).parent / "test1.tess")
polyhedra = Neper.generateVoronoiFromTessFile(tess_file)
gyroid = Tpms(
center=(0.5, 0.5, 0.5),
surface_function=surface_functions.gyroid,
offset=0.2,
)
gyroid = gyroid.generate(type_part="sheet").translate((0.5, 0.5, 0.5))
phases = []
for polyhedron in polyhedra:
shape = polyhedron.generate()
phases.append(Phase(shape=shape.intersect(gyroid)))
compound = cq.Compound.makeCompound([phase.shape for phase in phases])
step_file = str(Path(__file__).parent / "compound.step")
cq.exporters.export(compound, step_file)
vtk_file = str(Path(__file__).parent / "Gyroid-voro.vtk")
mesh(
mesh_file=step_file,
listPhases=phases,
size=0.05,
order=1,
output_file=vtk_file,
)